From de9621602b315671a3f9eba16cef3fdca827ed12 Mon Sep 17 00:00:00 2001 From: Tadgh Date: Sat, 18 Jul 2020 18:18:21 -0700 Subject: [PATCH] Update provider and create test skeletons for empi batch run --- .../provider/r4/JpaResourceProviderR4.java | 4 + .../ca/uhn/fhir/jpa/config/TestR4Config.java | 22 ++++ .../r4/ResourceProviderEmpiRunR4Test.java | 117 ++++++++++++++++++ .../fhir/jpa/empi/helper/EmpiHelperR4.java | 10 -- .../jpa/empi/provider/BaseLinkR4Test.java | 1 - .../fhir/empi/provider/EmpiProviderR4.java | 8 +- .../server/provider/ProviderConstants.java | 1 + 7 files changed, 148 insertions(+), 15 deletions(-) create mode 100644 hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderEmpiRunR4Test.java diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/provider/r4/JpaResourceProviderR4.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/provider/r4/JpaResourceProviderR4.java index 3560964fad6..ffce6ef09a6 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/provider/r4/JpaResourceProviderR4.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/provider/r4/JpaResourceProviderR4.java @@ -115,19 +115,23 @@ public class JpaResourceProviderR4 extends BaseJpaResour } @Operation(name = ProviderConstants.OPERATION_EMPI_BATCH_RUN, idempotent = false, returnParameters = { + @OperationParam(name = ProviderConstants.OPERATION_EMPI_BATCH_RUN_OUT_PARAM_SUBMIT_COUNT, type = IntegerType.class) }) public Parameters empiBatch( @IdParam IIdType theIdParam, @OperationParam(name = ProviderConstants.EMPI_BATCH_RUN_CRITERIA) StringType theCriteria, RequestDetails theRequest) { + //TODO actually return submitted count return super.doEmpiBatch(theIdParam, theCriteria.getValue(), theRequest); } @Operation(name = ProviderConstants.OPERATION_EMPI_BATCH_RUN, idempotent = false, returnParameters = { + @OperationParam(name = ProviderConstants.OPERATION_EMPI_BATCH_RUN_OUT_PARAM_SUBMIT_COUNT, type = IntegerType.class) }) public Parameters empiBatch( @OperationParam(name = ProviderConstants.EMPI_BATCH_RUN_CRITERIA) StringType theCriteria, RequestDetails theRequest) { + //TODO actually return submitted count return super.doEmpiBatch(null, theCriteria.getValue(), theRequest); } diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/config/TestR4Config.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/config/TestR4Config.java index 060069e9f09..6e7dbf301c0 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/config/TestR4Config.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/config/TestR4Config.java @@ -1,5 +1,6 @@ package ca.uhn.fhir.jpa.config; +import ca.uhn.fhir.empi.api.IEmpiBatchService; import ca.uhn.fhir.jpa.batch.BatchJobsConfig; import ca.uhn.fhir.jpa.batch.api.IBatchJobSubmitter; import ca.uhn.fhir.jpa.batch.svc.BatchJobSubmitterImpl; @@ -15,6 +16,7 @@ import net.ttddyy.dsproxy.listener.logging.SLF4JLogLevel; import net.ttddyy.dsproxy.support.ProxyDataSourceBuilder; import org.apache.commons.dbcp2.BasicDataSource; import org.hibernate.dialect.H2Dialect; +import org.hl7.fhir.instance.model.api.IIdType; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; @@ -72,6 +74,26 @@ public class TestR4Config extends BaseJavaConfigR4 { return new BulkExportDaoSvc(); } + @Bean + public IEmpiBatchService myEmpiBatchService() { + return new IEmpiBatchService() { + @Override + public void runEmpiOnAllTargets(String theCriteria) { + return; + } + + @Override + public void runEmpiOnTargetType(String theTargetType, String theCriteria) { + return; + } + + @Override + public void runEmpiOnTarget(IIdType theId, String theTargetType) { + return; + } + }; + } + @Bean public DataSource dataSource() { BasicDataSource retVal = new BasicDataSource() { diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderEmpiRunR4Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderEmpiRunR4Test.java new file mode 100644 index 00000000000..99a6560a1b9 --- /dev/null +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderEmpiRunR4Test.java @@ -0,0 +1,117 @@ +package ca.uhn.fhir.jpa.provider.r4; + +import ca.uhn.fhir.jpa.api.config.DaoConfig; +import ca.uhn.fhir.rest.server.exceptions.MethodNotAllowedException; +import ca.uhn.fhir.rest.server.provider.ProviderConstants; +import org.hl7.fhir.instance.model.api.IIdType; +import org.hl7.fhir.r4.model.Parameters; +import org.hl7.fhir.r4.model.Patient; +import org.hl7.fhir.r4.model.StringType; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; + +public class ResourceProviderEmpiRunR4Test extends BaseResourceProviderR4Test { + + private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(ResourceProviderEmpiRunR4Test.class); + private IIdType myOneVersionPatientId; + private IIdType myTwoVersionPatientId; + private IIdType myDeletedPatientId; + + + @Override + @BeforeEach + public void before() throws Exception { + super.before(); + + Patient p = new Patient(); + p.setId("PT-ONEVERSION"); + p.getMeta().addTag().setSystem("http://foo").setCode("bar"); + p.setActive(true); + p.addIdentifier().setSystem("foo").setValue("bar"); + p.addName().setFamily("FAM"); + myOneVersionPatientId = myPatientDao.update(p).getId(); + + p = new Patient(); + p.setId("PT-TWOVERSION"); + p.getMeta().addTag().setSystem("http://foo").setCode("bar"); + p.setActive(true); + myTwoVersionPatientId = myPatientDao.update(p).getId(); + p.setActive(false); + myTwoVersionPatientId = myPatientDao.update(p).getId(); + + p = new Patient(); + p.setId("PT-DELETED"); + p.getMeta().addTag().setSystem("http://foo").setCode("bar"); + p.setActive(true); + myDeletedPatientId = myPatientDao.update(p).getId(); + myDeletedPatientId = myPatientDao.delete(myDeletedPatientId).getId(); + } + + @Test + public void testWithEmpiDisabled() { + myDaoConfig.setExpungeEnabled(new DaoConfig().isExpungeEnabled()); + + Parameters input = new Parameters(); + input.addParameter() + .setName(ProviderConstants.EMPI_BATCH_RUN_CRITERIA) + .setValue(new StringType("Patient?")); + try { + myClient + .operation() + .onType(Patient.class) + .named("empi-batch-run") + .withParameters(input) + .execute(); + fail(); + } catch (MethodNotAllowedException e){ + assertEquals("HTTP 405 Method Not Allowed: $empi-batch-run is not enabled on this server", e.getMessage()); + } + } + + @Test + public void testEmpiBatchRunOnType() { + + Parameters input = new Parameters(); + input.addParameter() + .setName(ProviderConstants.EMPI_BATCH_RUN_CRITERIA) + .setValue(new StringType("Patient?name=Gary")); + Parameters output = myClient + .operation() + .onType(Patient.class) + .named("empi-batch-run") + .withParameters(input) + .execute(); + } + + @Test + public void testEmpiBatchRunOnInstance() { + + Parameters input = new Parameters(); + input.addParameter() + .setName(ProviderConstants.EMPI_BATCH_RUN_CRITERIA) + .setValue(new StringType("Patient?name=Gary")); + Parameters output = myClient + .operation() + .onType(Patient.class) + .named("empi-batch-run") + .withParameters(input) + .execute(); + } + @Test + public void testEmpiBatchRunOnServer() { + + Parameters input = new Parameters(); + input.addParameter() + .setName(ProviderConstants.EMPI_BATCH_RUN_CRITERIA) + .setValue(new StringType("Patient?name=Gary")); + Parameters output = myClient + .operation() + .onType(Patient.class) + .named("empi-batch-run") + .withParameters(input) + .execute(); + } +} 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 06ab1aa07d0..9e7a3f19c00 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 @@ -1,7 +1,6 @@ package ca.uhn.fhir.jpa.empi.helper; import ca.uhn.fhir.context.FhirContext; -import ca.uhn.fhir.empi.provider.EmpiProviderR4; import ca.uhn.fhir.jpa.api.dao.DaoRegistry; import ca.uhn.fhir.jpa.api.dao.IFhirResourceDao; import ca.uhn.fhir.jpa.api.model.DaoMethodOutcome; @@ -15,18 +14,9 @@ public class EmpiHelperR4 extends BaseEmpiHelper { @Autowired private DaoRegistry myDaoRegistry; - @Autowired - private EmpiProviderR4 myEmpiProviderR4; - public OutcomeAndLogMessageWrapper createWithLatch(IBaseResource theResource) throws InterruptedException { return createWithLatch(theResource, true); } - public OutcomeAndLogMessageWrapper batchWithLatch(int expectedRuns) throws InterruptedException { - myAfterEmpiLatch.setExpectedCount(expectedRuns); - myEmpiProviderR4.batchRunEmpi(null, null, null); - myAfterEmpiLatch.awaitExpected(); - return new OutcomeAndLogMessageWrapper(null, null); - } public OutcomeAndLogMessageWrapper createWithLatch(IBaseResource theBaseResource, boolean isExternalHttpRequest) throws InterruptedException { myAfterEmpiLatch.setExpectedCount(1); diff --git a/hapi-fhir-jpaserver-empi/src/test/java/ca/uhn/fhir/jpa/empi/provider/BaseLinkR4Test.java b/hapi-fhir-jpaserver-empi/src/test/java/ca/uhn/fhir/jpa/empi/provider/BaseLinkR4Test.java index 0c5e6b5e021..8e79c6092b3 100644 --- a/hapi-fhir-jpaserver-empi/src/test/java/ca/uhn/fhir/jpa/empi/provider/BaseLinkR4Test.java +++ b/hapi-fhir-jpaserver-empi/src/test/java/ca/uhn/fhir/jpa/empi/provider/BaseLinkR4Test.java @@ -26,7 +26,6 @@ public abstract class BaseLinkR4Test extends BaseProviderR4Test { protected StringType myPersonId; protected StringType myVersionlessPersonId; - @Override @BeforeEach public void before() { 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 2d274b8e686..935c6f2f915 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 @@ -166,16 +166,16 @@ public class EmpiProviderR4 extends BaseEmpiProvider { return (Parameters) myEmpiLinkUpdaterSvc.notDuplicatePerson(person, target, createEmpiContext(theRequestDetails)); } - @Operation(name = ProviderConstants.EMPI_BATCH_RUN, idempotent = true) + /** TODO remove this, once we get it working in the BaseResourceProvider **/ + @Operation(name = ProviderConstants.OPERATION_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_CRITERIA, max=1) StringType theCriteria, ServletRequestDetails theRequestDetails) { if (theTargetType == null) { - myEmpiBatchSvc.runEmpiOnAllTargets(theCriteria); + myEmpiBatchSvc.runEmpiOnAllTargets(theCriteria.getValue()); } else { - - myEmpiBatchSvc.runEmpiOnTargetType(theTargetType.toString(), theCriteria); + myEmpiBatchSvc.runEmpiOnTargetType(theTargetType.toString(), theCriteria.getValue()); } } } diff --git a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/provider/ProviderConstants.java b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/provider/ProviderConstants.java index a2482b19660..390bc67eb74 100644 --- a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/provider/ProviderConstants.java +++ b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/provider/ProviderConstants.java @@ -88,4 +88,5 @@ public class ProviderConstants { public static final String EMPI_BATCH_RUN_TARGET_TYPE = "targetType" ; public static final String EMPI_BATCH_RUN_CRITERIA= "criteria" ; public static final String EMPI_BATCH_RUN_RESOURCE_IDS = "resourceIds" ; + public static final String OPERATION_EMPI_BATCH_RUN_OUT_PARAM_SUBMIT_COUNT = "submitted" ; }