Fix bug caused by Persons with >1 historical version

This commit is contained in:
Tadgh 2020-07-23 14:35:28 -07:00
parent 9491a3e499
commit 90e96c1fb4
5 changed files with 28 additions and 9 deletions

View File

@ -32,6 +32,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;
/**
* This class is in charge of Clearing out existing EMPI links, as well as deleting all persons related to those EMPI Links.
@ -66,6 +67,9 @@ public class EmpiResetSvcImpl implements IEmpiResetSvc {
@Override
public long expungeAllEmpiLinks() {
List<Long> longs = myEmpiLinkDaoSvc.deleteAllEmpiLinksAndReturnPersonPids();
longs = longs.stream()
.distinct().collect(Collectors.toList());
myResourceExpungeService.expungeHistoricalVersionsOfIds(null, longs, new AtomicInteger(longs.size()));
myResourceExpungeService.expungeCurrentVersionOfResources(null, longs, new AtomicInteger(longs.size()));
return longs.size();
}

View File

@ -70,6 +70,17 @@ public class EmpiProviderClearLinkR4Test extends BaseLinkR4Test {
} catch (ResourceNotFoundException e) {}
}
@Test
public void testPersonsWithMultipleHistoricalVersionsCanBeDeleted() {
createPatientAndUpdateLinks(buildJanePatient());
createPatientAndUpdateLinks(buildJanePatient());
createPatientAndUpdateLinks(buildJanePatient());
createPatientAndUpdateLinks(buildJanePatient());
createPatientAndUpdateLinks(buildJanePatient());
myEmpiProviderR4.clearEmpiLinks(null);
assertNoPatientLinksExist();
}
@Test
public void testClearPractitionerLinks() {

View File

@ -58,7 +58,7 @@ public class EmpiProviderDstu3 extends BaseEmpiProvider {
private final IEmpiPersonMergerSvc myPersonMergerSvc;
private final IEmpiLinkUpdaterSvc myEmpiLinkUpdaterSvc;
private final IEmpiLinkQuerySvc myEmpiLinkQuerySvc;
private final IEmpiResetSvc myEmpiExpungeSvc;
private final IEmpiResetSvc myEmpiResetSvc;
private final IEmpiBatchService myEmpiBatchSvc;
/**
@ -67,13 +67,13 @@ public class EmpiProviderDstu3 extends BaseEmpiProvider {
* Note that this is not a spring bean. Any necessary injections should
* happen in the constructor
*/
public EmpiProviderDstu3(FhirContext theFhirContext, IEmpiMatchFinderSvc theEmpiMatchFinderSvc, IEmpiPersonMergerSvc thePersonMergerSvc, IEmpiLinkUpdaterSvc theEmpiLinkUpdaterSvc, IEmpiLinkQuerySvc theEmpiLinkQuerySvc, IResourceLoader theResourceLoader, IEmpiResetSvc theEmpiExpungeSvc, IEmpiBatchService theEmpiBatchSvc) {
public EmpiProviderDstu3(FhirContext theFhirContext, IEmpiMatchFinderSvc theEmpiMatchFinderSvc, IEmpiPersonMergerSvc thePersonMergerSvc, IEmpiLinkUpdaterSvc theEmpiLinkUpdaterSvc, IEmpiLinkQuerySvc theEmpiLinkQuerySvc, IResourceLoader theResourceLoader, IEmpiResetSvc theEmpiResetSvc, IEmpiBatchService theEmpiBatchSvc) {
super(theFhirContext, theResourceLoader);
myEmpiMatchFinderSvc = theEmpiMatchFinderSvc;
myPersonMergerSvc = thePersonMergerSvc;
myEmpiLinkUpdaterSvc = theEmpiLinkUpdaterSvc;
myEmpiLinkQuerySvc = theEmpiLinkQuerySvc;
myEmpiExpungeSvc = theEmpiExpungeSvc;
myEmpiResetSvc = theEmpiResetSvc;
myEmpiBatchSvc = theEmpiBatchSvc;
}
@ -175,13 +175,15 @@ public class EmpiProviderDstu3 extends BaseEmpiProvider {
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) {
@Operation(name = ProviderConstants.EMPI_CLEAR, returnParameters = {
@OperationParam(name = ProviderConstants.OPERATION_EMPI_BATCH_RUN_OUT_PARAM_SUBMIT_COUNT, type= DecimalType.class)
})
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())) {
resetCount = myEmpiExpungeSvc.expungeAllEmpiLinks();
resetCount = myEmpiResetSvc.expungeAllEmpiLinks();
} else {
resetCount = myEmpiExpungeSvc.expungeAllEmpiLinksOfTargetType(theTargetType.getValueNotNull());
resetCount = myEmpiResetSvc.expungeAllEmpiLinksOfTargetType(theTargetType.getValueNotNull());
}
Parameters parameters = new Parameters();
parameters.addParameter().setName(ProviderConstants.OPERATION_EMPI_CLEAR_OUT_PARAM_RESET_COUNT)

View File

@ -128,7 +128,9 @@ public class EmpiProviderR4 extends BaseEmpiProvider {
return (Person) myEmpiLinkUpdaterSvc.updateLink(person, target, matchResult, createEmpiContext(theRequestDetails));
}
@Operation(name = ProviderConstants.EMPI_CLEAR)
@Operation(name = ProviderConstants.EMPI_CLEAR, returnParameters = {
@OperationParam(name = ProviderConstants.OPERATION_EMPI_BATCH_RUN_OUT_PARAM_SUBMIT_COUNT, type=DecimalType.class)
})
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())) {