Fix an error parsing extensions with a value type of UUID (#2258)

This commit is contained in:
James Agnew 2020-12-18 10:57:31 -05:00 committed by GitHub
parent c745fb2561
commit f228b4a167
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 63 additions and 30 deletions

View File

@ -149,35 +149,44 @@ public class RuntimeChildUndeclaredExtensionDefinition extends BaseRuntimeChildD
ourLog.trace("Not adding specialization: {}", next.getImplementingClass());
}
if (!isSpecialization) {
if (!next.isStandardType()) {
if (!next.isStandardType()) {
continue;
}
String qualifiedName = next.getImplementingClass().getName();
/*
* We don't want user-defined custom datatypes ending up overriding the built in
* types here. It would probably be better for there to be a way for
* a datatype to indicate via its annotation that it's a built in
* type.
*/
if (!qualifiedName.startsWith("ca.uhn.fhir.model")) {
if (!qualifiedName.startsWith("org.hl7.fhir")) {
continue;
}
}
String qualifiedName = next.getImplementingClass().getName();
String attrName = createExtensionChildName(next);
if (isSpecialization && datatypeAttributeNameToDefinition.containsKey(attrName)) {
continue;
}
/*
* We don't want user-defined custom datatypes ending up overriding the built in
* types here. It would probably be better for there to be a way for
* a datatype to indicate via its annotation that it's a built in
* type.
*/
if (!qualifiedName.startsWith("ca.uhn.fhir.model")) {
if (!qualifiedName.startsWith("org.hl7.fhir")) {
continue;
}
}
String attrName = createExtensionChildName(next);
if (datatypeAttributeNameToDefinition.containsKey(attrName)) {
BaseRuntimeElementDefinition<?> existing = datatypeAttributeNameToDefinition.get(attrName);
if (datatypeAttributeNameToDefinition.containsKey(attrName)) {
BaseRuntimeElementDefinition<?> existing = datatypeAttributeNameToDefinition.get(attrName);
// We do allow built-in standard types to override extension types with the same element name,
// e.g. how EnumerationType extends CodeType but both serialize to "code". In this case,
// CodeType should win. If we aren't in a situation like that, there is a problem with the
// model so we should bail.
if (!existing.isStandardType()) {
throw new ConfigurationException("More than one child of " + getElementName() + " matches attribute name " + attrName + ". Found [" + existing.getImplementingClass().getName() + "] and [" + next.getImplementingClass().getName() + "]");
}
datatypeAttributeNameToDefinition.put(attrName, next);
datatypeAttributeNameToDefinition.put(attrName.toLowerCase(), next);
myDatatypeToAttributeName.put(next.getImplementingClass(), attrName);
}
datatypeAttributeNameToDefinition.put(attrName, next);
datatypeAttributeNameToDefinition.put(attrName.toLowerCase(), next);
myDatatypeToAttributeName.put(next.getImplementingClass(), attrName);
}
}

View File

@ -1,5 +1,5 @@
# This file contains version definitions
# Generated: 2019-02-09T15:41:48.934-05:00
# Generated: 2020-12-18T09:20:12.664-05:00
resource.Account=org.hl7.fhir.r4.model.Account
resource.ActivityDefinition=org.hl7.fhir.r4.model.ActivityDefinition
@ -190,11 +190,11 @@ datatype.SubstanceAmount=org.hl7.fhir.r4.model.SubstanceAmount
datatype.Timing=org.hl7.fhir.r4.model.Timing
datatype.TriggerDefinition=org.hl7.fhir.r4.model.TriggerDefinition
datatype.UsageContext=org.hl7.fhir.r4.model.UsageContext
datatype.base64binary=org.hl7.fhir.r4.model.Base64BinaryType
datatype.base64Binary=org.hl7.fhir.r4.model.Base64BinaryType
datatype.boolean=org.hl7.fhir.r4.model.BooleanType
datatype.canonical=org.hl7.fhir.r4.model.CanonicalType
datatype.code=org.hl7.fhir.r4.model.Enumeration
datatype.code.2=org.hl7.fhir.r4.model.CodeType
datatype.code=org.hl7.fhir.r4.model.CodeType
datatype.code.2=org.hl7.fhir.r4.model.Enumeration
datatype.date=org.hl7.fhir.r4.model.DateType
datatype.dateTime=org.hl7.fhir.r4.model.DateTimeType
datatype.decimal=org.hl7.fhir.r4.model.DecimalType
@ -209,4 +209,5 @@ datatype.time=org.hl7.fhir.r4.model.TimeType
datatype.unsignedInt=org.hl7.fhir.r4.model.UnsignedIntType
datatype.uri=org.hl7.fhir.r4.model.UriType
datatype.url=org.hl7.fhir.r4.model.UrlType
datatype.uuid=org.hl7.fhir.r4.model.UuidType
datatype.xhtml=org.hl7.fhir.utilities.xhtml.XhtmlNode

View File

@ -621,7 +621,25 @@ public class JsonParserR4Test extends BaseTest {
}
@Test
public void testParseExtensionWithUriValue() {
public void testParseExtensionWithUriValue_BuiltInStructure() {
String input = "{\n" +
"\"resourceType\": \"Basic\",\n" +
"\"meta\": {\n" +
"\"profile\": [ \"http://mycustom.url\" ]\n" +
"},\n" +
"\"extension\": [ {\n" +
"\"url\": \"http://myValue.url\",\n" +
"\"valueUuid\": \"ae644c07-1d4b-4ca4-bbf3-bd2023e294e5\"\n" +
"} ]\n" +
"}";
IParser jsonParser = ourCtx.newJsonParser();
Basic parsed = jsonParser.parseResource(Basic.class, input);
assertEquals("ae644c07-1d4b-4ca4-bbf3-bd2023e294e5", parsed.getExtensionByUrl("http://myValue.url").getValueAsPrimitive().getValueAsString());
}
@Test
public void testParseExtensionWithUriValue_CustomStructure() {
String input = "{\n" +
"\"resourceType\": \"Basic\",\n" +
"\"meta\": {\n" +

View File

@ -1,5 +1,5 @@
# This file contains version definitions
# Generated: 2020-11-01T13:50:23.569-05:00
# Generated: 2020-12-18T09:20:13.196-05:00
resource.Account=org.hl7.fhir.r5.model.Account
resource.ActivityDefinition=org.hl7.fhir.r5.model.ActivityDefinition
@ -205,8 +205,8 @@ datatype.dateTime=org.hl7.fhir.r5.model.DateTimeType
datatype.decimal=org.hl7.fhir.r5.model.DecimalType
datatype.id=org.hl7.fhir.r5.model.IdType
datatype.instant=org.hl7.fhir.r5.model.InstantType
datatype.integer=org.hl7.fhir.r5.model.Integer64Type
datatype.integer.2=org.hl7.fhir.r5.model.IntegerType
datatype.integer=org.hl7.fhir.r5.model.IntegerType
datatype.integer64=org.hl7.fhir.r5.model.Integer64Type
datatype.markdown=org.hl7.fhir.r5.model.MarkdownType
datatype.oid=org.hl7.fhir.r5.model.OidType
datatype.positiveInt=org.hl7.fhir.r5.model.PositiveIntType

View File

@ -127,8 +127,14 @@ public class VersionPropertyFileGeneratorMojo extends AbstractMojo {
public static void main(String[] theArgs) throws MojoFailureException {
VersionPropertyFileGeneratorMojo m = new VersionPropertyFileGeneratorMojo();
m.packageName = "org.hl7.fhir.r4.model";
m.targetFile = new File("hapi-fhir-structures-r4/src/main/resources/org/hl7/fhir/r4/model/fhirversion.properties");
m.execute();
m = new VersionPropertyFileGeneratorMojo();
m.packageName = "org.hl7.fhir.r5.model";
m.targetFile = new File("hapi-fhir-structures-r5/src/main/resources/org/hl7/fhir/r5/model/fhirversion.properties");
m.execute();
// m.packageName = "org.hl7.fhir.dstu3.model";
// m.targetFile = new File("../hapi-fhir-structures-dstu3/src/main/resources/org/hl7/fhir/dstu3/model/fhirversion.properties");
@ -136,7 +142,6 @@ public class VersionPropertyFileGeneratorMojo extends AbstractMojo {
// m.packageName = "org.hl7.fhir.dstu2016may.model";
// m.targetFile = new File("../hapi-fhir-structures-dstu2.1/src/main/resources/org/hl7/fhir/dstu2016may/model/fhirversion.properties");
m.execute();
}