unify bulk export patient type and bulk export patient instance (#5822)

* step one of unifying the bulk exports

* adding changelog

* review points

* spotless

---------

Co-authored-by: leif stawnyczy <leifstawnyczy@leifs-mbp.home>
This commit is contained in:
TipzCM 2024-04-05 15:03:16 -04:00 committed by GitHub
parent 3a5ff47c58
commit 620b46dd0a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 49 additions and 48 deletions

View File

@ -0,0 +1,7 @@
---
type: fix
issue: 5820
title: "Unifying the code paths for Patient type export and Patient instance export.
These paths should be the same, since type is defined by spec, but instance
is just 'syntactic sugar' on top of that spec (and so should be the same).
"

View File

@ -37,7 +37,6 @@ import ca.uhn.fhir.jpa.batch.models.Batch2JobStartResponse;
import ca.uhn.fhir.jpa.bulk.export.model.BulkExportResponseJson;
import ca.uhn.fhir.jpa.model.util.JpaConstants;
import ca.uhn.fhir.jpa.partition.IRequestPartitionHelperSvc;
import ca.uhn.fhir.model.primitive.IdDt;
import ca.uhn.fhir.model.primitive.StringDt;
import ca.uhn.fhir.rest.annotation.IdParam;
import ca.uhn.fhir.rest.annotation.Operation;
@ -77,7 +76,6 @@ import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
@ -293,11 +291,15 @@ public class BulkDataExportProvider {
*/
private void validateTargetsExists(
RequestDetails theRequestDetails, String theTargetResourceName, Iterable<IIdType> theIdParams) {
RequestPartitionId partitionId = myRequestPartitionHelperService.determineReadPartitionForRequestForRead(
theRequestDetails, theTargetResourceName, theIdParams.iterator().next());
SystemRequestDetails requestDetails = new SystemRequestDetails().setRequestPartitionId(partitionId);
for (IIdType nextId : theIdParams) {
myDaoRegistry.getResourceDao(theTargetResourceName).read(nextId, requestDetails);
if (theIdParams.iterator().hasNext()) {
RequestPartitionId partitionId = myRequestPartitionHelperService.determineReadPartitionForRequestForRead(
theRequestDetails,
theTargetResourceName,
theIdParams.iterator().next());
SystemRequestDetails requestDetails = new SystemRequestDetails().setRequestPartitionId(partitionId);
for (IIdType nextId : theIdParams) {
myDaoRegistry.getResourceDao(theTargetResourceName).read(nextId, requestDetails);
}
}
}
@ -364,26 +366,18 @@ public class BulkDataExportProvider {
@OperationParam(name = JpaConstants.PARAM_EXPORT_IDENTIFIER, min = 0, max = 1, typeName = "string")
IPrimitiveType<String> theExportIdentifier,
ServletRequestDetails theRequestDetails) {
validatePreferAsyncHeader(theRequestDetails, ProviderConstants.OPERATION_EXPORT);
if (thePatient != null) {
validateTargetsExists(
theRequestDetails,
"Patient",
thePatient.stream().map(s -> new IdDt(s.getValue())).collect(Collectors.toList()));
}
List<IPrimitiveType<String>> patientIds = thePatient != null ? thePatient : new ArrayList<>();
BulkExportJobParameters BulkExportJobParameters = buildPatientBulkExportOptions(
doPatientExport(
theRequestDetails,
theOutputFormat,
theType,
theSince,
theTypeFilter,
theExportIdentifier,
thePatient,
theTypePostFetchFilterUrl);
validateResourceTypesAllContainPatientSearchParams(BulkExportJobParameters.getResourceTypes());
startJob(theRequestDetails, BulkExportJobParameters);
theTypeFilter,
theTypePostFetchFilterUrl,
patientIds);
}
/**
@ -417,9 +411,34 @@ public class BulkDataExportProvider {
@OperationParam(name = JpaConstants.PARAM_EXPORT_IDENTIFIER, min = 0, max = 1, typeName = "string")
IPrimitiveType<String> theExportIdentifier,
ServletRequestDetails theRequestDetails) {
// call the type-level export to ensure spec compliance
patientExport(
theOutputFormat,
theType,
theSince,
theTypeFilter,
theTypePostFetchFilterUrl,
List.of(theIdParam),
theExportIdentifier,
theRequestDetails);
}
private void doPatientExport(
ServletRequestDetails theRequestDetails,
IPrimitiveType<String> theOutputFormat,
IPrimitiveType<String> theType,
IPrimitiveType<Date> theSince,
IPrimitiveType<String> theExportIdentifier,
List<IPrimitiveType<String>> theTypeFilter,
List<IPrimitiveType<String>> theTypePostFetchFilterUrl,
List<IPrimitiveType<String>> thePatientIds) {
validatePreferAsyncHeader(theRequestDetails, ProviderConstants.OPERATION_EXPORT);
validateTargetsExists(theRequestDetails, "Patient", List.of(theIdParam));
validateTargetsExists(
theRequestDetails,
"Patient",
thePatientIds.stream().map(c -> new IdType(c.getValue())).collect(Collectors.toList()));
BulkExportJobParameters BulkExportJobParameters = buildPatientBulkExportOptions(
theOutputFormat,
@ -427,7 +446,7 @@ public class BulkDataExportProvider {
theSince,
theTypeFilter,
theExportIdentifier,
theIdParam,
thePatientIds,
theTypePostFetchFilterUrl);
validateResourceTypesAllContainPatientSearchParams(BulkExportJobParameters.getResourceTypes());
@ -670,31 +689,6 @@ public class BulkDataExportProvider {
return BulkExportJobParameters;
}
private BulkExportJobParameters buildPatientBulkExportOptions(
IPrimitiveType<String> theOutputFormat,
IPrimitiveType<String> theType,
IPrimitiveType<Date> theSince,
List<IPrimitiveType<String>> theTypeFilter,
IPrimitiveType<String> theExportIdentifier,
IIdType thePatientId,
List<IPrimitiveType<String>> theTypePostFetchFilterUrl) {
IPrimitiveType<String> type = theType;
if (type == null) {
// set type to all patient compartment resources if it is null
type = new StringDt(String.join(",", getPatientCompartmentResources()));
}
BulkExportJobParameters BulkExportJobParameters = buildBulkExportJobParameters(
theOutputFormat,
type,
theSince,
theTypeFilter,
theExportIdentifier,
ExportStyle.PATIENT,
theTypePostFetchFilterUrl);
BulkExportJobParameters.setPatientIds(Collections.singleton(thePatientId.getValue()));
return BulkExportJobParameters;
}
private BulkExportJobParameters buildBulkExportJobParameters(
IPrimitiveType<String> theOutputFormat,
IPrimitiveType<String> theType,