|
|
@ -87,57 +87,33 @@ public class XmlParserDstu2Test {
|
|
|
|
" </entry>\n" +
|
|
|
|
" </entry>\n" +
|
|
|
|
"</Bundle>";
|
|
|
|
"</Bundle>";
|
|
|
|
//@formatter:on
|
|
|
|
//@formatter:on
|
|
|
|
|
|
|
|
|
|
|
|
Bundle b = ourCtx.newXmlParser().parseBundle(bundle);
|
|
|
|
Bundle b = ourCtx.newXmlParser().parseBundle(bundle);
|
|
|
|
assertEquals(1, b.getEntries().size());
|
|
|
|
assertEquals(1, b.getEntries().size());
|
|
|
|
|
|
|
|
|
|
|
|
Binary bin = (Binary) b.getEntries().get(0).getResource();
|
|
|
|
Binary bin = (Binary) b.getEntries().get(0).getResource();
|
|
|
|
assertArrayEquals(new byte[] {1,2,3,4}, bin.getContent());
|
|
|
|
assertArrayEquals(new byte[] { 1, 2, 3, 4 }, bin.getContent());
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
|
|
|
public void testParseMetaUpdatedDate() {
|
|
|
|
|
|
|
|
//@formatter:off
|
|
|
|
|
|
|
|
String input = "<Bundle xmlns=\"http://hl7.org/fhir\">\n" +
|
|
|
|
|
|
|
|
" <id value=\"e2ee823b-ee4d-472d-b79d-495c23f16b99\"/>\n" +
|
|
|
|
|
|
|
|
" <meta>\n" +
|
|
|
|
|
|
|
|
" <lastUpdated value=\"2015-06-22T15:48:57.554-04:00\"/>\n" +
|
|
|
|
|
|
|
|
" </meta>\n" +
|
|
|
|
|
|
|
|
" <type value=\"searchset\"/>\n" +
|
|
|
|
|
|
|
|
" <base value=\"http://localhost:58109/fhir/context\"/>\n" +
|
|
|
|
|
|
|
|
" <total value=\"0\"/>\n" +
|
|
|
|
|
|
|
|
" <link>\n" +
|
|
|
|
|
|
|
|
" <relation value=\"self\"/>\n" +
|
|
|
|
|
|
|
|
" <url value=\"http://localhost:58109/fhir/context/Patient?_pretty=true\"/>\n" +
|
|
|
|
|
|
|
|
" </link>\n" +
|
|
|
|
|
|
|
|
"</Bundle>";
|
|
|
|
|
|
|
|
//@formatter:on
|
|
|
|
|
|
|
|
ca.uhn.fhir.model.dstu2.resource.Bundle b = ourCtx.newXmlParser().parseResource(ca.uhn.fhir.model.dstu2.resource.Bundle.class, input);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
InstantDt updated = ResourceMetadataKeyEnum.UPDATED.get(b);
|
|
|
|
|
|
|
|
assertEquals("2015-06-22T15:48:57.554-04:00", updated.getValueAsString());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
public void testContainedResourceInExtensionUndeclared() {
|
|
|
|
public void testContainedResourceInExtensionUndeclared() {
|
|
|
|
Patient p = new Patient();
|
|
|
|
Patient p = new Patient();
|
|
|
|
p.addName().addFamily("PATIENT");
|
|
|
|
p.addName().addFamily("PATIENT");
|
|
|
|
|
|
|
|
|
|
|
|
Organization o = new Organization();
|
|
|
|
Organization o = new Organization();
|
|
|
|
o.setName("ORG");
|
|
|
|
o.setName("ORG");
|
|
|
|
p.addUndeclaredExtension(new ExtensionDt(false, "urn:foo", new ResourceReferenceDt(o)));
|
|
|
|
p.addUndeclaredExtension(new ExtensionDt(false, "urn:foo", new ResourceReferenceDt(o)));
|
|
|
|
|
|
|
|
|
|
|
|
String str = ourCtx.newXmlParser().encodeResourceToString(p);
|
|
|
|
String str = ourCtx.newXmlParser().encodeResourceToString(p);
|
|
|
|
ourLog.info(str);
|
|
|
|
ourLog.info(str);
|
|
|
|
|
|
|
|
|
|
|
|
p = ourCtx.newXmlParser().parseResource(Patient.class, str);
|
|
|
|
p = ourCtx.newXmlParser().parseResource(Patient.class, str);
|
|
|
|
assertEquals("PATIENT", p.getName().get(0).getFamily().get(0).getValue());
|
|
|
|
assertEquals("PATIENT", p.getName().get(0).getFamily().get(0).getValue());
|
|
|
|
|
|
|
|
|
|
|
|
List<ExtensionDt> exts = p.getUndeclaredExtensionsByUrl("urn:foo");
|
|
|
|
List<ExtensionDt> exts = p.getUndeclaredExtensionsByUrl("urn:foo");
|
|
|
|
assertEquals(1, exts.size());
|
|
|
|
assertEquals(1, exts.size());
|
|
|
|
ResourceReferenceDt rr = (ResourceReferenceDt)exts.get(0).getValue();
|
|
|
|
ResourceReferenceDt rr = (ResourceReferenceDt) exts.get(0).getValue();
|
|
|
|
o = (Organization) rr.getResource();
|
|
|
|
o = (Organization) rr.getResource();
|
|
|
|
assertEquals("ORG", o.getName());
|
|
|
|
assertEquals("ORG", o.getName());
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -148,67 +124,28 @@ public class XmlParserDstu2Test {
|
|
|
|
DurationDt duration = new DurationDt();
|
|
|
|
DurationDt duration = new DurationDt();
|
|
|
|
duration.setUnits("day").setValue(123L);
|
|
|
|
duration.setUnits("day").setValue(123L);
|
|
|
|
enc.setLength(duration);
|
|
|
|
enc.setLength(duration);
|
|
|
|
|
|
|
|
|
|
|
|
String str = ourCtx.newXmlParser().encodeResourceToString(enc);
|
|
|
|
String str = ourCtx.newXmlParser().encodeResourceToString(enc);
|
|
|
|
ourLog.info(str);
|
|
|
|
ourLog.info(str);
|
|
|
|
|
|
|
|
|
|
|
|
assertThat(str, not(containsString("meta")));
|
|
|
|
assertThat(str, not(containsString("meta")));
|
|
|
|
assertThat(str, containsString("<length><value value=\"123\"/><units value=\"day\"/></length>"));
|
|
|
|
assertThat(str, containsString("<length><value value=\"123\"/><units value=\"day\"/></length>"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
public void testEncodeAndParseBundleWithoutResourceIds() {
|
|
|
|
public void testEncodeAndParseBundleWithoutResourceIds() {
|
|
|
|
Organization org = new Organization();
|
|
|
|
Organization org = new Organization();
|
|
|
|
org.addIdentifier().setSystem("urn:system").setValue("someval");
|
|
|
|
org.addIdentifier().setSystem("urn:system").setValue("someval");
|
|
|
|
|
|
|
|
|
|
|
|
Bundle bundle = Bundle.withSingleResource(org);
|
|
|
|
Bundle bundle = Bundle.withSingleResource(org);
|
|
|
|
String str = ourCtx.newXmlParser().encodeBundleToString(bundle);
|
|
|
|
String str = ourCtx.newXmlParser().encodeBundleToString(bundle);
|
|
|
|
ourLog.info(str);
|
|
|
|
ourLog.info(str);
|
|
|
|
|
|
|
|
|
|
|
|
Bundle parsed = ourCtx.newXmlParser().parseBundle(str);
|
|
|
|
Bundle parsed = ourCtx.newXmlParser().parseBundle(str);
|
|
|
|
assertThat(parsed.getEntries().get(0).getResource().getId().getValue(), emptyOrNullString());
|
|
|
|
assertThat(parsed.getEntries().get(0).getResource().getId().getValue(), emptyOrNullString());
|
|
|
|
assertTrue(parsed.getEntries().get(0).getResource().getId().isEmpty());
|
|
|
|
assertTrue(parsed.getEntries().get(0).getResource().getId().isEmpty());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static void main(String[] args) {
|
|
|
|
|
|
|
|
IGenericClient c = ourCtx.newRestfulGenericClient("http://fhir-dev.healthintersections.com.au/open");
|
|
|
|
|
|
|
|
// c.registerInterceptor(new LoggingInterceptor(true));
|
|
|
|
|
|
|
|
c.read().resource("Patient").withId("324").execute();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
|
|
|
public void testEncodeBundleWithContained() {
|
|
|
|
|
|
|
|
DiagnosticReport rpt = new DiagnosticReport();
|
|
|
|
|
|
|
|
rpt.addResult().setResource(new Observation().setCode(new CodeableConceptDt().setText("Sharp1")).setId("#1"));
|
|
|
|
|
|
|
|
rpt.addResult().setResource(new Observation().setCode(new CodeableConceptDt().setText("Uuid1")).setId("urn:uuid:UUID1"));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ca.uhn.fhir.model.dstu2.resource.Bundle b = new ca.uhn.fhir.model.dstu2.resource.Bundle();
|
|
|
|
|
|
|
|
b.addEntry().setResource(rpt);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String encoded = ourCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(b);
|
|
|
|
|
|
|
|
ourLog.info(encoded);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assertThat(encoded, stringContainsInOrder(
|
|
|
|
|
|
|
|
"<DiagnosticReport",
|
|
|
|
|
|
|
|
"<contained",
|
|
|
|
|
|
|
|
"<Observation",
|
|
|
|
|
|
|
|
"<text value=\"Sharp1\"",
|
|
|
|
|
|
|
|
"</DiagnosticReport"
|
|
|
|
|
|
|
|
));
|
|
|
|
|
|
|
|
assertThat(encoded, not(stringContainsInOrder(
|
|
|
|
|
|
|
|
"<DiagnosticReport",
|
|
|
|
|
|
|
|
"<contained",
|
|
|
|
|
|
|
|
"<Observation",
|
|
|
|
|
|
|
|
"<contained",
|
|
|
|
|
|
|
|
"<Observation",
|
|
|
|
|
|
|
|
"</DiagnosticReport"
|
|
|
|
|
|
|
|
)));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
public void testEncodeAndParseContained() {
|
|
|
|
public void testEncodeAndParseContained() {
|
|
|
|
IParser xmlParser = ourCtx.newXmlParser().setPrettyPrint(true);
|
|
|
|
IParser xmlParser = ourCtx.newXmlParser().setPrettyPrint(true);
|
|
|
@ -260,7 +197,7 @@ public class XmlParserDstu2Test {
|
|
|
|
|
|
|
|
|
|
|
|
// And re-encode once more, with the references cleared
|
|
|
|
// And re-encode once more, with the references cleared
|
|
|
|
patient.getContained().getContainedResources().clear();
|
|
|
|
patient.getContained().getContainedResources().clear();
|
|
|
|
patient.getManagingOrganization().setReference((String)null);
|
|
|
|
patient.getManagingOrganization().setReference((String) null);
|
|
|
|
encoded = xmlParser.encodeResourceToString(patient);
|
|
|
|
encoded = xmlParser.encodeResourceToString(patient);
|
|
|
|
ourLog.info(encoded);
|
|
|
|
ourLog.info(encoded);
|
|
|
|
assertThat(encoded, stringContainsInOrder(Arrays.asList("<contained>", "<Organization ", "<id value=\"1\"/>", "</Organization", "</contained>", "<reference value=\"#1\"/>")));
|
|
|
|
assertThat(encoded, stringContainsInOrder(Arrays.asList("<contained>", "<Organization ", "<id value=\"1\"/>", "</Organization", "</contained>", "<reference value=\"#1\"/>")));
|
|
|
@ -269,7 +206,7 @@ public class XmlParserDstu2Test {
|
|
|
|
|
|
|
|
|
|
|
|
// And re-encode once more, with the references cleared and a manually set local ID
|
|
|
|
// And re-encode once more, with the references cleared and a manually set local ID
|
|
|
|
patient.getContained().getContainedResources().clear();
|
|
|
|
patient.getContained().getContainedResources().clear();
|
|
|
|
patient.getManagingOrganization().setReference((String)null);
|
|
|
|
patient.getManagingOrganization().setReference((String) null);
|
|
|
|
patient.getManagingOrganization().getResource().setId(("#333"));
|
|
|
|
patient.getManagingOrganization().getResource().setId(("#333"));
|
|
|
|
encoded = xmlParser.encodeResourceToString(patient);
|
|
|
|
encoded = xmlParser.encodeResourceToString(patient);
|
|
|
|
ourLog.info(encoded);
|
|
|
|
ourLog.info(encoded);
|
|
|
@ -278,7 +215,6 @@ public class XmlParserDstu2Test {
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
public void testEncodeAndParseExtensionOnResourceReference() {
|
|
|
|
public void testEncodeAndParseExtensionOnResourceReference() {
|
|
|
|
DataElement de = new DataElement();
|
|
|
|
DataElement de = new DataElement();
|
|
|
@ -291,20 +227,19 @@ public class XmlParserDstu2Test {
|
|
|
|
|
|
|
|
|
|
|
|
String str = ourCtx.newXmlParser().encodeResourceToString(de);
|
|
|
|
String str = ourCtx.newXmlParser().encodeResourceToString(de);
|
|
|
|
ourLog.info(str);
|
|
|
|
ourLog.info(str);
|
|
|
|
|
|
|
|
|
|
|
|
de = ourCtx.newXmlParser().parseResource(DataElement.class, str);
|
|
|
|
de = ourCtx.newXmlParser().parseResource(DataElement.class, str);
|
|
|
|
b = de.getElement().get(0).getBinding();
|
|
|
|
b = de.getElement().get(0).getBinding();
|
|
|
|
assertEquals("BINDING", b.getName());
|
|
|
|
assertEquals("BINDING", b.getName());
|
|
|
|
|
|
|
|
|
|
|
|
List<ExtensionDt> exts = b.getUndeclaredExtensionsByUrl("urn:foo");
|
|
|
|
List<ExtensionDt> exts = b.getUndeclaredExtensionsByUrl("urn:foo");
|
|
|
|
assertEquals(1, exts.size());
|
|
|
|
assertEquals(1, exts.size());
|
|
|
|
ResourceReferenceDt rr = (ResourceReferenceDt)exts.get(0).getValue();
|
|
|
|
ResourceReferenceDt rr = (ResourceReferenceDt) exts.get(0).getValue();
|
|
|
|
o = (Organization) rr.getResource();
|
|
|
|
o = (Organization) rr.getResource();
|
|
|
|
assertEquals("ORG", o.getName());
|
|
|
|
assertEquals("ORG", o.getName());
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
public void testEncodeAndParseExtensions() throws Exception {
|
|
|
|
public void testEncodeAndParseExtensions() throws Exception {
|
|
|
|
|
|
|
|
|
|
|
@ -348,12 +283,10 @@ public class XmlParserDstu2Test {
|
|
|
|
String enc = ourCtx.newXmlParser().encodeResourceToString(patient);
|
|
|
|
String enc = ourCtx.newXmlParser().encodeResourceToString(patient);
|
|
|
|
assertThat(enc, containsString("<Patient xmlns=\"http://hl7.org/fhir\"><extension url=\"http://example.com/extensions#someext\"><valueDateTime value=\"2011-01-02T11:13:15\"/></extension>"));
|
|
|
|
assertThat(enc, containsString("<Patient xmlns=\"http://hl7.org/fhir\"><extension url=\"http://example.com/extensions#someext\"><valueDateTime value=\"2011-01-02T11:13:15\"/></extension>"));
|
|
|
|
assertThat(enc, containsString("<modifierExtension url=\"http://example.com/extensions#modext\"><valueDate value=\"1995-01-02\"/></modifierExtension>"));
|
|
|
|
assertThat(enc, containsString("<modifierExtension url=\"http://example.com/extensions#modext\"><valueDate value=\"1995-01-02\"/></modifierExtension>"));
|
|
|
|
assertThat(
|
|
|
|
assertThat(enc, containsString("<extension url=\"http://example.com#parent\"><extension url=\"http://example.com#child\"><valueString value=\"value1\"/></extension><extension url=\"http://example.com#child\"><valueString value=\"value2\"/></extension></extension>"));
|
|
|
|
enc,
|
|
|
|
|
|
|
|
containsString("<extension url=\"http://example.com#parent\"><extension url=\"http://example.com#child\"><valueString value=\"value1\"/></extension><extension url=\"http://example.com#child\"><valueString value=\"value2\"/></extension></extension>"));
|
|
|
|
|
|
|
|
assertThat(enc, containsString("<given value=\"Joe\"><extension url=\"http://examples.com#givenext\"><valueString value=\"given\"/></extension></given>"));
|
|
|
|
assertThat(enc, containsString("<given value=\"Joe\"><extension url=\"http://examples.com#givenext\"><valueString value=\"given\"/></extension></given>"));
|
|
|
|
assertThat(enc, containsString("<given value=\"Shmoe\"><extension url=\"http://examples.com#givenext_parent\"><extension url=\"http://examples.com#givenext_child\"><valueString value=\"CHILD\"/></extension></extension></given>"));
|
|
|
|
assertThat(enc, containsString("<given value=\"Shmoe\"><extension url=\"http://examples.com#givenext_parent\"><extension url=\"http://examples.com#givenext_child\"><valueString value=\"CHILD\"/></extension></extension></given>"));
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
/*
|
|
|
|
* Now parse this back
|
|
|
|
* Now parse this back
|
|
|
|
*/
|
|
|
|
*/
|
|
|
@ -396,7 +329,7 @@ public class XmlParserDstu2Test {
|
|
|
|
public void testEncodeAndParseMetaProfileAndTags() {
|
|
|
|
public void testEncodeAndParseMetaProfileAndTags() {
|
|
|
|
Patient p = new Patient();
|
|
|
|
Patient p = new Patient();
|
|
|
|
p.addName().addFamily("FAMILY");
|
|
|
|
p.addName().addFamily("FAMILY");
|
|
|
|
|
|
|
|
|
|
|
|
List<IdDt> profiles = new ArrayList<IdDt>();
|
|
|
|
List<IdDt> profiles = new ArrayList<IdDt>();
|
|
|
|
profiles.add(new IdDt("http://foo/Profile1"));
|
|
|
|
profiles.add(new IdDt("http://foo/Profile1"));
|
|
|
|
profiles.add(new IdDt("http://foo/Profile2"));
|
|
|
|
profiles.add(new IdDt("http://foo/Profile2"));
|
|
|
@ -406,10 +339,10 @@ public class XmlParserDstu2Test {
|
|
|
|
tagList.addTag("scheme1", "term1", "label1");
|
|
|
|
tagList.addTag("scheme1", "term1", "label1");
|
|
|
|
tagList.addTag("scheme2", "term2", "label2");
|
|
|
|
tagList.addTag("scheme2", "term2", "label2");
|
|
|
|
ResourceMetadataKeyEnum.TAG_LIST.put(p, tagList);
|
|
|
|
ResourceMetadataKeyEnum.TAG_LIST.put(p, tagList);
|
|
|
|
|
|
|
|
|
|
|
|
String enc = ourCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(p);
|
|
|
|
String enc = ourCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(p);
|
|
|
|
ourLog.info(enc);
|
|
|
|
ourLog.info(enc);
|
|
|
|
|
|
|
|
|
|
|
|
//@formatter:off
|
|
|
|
//@formatter:off
|
|
|
|
assertThat(enc, stringContainsInOrder("<Patient xmlns=\"http://hl7.org/fhir\">",
|
|
|
|
assertThat(enc, stringContainsInOrder("<Patient xmlns=\"http://hl7.org/fhir\">",
|
|
|
|
"<meta>",
|
|
|
|
"<meta>",
|
|
|
@ -433,38 +366,37 @@ public class XmlParserDstu2Test {
|
|
|
|
"</name>",
|
|
|
|
"</name>",
|
|
|
|
"</Patient>"));
|
|
|
|
"</Patient>"));
|
|
|
|
//@formatter:on
|
|
|
|
//@formatter:on
|
|
|
|
|
|
|
|
|
|
|
|
Patient parsed = ourCtx.newXmlParser().parseResource(Patient.class, enc);
|
|
|
|
Patient parsed = ourCtx.newXmlParser().parseResource(Patient.class, enc);
|
|
|
|
List<IdDt> gotLabels = ResourceMetadataKeyEnum.PROFILES.get(parsed);
|
|
|
|
List<IdDt> gotLabels = ResourceMetadataKeyEnum.PROFILES.get(parsed);
|
|
|
|
|
|
|
|
|
|
|
|
assertEquals(2,gotLabels.size());
|
|
|
|
assertEquals(2, gotLabels.size());
|
|
|
|
|
|
|
|
|
|
|
|
IdDt label = (IdDt) gotLabels.get(0);
|
|
|
|
IdDt label = (IdDt) gotLabels.get(0);
|
|
|
|
assertEquals("http://foo/Profile1", label.getValue());
|
|
|
|
assertEquals("http://foo/Profile1", label.getValue());
|
|
|
|
label = (IdDt) gotLabels.get(1);
|
|
|
|
label = (IdDt) gotLabels.get(1);
|
|
|
|
assertEquals("http://foo/Profile2", label.getValue());
|
|
|
|
assertEquals("http://foo/Profile2", label.getValue());
|
|
|
|
|
|
|
|
|
|
|
|
tagList = ResourceMetadataKeyEnum.TAG_LIST.get(parsed);
|
|
|
|
tagList = ResourceMetadataKeyEnum.TAG_LIST.get(parsed);
|
|
|
|
assertEquals(2, tagList.size());
|
|
|
|
assertEquals(2, tagList.size());
|
|
|
|
|
|
|
|
|
|
|
|
assertEquals(new Tag("scheme1", "term1", "label1"), tagList.get(0));
|
|
|
|
assertEquals(new Tag("scheme1", "term1", "label1"), tagList.get(0));
|
|
|
|
assertEquals(new Tag("scheme2", "term2", "label2"), tagList.get(1));
|
|
|
|
assertEquals(new Tag("scheme2", "term2", "label2"), tagList.get(1));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
public void testEncodeAndParseMetaProfiles() {
|
|
|
|
public void testEncodeAndParseMetaProfiles() {
|
|
|
|
Patient p = new Patient();
|
|
|
|
Patient p = new Patient();
|
|
|
|
p.addName().addFamily("FAMILY");
|
|
|
|
p.addName().addFamily("FAMILY");
|
|
|
|
|
|
|
|
|
|
|
|
TagList tagList = new TagList();
|
|
|
|
TagList tagList = new TagList();
|
|
|
|
tagList.addTag("scheme1", "term1", "label1");
|
|
|
|
tagList.addTag("scheme1", "term1", "label1");
|
|
|
|
tagList.addTag("scheme2", "term2", "label2");
|
|
|
|
tagList.addTag("scheme2", "term2", "label2");
|
|
|
|
ResourceMetadataKeyEnum.TAG_LIST.put(p, tagList);
|
|
|
|
ResourceMetadataKeyEnum.TAG_LIST.put(p, tagList);
|
|
|
|
|
|
|
|
|
|
|
|
String enc = ourCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(p);
|
|
|
|
String enc = ourCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(p);
|
|
|
|
ourLog.info(enc);
|
|
|
|
ourLog.info(enc);
|
|
|
|
|
|
|
|
|
|
|
|
//@formatter:off
|
|
|
|
//@formatter:off
|
|
|
|
assertThat(enc, stringContainsInOrder("<Patient xmlns=\"http://hl7.org/fhir\">",
|
|
|
|
assertThat(enc, stringContainsInOrder("<Patient xmlns=\"http://hl7.org/fhir\">",
|
|
|
|
"<meta>",
|
|
|
|
"<meta>",
|
|
|
@ -486,32 +418,32 @@ public class XmlParserDstu2Test {
|
|
|
|
"</name>",
|
|
|
|
"</name>",
|
|
|
|
"</Patient>"));
|
|
|
|
"</Patient>"));
|
|
|
|
//@formatter:on
|
|
|
|
//@formatter:on
|
|
|
|
|
|
|
|
|
|
|
|
Patient parsed = ourCtx.newXmlParser().parseResource(Patient.class, enc);
|
|
|
|
Patient parsed = ourCtx.newXmlParser().parseResource(Patient.class, enc);
|
|
|
|
List<IdDt> gotLabels = ResourceMetadataKeyEnum.PROFILES.get(parsed);
|
|
|
|
List<IdDt> gotLabels = ResourceMetadataKeyEnum.PROFILES.get(parsed);
|
|
|
|
assertNull(gotLabels);
|
|
|
|
assertNull(gotLabels);
|
|
|
|
|
|
|
|
|
|
|
|
tagList = ResourceMetadataKeyEnum.TAG_LIST.get(parsed);
|
|
|
|
tagList = ResourceMetadataKeyEnum.TAG_LIST.get(parsed);
|
|
|
|
assertEquals(2, tagList.size());
|
|
|
|
assertEquals(2, tagList.size());
|
|
|
|
|
|
|
|
|
|
|
|
assertEquals(new Tag("scheme1", "term1", "label1"), tagList.get(0));
|
|
|
|
assertEquals(new Tag("scheme1", "term1", "label1"), tagList.get(0));
|
|
|
|
assertEquals(new Tag("scheme2", "term2", "label2"), tagList.get(1));
|
|
|
|
assertEquals(new Tag("scheme2", "term2", "label2"), tagList.get(1));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
public void testEncodeAndParseSecurityLabels() {
|
|
|
|
public void testEncodeAndParseSecurityLabels() {
|
|
|
|
Patient p = new Patient();
|
|
|
|
Patient p = new Patient();
|
|
|
|
p.addName().addFamily("FAMILY");
|
|
|
|
p.addName().addFamily("FAMILY");
|
|
|
|
|
|
|
|
|
|
|
|
List<BaseCodingDt> labels = new ArrayList<BaseCodingDt>();
|
|
|
|
List<BaseCodingDt> labels = new ArrayList<BaseCodingDt>();
|
|
|
|
labels.add(new CodingDt().setSystem("SYSTEM1").setCode("CODE1").setDisplay("DISPLAY1").setPrimary(true).setVersion("VERSION1"));
|
|
|
|
labels.add(new CodingDt().setSystem("SYSTEM1").setCode("CODE1").setDisplay("DISPLAY1").setPrimary(true).setVersion("VERSION1"));
|
|
|
|
labels.add(new CodingDt().setSystem("SYSTEM2").setCode("CODE2").setDisplay("DISPLAY2").setPrimary(false).setVersion("VERSION2"));
|
|
|
|
labels.add(new CodingDt().setSystem("SYSTEM2").setCode("CODE2").setDisplay("DISPLAY2").setPrimary(false).setVersion("VERSION2"));
|
|
|
|
|
|
|
|
|
|
|
|
ResourceMetadataKeyEnum.SECURITY_LABELS.put(p, labels);
|
|
|
|
ResourceMetadataKeyEnum.SECURITY_LABELS.put(p, labels);
|
|
|
|
|
|
|
|
|
|
|
|
String enc = ourCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(p);
|
|
|
|
String enc = ourCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(p);
|
|
|
|
ourLog.info(enc);
|
|
|
|
ourLog.info(enc);
|
|
|
|
|
|
|
|
|
|
|
|
//@formatter:off
|
|
|
|
//@formatter:off
|
|
|
|
assertThat(enc, stringContainsInOrder("<Patient xmlns=\"http://hl7.org/fhir\">",
|
|
|
|
assertThat(enc, stringContainsInOrder("<Patient xmlns=\"http://hl7.org/fhir\">",
|
|
|
|
"<meta>",
|
|
|
|
"<meta>",
|
|
|
@ -535,11 +467,11 @@ public class XmlParserDstu2Test {
|
|
|
|
"</name>",
|
|
|
|
"</name>",
|
|
|
|
"</Patient>"));
|
|
|
|
"</Patient>"));
|
|
|
|
//@formatter:on
|
|
|
|
//@formatter:on
|
|
|
|
|
|
|
|
|
|
|
|
Patient parsed = ourCtx.newXmlParser().parseResource(Patient.class, enc);
|
|
|
|
Patient parsed = ourCtx.newXmlParser().parseResource(Patient.class, enc);
|
|
|
|
List<BaseCodingDt> gotLabels = ResourceMetadataKeyEnum.SECURITY_LABELS.get(parsed);
|
|
|
|
List<BaseCodingDt> gotLabels = ResourceMetadataKeyEnum.SECURITY_LABELS.get(parsed);
|
|
|
|
|
|
|
|
|
|
|
|
assertEquals(2,gotLabels.size());
|
|
|
|
assertEquals(2, gotLabels.size());
|
|
|
|
|
|
|
|
|
|
|
|
CodingDt label = (CodingDt) gotLabels.get(0);
|
|
|
|
CodingDt label = (CodingDt) gotLabels.get(0);
|
|
|
|
assertEquals("SYSTEM1", label.getSystem());
|
|
|
|
assertEquals("SYSTEM1", label.getSystem());
|
|
|
@ -565,9 +497,9 @@ public class XmlParserDstu2Test {
|
|
|
|
comp.addSection().getContent().setResource(new AllergyIntolerance().setComment("Section0_Allergy0"));
|
|
|
|
comp.addSection().getContent().setResource(new AllergyIntolerance().setComment("Section0_Allergy0"));
|
|
|
|
comp.addSection().getContent().setResource(new AllergyIntolerance().setComment("Section1_Allergy0"));
|
|
|
|
comp.addSection().getContent().setResource(new AllergyIntolerance().setComment("Section1_Allergy0"));
|
|
|
|
comp.addSection().getContent().setResource(new AllergyIntolerance().setComment("Section2_Allergy0"));
|
|
|
|
comp.addSection().getContent().setResource(new AllergyIntolerance().setComment("Section2_Allergy0"));
|
|
|
|
|
|
|
|
|
|
|
|
IParser parser = ourCtx.newJsonParser().setPrettyPrint(true);
|
|
|
|
IParser parser = ourCtx.newJsonParser().setPrettyPrint(true);
|
|
|
|
|
|
|
|
|
|
|
|
String string = parser.encodeResourceToString(comp);
|
|
|
|
String string = parser.encodeResourceToString(comp);
|
|
|
|
ourLog.info(string);
|
|
|
|
ourLog.info(string);
|
|
|
|
|
|
|
|
|
|
|
@ -590,9 +522,9 @@ public class XmlParserDstu2Test {
|
|
|
|
comp.addSection().getContent().setResource(new AllergyIntolerance().setComment("Section0_Allergy0"));
|
|
|
|
comp.addSection().getContent().setResource(new AllergyIntolerance().setComment("Section0_Allergy0"));
|
|
|
|
comp.addSection().getContent().setResource(new AllergyIntolerance().setComment("Section1_Allergy0"));
|
|
|
|
comp.addSection().getContent().setResource(new AllergyIntolerance().setComment("Section1_Allergy0"));
|
|
|
|
comp.addSection().getContent().setResource(new AllergyIntolerance().setComment("Section2_Allergy0"));
|
|
|
|
comp.addSection().getContent().setResource(new AllergyIntolerance().setComment("Section2_Allergy0"));
|
|
|
|
|
|
|
|
|
|
|
|
IParser parser = ourCtx.newXmlParser().setPrettyPrint(true);
|
|
|
|
IParser parser = ourCtx.newXmlParser().setPrettyPrint(true);
|
|
|
|
|
|
|
|
|
|
|
|
String string = parser.encodeResourceToString(comp);
|
|
|
|
String string = parser.encodeResourceToString(comp);
|
|
|
|
ourLog.info(string);
|
|
|
|
ourLog.info(string);
|
|
|
|
|
|
|
|
|
|
|
@ -609,11 +541,11 @@ public class XmlParserDstu2Test {
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
public void testEncodeBinaryWithNoContentType() {
|
|
|
|
public void testEncodeBinaryWithNoContentType() {
|
|
|
|
Binary b = new Binary();
|
|
|
|
Binary b = new Binary();
|
|
|
|
b.setContent(new byte[] {1,2,3,4});
|
|
|
|
b.setContent(new byte[] { 1, 2, 3, 4 });
|
|
|
|
|
|
|
|
|
|
|
|
String output = ourCtx.newXmlParser().encodeResourceToString(b);
|
|
|
|
String output = ourCtx.newXmlParser().encodeResourceToString(b);
|
|
|
|
ourLog.info(output);
|
|
|
|
ourLog.info(output);
|
|
|
|
|
|
|
|
|
|
|
|
assertEquals("<Binary xmlns=\"http://hl7.org/fhir\"><content value=\"AQIDBA==\"/></Binary>", output);
|
|
|
|
assertEquals("<Binary xmlns=\"http://hl7.org/fhir\"><content value=\"AQIDBA==\"/></Binary>", output);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -622,25 +554,25 @@ public class XmlParserDstu2Test {
|
|
|
|
Patient p = new Patient();
|
|
|
|
Patient p = new Patient();
|
|
|
|
p.setId(IdDt.newRandomUuid());
|
|
|
|
p.setId(IdDt.newRandomUuid());
|
|
|
|
p.addName().addFamily("PATIENT");
|
|
|
|
p.addName().addFamily("PATIENT");
|
|
|
|
|
|
|
|
|
|
|
|
ca.uhn.fhir.model.dstu2.resource.Bundle b = new ca.uhn.fhir.model.dstu2.resource.Bundle();
|
|
|
|
ca.uhn.fhir.model.dstu2.resource.Bundle b = new ca.uhn.fhir.model.dstu2.resource.Bundle();
|
|
|
|
b.addEntry().setResource(p);
|
|
|
|
b.addEntry().setResource(p);
|
|
|
|
|
|
|
|
|
|
|
|
String encoded = ourCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(b);
|
|
|
|
String encoded = ourCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(b);
|
|
|
|
ourLog.info(encoded);
|
|
|
|
ourLog.info(encoded);
|
|
|
|
assertThat(encoded, stringContainsInOrder("<Bundle", "<entry>", "<base value=\"urn:uuid:\"/>", "<Patient", "<id value="));
|
|
|
|
assertThat(encoded, stringContainsInOrder("<Bundle", "<entry>", "<base value=\"urn:uuid:\"/>", "<Patient", "<id value="));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
public void testEncodeBundleContainingResourceWithUuidBaseBundleBaseIsSet() {
|
|
|
|
public void testEncodeBundleContainingResourceWithUuidBaseBundleBaseIsSet() {
|
|
|
|
Patient p = new Patient();
|
|
|
|
Patient p = new Patient();
|
|
|
|
p.setId(IdDt.newRandomUuid());
|
|
|
|
p.setId(IdDt.newRandomUuid());
|
|
|
|
p.addName().addFamily("PATIENT");
|
|
|
|
p.addName().addFamily("PATIENT");
|
|
|
|
|
|
|
|
|
|
|
|
ca.uhn.fhir.model.dstu2.resource.Bundle b = new ca.uhn.fhir.model.dstu2.resource.Bundle();
|
|
|
|
ca.uhn.fhir.model.dstu2.resource.Bundle b = new ca.uhn.fhir.model.dstu2.resource.Bundle();
|
|
|
|
b.setBase("urn:uuid:");
|
|
|
|
b.setBase("urn:uuid:");
|
|
|
|
b.addEntry().setResource(p);
|
|
|
|
b.addEntry().setResource(p);
|
|
|
|
|
|
|
|
|
|
|
|
String encoded = ourCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(b);
|
|
|
|
String encoded = ourCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(b);
|
|
|
|
ourLog.info(encoded);
|
|
|
|
ourLog.info(encoded);
|
|
|
|
assertThat(encoded, not(stringContainsInOrder("<Bundle", "<entry>", "<base value=\"urn:uuid:\"/>", "<Patient", "<id value=")));
|
|
|
|
assertThat(encoded, not(stringContainsInOrder("<Bundle", "<entry>", "<base value=\"urn:uuid:\"/>", "<Patient", "<id value=")));
|
|
|
@ -652,70 +584,85 @@ public class XmlParserDstu2Test {
|
|
|
|
Patient p = new Patient();
|
|
|
|
Patient p = new Patient();
|
|
|
|
p.setId(IdDt.newRandomUuid());
|
|
|
|
p.setId(IdDt.newRandomUuid());
|
|
|
|
p.addName().addFamily("PATIENT");
|
|
|
|
p.addName().addFamily("PATIENT");
|
|
|
|
|
|
|
|
|
|
|
|
ca.uhn.fhir.model.dstu2.resource.Bundle b = new ca.uhn.fhir.model.dstu2.resource.Bundle();
|
|
|
|
ca.uhn.fhir.model.dstu2.resource.Bundle b = new ca.uhn.fhir.model.dstu2.resource.Bundle();
|
|
|
|
b.setBase("urn:oid:");
|
|
|
|
b.setBase("urn:oid:");
|
|
|
|
b.addEntry().setResource(p);
|
|
|
|
b.addEntry().setResource(p);
|
|
|
|
|
|
|
|
|
|
|
|
String encoded = ourCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(b);
|
|
|
|
String encoded = ourCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(b);
|
|
|
|
ourLog.info(encoded);
|
|
|
|
ourLog.info(encoded);
|
|
|
|
assertThat(encoded, stringContainsInOrder("<Bundle", "<base value=\"urn:oid:\"/>", "<entry>", "<base value=\"urn:uuid:\"/>", "<Patient", "<id value="));
|
|
|
|
assertThat(encoded, stringContainsInOrder("<Bundle", "<base value=\"urn:oid:\"/>", "<entry>", "<base value=\"urn:uuid:\"/>", "<Patient", "<id value="));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
public void testEncodeBundleOldStyleContainingResourceWithUuidBase() {
|
|
|
|
public void testEncodeBundleOldStyleContainingResourceWithUuidBase() {
|
|
|
|
Patient p = new Patient();
|
|
|
|
Patient p = new Patient();
|
|
|
|
p.setId(IdDt.newRandomUuid());
|
|
|
|
p.setId(IdDt.newRandomUuid());
|
|
|
|
p.addName().addFamily("PATIENT");
|
|
|
|
p.addName().addFamily("PATIENT");
|
|
|
|
|
|
|
|
|
|
|
|
Bundle b = new Bundle();
|
|
|
|
Bundle b = new Bundle();
|
|
|
|
b.addEntry().setResource(p);
|
|
|
|
b.addEntry().setResource(p);
|
|
|
|
|
|
|
|
|
|
|
|
String encoded = ourCtx.newXmlParser().setPrettyPrint(true).encodeBundleToString(b);
|
|
|
|
String encoded = ourCtx.newXmlParser().setPrettyPrint(true).encodeBundleToString(b);
|
|
|
|
ourLog.info(encoded);
|
|
|
|
ourLog.info(encoded);
|
|
|
|
assertThat(encoded, stringContainsInOrder("<Bundle", "<entry>", "<base value=\"urn:uuid:\"/>", "<Patient", "<id value="));
|
|
|
|
assertThat(encoded, stringContainsInOrder("<Bundle", "<entry>", "<base value=\"urn:uuid:\"/>", "<Patient", "<id value="));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
public void testEncodeBundleOldStyleContainingResourceWithUuidBaseBundleBaseIsSet() {
|
|
|
|
public void testEncodeBundleOldStyleContainingResourceWithUuidBaseBundleBaseIsSet() {
|
|
|
|
Patient p = new Patient();
|
|
|
|
Patient p = new Patient();
|
|
|
|
p.setId(IdDt.newRandomUuid());
|
|
|
|
p.setId(IdDt.newRandomUuid());
|
|
|
|
p.addName().addFamily("PATIENT");
|
|
|
|
p.addName().addFamily("PATIENT");
|
|
|
|
|
|
|
|
|
|
|
|
Bundle b = new Bundle();
|
|
|
|
Bundle b = new Bundle();
|
|
|
|
b.getLinkBase().setValue("urn:uuid:");
|
|
|
|
b.getLinkBase().setValue("urn:uuid:");
|
|
|
|
b.addEntry().setResource(p);
|
|
|
|
b.addEntry().setResource(p);
|
|
|
|
|
|
|
|
|
|
|
|
String encoded = ourCtx.newXmlParser().setPrettyPrint(true).encodeBundleToString(b);
|
|
|
|
String encoded = ourCtx.newXmlParser().setPrettyPrint(true).encodeBundleToString(b);
|
|
|
|
ourLog.info(encoded);
|
|
|
|
ourLog.info(encoded);
|
|
|
|
assertThat(encoded, not(stringContainsInOrder("<Bundle", "<entry>", "<base value=\"urn:uuid:\"/>", "<Patient", "<id value=")));
|
|
|
|
assertThat(encoded, not(stringContainsInOrder("<Bundle", "<entry>", "<base value=\"urn:uuid:\"/>", "<Patient", "<id value=")));
|
|
|
|
assertThat(encoded, stringContainsInOrder("<Bundle", "<base value=\"urn:uuid:\"/>", "<entry>", "<Patient", "<id value="));
|
|
|
|
assertThat(encoded, stringContainsInOrder("<Bundle", "<base value=\"urn:uuid:\"/>", "<entry>", "<Patient", "<id value="));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
public void testEncodeBundleOldStyleContainingResourceWithUuidBaseBundleBaseIsSetDifferently() {
|
|
|
|
public void testEncodeBundleOldStyleContainingResourceWithUuidBaseBundleBaseIsSetDifferently() {
|
|
|
|
Patient p = new Patient();
|
|
|
|
Patient p = new Patient();
|
|
|
|
p.setId(IdDt.newRandomUuid());
|
|
|
|
p.setId(IdDt.newRandomUuid());
|
|
|
|
p.addName().addFamily("PATIENT");
|
|
|
|
p.addName().addFamily("PATIENT");
|
|
|
|
|
|
|
|
|
|
|
|
Bundle b = new Bundle();
|
|
|
|
Bundle b = new Bundle();
|
|
|
|
b.getLinkBase().setValue("urn:oid:");
|
|
|
|
b.getLinkBase().setValue("urn:oid:");
|
|
|
|
b.addEntry().setResource(p);
|
|
|
|
b.addEntry().setResource(p);
|
|
|
|
|
|
|
|
|
|
|
|
String encoded = ourCtx.newXmlParser().setPrettyPrint(true).encodeBundleToString(b);
|
|
|
|
String encoded = ourCtx.newXmlParser().setPrettyPrint(true).encodeBundleToString(b);
|
|
|
|
ourLog.info(encoded);
|
|
|
|
ourLog.info(encoded);
|
|
|
|
assertThat(encoded, stringContainsInOrder("<Bundle", "<base value=\"urn:oid:\"/>", "<entry>", "<base value=\"urn:uuid:\"/>", "<Patient", "<id value="));
|
|
|
|
assertThat(encoded, stringContainsInOrder("<Bundle", "<base value=\"urn:oid:\"/>", "<entry>", "<base value=\"urn:uuid:\"/>", "<Patient", "<id value="));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
|
|
|
public void testEncodeBundleWithContained() {
|
|
|
|
|
|
|
|
DiagnosticReport rpt = new DiagnosticReport();
|
|
|
|
|
|
|
|
rpt.addResult().setResource(new Observation().setCode(new CodeableConceptDt().setText("Sharp1")).setId("#1"));
|
|
|
|
|
|
|
|
rpt.addResult().setResource(new Observation().setCode(new CodeableConceptDt().setText("Uuid1")).setId("urn:uuid:UUID1"));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ca.uhn.fhir.model.dstu2.resource.Bundle b = new ca.uhn.fhir.model.dstu2.resource.Bundle();
|
|
|
|
|
|
|
|
b.addEntry().setResource(rpt);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String encoded = ourCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(b);
|
|
|
|
|
|
|
|
ourLog.info(encoded);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assertThat(encoded, stringContainsInOrder("<DiagnosticReport", "<contained", "<Observation", "<text value=\"Sharp1\"", "</DiagnosticReport"));
|
|
|
|
|
|
|
|
assertThat(encoded, not(stringContainsInOrder("<DiagnosticReport", "<contained", "<Observation", "<contained", "<Observation", "</DiagnosticReport")));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* See #113
|
|
|
|
* See #113
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
public void testEncodeContainedResources() {
|
|
|
|
public void testEncodeContainedResources() {
|
|
|
|
|
|
|
|
|
|
|
|
MedicationPrescription medicationPrescript = new MedicationPrescription();
|
|
|
|
MedicationPrescription medicationPrescript = new MedicationPrescription();
|
|
|
|
|
|
|
|
|
|
|
|
String medId = "123";
|
|
|
|
String medId = "123";
|
|
|
|
CodeableConceptDt codeDt = new CodeableConceptDt("urn:sys", "code1");
|
|
|
|
CodeableConceptDt codeDt = new CodeableConceptDt("urn:sys", "code1");
|
|
|
|
|
|
|
|
|
|
|
@ -733,38 +680,20 @@ public class XmlParserDstu2Test {
|
|
|
|
ResourceReferenceDt medRefDt = new ResourceReferenceDt("#" + medId);
|
|
|
|
ResourceReferenceDt medRefDt = new ResourceReferenceDt("#" + medId);
|
|
|
|
medRefDt.setDisplay("MedRef");
|
|
|
|
medRefDt.setDisplay("MedRef");
|
|
|
|
medicationPrescript.setMedication(medRefDt);
|
|
|
|
medicationPrescript.setMedication(medRefDt);
|
|
|
|
|
|
|
|
|
|
|
|
IParser p = ourCtx.newXmlParser().setPrettyPrint(true);
|
|
|
|
IParser p = ourCtx.newXmlParser().setPrettyPrint(true);
|
|
|
|
String encoded = p.encodeResourceToString(medicationPrescript);
|
|
|
|
String encoded = p.encodeResourceToString(medicationPrescript);
|
|
|
|
ourLog.info(encoded);
|
|
|
|
ourLog.info(encoded);
|
|
|
|
|
|
|
|
|
|
|
|
//@formatter:on
|
|
|
|
// @formatter:on
|
|
|
|
assertThat(encoded, stringContainsInOrder(
|
|
|
|
assertThat(
|
|
|
|
"<MedicationPrescription xmlns=\"http://hl7.org/fhir\">",
|
|
|
|
encoded,
|
|
|
|
"<contained>",
|
|
|
|
stringContainsInOrder("<MedicationPrescription xmlns=\"http://hl7.org/fhir\">", "<contained>", "<Medication xmlns=\"http://hl7.org/fhir\">", "<id value=\"123\"/>", "<code>", "<coding>", "<system value=\"urn:sys\"/>", "<code value=\"code1\"/>", "</coding>", "</code>", "</Medication>",
|
|
|
|
"<Medication xmlns=\"http://hl7.org/fhir\">",
|
|
|
|
"</contained>", "<medication>", "<reference value=\"#123\"/>", "<display value=\"MedRef\"/>", "</medication>", "</MedicationPrescription>"));
|
|
|
|
"<id value=\"123\"/>",
|
|
|
|
|
|
|
|
"<code>",
|
|
|
|
|
|
|
|
"<coding>",
|
|
|
|
|
|
|
|
"<system value=\"urn:sys\"/>",
|
|
|
|
|
|
|
|
"<code value=\"code1\"/>",
|
|
|
|
|
|
|
|
"</coding>",
|
|
|
|
|
|
|
|
"</code>",
|
|
|
|
|
|
|
|
"</Medication>",
|
|
|
|
|
|
|
|
"</contained>",
|
|
|
|
|
|
|
|
"<medication>",
|
|
|
|
|
|
|
|
"<reference value=\"#123\"/>",
|
|
|
|
|
|
|
|
"<display value=\"MedRef\"/>",
|
|
|
|
|
|
|
|
"</medication>",
|
|
|
|
|
|
|
|
"</MedicationPrescription>"));
|
|
|
|
|
|
|
|
//@formatter:off
|
|
|
|
//@formatter:off
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* See #113
|
|
|
|
* See #113
|
|
|
|
*/
|
|
|
|
*/
|
|
|
@ -792,27 +721,14 @@ public class XmlParserDstu2Test {
|
|
|
|
ourLog.info(encoded);
|
|
|
|
ourLog.info(encoded);
|
|
|
|
|
|
|
|
|
|
|
|
//@formatter:on
|
|
|
|
//@formatter:on
|
|
|
|
assertThat(encoded, stringContainsInOrder(
|
|
|
|
assertThat(
|
|
|
|
"<MedicationPrescription xmlns=\"http://hl7.org/fhir\">",
|
|
|
|
encoded,
|
|
|
|
"<contained>",
|
|
|
|
stringContainsInOrder("<MedicationPrescription xmlns=\"http://hl7.org/fhir\">", "<contained>", "<Medication xmlns=\"http://hl7.org/fhir\">", "<id value=\"1\"/>", "<code>", "<coding>", "<system value=\"urn:sys\"/>", "<code value=\"code1\"/>", "</coding>", "</code>", "</Medication>",
|
|
|
|
"<Medication xmlns=\"http://hl7.org/fhir\">",
|
|
|
|
"</contained>", "<medication>", "<reference value=\"#1\"/>", "<display value=\"MedRef\"/>", "</medication>", "</MedicationPrescription>"));
|
|
|
|
"<id value=\"1\"/>",
|
|
|
|
|
|
|
|
"<code>",
|
|
|
|
|
|
|
|
"<coding>",
|
|
|
|
|
|
|
|
"<system value=\"urn:sys\"/>",
|
|
|
|
|
|
|
|
"<code value=\"code1\"/>",
|
|
|
|
|
|
|
|
"</coding>",
|
|
|
|
|
|
|
|
"</code>",
|
|
|
|
|
|
|
|
"</Medication>",
|
|
|
|
|
|
|
|
"</contained>",
|
|
|
|
|
|
|
|
"<medication>",
|
|
|
|
|
|
|
|
"<reference value=\"#1\"/>",
|
|
|
|
|
|
|
|
"<display value=\"MedRef\"/>",
|
|
|
|
|
|
|
|
"</medication>",
|
|
|
|
|
|
|
|
"</MedicationPrescription>"));
|
|
|
|
|
|
|
|
//@formatter:off
|
|
|
|
//@formatter:off
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* See #113
|
|
|
|
* See #113
|
|
|
|
*/
|
|
|
|
*/
|
|
|
@ -844,29 +760,14 @@ public class XmlParserDstu2Test {
|
|
|
|
ourLog.info(encoded);
|
|
|
|
ourLog.info(encoded);
|
|
|
|
|
|
|
|
|
|
|
|
//@formatter:on
|
|
|
|
//@formatter:on
|
|
|
|
assertThat(encoded, stringContainsInOrder(
|
|
|
|
assertThat(
|
|
|
|
"<MedicationPrescription xmlns=\"http://hl7.org/fhir\">",
|
|
|
|
encoded,
|
|
|
|
"<contained>",
|
|
|
|
stringContainsInOrder("<MedicationPrescription xmlns=\"http://hl7.org/fhir\">", "<contained>", "<Medication xmlns=\"http://hl7.org/fhir\">", "<id value=\"123\"/>", "<code>", "<coding>", "<system value=\"urn:sys\"/>", "<code value=\"code1\"/>", "</coding>", "</code>", "</Medication>",
|
|
|
|
"<Medication xmlns=\"http://hl7.org/fhir\">",
|
|
|
|
"</contained>", "<medication>", "<reference value=\"#123\"/>", "<display value=\"MedRef\"/>", "</medication>", "</MedicationPrescription>"));
|
|
|
|
"<id value=\"123\"/>",
|
|
|
|
|
|
|
|
"<code>",
|
|
|
|
|
|
|
|
"<coding>",
|
|
|
|
|
|
|
|
"<system value=\"urn:sys\"/>",
|
|
|
|
|
|
|
|
"<code value=\"code1\"/>",
|
|
|
|
|
|
|
|
"</coding>",
|
|
|
|
|
|
|
|
"</code>",
|
|
|
|
|
|
|
|
"</Medication>",
|
|
|
|
|
|
|
|
"</contained>",
|
|
|
|
|
|
|
|
"<medication>",
|
|
|
|
|
|
|
|
"<reference value=\"#123\"/>",
|
|
|
|
|
|
|
|
"<display value=\"MedRef\"/>",
|
|
|
|
|
|
|
|
"</medication>",
|
|
|
|
|
|
|
|
"</MedicationPrescription>"));
|
|
|
|
|
|
|
|
//@formatter:off
|
|
|
|
//@formatter:off
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
public void testEncodeContainedWithNarrativeIsSuppresed() throws Exception {
|
|
|
|
public void testEncodeContainedWithNarrativeIsSuppresed() throws Exception {
|
|
|
|
IParser parser = ourCtx.newXmlParser().setPrettyPrint(true);
|
|
|
|
IParser parser = ourCtx.newXmlParser().setPrettyPrint(true);
|
|
|
@ -894,6 +795,43 @@ public class XmlParserDstu2Test {
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* #158
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
|
|
|
public void testEncodeEmptyTag() {
|
|
|
|
|
|
|
|
TagList tagList = new TagList();
|
|
|
|
|
|
|
|
tagList.addTag(null, null, null);
|
|
|
|
|
|
|
|
tagList.addTag(null, null, "Label");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Patient p = new Patient();
|
|
|
|
|
|
|
|
ResourceMetadataKeyEnum.TAG_LIST.put(p, tagList);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String encoded = ourCtx.newXmlParser().encodeResourceToString(p);
|
|
|
|
|
|
|
|
assertThat(encoded, not(containsString("tag")));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* #158
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
|
|
|
public void testEncodeEmptyTag2() {
|
|
|
|
|
|
|
|
TagList tagList = new TagList();
|
|
|
|
|
|
|
|
tagList.addTag("scheme", "code", null);
|
|
|
|
|
|
|
|
tagList.addTag(null, null, "Label");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Patient p = new Patient();
|
|
|
|
|
|
|
|
ResourceMetadataKeyEnum.TAG_LIST.put(p, tagList);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String encoded = ourCtx.newXmlParser().encodeResourceToString(p);
|
|
|
|
|
|
|
|
assertThat(encoded, containsString("tag"));
|
|
|
|
|
|
|
|
assertThat(encoded, containsString("scheme"));
|
|
|
|
|
|
|
|
assertThat(encoded, not(containsString("Label")));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
public void testEncodeExtensionWithResourceContent() {
|
|
|
|
public void testEncodeExtensionWithResourceContent() {
|
|
|
@ -915,6 +853,7 @@ public class XmlParserDstu2Test {
|
|
|
|
assertEquals("Organization/123", ref.getReference().getValue());
|
|
|
|
assertEquals("Organization/123", ref.getReference().getValue());
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
public void testEncodeNonContained() {
|
|
|
|
public void testEncodeNonContained() {
|
|
|
@ -956,6 +895,7 @@ public class XmlParserDstu2Test {
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
public void testMoreExtensions() throws Exception {
|
|
|
|
public void testMoreExtensions() throws Exception {
|
|
|
|
|
|
|
|
|
|
|
@ -1056,7 +996,7 @@ public class XmlParserDstu2Test {
|
|
|
|
assertTrue(d.toString(), d.identical());
|
|
|
|
assertTrue(d.toString(), d.identical());
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
public void testParseAndEncodeBundleNewStyle() throws Exception {
|
|
|
|
public void testParseAndEncodeBundleNewStyle() throws Exception {
|
|
|
|
String content = IOUtils.toString(XmlParserDstu2Test.class.getResourceAsStream("/bundle-example.xml"));
|
|
|
|
String content = IOUtils.toString(XmlParserDstu2Test.class.getResourceAsStream("/bundle-example.xml"));
|
|
|
@ -1301,48 +1241,29 @@ public class XmlParserDstu2Test {
|
|
|
|
//@formatter:on
|
|
|
|
//@formatter:on
|
|
|
|
DataElement de = ourCtx.newXmlParser().parseResource(DataElement.class, input);
|
|
|
|
DataElement de = ourCtx.newXmlParser().parseResource(DataElement.class, input);
|
|
|
|
String output = ourCtx.newXmlParser().encodeResourceToString(de).replace(" xmlns=\"http://hl7.org/fhir\"", "");
|
|
|
|
String output = ourCtx.newXmlParser().encodeResourceToString(de).replace(" xmlns=\"http://hl7.org/fhir\"", "");
|
|
|
|
|
|
|
|
|
|
|
|
ElementDefinitionDt elem = de.getElement().get(0);
|
|
|
|
ElementDefinitionDt elem = de.getElement().get(0);
|
|
|
|
Binding b = elem.getBinding();
|
|
|
|
Binding b = elem.getBinding();
|
|
|
|
assertEquals("Gender", b.getName());
|
|
|
|
assertEquals("Gender", b.getName());
|
|
|
|
|
|
|
|
|
|
|
|
ResourceReferenceDt ref = (ResourceReferenceDt) b.getValueSet();
|
|
|
|
ResourceReferenceDt ref = (ResourceReferenceDt) b.getValueSet();
|
|
|
|
assertEquals("#2179414", ref.getReference().getValue());
|
|
|
|
assertEquals("#2179414", ref.getReference().getValue());
|
|
|
|
|
|
|
|
|
|
|
|
assertEquals(2, ref.getUndeclaredExtensions().size());
|
|
|
|
assertEquals(2, ref.getUndeclaredExtensions().size());
|
|
|
|
ExtensionDt ext = ref.getUndeclaredExtensions().get(0);
|
|
|
|
ExtensionDt ext = ref.getUndeclaredExtensions().get(0);
|
|
|
|
assertEquals("http://hl7.org/fhir/StructureDefinition/11179-permitted-value-valueset", ext.getUrl());
|
|
|
|
assertEquals("http://hl7.org/fhir/StructureDefinition/11179-permitted-value-valueset", ext.getUrl());
|
|
|
|
assertEquals(ResourceReferenceDt.class, ext.getValue().getClass());
|
|
|
|
assertEquals(ResourceReferenceDt.class, ext.getValue().getClass());
|
|
|
|
assertEquals("#2179414-permitted", ((ResourceReferenceDt)ext.getValue()).getReference().getValue());
|
|
|
|
assertEquals("#2179414-permitted", ((ResourceReferenceDt) ext.getValue()).getReference().getValue());
|
|
|
|
|
|
|
|
|
|
|
|
ourLog.info(ourCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(de));
|
|
|
|
ourLog.info(ourCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(de));
|
|
|
|
|
|
|
|
|
|
|
|
assertThat(output, containsString("http://hl7.org/fhir/StructureDefinition/11179-permitted-value-valueset"));
|
|
|
|
assertThat(output, containsString("http://hl7.org/fhir/StructureDefinition/11179-permitted-value-valueset"));
|
|
|
|
|
|
|
|
|
|
|
|
ourLog.info("Expected: {}", input);
|
|
|
|
ourLog.info("Expected: {}", input);
|
|
|
|
ourLog.info("Actual : {}", output);
|
|
|
|
ourLog.info("Actual : {}", output);
|
|
|
|
assertEquals(input, output);
|
|
|
|
assertEquals(input, output);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* See #191
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
|
|
|
public void testParseBundleWithLinksOfUnknownRelation() throws Exception {
|
|
|
|
|
|
|
|
String input =IOUtils.toString(XmlParserDstu2Test.class.getResourceAsStream("/bundle_orion.xml"));
|
|
|
|
|
|
|
|
ca.uhn.fhir.model.dstu2.resource.Bundle parsed = ourCtx.newXmlParser().parseResource(ca.uhn.fhir.model.dstu2.resource.Bundle.class, input);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Link link = parsed.getLink().get(0);
|
|
|
|
|
|
|
|
assertEquals("just trying add link", link.getRelation());
|
|
|
|
|
|
|
|
assertEquals("blarion", link.getUrl());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Entry entry = parsed.getEntry().get(0);
|
|
|
|
|
|
|
|
link = entry.getLink().get(0);
|
|
|
|
|
|
|
|
assertEquals("orionhealth.edit", link.getRelation());
|
|
|
|
|
|
|
|
assertEquals("Observation", link.getUrl());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
public void testParseBundleNewWithPlaceholderIds() {
|
|
|
|
public void testParseBundleNewWithPlaceholderIds() {
|
|
|
|
//@formatter:off
|
|
|
|
//@formatter:off
|
|
|
@ -1358,10 +1279,10 @@ public class XmlParserDstu2Test {
|
|
|
|
" </entry>\n" +
|
|
|
|
" </entry>\n" +
|
|
|
|
"</Bundle>\n";
|
|
|
|
"</Bundle>\n";
|
|
|
|
//@formatter:on
|
|
|
|
//@formatter:on
|
|
|
|
|
|
|
|
|
|
|
|
ca.uhn.fhir.model.dstu2.resource.Bundle parsed = ourCtx.newXmlParser().parseResource(ca.uhn.fhir.model.dstu2.resource.Bundle.class, input);
|
|
|
|
ca.uhn.fhir.model.dstu2.resource.Bundle parsed = ourCtx.newXmlParser().parseResource(ca.uhn.fhir.model.dstu2.resource.Bundle.class, input);
|
|
|
|
assertEquals("urn:oid:0.1.2.3", parsed.getEntry().get(0).getResource().getId().getValue());
|
|
|
|
assertEquals("urn:oid:0.1.2.3", parsed.getEntry().get(0).getResource().getId().getValue());
|
|
|
|
|
|
|
|
|
|
|
|
//@formatter:off
|
|
|
|
//@formatter:off
|
|
|
|
input = "<Bundle xmlns=\"http://hl7.org/fhir\">\n" +
|
|
|
|
input = "<Bundle xmlns=\"http://hl7.org/fhir\">\n" +
|
|
|
|
" <id value=\"ringholm1430996763590912\"/>\n" +
|
|
|
|
" <id value=\"ringholm1430996763590912\"/>\n" +
|
|
|
@ -1378,7 +1299,7 @@ public class XmlParserDstu2Test {
|
|
|
|
|
|
|
|
|
|
|
|
parsed = ourCtx.newXmlParser().parseResource(ca.uhn.fhir.model.dstu2.resource.Bundle.class, input);
|
|
|
|
parsed = ourCtx.newXmlParser().parseResource(ca.uhn.fhir.model.dstu2.resource.Bundle.class, input);
|
|
|
|
assertEquals("urn:oid:0.1.2.3", parsed.getEntry().get(0).getResource().getId().getValue());
|
|
|
|
assertEquals("urn:oid:0.1.2.3", parsed.getEntry().get(0).getResource().getId().getValue());
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
@ -1397,11 +1318,11 @@ public class XmlParserDstu2Test {
|
|
|
|
" </entry>\n" +
|
|
|
|
" </entry>\n" +
|
|
|
|
"</Bundle>\n";
|
|
|
|
"</Bundle>\n";
|
|
|
|
//@formatter:on
|
|
|
|
//@formatter:on
|
|
|
|
|
|
|
|
|
|
|
|
ca.uhn.fhir.model.dstu2.resource.Bundle parsed = ourCtx.newXmlParser().parseResource(ca.uhn.fhir.model.dstu2.resource.Bundle.class, input);
|
|
|
|
ca.uhn.fhir.model.dstu2.resource.Bundle parsed = ourCtx.newXmlParser().parseResource(ca.uhn.fhir.model.dstu2.resource.Bundle.class, input);
|
|
|
|
assertEquals("urn:oid:0.1.2.3", parsed.getEntry().get(0).getResource().getId().getValue());
|
|
|
|
assertEquals("urn:oid:0.1.2.3", parsed.getEntry().get(0).getResource().getId().getValue());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
public void testParseBundleNewWithPlaceholderIdsInBase2() {
|
|
|
|
public void testParseBundleNewWithPlaceholderIdsInBase2() {
|
|
|
|
//@formatter:off
|
|
|
|
//@formatter:off
|
|
|
@ -1417,10 +1338,10 @@ public class XmlParserDstu2Test {
|
|
|
|
" </entry>\n" +
|
|
|
|
" </entry>\n" +
|
|
|
|
"</Bundle>\n";
|
|
|
|
"</Bundle>\n";
|
|
|
|
//@formatter:on
|
|
|
|
//@formatter:on
|
|
|
|
|
|
|
|
|
|
|
|
ca.uhn.fhir.model.dstu2.resource.Bundle parsed = ourCtx.newXmlParser().parseResource(ca.uhn.fhir.model.dstu2.resource.Bundle.class, input);
|
|
|
|
ca.uhn.fhir.model.dstu2.resource.Bundle parsed = ourCtx.newXmlParser().parseResource(ca.uhn.fhir.model.dstu2.resource.Bundle.class, input);
|
|
|
|
assertEquals("urn:uuid:0.1.2.3", parsed.getEntry().get(0).getResource().getId().getValue());
|
|
|
|
assertEquals("urn:uuid:0.1.2.3", parsed.getEntry().get(0).getResource().getId().getValue());
|
|
|
|
|
|
|
|
|
|
|
|
//@formatter:off
|
|
|
|
//@formatter:off
|
|
|
|
input = "<Bundle xmlns=\"http://hl7.org/fhir\">\n" +
|
|
|
|
input = "<Bundle xmlns=\"http://hl7.org/fhir\">\n" +
|
|
|
|
" <id value=\"ringholm1430996763590912\"/>\n" +
|
|
|
|
" <id value=\"ringholm1430996763590912\"/>\n" +
|
|
|
@ -1434,7 +1355,7 @@ public class XmlParserDstu2Test {
|
|
|
|
" </entry>\n" +
|
|
|
|
" </entry>\n" +
|
|
|
|
"</Bundle>\n";
|
|
|
|
"</Bundle>\n";
|
|
|
|
//@formatter:on
|
|
|
|
//@formatter:on
|
|
|
|
|
|
|
|
|
|
|
|
parsed = ourCtx.newXmlParser().parseResource(ca.uhn.fhir.model.dstu2.resource.Bundle.class, input);
|
|
|
|
parsed = ourCtx.newXmlParser().parseResource(ca.uhn.fhir.model.dstu2.resource.Bundle.class, input);
|
|
|
|
assertEquals("urn:uuid:0.1.2.3", parsed.getEntry().get(0).getResource().getId().getValue());
|
|
|
|
assertEquals("urn:uuid:0.1.2.3", parsed.getEntry().get(0).getResource().getId().getValue());
|
|
|
|
|
|
|
|
|
|
|
@ -1468,10 +1389,9 @@ public class XmlParserDstu2Test {
|
|
|
|
" </entry>\n" +
|
|
|
|
" </entry>\n" +
|
|
|
|
"</Bundle>";
|
|
|
|
"</Bundle>";
|
|
|
|
//@formatter:on
|
|
|
|
//@formatter:on
|
|
|
|
|
|
|
|
|
|
|
|
Bundle b = ourCtx.newXmlParser().parseBundle(bundle);
|
|
|
|
Bundle b = ourCtx.newXmlParser().parseBundle(bundle);
|
|
|
|
assertEquals(1, b.getEntries().size());
|
|
|
|
assertEquals(1, b.getEntries().size());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -1490,10 +1410,10 @@ public class XmlParserDstu2Test {
|
|
|
|
" </entry>\n" +
|
|
|
|
" </entry>\n" +
|
|
|
|
"</Bundle>\n";
|
|
|
|
"</Bundle>\n";
|
|
|
|
//@formatter:on
|
|
|
|
//@formatter:on
|
|
|
|
|
|
|
|
|
|
|
|
Bundle parsed = ourCtx.newXmlParser().parseBundle(input);
|
|
|
|
Bundle parsed = ourCtx.newXmlParser().parseBundle(input);
|
|
|
|
assertEquals("urn:oid:0.1.2.3", parsed.getEntries().get(0).getResource().getId().getValue());
|
|
|
|
assertEquals("urn:oid:0.1.2.3", parsed.getEntries().get(0).getResource().getId().getValue());
|
|
|
|
|
|
|
|
|
|
|
|
//@formatter:off
|
|
|
|
//@formatter:off
|
|
|
|
input = "<Bundle xmlns=\"http://hl7.org/fhir\">\n" +
|
|
|
|
input = "<Bundle xmlns=\"http://hl7.org/fhir\">\n" +
|
|
|
|
" <id value=\"ringholm1430996763590912\"/>\n" +
|
|
|
|
" <id value=\"ringholm1430996763590912\"/>\n" +
|
|
|
@ -1507,18 +1427,35 @@ public class XmlParserDstu2Test {
|
|
|
|
" </entry>\n" +
|
|
|
|
" </entry>\n" +
|
|
|
|
"</Bundle>\n";
|
|
|
|
"</Bundle>\n";
|
|
|
|
//@formatter:on
|
|
|
|
//@formatter:on
|
|
|
|
|
|
|
|
|
|
|
|
parsed = ourCtx.newXmlParser().parseBundle(input);
|
|
|
|
parsed = ourCtx.newXmlParser().parseBundle(input);
|
|
|
|
assertEquals("urn:oid:0.1.2.3", parsed.getEntries().get(0).getResource().getId().getValue());
|
|
|
|
assertEquals("urn:oid:0.1.2.3", parsed.getEntries().get(0).getResource().getId().getValue());
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
public void testParseBundleWithBinary() {
|
|
|
|
public void testParseBundleWithBinary() {
|
|
|
|
// TODO: implement this test, make sure we handle ID and meta correctly in Binary
|
|
|
|
// TODO: implement this test, make sure we handle ID and meta correctly in Binary
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* See #191
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
|
|
|
public void testParseBundleWithLinksOfUnknownRelation() throws Exception {
|
|
|
|
|
|
|
|
String input = IOUtils.toString(XmlParserDstu2Test.class.getResourceAsStream("/bundle_orion.xml"));
|
|
|
|
|
|
|
|
ca.uhn.fhir.model.dstu2.resource.Bundle parsed = ourCtx.newXmlParser().parseResource(ca.uhn.fhir.model.dstu2.resource.Bundle.class, input);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Link link = parsed.getLink().get(0);
|
|
|
|
|
|
|
|
assertEquals("just trying add link", link.getRelation());
|
|
|
|
|
|
|
|
assertEquals("blarion", link.getUrl());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Entry entry = parsed.getEntry().get(0);
|
|
|
|
|
|
|
|
link = entry.getLink().get(0);
|
|
|
|
|
|
|
|
assertEquals("orionhealth.edit", link.getRelation());
|
|
|
|
|
|
|
|
assertEquals("Observation", link.getUrl());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* see #144 and #146
|
|
|
|
* see #144 and #146
|
|
|
|
*/
|
|
|
|
*/
|
|
|
@ -1534,10 +1471,10 @@ public class XmlParserDstu2Test {
|
|
|
|
Patient p = new Patient();
|
|
|
|
Patient p = new Patient();
|
|
|
|
p.addName().addFamily("patient family");
|
|
|
|
p.addName().addFamily("patient family");
|
|
|
|
o.getSubject().setResource(p);
|
|
|
|
o.getSubject().setResource(p);
|
|
|
|
|
|
|
|
|
|
|
|
String enc = parser.encodeResourceToString(o);
|
|
|
|
String enc = parser.encodeResourceToString(o);
|
|
|
|
ourLog.info(enc);
|
|
|
|
ourLog.info(enc);
|
|
|
|
|
|
|
|
|
|
|
|
//@formatter:off
|
|
|
|
//@formatter:off
|
|
|
|
assertThat(enc, stringContainsInOrder(
|
|
|
|
assertThat(enc, stringContainsInOrder(
|
|
|
|
"<Observation xmlns=\"http://hl7.org/fhir\">",
|
|
|
|
"<Observation xmlns=\"http://hl7.org/fhir\">",
|
|
|
@ -1548,15 +1485,14 @@ public class XmlParserDstu2Test {
|
|
|
|
"<reference value=\"#1\"/>"
|
|
|
|
"<reference value=\"#1\"/>"
|
|
|
|
));
|
|
|
|
));
|
|
|
|
//@formatter:on
|
|
|
|
//@formatter:on
|
|
|
|
|
|
|
|
|
|
|
|
o = parser.parseResource(Observation.class, enc);
|
|
|
|
o = parser.parseResource(Observation.class, enc);
|
|
|
|
assertEquals("obs text", o.getCode().getText());
|
|
|
|
assertEquals("obs text", o.getCode().getText());
|
|
|
|
|
|
|
|
|
|
|
|
assertNotNull(o.getSubject().getResource());
|
|
|
|
assertNotNull(o.getSubject().getResource());
|
|
|
|
p = (Patient) o.getSubject().getResource();
|
|
|
|
p = (Patient) o.getSubject().getResource();
|
|
|
|
assertEquals("patient family", p.getNameFirstRep().getFamilyAsSingleString());
|
|
|
|
assertEquals("patient family", p.getNameFirstRep().getFamilyAsSingleString());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Thanks to Alexander Kley!
|
|
|
|
* Thanks to Alexander Kley!
|
|
|
@ -1584,7 +1520,7 @@ public class XmlParserDstu2Test {
|
|
|
|
ca.uhn.fhir.model.dstu2.resource.DocumentManifest actual = ourCtx.newXmlParser().parseResource(ca.uhn.fhir.model.dstu2.resource.DocumentManifest.class, encoded);
|
|
|
|
ca.uhn.fhir.model.dstu2.resource.DocumentManifest actual = ourCtx.newXmlParser().parseResource(ca.uhn.fhir.model.dstu2.resource.DocumentManifest.class, encoded);
|
|
|
|
assertEquals(1, actual.getContained().getContainedResources().size());
|
|
|
|
assertEquals(1, actual.getContained().getContainedResources().size());
|
|
|
|
assertEquals(1, actual.getContent().size());
|
|
|
|
assertEquals(1, actual.getContent().size());
|
|
|
|
assertNotNull(((ResourceReferenceDt)actual.getContent().get(0).getP()).getResource());
|
|
|
|
assertNotNull(((ResourceReferenceDt) actual.getContent().get(0).getP()).getResource());
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -1621,10 +1557,10 @@ public class XmlParserDstu2Test {
|
|
|
|
" </entry>\n" +
|
|
|
|
" </entry>\n" +
|
|
|
|
"</Bundle>";
|
|
|
|
"</Bundle>";
|
|
|
|
//@formatter:on
|
|
|
|
//@formatter:on
|
|
|
|
|
|
|
|
|
|
|
|
Bundle b = ourCtx.newXmlParser().parseBundle(bundle);
|
|
|
|
Bundle b = ourCtx.newXmlParser().parseBundle(bundle);
|
|
|
|
assertEquals(1, b.getEntries().size());
|
|
|
|
assertEquals(1, b.getEntries().size());
|
|
|
|
|
|
|
|
|
|
|
|
Patient pt = (Patient) b.getEntries().get(0).getResource();
|
|
|
|
Patient pt = (Patient) b.getEntries().get(0).getResource();
|
|
|
|
assertEquals("http://foo/fhirBase2/Patient/1/_history/2", pt.getId().getValue());
|
|
|
|
assertEquals("http://foo/fhirBase2/Patient/1/_history/2", pt.getId().getValue());
|
|
|
|
assertEquals("2012-01-02", pt.getBirthDateElement().getValueAsString());
|
|
|
|
assertEquals("2012-01-02", pt.getBirthDateElement().getValueAsString());
|
|
|
@ -1633,22 +1569,46 @@ public class XmlParserDstu2Test {
|
|
|
|
assertEquals("POST", ResourceMetadataKeyEnum.ENTRY_TRANSACTION_METHOD.get(pt).getCode());
|
|
|
|
assertEquals("POST", ResourceMetadataKeyEnum.ENTRY_TRANSACTION_METHOD.get(pt).getCode());
|
|
|
|
assertEquals("http://foo/Patient?identifier=value", ResourceMetadataKeyEnum.LINK_SEARCH.get(pt));
|
|
|
|
assertEquals("http://foo/Patient?identifier=value", ResourceMetadataKeyEnum.LINK_SEARCH.get(pt));
|
|
|
|
assertEquals("2001-02-22T11:22:33-05:00", ResourceMetadataKeyEnum.UPDATED.get(pt).getValueAsString());
|
|
|
|
assertEquals("2001-02-22T11:22:33-05:00", ResourceMetadataKeyEnum.UPDATED.get(pt).getValueAsString());
|
|
|
|
|
|
|
|
|
|
|
|
Bundle toBundle = new Bundle();
|
|
|
|
Bundle toBundle = new Bundle();
|
|
|
|
toBundle.getLinkBase().setValue("http://foo/fhirBase1");
|
|
|
|
toBundle.getLinkBase().setValue("http://foo/fhirBase1");
|
|
|
|
toBundle.getTotalResults().setValue(1);
|
|
|
|
toBundle.getTotalResults().setValue(1);
|
|
|
|
toBundle.getLinkSelf().setValue("http://localhost:52788/Binary?_pretty=true");
|
|
|
|
toBundle.getLinkSelf().setValue("http://localhost:52788/Binary?_pretty=true");
|
|
|
|
|
|
|
|
|
|
|
|
toBundle.addResource(pt, ourCtx, "http://foo/fhirBase1");
|
|
|
|
toBundle.addResource(pt, ourCtx, "http://foo/fhirBase1");
|
|
|
|
String reEncoded = ourCtx.newXmlParser().setPrettyPrint(true).encodeBundleToString(toBundle);
|
|
|
|
String reEncoded = ourCtx.newXmlParser().setPrettyPrint(true).encodeBundleToString(toBundle);
|
|
|
|
|
|
|
|
|
|
|
|
ourLog.info(reEncoded);
|
|
|
|
ourLog.info(reEncoded);
|
|
|
|
|
|
|
|
|
|
|
|
Diff d = new Diff(new StringReader(bundle), new StringReader(reEncoded));
|
|
|
|
Diff d = new Diff(new StringReader(bundle), new StringReader(reEncoded));
|
|
|
|
assertTrue(d.toString(), d.identical());
|
|
|
|
assertTrue(d.toString(), d.identical());
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
|
|
|
public void testParseMetaUpdatedDate() {
|
|
|
|
|
|
|
|
//@formatter:off
|
|
|
|
|
|
|
|
String input = "<Bundle xmlns=\"http://hl7.org/fhir\">\n" +
|
|
|
|
|
|
|
|
" <id value=\"e2ee823b-ee4d-472d-b79d-495c23f16b99\"/>\n" +
|
|
|
|
|
|
|
|
" <meta>\n" +
|
|
|
|
|
|
|
|
" <lastUpdated value=\"2015-06-22T15:48:57.554-04:00\"/>\n" +
|
|
|
|
|
|
|
|
" </meta>\n" +
|
|
|
|
|
|
|
|
" <type value=\"searchset\"/>\n" +
|
|
|
|
|
|
|
|
" <base value=\"http://localhost:58109/fhir/context\"/>\n" +
|
|
|
|
|
|
|
|
" <total value=\"0\"/>\n" +
|
|
|
|
|
|
|
|
" <link>\n" +
|
|
|
|
|
|
|
|
" <relation value=\"self\"/>\n" +
|
|
|
|
|
|
|
|
" <url value=\"http://localhost:58109/fhir/context/Patient?_pretty=true\"/>\n" +
|
|
|
|
|
|
|
|
" </link>\n" +
|
|
|
|
|
|
|
|
"</Bundle>";
|
|
|
|
|
|
|
|
//@formatter:on
|
|
|
|
|
|
|
|
ca.uhn.fhir.model.dstu2.resource.Bundle b = ourCtx.newXmlParser().parseResource(ca.uhn.fhir.model.dstu2.resource.Bundle.class, input);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
InstantDt updated = ResourceMetadataKeyEnum.UPDATED.get(b);
|
|
|
|
|
|
|
|
assertEquals("2015-06-22T15:48:57.554-04:00", updated.getValueAsString());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
public void testParseNarrative() throws Exception {
|
|
|
|
public void testParseNarrative() throws Exception {
|
|
|
|
//@formatter:off
|
|
|
|
//@formatter:off
|
|
|
@ -1661,11 +1621,11 @@ public class XmlParserDstu2Test {
|
|
|
|
" </text>\n" +
|
|
|
|
" </text>\n" +
|
|
|
|
"</Patient>";
|
|
|
|
"</Patient>";
|
|
|
|
//@formatter:on
|
|
|
|
//@formatter:on
|
|
|
|
|
|
|
|
|
|
|
|
Patient p = ourCtx.newXmlParser().parseResource(Patient.class, res);
|
|
|
|
Patient p = ourCtx.newXmlParser().parseResource(Patient.class, res);
|
|
|
|
assertEquals(htmlNs, p.getText().getDiv().getValueAsString());
|
|
|
|
assertEquals(htmlNs, p.getText().getDiv().getValueAsString());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* See #163
|
|
|
|
* See #163
|
|
|
|
*/
|
|
|
|
*/
|
|
|
@ -1688,10 +1648,10 @@ public class XmlParserDstu2Test {
|
|
|
|
|
|
|
|
|
|
|
|
String bundleText = xmlParser.encodeResourceToString(bundle);
|
|
|
|
String bundleText = xmlParser.encodeResourceToString(bundle);
|
|
|
|
ourLog.info(bundleText);
|
|
|
|
ourLog.info(bundleText);
|
|
|
|
|
|
|
|
|
|
|
|
ca.uhn.fhir.model.dstu2.resource.Bundle reincarnatedBundle = xmlParser.parseResource (ca.uhn.fhir.model.dstu2.resource.Bundle.class, bundleText);
|
|
|
|
ca.uhn.fhir.model.dstu2.resource.Bundle reincarnatedBundle = xmlParser.parseResource(ca.uhn.fhir.model.dstu2.resource.Bundle.class, bundleText);
|
|
|
|
Patient reincarnatedPatient = reincarnatedBundle.getAllPopulatedChildElementsOfType(Patient.class).get(0);
|
|
|
|
Patient reincarnatedPatient = reincarnatedBundle.getAllPopulatedChildElementsOfType(Patient.class).get(0);
|
|
|
|
|
|
|
|
|
|
|
|
assertEquals("Patient", patient.getId().getResourceType());
|
|
|
|
assertEquals("Patient", patient.getId().getResourceType());
|
|
|
|
assertEquals("Patient", reincarnatedPatient.getId().getResourceType());
|
|
|
|
assertEquals("Patient", reincarnatedPatient.getId().getResourceType());
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -1703,6 +1663,10 @@ public class XmlParserDstu2Test {
|
|
|
|
XMLUnit.setIgnoreWhitespace(true);
|
|
|
|
XMLUnit.setIgnoreWhitespace(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static void main(String[] args) {
|
|
|
|
|
|
|
|
IGenericClient c = ourCtx.newRestfulGenericClient("http://fhir-dev.healthintersections.com.au/open");
|
|
|
|
|
|
|
|
// c.registerInterceptor(new LoggingInterceptor(true));
|
|
|
|
|
|
|
|
c.read().resource("Patient").withId("324").execute();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|