Fix #158 - Don't encode empty tags

This commit is contained in:
jamesagnew 2015-07-18 17:35:54 -04:00
parent af0db664db
commit a35d20b999
9 changed files with 881 additions and 836 deletions

View File

@ -138,9 +138,12 @@ public class Tag extends BaseElement implements IElement {
return result; return result;
} }
/**
* Returns <code>true</code> if either scheme or term is populated.
*/
@Override @Override
public boolean isEmpty() { public boolean isEmpty() {
return StringUtils.isBlank(myLabel) && StringUtils.isBlank(myScheme) && StringUtils.isBlank(myTerm); return StringUtils.isBlank(myScheme) && StringUtils.isBlank(myTerm);
} }
/** /**

View File

@ -191,7 +191,12 @@ public class TagList implements Set<Tag>, Serializable, IBase {
@Override @Override
public boolean isEmpty() { public boolean isEmpty() {
return myTagSet.isEmpty(); for (Tag next : myTagSet) {
if (next.isEmpty() == false) {
return false;
}
}
return true;
} }
@Override @Override

View File

@ -754,6 +754,9 @@ public class JsonParser extends BaseParser implements IParser {
if (tags != null && tags.isEmpty() == false) { if (tags != null && tags.isEmpty() == false) {
theEventWriter.writeStartArray("tag"); theEventWriter.writeStartArray("tag");
for (Tag tag : tags) { for (Tag tag : tags) {
if (tag.isEmpty()) {
continue;
}
theEventWriter.writeStartObject(); theEventWriter.writeStartObject();
writeOptionalTagWithTextNode(theEventWriter, "system", tag.getScheme()); writeOptionalTagWithTextNode(theEventWriter, "system", tag.getScheme());
writeOptionalTagWithTextNode(theEventWriter, "code", tag.getTerm()); writeOptionalTagWithTextNode(theEventWriter, "code", tag.getTerm());

View File

@ -820,6 +820,9 @@ public class XmlParser extends BaseParser implements IParser {
} }
if (tags != null) { if (tags != null) {
for (Tag tag : tags) { for (Tag tag : tags) {
if (tag.isEmpty()) {
continue;
}
theEventWriter.writeStartElement("tag"); theEventWriter.writeStartElement("tag");
writeOptionalTagWithValue(theEventWriter, "system", tag.getScheme()); writeOptionalTagWithValue(theEventWriter, "system", tag.getScheme());
writeOptionalTagWithValue(theEventWriter, "code", tag.getTerm()); writeOptionalTagWithValue(theEventWriter, "code", tag.getTerm());

View File

@ -36,6 +36,12 @@
<artifactId>junit</artifactId> <artifactId>junit</artifactId>
<version>${junit_version}</version> <version>${junit_version}</version>
<scope>test</scope> <scope>test</scope>
<exclusions>
<exclusion>
<artifactId>hamcrest-core</artifactId>
<groupId>org.hamcrest</groupId>
</exclusion>
</exclusions>
</dependency> </dependency>
<dependency> <dependency>
<groupId>xmlunit</groupId> <groupId>xmlunit</groupId>

View File

@ -92,31 +92,7 @@ public class XmlParserDstu2Test {
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());
} }
@ -137,7 +113,7 @@ public class XmlParserDstu2Test {
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());
} }
@ -156,9 +132,6 @@ public class XmlParserDstu2Test {
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();
@ -173,42 +146,6 @@ public class XmlParserDstu2Test {
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();
@ -298,13 +234,12 @@ public class XmlParserDstu2Test {
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,9 +283,7 @@ 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>"));
@ -437,7 +370,7 @@ public class XmlParserDstu2Test {
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());
@ -451,7 +384,6 @@ public class XmlParserDstu2Test {
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();
@ -539,7 +471,7 @@ public class XmlParserDstu2Test {
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());
@ -609,7 +541,7 @@ 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);
@ -692,7 +624,6 @@ public class XmlParserDstu2Test {
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();
@ -708,6 +639,22 @@ public class XmlParserDstu2Test {
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
*/ */
@ -738,33 +685,15 @@ public class XmlParserDstu2Test {
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);
@ -895,6 +796,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() {
IParser parser = ourCtx.newXmlParser(); IParser parser = ourCtx.newXmlParser();
@ -916,6 +854,7 @@ public class XmlParserDstu2Test {
} }
@Test @Test
public void testEncodeNonContained() { public void testEncodeNonContained() {
// Create an organization // Create an organization
@ -956,6 +895,7 @@ public class XmlParserDstu2Test {
} }
@Test @Test
public void testMoreExtensions() throws Exception { public void testMoreExtensions() throws Exception {
@ -1313,7 +1253,7 @@ public class XmlParserDstu2Test {
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));
@ -1324,25 +1264,6 @@ public class XmlParserDstu2Test {
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
@ -1472,7 +1393,6 @@ public class XmlParserDstu2Test {
Bundle b = ourCtx.newXmlParser().parseBundle(bundle); Bundle b = ourCtx.newXmlParser().parseBundle(bundle);
assertEquals(1, b.getEntries().size()); assertEquals(1, b.getEntries().size());
} }
@Test @Test
@ -1513,12 +1433,29 @@ public class XmlParserDstu2Test {
} }
@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
*/ */
@ -1557,7 +1494,6 @@ public class XmlParserDstu2Test {
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());
} }
@ -1649,6 +1585,30 @@ public class XmlParserDstu2Test {
} }
@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
@ -1689,7 +1649,7 @@ 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());
@ -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();
}
} }

View File

@ -59,6 +59,8 @@ import org.xml.sax.SAXException;
import ca.uhn.fhir.context.ConfigurationException; import ca.uhn.fhir.context.ConfigurationException;
import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.model.api.ResourceMetadataKeyEnum;
import ca.uhn.fhir.model.api.TagList;
import ca.uhn.fhir.model.base.composite.BaseNarrativeDt; import ca.uhn.fhir.model.base.composite.BaseNarrativeDt;
import ca.uhn.fhir.narrative.INarrativeGenerator; import ca.uhn.fhir.narrative.INarrativeGenerator;
import ca.uhn.fhir.parser.JsonParserHl7OrgTest.MyPatientWithOneDeclaredAddressExtension; import ca.uhn.fhir.parser.JsonParserHl7OrgTest.MyPatientWithOneDeclaredAddressExtension;
@ -598,6 +600,27 @@ public class XmlParserHl7OrgDstu2Test {
} }
/**
* #158
*/
@Test
public void testEncodeEmptyTag() {
Patient p = new Patient();
p.getMeta().addTag();
String encoded = ourCtx.newXmlParser().encodeResourceToString(p);
assertThat(encoded, not(containsString("tag")));
// With tag
p = new Patient();
p.getMeta().addTag().setSystem("sys").setCode("code");
encoded = ourCtx.newXmlParser().encodeResourceToString(p);
assertThat(encoded, (containsString("tag")));
}
/** /**
* Thanks to Alexander Kley! * Thanks to Alexander Kley!
*/ */

View File

@ -37,6 +37,10 @@
into a BaseServerResponseException. This is useful so that servers using ResponseHighlighterInterceptor into a BaseServerResponseException. This is useful so that servers using ResponseHighlighterInterceptor
will highlight exceptions even if they aren't created with an OperationOutcome. will highlight exceptions even if they aren't created with an OperationOutcome.
</action> </action>
<action type="fix" issue="158">
XmlParser and JsonParser in DSTU2 mode should not encode empty
tags in resource. Thanks to Bill De Beaubien for reporting!
</action>
</release> </release>
<release version="1.1" date="2015-07-13"> <release version="1.1" date="2015-07-13">
<action type="add"> <action type="add">