Fix #178 - Allow links in Bundle.entry when parsing old Bundle in DSTU2 mode

This commit is contained in:
jamesagnew 2015-06-04 08:19:17 -04:00
parent 177afd9f4d
commit 8c3c8e215f
5 changed files with 51 additions and 0 deletions

View File

@ -1054,6 +1054,8 @@ class ParserState<T> {
push(new PreResourceStateHapi(myEntry, myResourceType).setRequireResourceType(false));
} else if ("deleted".equals(theLocalPart)) {
push(new BundleEntryDeletedState(getPreResourceState(), myEntry));
} else if ("link".equals(theLocalPart)) {
push(new BundleLinkState(myEntry));
} else {
throw new DataFormatException("Unexpected element in entry: " + theLocalPart);
}

View File

@ -400,6 +400,8 @@ public class XmlParser extends BaseParser implements IParser {
writeOptionalTagWithValue(theEventWriter, "base", determineResourceBaseUrl(bundleBaseUrl, nextEntry));
writeBundleResourceLink(theEventWriter, "alternate", nextEntry.getLinkAlternate());
IResource resource = nextEntry.getResource();
if (resource != null && !resource.isEmpty() && !deleted) {
theEventWriter.writeStartElement("resource");

View File

@ -1053,6 +1053,7 @@ public class XmlParserDstu2Test {
assertEquals(2, parsed.getEntries().size());
assertEquals("http://foo?search", parsed.getEntries().get(0).getLinkSearch().getValue());
assertEquals("http://example.com/base/MedicationPrescription/3123/_history/1", parsed.getEntries().get(0).getLinkAlternate().getValue());
MedicationPrescription p = (MedicationPrescription) parsed.getEntries().get(0).getResource();
assertEquals("Patient/347", p.getPatient().getReference().getValue());
assertEquals("2014-08-16T05:31:17Z", ResourceMetadataKeyEnum.UPDATED.get(p).getValueAsString());
@ -1086,6 +1087,8 @@ public class XmlParserDstu2Test {
assertEquals("https://example.com/base/MedicationPrescription?patient=347&_include=MedicationPrescription.medication", parsed.getLink().get(1).getUrlElement().getValueAsString());
assertEquals(2, parsed.getEntry().size());
assertEquals("alternate", parsed.getEntry().get(0).getLink().get(0).getRelation());
assertEquals("http://example.com/base/MedicationPrescription/3123/_history/1", parsed.getEntry().get(0).getLink().get(0).getUrl());
assertEquals("http://foo?search", parsed.getEntry().get(0).getTransaction().getUrlElement().getValueAsString());
MedicationPrescription p = (MedicationPrescription) parsed.getEntry().get(0).getResource();
@ -1215,6 +1218,41 @@ public class XmlParserDstu2Test {
}
@Test
public void testParseBundleOldStyleWithUnknownLinks() throws Exception {
//@formatter:off
String bundle = "<Bundle xmlns=\"http://hl7.org/fhir\">\n" +
" <base value=\"http://foo/fhirBase1\"/>\n" +
" <total value=\"1\"/>\n" +
" <link>\n" +
" <relation value=\"foo\"/>\n" +
" <url value=\"http://localhost:52788/Binary?_pretty=true\"/>\n" +
" </link>\n" +
" <entry>\n" +
" <link>\n" +
" <relation value=\"bar\"/>\n" +
" <url value=\"http://localhost:52788/Binary?_pretty=true\"/>\n" +
" </link>\n" +
" <resource>\n" +
" <Patient xmlns=\"http://hl7.org/fhir\">\n" +
" <id value=\"1\"/>\n" +
" <meta>\n" +
" <versionId value=\"2\"/>\n" +
" <lastUpdated value=\"2001-02-22T11:22:33-05:00\"/>\n" +
" </meta>\n" +
" <birthDate value=\"2012-01-02\"/>\n" +
" </Patient>\n" +
" </resource>\n" +
" </entry>\n" +
"</Bundle>";
//@formatter:on
Bundle b = ourCtx.newXmlParser().parseBundle(bundle);
assertEquals(1, b.getEntries().size());
}
/**
* See #103
*/

View File

@ -16,6 +16,10 @@
<url value="https://example.com/base/MedicationPrescription?patient=347&amp;_include=MedicationPrescription.medication"/>
</link>
<entry>
<link>
<relation value="alternate"/>
<url value="http://example.com/base/MedicationPrescription/3123/_history/1"/>
</link>
<resource>
<MedicationPrescription>
<id value="3123"/>

View File

@ -55,6 +55,11 @@
<action type="add">
Web tester UI now supports _revinclude
</action>
<action type="fix" issue="178">
Support link elements in Bundle.entry when parsing in DSTU2 mode
using the old (non-resource) Bundle class. Thanks to GitHub user
@joedai for reporting!
</action>
</release>
<release version="1.0" date="2015-May-8">
<action type="add">