This commit is contained in:
Tadgh 2020-07-15 12:27:49 -07:00
parent 9d7df0cdda
commit 80b59599fc
5 changed files with 48 additions and 14 deletions

View File

@ -15,6 +15,7 @@ import ca.uhn.fhir.rest.api.server.IBundleProvider;
import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
import ca.uhn.fhir.rest.server.provider.ProviderConstants;
import org.hl7.fhir.instance.model.api.IBaseResource;
import org.hl7.fhir.r4.model.StringType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.MessageChannel;
@ -36,21 +37,25 @@ public class EmpiBatchSvcImpl implements IEmpiBatchService {
@Autowired
private FhirContext myFhirContext;
@Autowired
private EmpiSearchParamSvc myEmpiSearchParamSvc;
@Autowired
private IChannelFactory myChannelFactory;
@Override
public void runEmpiOnAllTargets() {
runEmpiOnTargetType("Patient");
runEmpiOnTargetType("Practitioner");
public void runEmpiOnAllTargets(StringType theCriteria) {
runEmpiOnTargetType("Patient", theCriteria);
runEmpiOnTargetType("Practitioner", theCriteria);
}
@Override
public void runEmpiOnTargetType(String theTargetType) {
public void runEmpiOnTargetType(String theTargetType, StringType theCriteria) {
getTargetTypeOrThrowException(theTargetType);
SearchParameterMap spMap = getSearchParameterMapFromCriteria(theTargetType, theCriteria);
IFhirResourceDao patientDao = myDaoRegistry.getResourceDao(theTargetType);
IBundleProvider search = patientDao.search(new SearchParameterMap().setLoadSynchronous(true));
IBundleProvider search = patientDao.search(spMap.setLoadSynchronous(true));
List<IBaseResource> resources = search.getResources(0, search.size());
@ -61,7 +66,16 @@ public class EmpiBatchSvcImpl implements IEmpiBatchService {
rmjm.setPayload(resourceModifiedMessage);
myEmpiChannelProducer.send(rmjm);
}
}
private SearchParameterMap getSearchParameterMapFromCriteria(String theTargetType, StringType theCriteria) {
SearchParameterMap spMap;
if (theCriteria != null) {
spMap = myEmpiSearchParamSvc.mapFromCriteria(theTargetType, theCriteria.getValueNotNull());
} else {
spMap = new SearchParameterMap();
}
return spMap;
}
private EmpiTargetType getTargetTypeOrThrowException(String theResourceType) {

View File

@ -23,7 +23,7 @@ public class EmpiHelperR4 extends BaseEmpiHelper {
}
public OutcomeAndLogMessageWrapper batchWithLatch(int expectedRuns) throws InterruptedException {
myAfterEmpiLatch.setExpectedCount(expectedRuns);
myEmpiProviderR4.batchRunEmpi(null, null);
myEmpiProviderR4.batchRunEmpi(null, null, null);
myAfterEmpiLatch.awaitExpected();
return new OutcomeAndLogMessageWrapper(null, null);
}

View File

@ -4,11 +4,15 @@ import ca.uhn.fhir.interceptor.api.IInterceptorService;
import ca.uhn.fhir.interceptor.api.Pointcut;
import ca.uhn.fhir.jpa.empi.BaseEmpiR4Test;
import ca.uhn.test.concurrency.PointcutLatch;
import org.apache.commons.lang3.time.DateUtils;
import org.hl7.fhir.r4.model.StringType;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.Date;
class EmpiBatchSvcImplTest extends BaseEmpiR4Test {
@Autowired
@ -44,7 +48,7 @@ class EmpiBatchSvcImplTest extends BaseEmpiR4Test {
afterEmpiLatch.setExpectedCount(20);
//SUT
myEmpiBatchSvc.runEmpiOnAllTargets();
myEmpiBatchSvc.runEmpiOnAllTargets(null);
afterEmpiLatch.awaitExpected();
assertLinkCount(20);
@ -61,7 +65,7 @@ class EmpiBatchSvcImplTest extends BaseEmpiR4Test {
afterEmpiLatch.setExpectedCount(10);
//SUT
myEmpiBatchSvc.runEmpiOnAllTargets();
myEmpiBatchSvc.runEmpiOnAllTargets(null);
afterEmpiLatch.awaitExpected();
assertLinkCount(10);
@ -78,11 +82,24 @@ class EmpiBatchSvcImplTest extends BaseEmpiR4Test {
afterEmpiLatch.setExpectedCount(10);
//SUT
myEmpiBatchSvc.runEmpiOnAllTargets();
myEmpiBatchSvc.runEmpiOnAllTargets(null);
afterEmpiLatch.awaitExpected();
assertLinkCount(10);
}
@Test
public void testEmpiOnTargetTypeWithCriteria() throws InterruptedException {
createPatient(buildPatientWithNameIdAndBirthday("gary", "gary_id", new Date()));
createPatient(buildPatientWithNameIdAndBirthday("john", "john_id", DateUtils.addDays(new Date(), -300)));
assertLinkCount(0);
afterEmpiLatch.setExpectedCount(1);
myEmpiBatchSvc.runEmpiOnAllTargets(new StringType("Patient?name=gary"));
afterEmpiLatch.awaitExpected();
}
}

View File

@ -1,8 +1,10 @@
package ca.uhn.fhir.empi.api;
import org.hl7.fhir.r4.model.StringType;
public interface IEmpiBatchService {
void runEmpiOnAllTargets();
void runEmpiOnAllTargets(StringType theCriteria);
void runEmpiOnTargetType(String theTargetType);
void runEmpiOnTargetType(String theTargetType, StringType theCriteria);
}

View File

@ -168,13 +168,14 @@ public class EmpiProviderR4 extends BaseEmpiProvider {
@Operation(name = ProviderConstants.EMPI_BATCH_RUN, idempotent = true)
public void batchRunEmpi(@OperationParam(name= ProviderConstants.EMPI_BATCH_RUN_TARGET_TYPE, max=1) StringType theTargetType,
@OperationParam(name= ProviderConstants.EMPI_BATCH_RUN_TARGET_TYPE, max=1) StringType theQueryString,
@OperationParam(name= ProviderConstants.EMPI_BATCH_RUN_TARGET_TYPE, max=1) StringType theCriteria,
ServletRequestDetails theRequestDetails) {
if (theTargetType == null) {
myEmpiBatchSvc.runEmpiOnAllTargets();
myEmpiBatchSvc.runEmpiOnAllTargets(theCriteria);
} else {
myEmpiBatchSvc.runEmpiOnTargetType(theTargetType.toString());
myEmpiBatchSvc.runEmpiOnTargetType(theTargetType.toString(), theCriteria);
}
}
}