This commit is contained in:
Tadgh 2020-07-28 08:42:45 -07:00
parent 606b642b1e
commit f6d44fe50c
3 changed files with 20 additions and 9 deletions

View File

@ -239,7 +239,7 @@ public class EmpiLinkDaoSvc {
private List<Long> deleteEmpiLinksAndReturnPersonPids(List<EmpiLink> theLinks) {
List<Long> collect = theLinks.stream().map(EmpiLink::getPersonPid).distinct().collect(Collectors.toList());
theLinks.forEach(empiLink -> myEmpiLinkDao.delete(empiLink));
myEmpiLinkDao.deleteAll(theLinks);
return collect;
}

View File

@ -27,7 +27,6 @@ import ca.uhn.fhir.jpa.api.dao.IFhirResourceDao;
import ca.uhn.fhir.jpa.api.model.DeleteConflict;
import ca.uhn.fhir.jpa.api.model.DeleteConflictList;
import ca.uhn.fhir.jpa.dao.expunge.IResourceExpungeService;
import ca.uhn.fhir.jpa.dao.tx.HapiTransactionService;
import ca.uhn.fhir.jpa.empi.dao.EmpiLinkDaoSvc;
import ca.uhn.fhir.model.primitive.IdDt;
import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
@ -37,7 +36,10 @@ import org.hl7.fhir.r4.model.IdType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.support.TransactionTemplate;
import javax.annotation.PostConstruct;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
@ -55,7 +57,9 @@ public class EmpiResetSvcImpl implements IEmpiResetSvc {
@Autowired
private DaoRegistry myDaoRegistry;
@Autowired
private HapiTransactionService myTransactionService;
private PlatformTransactionManager myTransactionManager;
private TransactionTemplate myTxTemplate;
@Override
public long expungeAllEmpiLinksOfTargetType(String theResourceType) {
@ -74,14 +78,14 @@ public class EmpiResetSvcImpl implements IEmpiResetSvc {
private void deleteResourcesAndHandleConflicts(List<Long> theLongs) {
DeleteConflictList
deleteConflictList = new DeleteConflictList();
myTransactionService.execute(null, tx -> {
myTxTemplate.execute(tx -> {
theLongs.stream().forEach(pid -> deleteCascade(pid, deleteConflictList));
return null;
});
IFhirResourceDao personDao = myDaoRegistry.getResourceDao("Person");
while (!deleteConflictList.isEmpty()) {
myTransactionService.execute(null, tx -> {
myTxTemplate.execute(tx -> {
deleteConflictBatch(deleteConflictList, personDao);
return null;
});
@ -95,6 +99,12 @@ public class EmpiResetSvcImpl implements IEmpiResetSvc {
}
}
@PostConstruct
public void start() {
myTxTemplate = new TransactionTemplate(myTransactionManager);
}
/**
* TODO GGG this operation likely won't scale very well. Consider adding slicing
*/
@ -128,7 +138,8 @@ public class EmpiResetSvcImpl implements IEmpiResetSvc {
private void deleteCascade(Long pid, DeleteConflictList theDeleteConflictList) {
ourLog.debug("About to cascade delete: " + pid);
IFhirResourceDao resourceDao = myDaoRegistry.getResourceDao("Person");
resourceDao.delete(new IdType("Person/" + pid), theDeleteConflictList, null, null);
myTxTemplate.executeWithoutResult((tx) -> resourceDao.delete(new IdType("Person/" + pid), theDeleteConflictList, null, null));
}
}

View File

@ -50,17 +50,17 @@ public class EmpiProviderLoader {
@Autowired
private IResourceLoader myResourceLoader;
@Autowired
private IEmpiResetSvc myEmpiExpungeSvc;
private IEmpiResetSvc myEmpiResetSvc;
@Autowired
private IEmpiBatchService myEmpiBatchSvc;
public void loadProvider() {
switch (myFhirContext.getVersion().getVersion()) {
case DSTU3:
myResourceProviderFactory.addSupplier(() -> new EmpiProviderDstu3(myFhirContext, myEmpiMatchFinderSvc, myPersonMergerSvc, myEmpiLinkUpdaterSvc, myEmpiLinkQuerySvc, myResourceLoader, myEmpiExpungeSvc, myEmpiBatchSvc));
myResourceProviderFactory.addSupplier(() -> new EmpiProviderDstu3(myFhirContext, myEmpiMatchFinderSvc, myPersonMergerSvc, myEmpiLinkUpdaterSvc, myEmpiLinkQuerySvc, myResourceLoader, myEmpiResetSvc, myEmpiBatchSvc));
break;
case R4:
myResourceProviderFactory.addSupplier(() -> new EmpiProviderR4(myFhirContext, myEmpiMatchFinderSvc, myPersonMergerSvc, myEmpiLinkUpdaterSvc, myEmpiLinkQuerySvc, myResourceLoader, myEmpiExpungeSvc, myEmpiBatchSvc));
myResourceProviderFactory.addSupplier(() -> new EmpiProviderR4(myFhirContext, myEmpiMatchFinderSvc, myPersonMergerSvc, myEmpiLinkUpdaterSvc, myEmpiLinkQuerySvc, myResourceLoader, myEmpiResetSvc, myEmpiBatchSvc));
break;
default:
throw new ConfigurationException("EMPI not supported for FHIR version " + myFhirContext.getVersion().getVersion());