Skip to content

Commit 9ae60f1

Browse files
Ignore contained resources in IPA generation reference check so they are not removed (hapifhir#6754)
* Ignore contained resources in IPA generation reference check so they are not removed * Fix coding display to exactly match LOINC, otherwise validator complains * Add test case to verify contained resource reference being retained * Credit for hapifhir#6754 --------- Co-authored-by: James Agnew <[email protected]>
1 parent 20a1c56 commit 9ae60f1

File tree

4 files changed

+52
-2
lines changed

4 files changed

+52
-2
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
type: fix
3+
issue: 6754
4+
title: "The IPS generator will no longer strip references to contained resources when
5+
assembling data to create an IPS document. Thanks to Xun Ma for the contribution!"

hapi-fhir-jpaserver-ips/src/main/java/ca/uhn/fhir/jpa/ips/generator/IpsGeneratorSvcImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ private void updateReferencesInInclusionsForSection(
234234
.getResourceReference()
235235
.getReferenceElement()
236236
.getValue();
237-
if (isNotBlank(existingReference)) {
237+
if (isNotBlank(existingReference) && !existingReference.startsWith("#")) {
238238
existingReference = new IdType(existingReference)
239239
.toUnqualifiedVersionless()
240240
.getValue();
@@ -480,7 +480,7 @@ private CompositionBuilder createComposition(
480480

481481
compositionBuilder.setStatus(Composition.CompositionStatus.FINAL.toCode());
482482
compositionBuilder.setSubject(thePatient.getIdElement().toUnqualifiedVersionless());
483-
compositionBuilder.addTypeCoding("http://loinc.org", "60591-5", "Patient Summary Document");
483+
compositionBuilder.addTypeCoding("http://loinc.org", "60591-5", "Patient summary Document");
484484
compositionBuilder.setDate(InstantType.now());
485485
compositionBuilder.setTitle(theStrategy.createTitle(context));
486486
compositionBuilder.setConfidentiality(theStrategy.createConfidentiality(context));

hapi-fhir-jpaserver-ips/src/test/java/ca/uhn/fhir/jpa/ips/generator/IpsGeneratorSvcImplTest.java

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -617,6 +617,46 @@ public void testReferencesUpdatedInSecondaryInclusions() {
617617
assertEquals(1, illnessHistorySection.getEntry().size());
618618
}
619619

620+
/**
621+
* While resources not in the Bundle have their references removed, contained resources should retain their references. They are still included information despite not technically being in the Bundle.
622+
*/
623+
@Test
624+
public void testContainedResourceReferenceNotRemoved() {
625+
// Setup Patient
626+
initializeGenerationStrategy(
627+
List.of(t->Section.newBuilder(t).withNoInfoGenerator(null).build())
628+
);
629+
registerPatientDaoWithRead();
630+
631+
// Setup MedicationStatement with contained Medication
632+
Medication medication = createSecondaryMedication(MEDICATION_ID);
633+
MedicationStatement medicationStatement = createPrimaryMedicationStatement(MEDICATION_ID, MEDICATION_STATEMENT_ID);
634+
medicationStatement.addContained(medication);
635+
medicationStatement.getMedicationReference().setReference("#" + MEDICATION_ID);
636+
IFhirResourceDao<MedicationStatement> medicationStatementDao = registerResourceDaoWithNoData(MedicationStatement.class);
637+
when(medicationStatementDao.search(any(), any())).thenReturn(new SimpleBundleProvider(Lists.newArrayList(medicationStatement)));
638+
639+
Patient patient = new Patient();
640+
patient.setId(PATIENT_ID);
641+
ResourceMetadataKeyEnum.ENTRY_SEARCH_MODE.put(patient, BundleEntrySearchModeEnum.INCLUDE);
642+
643+
registerRemainingResourceDaos();
644+
645+
// Test
646+
Bundle outcome = (Bundle) mySvc.generateIps(new SystemRequestDetails(), new IdType(PATIENT_ID), null);
647+
648+
MedicationStatement result = (MedicationStatement) outcome
649+
.getEntry()
650+
.stream()
651+
.filter(t -> medicationStatement.fhirType().equals(t.getResource().getResourceType().name()))
652+
.map(Bundle.BundleEntryComponent::getResource)
653+
.findFirst().orElseThrow();
654+
655+
assert(result.hasMedicationReference());
656+
assert(result.getMedicationReference().hasReference());
657+
assertEquals(result.getMedicationReference().getReference(), "#" + MEDICATION_ID);
658+
}
659+
620660
@Test
621661
public void testPatientIsReturnedAsAnIncludeResource() {
622662
// Setup Patient

pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -979,6 +979,11 @@
979979
<name>Dylan Krause</name>
980980
<organization>Corbalt</organization>
981981
</developer>
982+
<developer>
983+
<id>xmhorsehead</id>
984+
<name>Xun Ma</name>
985+
<organization>CSIRO</organization>
986+
</developer>
982987
</developers>
983988

984989
<licenses>

0 commit comments

Comments
 (0)