From f228b4a167c4f0765adc909318cb4a704f1292c8 Mon Sep 17 00:00:00 2001 From: James Agnew Date: Fri, 18 Dec 2020 10:57:31 -0500 Subject: [PATCH] Fix an error parsing extensions with a value type of UUID (#2258) --- ...imeChildUndeclaredExtensionDefinition.java | 51 +++++++++++-------- .../hl7/fhir/r4/model/fhirversion.properties | 9 ++-- .../ca/uhn/fhir/parser/JsonParserR4Test.java | 20 +++++++- .../hl7/fhir/r5/model/fhirversion.properties | 6 +-- .../VersionPropertyFileGeneratorMojo.java | 7 ++- 5 files changed, 63 insertions(+), 30 deletions(-) diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeChildUndeclaredExtensionDefinition.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeChildUndeclaredExtensionDefinition.java index d59538db803..b55f95c5c69 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeChildUndeclaredExtensionDefinition.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeChildUndeclaredExtensionDefinition.java @@ -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); } } diff --git a/hapi-fhir-structures-r4/src/main/resources/org/hl7/fhir/r4/model/fhirversion.properties b/hapi-fhir-structures-r4/src/main/resources/org/hl7/fhir/r4/model/fhirversion.properties index 2bc5c7e38ef..c666ad7de79 100644 --- a/hapi-fhir-structures-r4/src/main/resources/org/hl7/fhir/r4/model/fhirversion.properties +++ b/hapi-fhir-structures-r4/src/main/resources/org/hl7/fhir/r4/model/fhirversion.properties @@ -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 diff --git a/hapi-fhir-structures-r4/src/test/java/ca/uhn/fhir/parser/JsonParserR4Test.java b/hapi-fhir-structures-r4/src/test/java/ca/uhn/fhir/parser/JsonParserR4Test.java index 36ec92a5f0f..a12db7810f3 100644 --- a/hapi-fhir-structures-r4/src/test/java/ca/uhn/fhir/parser/JsonParserR4Test.java +++ b/hapi-fhir-structures-r4/src/test/java/ca/uhn/fhir/parser/JsonParserR4Test.java @@ -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" + diff --git a/hapi-fhir-structures-r5/src/main/resources/org/hl7/fhir/r5/model/fhirversion.properties b/hapi-fhir-structures-r5/src/main/resources/org/hl7/fhir/r5/model/fhirversion.properties index b72b9646be2..ceb01a89f4a 100644 --- a/hapi-fhir-structures-r5/src/main/resources/org/hl7/fhir/r5/model/fhirversion.properties +++ b/hapi-fhir-structures-r5/src/main/resources/org/hl7/fhir/r5/model/fhirversion.properties @@ -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 diff --git a/hapi-tinder-plugin/src/main/java/ca/uhn/fhir/tinder/VersionPropertyFileGeneratorMojo.java b/hapi-tinder-plugin/src/main/java/ca/uhn/fhir/tinder/VersionPropertyFileGeneratorMojo.java index 290ff32fe56..20313a1166b 100644 --- a/hapi-tinder-plugin/src/main/java/ca/uhn/fhir/tinder/VersionPropertyFileGeneratorMojo.java +++ b/hapi-tinder-plugin/src/main/java/ca/uhn/fhir/tinder/VersionPropertyFileGeneratorMojo.java @@ -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(); }