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.bulk.export.model.BulkExportResponseJson;
|
||||||
import ca.uhn.fhir.jpa.model.util.JpaConstants;
|
import ca.uhn.fhir.jpa.model.util.JpaConstants;
|
||||||
import ca.uhn.fhir.jpa.partition.IRequestPartitionHelperSvc;
|
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.model.primitive.StringDt;
|
||||||
import ca.uhn.fhir.rest.annotation.IdParam;
|
import ca.uhn.fhir.rest.annotation.IdParam;
|
||||||
import ca.uhn.fhir.rest.annotation.Operation;
|
import ca.uhn.fhir.rest.annotation.Operation;
|
||||||
|
@ -77,7 +76,6 @@ import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -293,13 +291,17 @@ public class BulkDataExportProvider {
|
||||||
*/
|
*/
|
||||||
private void validateTargetsExists(
|
private void validateTargetsExists(
|
||||||
RequestDetails theRequestDetails, String theTargetResourceName, Iterable<IIdType> theIdParams) {
|
RequestDetails theRequestDetails, String theTargetResourceName, Iterable<IIdType> theIdParams) {
|
||||||
|
if (theIdParams.iterator().hasNext()) {
|
||||||
RequestPartitionId partitionId = myRequestPartitionHelperService.determineReadPartitionForRequestForRead(
|
RequestPartitionId partitionId = myRequestPartitionHelperService.determineReadPartitionForRequestForRead(
|
||||||
theRequestDetails, theTargetResourceName, theIdParams.iterator().next());
|
theRequestDetails,
|
||||||
|
theTargetResourceName,
|
||||||
|
theIdParams.iterator().next());
|
||||||
SystemRequestDetails requestDetails = new SystemRequestDetails().setRequestPartitionId(partitionId);
|
SystemRequestDetails requestDetails = new SystemRequestDetails().setRequestPartitionId(partitionId);
|
||||||
for (IIdType nextId : theIdParams) {
|
for (IIdType nextId : theIdParams) {
|
||||||
myDaoRegistry.getResourceDao(theTargetResourceName).read(nextId, requestDetails);
|
myDaoRegistry.getResourceDao(theTargetResourceName).read(nextId, requestDetails);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void validateResourceTypesAllContainPatientSearchParams(Collection<String> theResourceTypes) {
|
private void validateResourceTypesAllContainPatientSearchParams(Collection<String> theResourceTypes) {
|
||||||
if (theResourceTypes != null) {
|
if (theResourceTypes != null) {
|
||||||
|
@ -364,26 +366,18 @@ public class BulkDataExportProvider {
|
||||||
@OperationParam(name = JpaConstants.PARAM_EXPORT_IDENTIFIER, min = 0, max = 1, typeName = "string")
|
@OperationParam(name = JpaConstants.PARAM_EXPORT_IDENTIFIER, min = 0, max = 1, typeName = "string")
|
||||||
IPrimitiveType<String> theExportIdentifier,
|
IPrimitiveType<String> theExportIdentifier,
|
||||||
ServletRequestDetails theRequestDetails) {
|
ServletRequestDetails theRequestDetails) {
|
||||||
validatePreferAsyncHeader(theRequestDetails, ProviderConstants.OPERATION_EXPORT);
|
|
||||||
|
|
||||||
if (thePatient != null) {
|
List<IPrimitiveType<String>> patientIds = thePatient != null ? thePatient : new ArrayList<>();
|
||||||
validateTargetsExists(
|
|
||||||
|
doPatientExport(
|
||||||
theRequestDetails,
|
theRequestDetails,
|
||||||
"Patient",
|
|
||||||
thePatient.stream().map(s -> new IdDt(s.getValue())).collect(Collectors.toList()));
|
|
||||||
}
|
|
||||||
|
|
||||||
BulkExportJobParameters BulkExportJobParameters = buildPatientBulkExportOptions(
|
|
||||||
theOutputFormat,
|
theOutputFormat,
|
||||||
theType,
|
theType,
|
||||||
theSince,
|
theSince,
|
||||||
theTypeFilter,
|
|
||||||
theExportIdentifier,
|
theExportIdentifier,
|
||||||
thePatient,
|
theTypeFilter,
|
||||||
theTypePostFetchFilterUrl);
|
theTypePostFetchFilterUrl,
|
||||||
validateResourceTypesAllContainPatientSearchParams(BulkExportJobParameters.getResourceTypes());
|
patientIds);
|
||||||
|
|
||||||
startJob(theRequestDetails, BulkExportJobParameters);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -417,9 +411,34 @@ public class BulkDataExportProvider {
|
||||||
@OperationParam(name = JpaConstants.PARAM_EXPORT_IDENTIFIER, min = 0, max = 1, typeName = "string")
|
@OperationParam(name = JpaConstants.PARAM_EXPORT_IDENTIFIER, min = 0, max = 1, typeName = "string")
|
||||||
IPrimitiveType<String> theExportIdentifier,
|
IPrimitiveType<String> theExportIdentifier,
|
||||||
ServletRequestDetails theRequestDetails) {
|
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);
|
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(
|
BulkExportJobParameters BulkExportJobParameters = buildPatientBulkExportOptions(
|
||||||
theOutputFormat,
|
theOutputFormat,
|
||||||
|
@ -427,7 +446,7 @@ public class BulkDataExportProvider {
|
||||||
theSince,
|
theSince,
|
||||||
theTypeFilter,
|
theTypeFilter,
|
||||||
theExportIdentifier,
|
theExportIdentifier,
|
||||||
theIdParam,
|
thePatientIds,
|
||||||
theTypePostFetchFilterUrl);
|
theTypePostFetchFilterUrl);
|
||||||
validateResourceTypesAllContainPatientSearchParams(BulkExportJobParameters.getResourceTypes());
|
validateResourceTypesAllContainPatientSearchParams(BulkExportJobParameters.getResourceTypes());
|
||||||
|
|
||||||
|
@ -670,31 +689,6 @@ public class BulkDataExportProvider {
|
||||||
return BulkExportJobParameters;
|
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(
|
private BulkExportJobParameters buildBulkExportJobParameters(
|
||||||
IPrimitiveType<String> theOutputFormat,
|
IPrimitiveType<String> theOutputFormat,
|
||||||
IPrimitiveType<String> theType,
|
IPrimitiveType<String> theType,
|
||||||
|
|
Loading…
Reference in New Issue