From 5f5b3db4a1f1729c042589d051a7efc438290e61 Mon Sep 17 00:00:00 2001 From: Tadgh Date: Thu, 31 Aug 2023 11:58:28 -0700 Subject: [PATCH] Fix, test changelog (#5266) --- .../5265-group-bulk-export-forward-refs.yaml | 4 ++ .../fhir/jpa/bulk/BulkExportUseCaseTest.java | 41 +++++++++++++++++++ .../jobs/export/BulkDataExportProvider.java | 4 ++ 3 files changed, 49 insertions(+) create mode 100644 hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/7_0_0/5265-group-bulk-export-forward-refs.yaml diff --git a/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/7_0_0/5265-group-bulk-export-forward-refs.yaml b/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/7_0_0/5265-group-bulk-export-forward-refs.yaml new file mode 100644 index 00000000000..c18ae9b1b45 --- /dev/null +++ b/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/7_0_0/5265-group-bulk-export-forward-refs.yaml @@ -0,0 +1,4 @@ +--- +type: fix +jira: SMILE-7307 +title: "Previously, executing a Group Bulk Export without defining the `_type` parameter would accidentally omit `Patient` and `Organization` types. This has been corrected." diff --git a/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/bulk/BulkExportUseCaseTest.java b/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/bulk/BulkExportUseCaseTest.java index 5329366c9f9..a403417ffa4 100644 --- a/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/bulk/BulkExportUseCaseTest.java +++ b/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/bulk/BulkExportUseCaseTest.java @@ -604,6 +604,47 @@ public class BulkExportUseCaseTest extends BaseResourceProviderR4Test { @Nested public class GroupBulkExportTests { + + @Test + public void testGroupExportSuccessfulyExportsPatientForwardReferences() { + BundleBuilder bb = new BundleBuilder(myFhirContext); + + Group group = new Group(); + group.setId("Group/G"); + group.setActive(true); + bb.addTransactionUpdateEntry(group); + + Practitioner pract = new Practitioner(); + pract.setId("PRACT-IN-GROUP"); + bb.addTransactionUpdateEntry(pract); + + Organization organization = new Organization(); + organization.setId("ORG-IN-GROUP"); + bb.addTransactionUpdateEntry(organization); + + Patient patient = new Patient(); + patient.setId("PAT-IN-GROUP"); + patient.setGender(Enumerations.AdministrativeGender.FEMALE); + patient.setActive(true); + patient.setManagingOrganization(new Reference("Organization/ORG-IN-GROUP")); + patient.setGeneralPractitioner(List.of(new Reference("Practitioner/PRACT-IN-GROUP"))); + bb.addTransactionUpdateEntry(patient); + + group.addMember().getEntity().setReference("Patient/PAT-IN-GROUP"); + + myClient.transaction().withBundle(bb.getBundle()).execute(); + + HashSet resourceTypes = Sets.newHashSet(); + BulkExportJobResults bulkExportJobResults = startGroupBulkExportJobAndAwaitCompletion(resourceTypes, new HashSet<>(), "G"); + Map> firstMap = convertJobResultsToResources(bulkExportJobResults); + + assertThat(firstMap.keySet(), hasSize(4)); + assertThat(firstMap.get("Group"), hasSize(1)); + assertThat(firstMap.get("Patient"), hasSize(1)); + assertThat(firstMap.get("Practitioner"), hasSize(1)); + assertThat(firstMap.get("Organization"), hasSize(1)); + } + @Test public void testVeryLargeGroup() { diff --git a/hapi-fhir-storage-batch2-jobs/src/main/java/ca/uhn/fhir/batch2/jobs/export/BulkDataExportProvider.java b/hapi-fhir-storage-batch2-jobs/src/main/java/ca/uhn/fhir/batch2/jobs/export/BulkDataExportProvider.java index d68bdea9ae0..9fd2ef9d265 100644 --- a/hapi-fhir-storage-batch2-jobs/src/main/java/ca/uhn/fhir/batch2/jobs/export/BulkDataExportProvider.java +++ b/hapi-fhir-storage-batch2-jobs/src/main/java/ca/uhn/fhir/batch2/jobs/export/BulkDataExportProvider.java @@ -264,6 +264,10 @@ public class BulkDataExportProvider { } else { // all patient resource types Set groupTypes = new HashSet<>(getPatientCompartmentResources()); + + // Add the forward reference resource types from the patients, e.g. Practitioner, Organization + groupTypes.addAll(PATIENT_BULK_EXPORT_FORWARD_REFERENCE_RESOURCE_TYPES); + groupTypes.removeIf(t -> !myDaoRegistry.isResourceTypeSupported(t)); BulkExportJobParameters.setResourceTypes(groupTypes); }