From fc82ed4e44885b898e77e8bfe3f78bf51677ae20 Mon Sep 17 00:00:00 2001 From: James Agnew Date: Wed, 28 Sep 2022 12:46:00 -0400 Subject: [PATCH] One more tweak to #4093 (#4094) * One more tweak to #4093 * Add changelog --- ...revent-mixed-restypes-in-bulk-export2.yaml | 5 +++ .../uhn/fhir/jpa/bulk/BulkDataExportTest.java | 41 +++++++++++++++++++ .../jobs/export/FetchResourceIdsStep.java | 15 ++++++- 3 files changed, 59 insertions(+), 2 deletions(-) create mode 100644 hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/6_2_0/4094-prevent-mixed-restypes-in-bulk-export2.yaml diff --git a/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/6_2_0/4094-prevent-mixed-restypes-in-bulk-export2.yaml b/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/6_2_0/4094-prevent-mixed-restypes-in-bulk-export2.yaml new file mode 100644 index 00000000000..ecb12b165e1 --- /dev/null +++ b/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/6_2_0/4094-prevent-mixed-restypes-in-bulk-export2.yaml @@ -0,0 +1,5 @@ +--- +type: fix +issue: 4094 +title: "A previous fix resulted in Bulk Export files containing duplicate resources, which is + not allowed in the bulk data access IG. This has been corrected." diff --git a/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/bulk/BulkDataExportTest.java b/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/bulk/BulkDataExportTest.java index 22ea23c5c22..9bda1c7a9f2 100644 --- a/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/bulk/BulkDataExportTest.java +++ b/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/bulk/BulkDataExportTest.java @@ -363,6 +363,47 @@ public class BulkDataExportTest extends BaseResourceProviderR4Test { verifyBulkExportResults(options, List.of("Patient/P1", practId, orgId, encId, encId2, locId), List.of("Patient/P2", orgId2, encId3, locId2)); } + @Test + public void testGroupBulkExportGroupIncludePractitionerLinkedFromTwoResourceTypes() { + // Create some resources + Practitioner practitioner = new Practitioner(); + practitioner.setActive(true); + String practId = myClient.create().resource(practitioner).execute().getId().toUnqualifiedVersionless().getValue(); + + Patient patient = new Patient(); + patient.setId("P1"); + patient.setActive(true); + patient.addGeneralPractitioner().setReference(practId); + myClient.update().resource(patient).execute(); + + Encounter encounter = new Encounter(); + encounter.setStatus(Encounter.EncounterStatus.INPROGRESS); + encounter.setSubject(new Reference("Patient/P1")); + encounter.addParticipant().setIndividual(new Reference(practId)); + String encId = myClient.create().resource(encounter).execute().getId().toUnqualifiedVersionless().getValue(); + + Observation observation = new Observation(); + observation.setStatus(Observation.ObservationStatus.FINAL); + observation.setSubject(new Reference("Patient/P1")); + observation.getPerformerFirstRep().setReference(practId); + String obsId = myClient.create().resource(observation).execute().getId().toUnqualifiedVersionless().getValue(); + + Group group = new Group(); + group.setId("Group/G1"); + group.setActive(true); + group.addMember().getEntity().setReference("Patient/P1"); + myClient.update().resource(group).execute(); + + // set the export options + BulkDataExportOptions options = new BulkDataExportOptions(); + options.setResourceTypes(Sets.newHashSet("Patient", "Encounter", "Observation")); + options.setGroupId(new IdType("Group", "G1")); + options.setFilters(new HashSet<>()); + options.setExportStyle(BulkDataExportOptions.ExportStyle.GROUP); + options.setOutputFormat(Constants.CT_FHIR_NDJSON); + verifyBulkExportResults(options, List.of("Patient/P1", practId, encId, obsId), Collections.emptyList()); + } + @Test public void testGroupBulkExportGroupIncludeDevice_ShouldShowUp() { // Create some resources diff --git a/hapi-fhir-storage-batch2-jobs/src/main/java/ca/uhn/fhir/batch2/jobs/export/FetchResourceIdsStep.java b/hapi-fhir-storage-batch2-jobs/src/main/java/ca/uhn/fhir/batch2/jobs/export/FetchResourceIdsStep.java index 6238ca12e6b..153d318ca39 100644 --- a/hapi-fhir-storage-batch2-jobs/src/main/java/ca/uhn/fhir/batch2/jobs/export/FetchResourceIdsStep.java +++ b/hapi-fhir-storage-batch2-jobs/src/main/java/ca/uhn/fhir/batch2/jobs/export/FetchResourceIdsStep.java @@ -39,8 +39,10 @@ import org.springframework.beans.factory.annotation.Autowired; import javax.annotation.Nonnull; import java.util.ArrayList; +import java.util.HashSet; import java.util.Iterator; import java.util.List; +import java.util.Set; public class FetchResourceIdsStep implements IFirstJobStepWorker { private static final Logger ourLog = LoggerFactory.getLogger(FetchResourceIdsStep.class); @@ -67,6 +69,8 @@ public class FetchResourceIdsStep implements IFirstJobStepWorker submittedIds = new HashSet<>(); + for (String resourceType : params.getResourceTypes()) { providerParams.setResourceType(resourceType); @@ -81,12 +85,19 @@ public class FetchResourceIdsStep implements IFirstJobStepWorker= so that we know (with confidence) // that every batch is <= 1000 items if (idsToSubmit.size() >= MAX_IDS_TO_BATCH) {