Skip to content

Commit

Permalink
Tweak to #683
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesagnew committed Jul 14, 2017
1 parent ef3f720 commit f7d4296
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 63 deletions.
Expand Up @@ -99,7 +99,11 @@ public BaseRuntimeElementCompositeDefinition(String theName, Class<? extends T>
if (childOrder != null) {
forcedOrder = new HashMap<String, Integer>();
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);
}
}
}
Expand Down
Expand Up @@ -47,8 +47,7 @@ WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWIS
* 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 {
Expand Down
Expand Up @@ -86,8 +86,69 @@ public void after() {
ourCtx.setNarrativeGenerator(null);
}

/**
* 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 = "<Bundle xmlns=\"http://hl7.org/fhir\">\n" +
" <base value=\"http://localhost:52788\"/>\n" +
" <total value=\"1\"/>\n" +
" <link>\n" +
" <relation value=\"self\"/>\n" +
" <url value=\"http://localhost:52788/Binary?_pretty=true\"/>\n" +
" </link>\n" +
" <entry>\n" +
" <resource>\n" +
" <Binary xmlns=\"http://hl7.org/fhir\">\n" +
" <id value=\"1\"/>\n" +
" <meta/>\n" +
" <contentType value=\"text/plain\"/>\n" +
" <content value=\"AQIDBA==\"/>\n" +
" </Binary>\n" +
" </resource>\n" +
" </entry>\n" +
"</Bundle>";

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 testActivityDefinitionElementsOrder() throws Exception {
public void testChildOrderWithChoiceType() throws Exception {
final String origContent = "<ActivityDefinition xmlns=\"http://hl7.org/fhir\"><id value=\"x1\"/><url value=\"http://testing.org\"/><status value=\"draft\"/><timingDateTime value=\"2011-02-03\"/></ActivityDefinition>";
final IParser parser = ourCtx.newXmlParser();
DefaultProfileValidationSupport validationSupport = new DefaultProfileValidationSupport();
Expand Down Expand Up @@ -121,7 +182,7 @@ public void testActivityDefinitionElementsOrder() throws Exception {
// verify that the original and newly serialized match
Assert.assertEquals(origContent, content);
}

@Test
public void testConceptMapElementsOrder() throws Exception {
final String origContent = "<ConceptMap xmlns=\"http://hl7.org/fhir\"><id value=\"x1\"/><url value=\"http://testing.org\"/><status value=\"draft\"/><sourceUri value=\"http://url1\"/></ConceptMap>";
Expand Down Expand Up @@ -158,64 +219,6 @@ public void testConceptMapElementsOrder() throws Exception {
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 = "<Bundle xmlns=\"http://hl7.org/fhir\">\n" +
" <base value=\"http://localhost:52788\"/>\n" +
" <total value=\"1\"/>\n" +
" <link>\n" +
" <relation value=\"self\"/>\n" +
" <url value=\"http://localhost:52788/Binary?_pretty=true\"/>\n" +
" </link>\n" +
" <entry>\n" +
" <resource>\n" +
" <Binary xmlns=\"http://hl7.org/fhir\">\n" +
" <id value=\"1\"/>\n" +
" <meta/>\n" +
" <contentType value=\"text/plain\"/>\n" +
" <content value=\"AQIDBA==\"/>\n" +
" </Binary>\n" +
" </resource>\n" +
" </entry>\n" +
"</Bundle>";

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();
Expand Down

0 comments on commit f7d4296

Please sign in to comment.