mirror of
https://github.com/hapifhir/hapi-fhir.git
synced 2025-02-17 02:15:22 +00:00
Fix Xml parse issue: do not override the references with global contained resources if they have already been resolved
This commit is contained in:
parent
300c4e66ba
commit
2b23a6f2f0
@ -1054,6 +1054,8 @@ class ParserState<T> {
|
||||
private void stitchBundleCrossReferences() {
|
||||
final boolean bundle = "Bundle".equals(myContext.getResourceDefinition(myInstance).getName());
|
||||
if (bundle) {
|
||||
//if (myGlobalReferences.stream().map(x -> x.))
|
||||
//throw new DataFormatException("resourceType does not appear to be 'TagList', found: " + theLocalPart);
|
||||
|
||||
FhirTerser t = myContext.newTerser();
|
||||
|
||||
@ -1074,7 +1076,7 @@ class ParserState<T> {
|
||||
*/
|
||||
for (IBaseResource next : myGlobalResources) {
|
||||
IIdType id = next.getIdElement();
|
||||
if (id != null && id.isEmpty() == false) {
|
||||
if (id != null && !id.isEmpty()) {
|
||||
String resName = myContext.getResourceDefinition(next).getName();
|
||||
IIdType idType = id.withResourceType(resName).toUnqualifiedVersionless();
|
||||
idToResource.put(idType.getValueAsString(), next);
|
||||
@ -1082,10 +1084,11 @@ class ParserState<T> {
|
||||
}
|
||||
|
||||
for (IBaseReference nextRef : myGlobalReferences) {
|
||||
if (nextRef.isEmpty() == false && nextRef.getReferenceElement() != null) {
|
||||
if (!nextRef.isEmpty() && nextRef.getReferenceElement() != null) {
|
||||
IIdType unqualifiedVersionless = nextRef.getReferenceElement().toUnqualifiedVersionless();
|
||||
IBaseResource target = idToResource.get(unqualifiedVersionless.getValueAsString());
|
||||
if (target != null) {
|
||||
// resource can already be filled with local contained resource by populateTarget()
|
||||
if (target != null && nextRef.getResource() == null) {
|
||||
nextRef.setResource(target);
|
||||
}
|
||||
}
|
||||
|
@ -7,18 +7,25 @@ import static org.junit.Assert.assertNotEquals;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
import ca.uhn.fhir.test.BaseTest;
|
||||
|
||||
import org.hl7.fhir.instance.model.api.IBaseResource;
|
||||
import org.hl7.fhir.r4.model.Bundle;
|
||||
import org.hl7.fhir.r4.model.Composition;
|
||||
import org.hl7.fhir.r4.model.DocumentReference;
|
||||
import org.hl7.fhir.r4.model.MessageHeader;
|
||||
import org.hl7.fhir.r4.model.Narrative;
|
||||
import org.hl7.fhir.r4.model.Observation;
|
||||
import org.hl7.fhir.r4.model.Patient;
|
||||
import org.junit.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import ca.uhn.fhir.context.FhirContext;
|
||||
import com.google.common.base.Charsets;
|
||||
import com.google.common.io.Resources;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
|
||||
public class XmlParserR4Test extends BaseTest {
|
||||
private static final Logger ourLog = LoggerFactory.getLogger(XmlParserR4Test.class);
|
||||
@ -79,6 +86,21 @@ public class XmlParserR4Test extends BaseTest {
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseBundleWithMultipleNestedContainedResources() throws Exception {
|
||||
URL url = Resources.getResource("bundle-with-two-patient-resources.xml");
|
||||
String text = Resources.toString(url, Charsets.UTF_8);
|
||||
Bundle input = ourCtx.newXmlParser().parseResource(Bundle.class, text);
|
||||
assertEquals("12346", getPatientIdValue(input, 0));
|
||||
assertEquals("12345", getPatientIdValue(input, 1));
|
||||
}
|
||||
|
||||
private String getPatientIdValue(Bundle input, int entry) {
|
||||
final DocumentReference documentReference = (DocumentReference)input.getEntry().get(entry).getResource();
|
||||
final Patient patient = (Patient) documentReference.getSubject().getResource();
|
||||
return patient.getIdentifier().get(0).getValue();
|
||||
}
|
||||
|
||||
/**
|
||||
* See #1658
|
||||
*/
|
||||
|
@ -0,0 +1,197 @@
|
||||
<Bundle xmlns="http://hl7.org/fhir">
|
||||
<meta>
|
||||
<profile value="http://forcare.com/fhir/createCda" />
|
||||
</meta>
|
||||
<type value="transaction" />
|
||||
<entry>
|
||||
<resource>
|
||||
<DocumentReference>
|
||||
<id value="doc1" />
|
||||
<contained>
|
||||
<Patient>
|
||||
<id value="patient" />
|
||||
<identifier>
|
||||
<system value="urn:oid:1.3.6.1.4.1.21367.2005.3.7" />
|
||||
<value value="12346" />
|
||||
</identifier>
|
||||
<name>
|
||||
<use value="official" />
|
||||
<family value="Beugels" />
|
||||
<given value="Kees" />
|
||||
</name>
|
||||
<gender value="male" />
|
||||
<birthDate value="1986-11-28" />
|
||||
</Patient>
|
||||
</contained>
|
||||
<subject>
|
||||
<reference value="#patient" />
|
||||
</subject>
|
||||
<type>
|
||||
<coding>
|
||||
<system value="2.16.840.1.113883.6.1" />
|
||||
<code value="57016-8" />
|
||||
<display value="Privacy Policy Acknowledgment" />
|
||||
</coding>
|
||||
</type>
|
||||
<category>
|
||||
<coding>
|
||||
<system value="2.16.840.1.113883.6.1" />
|
||||
<code value="57016-8" />
|
||||
<display value="Privacy Policy Acknowledgment" />
|
||||
</coding>
|
||||
</category>
|
||||
<author>
|
||||
<reference value="#patient" />
|
||||
</author>
|
||||
<date value="2016-05-04T08:18:03.203Z" />
|
||||
<status value="current" />
|
||||
<description value="Hospital Privacy Consent" />
|
||||
<securityLabel>
|
||||
<coding>
|
||||
<system value="2.16.840.1.113883.5.25" />
|
||||
<code value="N" />
|
||||
<display value="Normal" />
|
||||
</coding>
|
||||
</securityLabel>
|
||||
<content>
|
||||
<attachment>
|
||||
<contentType value="text/xml" />
|
||||
<language value="en-US" />
|
||||
<url value="urn:uuid:d7d8ffca-e364-484b-bbf9-6a730854aea5" />
|
||||
</attachment>
|
||||
<format>
|
||||
<system value="1.3.6.1.4.1.19376.1.2.3" />
|
||||
<code value="urn:ihe:iti:bppc-sd:2007" />
|
||||
<display value="Basic Patient Privacy Consent (scanned part)" />
|
||||
</format>
|
||||
</content>
|
||||
<context>
|
||||
<event>
|
||||
<coding>
|
||||
<system value="1.2.826.0.1.3680043.2.1611.2.10" />
|
||||
<code value="allowMedicalDoctorsFromHospitalAToSeeDocuments" />
|
||||
<display value="I allow Medical Doctors in Hospital A to access my medical record" />
|
||||
</coding>
|
||||
</event>
|
||||
<event>
|
||||
<coding>
|
||||
<system value="1.2.826.0.1.3680043.2.1611.2.10" />
|
||||
<code value="denyMedicalDoctorsFromHospitalBToSeeDocuments" />
|
||||
<display value="I deny Medical Doctors in Hospital B to access my medical record" />
|
||||
</coding>
|
||||
</event>
|
||||
<period>
|
||||
<start value="2016-05-04T08:18:03.203Z" />
|
||||
<end value="2016-09-04T08:18:03.203Z" />
|
||||
</period>
|
||||
<facilityType>
|
||||
<coding>
|
||||
<system value="2.16.840.1.113883.5.10588" />
|
||||
<code value="HOSP" />
|
||||
<display value="Hospital" />
|
||||
</coding>
|
||||
</facilityType>
|
||||
<practiceSetting>
|
||||
<coding>
|
||||
<system value="2.16.840.1.113883.2.1.6.8" />
|
||||
<code value="300" />
|
||||
<display value="General Medicine" />
|
||||
</coding>
|
||||
</practiceSetting>
|
||||
</context>
|
||||
</DocumentReference>
|
||||
</resource>
|
||||
</entry>
|
||||
<entry>
|
||||
<resource>
|
||||
<DocumentReference xmlns="http://hl7.org/fhir">
|
||||
<id value="doc2" />
|
||||
<contained>
|
||||
<Patient xmlns="http://hl7.org/fhir">
|
||||
<id value="patient" />
|
||||
<identifier>
|
||||
<system value="urn:oid:1.3.6.1.4.1.21367.2005.3.7" />
|
||||
<value value="12345" />
|
||||
</identifier>
|
||||
<name>
|
||||
<use value="official" />
|
||||
<family value="Bakker" />
|
||||
<given value="Eddy" />
|
||||
</name>
|
||||
<gender value="male" />
|
||||
<birthDate value="1986-11-28" />
|
||||
</Patient>
|
||||
</contained>
|
||||
<subject>
|
||||
<reference value="#patient" />
|
||||
</subject>
|
||||
<type>
|
||||
<coding>
|
||||
<system value="2.16.840.1.113883.6.1" />
|
||||
<code value="57016-8" />
|
||||
<display value="Privacy Policy Acknowledgment" />
|
||||
</coding>
|
||||
</type>
|
||||
<category>
|
||||
<coding>
|
||||
<system value="2.16.840.1.113883.6.1" />
|
||||
<code value="57016-8" />
|
||||
<display value="Privacy Policy Acknowledgment" />
|
||||
</coding>
|
||||
</category>
|
||||
<author>
|
||||
<reference value="#patient" />
|
||||
</author>
|
||||
<date value="2016-05-04T08:18:03.203Z" />
|
||||
<status value="current" />
|
||||
<description value="GPs Privacy Consent" />
|
||||
<securityLabel>
|
||||
<coding>
|
||||
<system value="2.16.840.1.113883.5.25" />
|
||||
<code value="N" />
|
||||
<display value="Normal" />
|
||||
</coding>
|
||||
</securityLabel>
|
||||
<content>
|
||||
<attachment>
|
||||
<contentType value="text/xml" />
|
||||
<language value="en-US" />
|
||||
<url value="urn:uuid:d7d8ffca-e364-484b-bbf9-6a730854aea5" />
|
||||
</attachment>
|
||||
<format>
|
||||
<system value="1.3.6.1.4.1.19376.1.2.3" />
|
||||
<code value="urn:ihe:iti:bppc-sd:2007" />
|
||||
<display value="Basic Patient Privacy Consent (scanned part)" />
|
||||
</format>
|
||||
</content>
|
||||
<context>
|
||||
<event>
|
||||
<coding>
|
||||
<system value="1.2.826.0.1.3680043.2.1611.2.10" />
|
||||
<code value="denyGeneralPractitionersFromHestiaToSeeDocuments" />
|
||||
<display value="I deny Medical Doctors in Hestia General Practitioners to access my medical record" />
|
||||
</coding>
|
||||
</event>
|
||||
<period>
|
||||
<start value="2016-05-04T08:18:03.203Z" />
|
||||
<end value="2016-09-04T08:18:03.203Z" />
|
||||
</period>
|
||||
<facilityType>
|
||||
<coding>
|
||||
<system value="2.16.840.1.113883.5.10588" />
|
||||
<code value="HOSP" />
|
||||
<display value="Hospital" />
|
||||
</coding>
|
||||
</facilityType>
|
||||
<practiceSetting>
|
||||
<coding>
|
||||
<system value="2.16.840.1.113883.2.1.6.8" />
|
||||
<code value="300" />
|
||||
<display value="General Medicine" />
|
||||
</coding>
|
||||
</practiceSetting>
|
||||
</context>
|
||||
</DocumentReference>
|
||||
</resource>
|
||||
</entry>
|
||||
</Bundle>
|
Loading…
x
Reference in New Issue
Block a user