One more tweak to #4093 (#4094)

* One more tweak to #4093

* Add changelog
This commit is contained in:
James Agnew 2022-09-28 12:46:00 -04:00 committed by GitHub
parent 31e13e6adb
commit fc82ed4e44
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 59 additions and 2 deletions

View File

@ -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."

View File

@ -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

View File

@ -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<BulkExportJobParameters, BulkExportIdList> {
private static final Logger ourLog = LoggerFactory.getLogger(FetchResourceIdsStep.class);
@ -67,6 +69,8 @@ public class FetchResourceIdsStep implements IFirstJobStepWorker<BulkExportJobPa
int submissionCount = 0;
try {
Set<Id> submittedIds = new HashSet<>();
for (String resourceType : params.getResourceTypes()) {
providerParams.setResourceType(resourceType);
@ -81,12 +85,19 @@ public class FetchResourceIdsStep implements IFirstJobStepWorker<BulkExportJobPa
while (pidIterator.hasNext()) {
ResourcePersistentId pid = pidIterator.next();
Id id;
if (pid.getResourceType() != null) {
idsToSubmit.add(Id.getIdFromPID(pid, pid.getResourceType()));
id = Id.getIdFromPID(pid, pid.getResourceType());
} else {
idsToSubmit.add(Id.getIdFromPID(pid, resourceType));
id = Id.getIdFromPID(pid, resourceType);
}
if (!submittedIds.add(id)) {
continue;
}
idsToSubmit.add(id);
// >= so that we know (with confidence)
// that every batch is <= 1000 items
if (idsToSubmit.size() >= MAX_IDS_TO_BATCH) {