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 6859533a3bb..4e7ce7988cc 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,7 +47,8 @@ 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[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"}) public class ActivityDefinition extends MetadataResource { public enum ActivityDefinitionKind { diff --git a/hapi-fhir-structures-dstu3/src/main/java/org/hl7/fhir/dstu3/model/ConceptMap.java b/hapi-fhir-structures-dstu3/src/main/java/org/hl7/fhir/dstu3/model/ConceptMap.java index ebb30d41722..7133530ea7a 100644 --- a/hapi-fhir-structures-dstu3/src/main/java/org/hl7/fhir/dstu3/model/ConceptMap.java +++ b/hapi-fhir-structures-dstu3/src/main/java/org/hl7/fhir/dstu3/model/ConceptMap.java @@ -47,7 +47,8 @@ import org.hl7.fhir.exceptions.FHIRException; * A statement of relationships from one set of concepts to one or more other concepts - either code systems or data elements, or classes in class models. */ @ResourceDef(name="ConceptMap", profile="http://hl7.org/fhir/Profile/ConceptMap") -@ChildOrder(names={"url", "identifier", "version", "name", "title", "status", "experimental", "date", "publisher", "contact", "description", "useContext", "jurisdiction", "purpose", "copyright", "source[x]", "target[x]", "group"}) +//@ChildOrder(names={"url", "identifier", "version", "name", "title", "status", "experimental", "date", "publisher", "contact", "description", "useContext", "jurisdiction", "purpose", "copyright", "source[x]", "target[x]", "group"}) +@ChildOrder(names={"url", "identifier", "version", "name", "title", "status", "experimental", "date", "publisher", "contact", "description", "useContext", "jurisdiction", "purpose", "copyright", "source", "target", "group"}) public class ConceptMap extends MetadataResource { public enum ConceptMapGroupUnmappedMode { diff --git a/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/parser/JsonParserDstu3Test.java b/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/parser/JsonParserDstu3Test.java index 8ffee00417e..ab3e464b5d7 100644 --- a/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/parser/JsonParserDstu3Test.java +++ b/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/parser/JsonParserDstu3Test.java @@ -36,6 +36,8 @@ import java.util.UUID; import org.apache.commons.io.IOUtils; import org.hamcrest.Matchers; import org.hamcrest.core.StringContains; +import org.hl7.fhir.dstu3.hapi.validation.DefaultProfileValidationSupport; +import org.hl7.fhir.dstu3.hapi.validation.FhirInstanceValidator; import org.hl7.fhir.dstu3.model.*; import org.hl7.fhir.dstu3.model.Address.AddressUse; import org.hl7.fhir.dstu3.model.Address.AddressUseEnumFactory; @@ -71,6 +73,9 @@ import ca.uhn.fhir.parser.json.JsonLikeValue.ValueType; import ca.uhn.fhir.rest.server.Constants; import ca.uhn.fhir.util.TestUtil; import ca.uhn.fhir.validation.FhirValidator; +import ca.uhn.fhir.validation.IValidationContext; +import ca.uhn.fhir.validation.SingleValidationMessage; +import ca.uhn.fhir.validation.ValidationContext; import ca.uhn.fhir.validation.ValidationResult; import net.sf.json.JSON; import net.sf.json.JSONSerializer; @@ -84,6 +89,78 @@ public class JsonParserDstu3Test { public void after() { ourCtx.setNarrativeGenerator(null); } + + @Test + public void testActivityDefinitionElementsOrder() throws Exception { + final String origContent = "{\"resourceType\":\"ActivityDefinition\",\"id\":\"x1\",\"url\":\"http://testing.org\",\"status\":\"draft\",\"timingDateTime\":\"2011-02-03\"}"; + final IParser parser = ourCtx.newJsonParser(); + DefaultProfileValidationSupport validationSupport = new DefaultProfileValidationSupport(); + + // verify that InstanceValidator likes the format + { + IValidationContext validationCtx = ValidationContext.forText(ourCtx, origContent); + new FhirInstanceValidator(validationSupport).validateResource(validationCtx); + ValidationResult result = validationCtx.toResult(); + for (SingleValidationMessage msg : result.getMessages()) { + ourLog.info("{}", msg); + } + Assert.assertEquals(0, result.getMessages().size()); + } + + ActivityDefinition fhirObj = parser.parseResource(ActivityDefinition.class, origContent); + String content = parser.encodeResourceToString(fhirObj); + ourLog.info("Serialized form: {}", content); + + // verify that InstanceValidator still likes the format + { + IValidationContext validationCtx = ValidationContext.forText(ourCtx, content); + new FhirInstanceValidator(validationSupport).validateResource(validationCtx); + ValidationResult result = validationCtx.toResult(); + for (SingleValidationMessage msg : result.getMessages()) { + ourLog.info("{}", msg); + } + Assert.assertEquals(0, result.getMessages().size()); + } + + // verify that the original and newly serialized match + Assert.assertEquals(origContent, content); + } + + @Test + public void testConceptMapElementsOrder() throws Exception { + final String origContent = "{\"resourceType\":\"ConceptMap\",\"id\":\"x1\",\"url\":\"http://testing.org\",\"status\":\"draft\",\"sourceUri\":\"http://y1\"}"; + final IParser parser = ourCtx.newJsonParser(); + DefaultProfileValidationSupport validationSupport = new DefaultProfileValidationSupport(); + + // verify that InstanceValidator likes the format + { + IValidationContext validationCtx = ValidationContext.forText(ourCtx, origContent); + new FhirInstanceValidator(validationSupport).validateResource(validationCtx); + ValidationResult result = validationCtx.toResult(); + for (SingleValidationMessage msg : result.getMessages()) { + ourLog.info("{}", msg); + } + Assert.assertEquals(0, result.getMessages().size()); + } + + ConceptMap fhirObj = parser.parseResource(ConceptMap.class, origContent); + String content = parser.encodeResourceToString(fhirObj); + ourLog.info("Serialized form: {}", content); + + // verify that InstanceValidator still likes the format + { + IValidationContext validationCtx = ValidationContext.forText(ourCtx, content); + new FhirInstanceValidator(validationSupport).validateResource(validationCtx); + ValidationResult result = validationCtx.toResult(); + for (SingleValidationMessage msg : result.getMessages()) { + ourLog.info("{}", msg); + } + Assert.assertEquals(0, result.getMessages().size()); + } + + // verify that the original and newly serialized match + Assert.assertEquals(origContent, content); + } /** * See #563 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 e782d8913c1..5ededaf9f1d 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 @@ -34,6 +34,8 @@ import org.custommonkey.xmlunit.XMLUnit; import org.hamcrest.collection.IsEmptyCollection; import org.hamcrest.core.StringContains; import org.hamcrest.text.StringContainsInOrder; +import org.hl7.fhir.dstu3.hapi.validation.DefaultProfileValidationSupport; +import org.hl7.fhir.dstu3.hapi.validation.FhirInstanceValidator; import org.hl7.fhir.dstu3.model.*; import org.hl7.fhir.dstu3.model.Address.AddressUse; import org.hl7.fhir.dstu3.model.Address.AddressUseEnumFactory; @@ -67,6 +69,10 @@ import ca.uhn.fhir.parser.PatientWithCustomCompositeExtension.FooParentExtension import ca.uhn.fhir.rest.client.IGenericClient; import ca.uhn.fhir.rest.server.Constants; import ca.uhn.fhir.util.TestUtil; +import ca.uhn.fhir.validation.IValidationContext; +import ca.uhn.fhir.validation.SingleValidationMessage; +import ca.uhn.fhir.validation.ValidationContext; +import ca.uhn.fhir.validation.ValidationResult; public class XmlParserDstu3Test { private static FhirContext ourCtx = FhirContext.forDstu3(); @@ -79,6 +85,78 @@ public class XmlParserDstu3Test { } ourCtx.setNarrativeGenerator(null); } + + @Test + public void testActivityDefinitionElementsOrder() throws Exception { + final String origContent = ""; + final IParser parser = ourCtx.newXmlParser(); + DefaultProfileValidationSupport validationSupport = new DefaultProfileValidationSupport(); + + // verify that InstanceValidator likes the format + { + IValidationContext validationCtx = ValidationContext.forText(ourCtx, origContent); + new FhirInstanceValidator(validationSupport).validateResource(validationCtx); + ValidationResult result = validationCtx.toResult(); + for (SingleValidationMessage msg : result.getMessages()) { + ourLog.info("{}", msg); + } + Assert.assertEquals(0, result.getMessages().size()); + } + + ActivityDefinition fhirObj = parser.parseResource(ActivityDefinition.class, origContent); + String content = parser.encodeResourceToString(fhirObj); + ourLog.info("Serialized form: {}", content); + + // verify that InstanceValidator still likes the format + { + IValidationContext validationCtx = ValidationContext.forText(ourCtx, content); + new FhirInstanceValidator(validationSupport).validateResource(validationCtx); + ValidationResult result = validationCtx.toResult(); + for (SingleValidationMessage msg : result.getMessages()) { + ourLog.info("{}", msg); + } + Assert.assertEquals(0, result.getMessages().size()); + } + + // verify that the original and newly serialized match + Assert.assertEquals(origContent, content); + } + + @Test + public void testConceptMapElementsOrder() throws Exception { + final String origContent = ""; + final IParser parser = ourCtx.newXmlParser(); + DefaultProfileValidationSupport validationSupport = new DefaultProfileValidationSupport(); + + // verify that InstanceValidator likes the format + { + IValidationContext validationCtx = ValidationContext.forText(ourCtx, origContent); + new FhirInstanceValidator(validationSupport).validateResource(validationCtx); + ValidationResult result = validationCtx.toResult(); + for (SingleValidationMessage msg : result.getMessages()) { + ourLog.info("{}", msg); + } + Assert.assertEquals(0, result.getMessages().size()); + } + + ConceptMap fhirObj = parser.parseResource(ConceptMap.class, origContent); + String content = parser.encodeResourceToString(fhirObj); + ourLog.info("Serialized form: {}", content); + + // verify that InstanceValidator still likes the format + { + IValidationContext validationCtx = ValidationContext.forText(ourCtx, content); + new FhirInstanceValidator(validationSupport).validateResource(validationCtx); + ValidationResult result = validationCtx.toResult(); + for (SingleValidationMessage msg : result.getMessages()) { + ourLog.info("{}", msg); + } + Assert.assertEquals(0, result.getMessages().size()); + } + + // verify that the original and newly serialized match + Assert.assertEquals(origContent, content); + } /** * See #544