Update provider and create test skeletons for empi batch run

This commit is contained in:
Tadgh 2020-07-18 18:18:21 -07:00
parent b79ed21672
commit de9621602b
7 changed files with 148 additions and 15 deletions

View File

@ -115,19 +115,23 @@ public class JpaResourceProviderR4<T extends IAnyResource> 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);
}

View File

@ -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() {

View File

@ -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();
}
}

View File

@ -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);

View File

@ -26,7 +26,6 @@ public abstract class BaseLinkR4Test extends BaseProviderR4Test {
protected StringType myPersonId;
protected StringType myVersionlessPersonId;
@Override
@BeforeEach
public void before() {

View File

@ -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());
}
}
}

View File

@ -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" ;
}