From f7d4296046fd5e6b20778825744cee66dbffff81 Mon Sep 17 00:00:00 2001 From: James Date: Fri, 14 Jul 2017 06:16:41 -0400 Subject: [PATCH] Tweak to #683 --- ...BaseRuntimeElementCompositeDefinition.java | 6 +- .../fhir/dstu3/model/ActivityDefinition.java | 3 +- .../uhn/fhir/parser/XmlParserDstu3Test.java | 123 +++++++++--------- 3 files changed, 69 insertions(+), 63 deletions(-) diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/BaseRuntimeElementCompositeDefinition.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/BaseRuntimeElementCompositeDefinition.java index 7015e0e6425..04960d0ef19 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/BaseRuntimeElementCompositeDefinition.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/BaseRuntimeElementCompositeDefinition.java @@ -99,7 +99,11 @@ public abstract class BaseRuntimeElementCompositeDefinition ext if (childOrder != null) { forcedOrder = new HashMap(); for (int i = 0; i < childOrder.names().length; i++) { - forcedOrder.put(childOrder.names()[i], i); + String nextName = childOrder.names()[i]; + if (nextName.endsWith("[x]")) { + nextName = nextName.substring(0, nextName.length() - 3); + } + forcedOrder.put(nextName, i); } } } diff --git a/hapi-fhir-structures-dstu3/src/main/java/org/hl7/fhir/dstu3/model/ActivityDefinition.java b/hapi-fhir-structures-dstu3/src/main/java/org/hl7/fhir/dstu3/model/ActivityDefinition.java index 4e7ce7988cc..6859533a3bb 100644 --- a/hapi-fhir-structures-dstu3/src/main/java/org/hl7/fhir/dstu3/model/ActivityDefinition.java +++ b/hapi-fhir-structures-dstu3/src/main/java/org/hl7/fhir/dstu3/model/ActivityDefinition.java @@ -47,8 +47,7 @@ import org.hl7.fhir.exceptions.FHIRException; * This resource allows for the definition of some activity to be performed, independent of a particular patient, practitioner, or other performance context. */ @ResourceDef(name="ActivityDefinition", profile="http://hl7.org/fhir/Profile/ActivityDefinition") -//@ChildOrder(names={"url", "identifier", "version", "name", "title", "status", "experimental", "date", "publisher", "description", "purpose", "usage", "approvalDate", "lastReviewDate", "effectivePeriod", "useContext", "jurisdiction", "topic", "contributor", "contact", "copyright", "relatedArtifact", "library", "kind", "code", "timing[x]", "location", "participant", "product[x]", "quantity", "dosage", "bodySite", "transform", "dynamicValue"}) -@ChildOrder(names={"url", "identifier", "version", "name", "title", "status", "experimental", "date", "publisher", "description", "purpose", "usage", "approvalDate", "lastReviewDate", "effectivePeriod", "useContext", "jurisdiction", "topic", "contributor", "contact", "copyright", "relatedArtifact", "library", "kind", "code", "timing", "location", "participant", "product", "quantity", "dosage", "bodySite", "transform", "dynamicValue"}) +@ChildOrder(names={"url", "identifier", "version", "name", "title", "status", "experimental", "date", "publisher", "description", "purpose", "usage", "approvalDate", "lastReviewDate", "effectivePeriod", "useContext", "jurisdiction", "topic", "contributor", "contact", "copyright", "relatedArtifact", "library", "kind", "code", "timing[x]", "location", "participant", "product[x]", "quantity", "dosage", "bodySite", "transform", "dynamicValue"}) public class ActivityDefinition extends MetadataResource { public enum ActivityDefinitionKind { diff --git a/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/parser/XmlParserDstu3Test.java b/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/parser/XmlParserDstu3Test.java index 5ededaf9f1d..831bc8afc1c 100644 --- a/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/parser/XmlParserDstu3Test.java +++ b/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/parser/XmlParserDstu3Test.java @@ -86,8 +86,69 @@ public class XmlParserDstu3Test { ourCtx.setNarrativeGenerator(null); } + /** + * See #544 + */ @Test - public void testActivityDefinitionElementsOrder() throws Exception { + public void testBundleStitchReferencesByUuid() throws Exception { + Bundle bundle = new Bundle(); + + DocumentManifest dm = new DocumentManifest(); + dm.getSubject().setReference("urn:uuid:96e85cca-9797-45d6-834a-c4eb27f331d3"); + bundle.addEntry().setResource(dm); + + Patient patient = new Patient(); + patient.addName().setFamily("FAMILY"); + bundle.addEntry().setResource(patient).setFullUrl("urn:uuid:96e85cca-9797-45d6-834a-c4eb27f331d3"); + + String encoded = ourCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(bundle); + ourLog.info(encoded); + + bundle = ourCtx.newXmlParser().parseResource(Bundle.class, encoded); + dm = (DocumentManifest) bundle.getEntry().get(0).getResource(); + + assertEquals("urn:uuid:96e85cca-9797-45d6-834a-c4eb27f331d3", dm.getSubject().getReference()); + + Patient subject = (Patient) dm.getSubject().getResource(); + assertNotNull(subject); + assertEquals("FAMILY", subject.getNameFirstRep().getFamily()); + } + + @Test + public void testBundleWithBinary() { + + String bundle = "\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + ""; + + Bundle b = ourCtx.newXmlParser().parseResource(Bundle.class, bundle); + assertEquals(1, b.getEntry().size()); + + Binary bin = (Binary) b.getEntry().get(0).getResource(); + assertArrayEquals(new byte[] { 1, 2, 3, 4 }, bin.getContent()); + + } + + /** + * See #683 + */ + @Test + public void testChildOrderWithChoiceType() throws Exception { final String origContent = ""; final IParser parser = ourCtx.newXmlParser(); DefaultProfileValidationSupport validationSupport = new DefaultProfileValidationSupport(); @@ -121,7 +182,7 @@ public class XmlParserDstu3Test { // verify that the original and newly serialized match Assert.assertEquals(origContent, content); } - + @Test public void testConceptMapElementsOrder() throws Exception { final String origContent = ""; @@ -158,64 +219,6 @@ public class XmlParserDstu3Test { Assert.assertEquals(origContent, content); } - /** - * See #544 - */ - @Test - public void testBundleStitchReferencesByUuid() throws Exception { - Bundle bundle = new Bundle(); - - DocumentManifest dm = new DocumentManifest(); - dm.getSubject().setReference("urn:uuid:96e85cca-9797-45d6-834a-c4eb27f331d3"); - bundle.addEntry().setResource(dm); - - Patient patient = new Patient(); - patient.addName().setFamily("FAMILY"); - bundle.addEntry().setResource(patient).setFullUrl("urn:uuid:96e85cca-9797-45d6-834a-c4eb27f331d3"); - - String encoded = ourCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(bundle); - ourLog.info(encoded); - - bundle = ourCtx.newXmlParser().parseResource(Bundle.class, encoded); - dm = (DocumentManifest) bundle.getEntry().get(0).getResource(); - - assertEquals("urn:uuid:96e85cca-9797-45d6-834a-c4eb27f331d3", dm.getSubject().getReference()); - - Patient subject = (Patient) dm.getSubject().getResource(); - assertNotNull(subject); - assertEquals("FAMILY", subject.getNameFirstRep().getFamily()); - } - - @Test - public void testBundleWithBinary() { - - String bundle = "\n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - ""; - - Bundle b = ourCtx.newXmlParser().parseResource(Bundle.class, bundle); - assertEquals(1, b.getEntry().size()); - - Binary bin = (Binary) b.getEntry().get(0).getResource(); - assertArrayEquals(new byte[] { 1, 2, 3, 4 }, bin.getContent()); - - } - @Test public void testContainedResourceInExtensionUndeclared() { Patient p = new Patient();