Add DSTU3 clear operation

This commit is contained in:
Tadgh 2020-07-23 09:37:11 -07:00
parent e9adebc412
commit 9491a3e499
5 changed files with 38 additions and 10 deletions

View File

@ -46,12 +46,12 @@ public class EmpiResetSvcImpl implements IEmpiResetSvc {
@Autowired @Autowired
private IResourceExpungeService myResourceExpungeService; private IResourceExpungeService myResourceExpungeService;
@Override @Override
public void expungeAllEmpiLinksOfTargetType(String theResourceType) { public long expungeAllEmpiLinksOfTargetType(String theResourceType) {
throwExceptionIfInvalidTargetType(theResourceType); throwExceptionIfInvalidTargetType(theResourceType);
List<Long> longs = myEmpiLinkDaoSvc.deleteAllEmpiLinksOfTypeAndReturnPersonPids(theResourceType); List<Long> longs = myEmpiLinkDaoSvc.deleteAllEmpiLinksOfTypeAndReturnPersonPids(theResourceType);
myResourceExpungeService.expungeCurrentVersionOfResources(null, longs, new AtomicInteger(longs.size())); myResourceExpungeService.expungeCurrentVersionOfResources(null, longs, new AtomicInteger(longs.size()));
return longs.size();
} }
private void throwExceptionIfInvalidTargetType(String theResourceType) { private void throwExceptionIfInvalidTargetType(String theResourceType) {
@ -64,9 +64,10 @@ public class EmpiResetSvcImpl implements IEmpiResetSvc {
* TODO GGG this operation likely won't scale very well. Consider adding slicing * TODO GGG this operation likely won't scale very well. Consider adding slicing
*/ */
@Override @Override
public void expungeAllEmpiLinks() { public long expungeAllEmpiLinks() {
List<Long> longs = myEmpiLinkDaoSvc.deleteAllEmpiLinksAndReturnPersonPids(); List<Long> longs = myEmpiLinkDaoSvc.deleteAllEmpiLinksAndReturnPersonPids();
myResourceExpungeService.expungeCurrentVersionOfResources(null, longs, new AtomicInteger(longs.size())); myResourceExpungeService.expungeCurrentVersionOfResources(null, longs, new AtomicInteger(longs.size()));
return longs.size();
} }
} }

View File

@ -23,12 +23,19 @@ package ca.uhn.fhir.empi.api;
public interface IEmpiResetSvc { public interface IEmpiResetSvc {
/** /**
* Given a resource type, delete the underlying empi links, and their related person objects. * Given a resource type, delete the underlying EMPI links, and their related person objects.
* *
* @param theResourceType The type of resources * @param theResourceType The type of resources
*
* @return the count of deleted EMPI links
*/ */
void expungeAllEmpiLinksOfTargetType(String theResourceType); long expungeAllEmpiLinksOfTargetType(String theResourceType);
/**
void expungeAllEmpiLinks(); * Delete all EMPI links, and their related Person objects.
*
*
* @return the count of deleted EMPI links
*/
long expungeAllEmpiLinks();
} }

View File

@ -37,6 +37,7 @@ import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
import ca.uhn.fhir.rest.server.provider.ProviderConstants; import ca.uhn.fhir.rest.server.provider.ProviderConstants;
import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails; import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails;
import ca.uhn.fhir.validation.IResourceLoader; import ca.uhn.fhir.validation.IResourceLoader;
import org.apache.commons.lang3.StringUtils;
import org.hl7.fhir.dstu3.model.Bundle; import org.hl7.fhir.dstu3.model.Bundle;
import org.hl7.fhir.dstu3.model.DecimalType; import org.hl7.fhir.dstu3.model.DecimalType;
import org.hl7.fhir.dstu3.model.InstantType; import org.hl7.fhir.dstu3.model.InstantType;
@ -174,6 +175,20 @@ public class EmpiProviderDstu3 extends BaseEmpiProvider {
return theCriteria == null ? null : theCriteria.getValueAsString(); return theCriteria == null ? null : theCriteria.getValueAsString();
} }
@Operation(name = ProviderConstants.EMPI_CLEAR)
public Parameters clearEmpiLinks(@OperationParam(name=ProviderConstants.EMPI_CLEAR_TARGET_TYPE, min = 0, max = 1) org.hl7.fhir.r4.model.StringType theTargetType) {
long resetCount;
if (theTargetType == null || StringUtils.isBlank(theTargetType.getValue())) {
resetCount = myEmpiExpungeSvc.expungeAllEmpiLinks();
} else {
resetCount = myEmpiExpungeSvc.expungeAllEmpiLinksOfTargetType(theTargetType.getValueNotNull());
}
Parameters parameters = new Parameters();
parameters.addParameter().setName(ProviderConstants.OPERATION_EMPI_CLEAR_OUT_PARAM_RESET_COUNT)
.setValue(new DecimalType(resetCount));
return parameters;
}
@Operation(name = ProviderConstants.OPERATION_EMPI_BATCH_RUN, idempotent = false, type = Patient.class, returnParameters = { @Operation(name = ProviderConstants.OPERATION_EMPI_BATCH_RUN, idempotent = false, type = Patient.class, returnParameters = {
@OperationParam(name = ProviderConstants.OPERATION_EMPI_BATCH_RUN_OUT_PARAM_SUBMIT_COUNT, type = DecimalType.class) @OperationParam(name = ProviderConstants.OPERATION_EMPI_BATCH_RUN_OUT_PARAM_SUBMIT_COUNT, type = DecimalType.class)
}) })

View File

@ -130,12 +130,16 @@ public class EmpiProviderR4 extends BaseEmpiProvider {
@Operation(name = ProviderConstants.EMPI_CLEAR) @Operation(name = ProviderConstants.EMPI_CLEAR)
public Parameters clearEmpiLinks(@OperationParam(name=ProviderConstants.EMPI_CLEAR_TARGET_TYPE, min = 0, max = 1) StringType theTargetType) { public Parameters clearEmpiLinks(@OperationParam(name=ProviderConstants.EMPI_CLEAR_TARGET_TYPE, min = 0, max = 1) StringType theTargetType) {
long resetCount;
if (theTargetType == null || StringUtils.isBlank(theTargetType.getValue())) { if (theTargetType == null || StringUtils.isBlank(theTargetType.getValue())) {
myEmpiExpungeSvc.expungeAllEmpiLinks(); resetCount = myEmpiExpungeSvc.expungeAllEmpiLinks();
} else { } else {
myEmpiExpungeSvc.expungeAllEmpiLinksOfTargetType(theTargetType.getValueNotNull()); resetCount = myEmpiExpungeSvc.expungeAllEmpiLinksOfTargetType(theTargetType.getValueNotNull());
} }
return new Parameters(); Parameters parameters = new Parameters();
parameters.addParameter().setName(ProviderConstants.OPERATION_EMPI_CLEAR_OUT_PARAM_RESET_COUNT)
.setValue(new DecimalType(resetCount));
return parameters;
} }
@Operation(name = ProviderConstants.EMPI_QUERY_LINKS, idempotent = true) @Operation(name = ProviderConstants.EMPI_QUERY_LINKS, idempotent = true)

View File

@ -89,4 +89,5 @@ public class ProviderConstants {
public static final String EMPI_BATCH_RUN_CRITERIA= "criteria" ; public static final String EMPI_BATCH_RUN_CRITERIA= "criteria" ;
public static final String EMPI_BATCH_RUN_RESOURCE_IDS = "resourceIds" ; public static final String EMPI_BATCH_RUN_RESOURCE_IDS = "resourceIds" ;
public static final String OPERATION_EMPI_BATCH_RUN_OUT_PARAM_SUBMIT_COUNT = "submitted" ; public static final String OPERATION_EMPI_BATCH_RUN_OUT_PARAM_SUBMIT_COUNT = "submitted" ;
public static final String OPERATION_EMPI_CLEAR_OUT_PARAM_RESET_COUNT = "reset";
} }