From 80b59599fcb547abb31a118e62797cbf0854789a Mon Sep 17 00:00:00 2001 From: Tadgh Date: Wed, 15 Jul 2020 12:27:49 -0700 Subject: [PATCH] wip --- .../fhir/jpa/empi/svc/EmpiBatchSvcImpl.java | 24 +++++++++++++++---- .../fhir/jpa/empi/helper/EmpiHelperR4.java | 2 +- .../jpa/empi/svc/EmpiBatchSvcImplTest.java | 23 +++++++++++++++--- .../uhn/fhir/empi/api/IEmpiBatchService.java | 6 +++-- .../fhir/empi/provider/EmpiProviderR4.java | 7 +++--- 5 files changed, 48 insertions(+), 14 deletions(-) diff --git a/hapi-fhir-jpaserver-empi/src/main/java/ca/uhn/fhir/jpa/empi/svc/EmpiBatchSvcImpl.java b/hapi-fhir-jpaserver-empi/src/main/java/ca/uhn/fhir/jpa/empi/svc/EmpiBatchSvcImpl.java index 3988dac0435..a2f92f0c9eb 100644 --- a/hapi-fhir-jpaserver-empi/src/main/java/ca/uhn/fhir/jpa/empi/svc/EmpiBatchSvcImpl.java +++ b/hapi-fhir-jpaserver-empi/src/main/java/ca/uhn/fhir/jpa/empi/svc/EmpiBatchSvcImpl.java @@ -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 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) { diff --git a/hapi-fhir-jpaserver-empi/src/test/java/ca/uhn/fhir/jpa/empi/helper/EmpiHelperR4.java b/hapi-fhir-jpaserver-empi/src/test/java/ca/uhn/fhir/jpa/empi/helper/EmpiHelperR4.java index 88163d75add..06ab1aa07d0 100644 --- a/hapi-fhir-jpaserver-empi/src/test/java/ca/uhn/fhir/jpa/empi/helper/EmpiHelperR4.java +++ b/hapi-fhir-jpaserver-empi/src/test/java/ca/uhn/fhir/jpa/empi/helper/EmpiHelperR4.java @@ -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); } diff --git a/hapi-fhir-jpaserver-empi/src/test/java/ca/uhn/fhir/jpa/empi/svc/EmpiBatchSvcImplTest.java b/hapi-fhir-jpaserver-empi/src/test/java/ca/uhn/fhir/jpa/empi/svc/EmpiBatchSvcImplTest.java index 22c94a9fbe8..a9a7879a9fd 100644 --- a/hapi-fhir-jpaserver-empi/src/test/java/ca/uhn/fhir/jpa/empi/svc/EmpiBatchSvcImplTest.java +++ b/hapi-fhir-jpaserver-empi/src/test/java/ca/uhn/fhir/jpa/empi/svc/EmpiBatchSvcImplTest.java @@ -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(); + } + } diff --git a/hapi-fhir-server-empi/src/main/java/ca/uhn/fhir/empi/api/IEmpiBatchService.java b/hapi-fhir-server-empi/src/main/java/ca/uhn/fhir/empi/api/IEmpiBatchService.java index ed6b91cac55..468f3f5ec58 100644 --- a/hapi-fhir-server-empi/src/main/java/ca/uhn/fhir/empi/api/IEmpiBatchService.java +++ b/hapi-fhir-server-empi/src/main/java/ca/uhn/fhir/empi/api/IEmpiBatchService.java @@ -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); } diff --git a/hapi-fhir-server-empi/src/main/java/ca/uhn/fhir/empi/provider/EmpiProviderR4.java b/hapi-fhir-server-empi/src/main/java/ca/uhn/fhir/empi/provider/EmpiProviderR4.java index 9ef0259d97b..137c9deb5e1 100644 --- a/hapi-fhir-server-empi/src/main/java/ca/uhn/fhir/empi/provider/EmpiProviderR4.java +++ b/hapi-fhir-server-empi/src/main/java/ca/uhn/fhir/empi/provider/EmpiProviderR4.java @@ -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); } } }