Add changelog, add test, add implementation to short-circuit logic in group export (#3701)

This commit is contained in:
Tadgh 2022-06-15 11:22:42 -04:00 committed by GitHub
parent e2effc65b8
commit bf2f126c91
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 70 additions and 1 deletions

View File

@ -0,0 +1,6 @@
---
type: fix
issue: 3700
jira: SMILE-4488
title: "Previously, Group Bulk Export would expand into other groups, due to the nature of `Group.member` being part of the patient search compartment.
This has been fixed, and now, Group Bulk Export will only ever export the Group resource specified in the request, regardless of patient membership."

View File

@ -51,6 +51,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
@ -91,6 +92,10 @@ public class GroupBulkItemReader extends BaseJpaBulkItemReader implements ItemRe
@Override
protected Iterator<ResourcePersistentId> getResourcePidIterator() {
//Short circuit out if we detect we are attempting to export groups.
if (myResourceType.equalsIgnoreCase("Group")) {
return getSingletonGroupIterator();
}
//Short circuit out if we detect we are attempting to extract patients
if (myResourceType.equalsIgnoreCase("Patient")) {
@ -98,7 +103,6 @@ public class GroupBulkItemReader extends BaseJpaBulkItemReader implements ItemRe
}
//First lets expand the group so we get a list of all patient IDs of the group, and MDM-matched patient IDs of the group.
Set<String> expandedMemberResourceIds = expandAllPatientPidsFromGroup();
if (ourLog.isDebugEnabled()) {
@ -119,6 +123,18 @@ public class GroupBulkItemReader extends BaseJpaBulkItemReader implements ItemRe
return myExpandedMemberPids.iterator();
}
/**
* If we are exporting a group during group export, we intentionally do not expand to other groups the member might be part of.
* This code short-circuits the standard "expand group into its members then check the search compartment" logic.
*
* @return An iterator containing a single Group ID.
*/
private Iterator<ResourcePersistentId> getSingletonGroupIterator() {
String stringedId = new IdDt(myGroupId).getIdPart();
ResourcePersistentId groupId = myIdHelperService.resolveResourcePersistentIds(RequestPartitionId.allPartitions(), myResourceType, stringedId);
return Collections.singletonList(groupId).iterator();
}
/**
* In case we are doing a Group Bulk Export and resourceType `Patient` is requested, we can just return the group members,
* possibly expanded by MDM, and don't have to go and fetch other resource DAOs.

View File

@ -967,7 +967,54 @@ public class BulkDataExportSvcImplR4Test extends BaseJpaR4Test {
assertThat(nextContents, is(containsString("CT5")));
assertThat(nextContents, is(containsString("CT7")));
assertThat(nextContents, is(containsString("CT9")));
}
/**
* See https://github.com/hapifhir/hapi-fhir/issues/3700
*/
@Test
public void testGroupBatchJobDoesNotExpandOtherGroups() {
//Given there are two groups, and they each contain the same member
Patient patient = new Patient();
patient.setId("patient1");
IIdType id = myPatientDao.update(patient).getId();
Group g1 = new Group();
g1.setId("group1");
g1.addMember().setEntity(new Reference(id));
Group g2 = new Group();
g2.setId("group2");
g2.addMember().setEntity(new Reference(id));
IIdType group1Id = myGroupDao.update(g1).getId();
IIdType group2Id = myGroupDao.update(g2).getId();
//When we attempt to export one of those groups
BulkDataExportOptions bulkDataExportOptions = new BulkDataExportOptions();
bulkDataExportOptions.setOutputFormat(null);
bulkDataExportOptions.setResourceTypes(Sets.newHashSet("Group"));
bulkDataExportOptions.setSince(null);
bulkDataExportOptions.setFilters(null);
bulkDataExportOptions.setGroupId(group1Id);
bulkDataExportOptions.setExpandMdm(false);
bulkDataExportOptions.setExportStyle(BulkDataExportOptions.ExportStyle.GROUP);
// Create a bulk job
IBulkDataExportSvc.JobInfo jobDetails = myBulkDataExportSvc.submitJob(bulkDataExportOptions, true, null);
myBulkDataExportJobSchedulingHelper.startSubmittedJobs();
awaitAllBulkJobCompletions();
IBulkDataExportSvc.JobInfo jobInfo = myBulkDataExportSvc.getJobInfoOrThrowResourceNotFound(jobDetails.getJobId());
assertThat(jobInfo.getStatus(), equalTo(BulkExportJobStatusEnum.COMPLETE));
assertThat(jobInfo.getFiles().size(), equalTo(1));
assertThat(jobInfo.getFiles().get(0).getResourceType(), is(equalTo("Group")));
//Then only the requested group should be exported.
String nextContents = getBinaryContents(jobInfo, 0);
assertThat(nextContents, is(containsString("group1")));
assertThat(nextContents, is(not(containsString("group2"))));
}