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:
parent
3a5ff47c58
commit
620b46dd0a
|
@ -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).
|
||||
"
|
|
@ -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,13 +291,17 @@ public class BulkDataExportProvider {
|
|||
*/
|
||||
private void validateTargetsExists(
|
||||
RequestDetails theRequestDetails, String theTargetResourceName, Iterable<IIdType> theIdParams) {
|
||||
if (theIdParams.iterator().hasNext()) {
|
||||
RequestPartitionId partitionId = myRequestPartitionHelperService.determineReadPartitionForRequestForRead(
|
||||
theRequestDetails, theTargetResourceName, theIdParams.iterator().next());
|
||||
theRequestDetails,
|
||||
theTargetResourceName,
|
||||
theIdParams.iterator().next());
|
||||
SystemRequestDetails requestDetails = new SystemRequestDetails().setRequestPartitionId(partitionId);
|
||||
for (IIdType nextId : theIdParams) {
|
||||
myDaoRegistry.getResourceDao(theTargetResourceName).read(nextId, requestDetails);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void validateResourceTypesAllContainPatientSearchParams(Collection<String> theResourceTypes) {
|
||||
if (theResourceTypes != null) {
|
||||
|
@ -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(
|
||||
List<IPrimitiveType<String>> patientIds = thePatient != null ? thePatient : new ArrayList<>();
|
||||
|
||||
doPatientExport(
|
||||
theRequestDetails,
|
||||
"Patient",
|
||||
thePatient.stream().map(s -> new IdDt(s.getValue())).collect(Collectors.toList()));
|
||||
}
|
||||
|
||||
BulkExportJobParameters BulkExportJobParameters = buildPatientBulkExportOptions(
|
||||
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,
|
||||
|
|
Loading…
Reference in New Issue