From c0bef70e12c44246326e39c7ef06211b13f84043 Mon Sep 17 00:00:00 2001 From: Tadgh Date: Fri, 13 Nov 2020 16:42:09 -0500 Subject: [PATCH] Add optional resource type to EMPI provider method --- .../provider/EmpiProviderBatchR4Test.java | 36 ++++++++++++++++--- .../fhir/empi/provider/EmpiProviderR4.java | 20 ++++++++--- .../server/provider/ProviderConstants.java | 1 + 3 files changed, 48 insertions(+), 9 deletions(-) diff --git a/hapi-fhir-jpaserver-empi/src/test/java/ca/uhn/fhir/jpa/empi/provider/EmpiProviderBatchR4Test.java b/hapi-fhir-jpaserver-empi/src/test/java/ca/uhn/fhir/jpa/empi/provider/EmpiProviderBatchR4Test.java index 630f0a64803..918e35c5e3d 100644 --- a/hapi-fhir-jpaserver-empi/src/test/java/ca/uhn/fhir/jpa/empi/provider/EmpiProviderBatchR4Test.java +++ b/hapi-fhir-jpaserver-empi/src/test/java/ca/uhn/fhir/jpa/empi/provider/EmpiProviderBatchR4Test.java @@ -7,6 +7,8 @@ import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException; import ca.uhn.test.concurrency.PointcutLatch; import org.hl7.fhir.instance.model.api.IAnyResource; import org.hl7.fhir.r4.model.IdType; +import org.hl7.fhir.r4.model.Medication; +import org.hl7.fhir.r4.model.Organization; import org.hl7.fhir.r4.model.Practitioner; import org.hl7.fhir.r4.model.StringType; import org.junit.jupiter.api.AfterEach; @@ -23,10 +25,16 @@ import static org.junit.jupiter.api.Assertions.fail; public class EmpiProviderBatchR4Test extends BaseLinkR4Test { + public static final String ORGANIZATION_DUMMY = "Organization/dummy"; protected Practitioner myPractitioner; protected StringType myPractitionerId; - protected IAnyResource myGoldenPractitier; + protected IAnyResource myGoldenPractitioner; protected StringType myGoldenPractitionerId; + protected Medication myMedication; + protected StringType myMedicationId; + protected IAnyResource myGoldenMedication; + protected StringType myGoldenMedicationId; + @Autowired IInterceptorService myInterceptorService; @@ -38,8 +46,19 @@ public class EmpiProviderBatchR4Test extends BaseLinkR4Test { super.before(); myPractitioner = createPractitionerAndUpdateLinks(buildPractitionerWithNameAndId("some_pract", "some_pract_id")); myPractitionerId = new StringType(myPractitioner.getIdElement().getValue()); - myGoldenPractitier = getGoldenResourceFromTargetResource(myPractitioner); - myGoldenPractitionerId = new StringType(myGoldenPractitier.getIdElement().getValue()); + myGoldenPractitioner = getGoldenResourceFromTargetResource(myPractitioner); + myGoldenPractitionerId = new StringType(myGoldenPractitioner.getIdElement().getValue()); + + Organization dummyOrganization = new Organization(); + dummyOrganization.setId(ORGANIZATION_DUMMY); + myOrganizationDao.update(dummyOrganization); + + myMedication = createMedicationAndUpdateLinks(buildMedication(ORGANIZATION_DUMMY)); + myMedicationId = new StringType(myMedication.getIdElement().getValue()); + myGoldenMedication = getGoldenResourceFromTargetResource(myMedication); + myGoldenMedicationId = new StringType(myGoldenMedication.getIdElement().getValue()); + + myInterceptorService.registerAnonymousInterceptor(Pointcut.EMPI_AFTER_PERSISTED_RESOURCE_CHECKED, afterEmpiLatch); } @@ -49,6 +68,15 @@ public class EmpiProviderBatchR4Test extends BaseLinkR4Test { super.after(); } + @Test + public void testBatchRunOnAllMedications() throws InterruptedException { + StringType criteria = null; + myEmpiProviderR4.clearEmpiLinks(null, myRequestDetails); + + afterEmpiLatch.runWithExpectedCount(1, () -> myEmpiProviderR4.empiBatchOnAllTargets(new StringType("Medication"), criteria, null)); + assertLinkCount(1); + } + @Test public void testBatchRunOnAllPractitioners() throws InterruptedException { StringType criteria = null; @@ -106,7 +134,7 @@ public class EmpiProviderBatchR4Test extends BaseLinkR4Test { StringType criteria = new StringType(""); myEmpiProviderR4.clearEmpiLinks(null, myRequestDetails); afterEmpiLatch.runWithExpectedCount(2, () -> { - myEmpiProviderR4.empiBatchOnAllTargets(criteria, null); + myEmpiProviderR4.empiBatchOnAllTargets(null, criteria, null); }); assertLinkCount(2); } 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 283f9a4bcb9..8568944d716 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 @@ -217,17 +217,27 @@ public class EmpiProviderR4 extends BaseEmpiProvider { }) public Parameters empiBatchOnAllTargets( //TODO GGG MDM: also have to take it an optional resourceType here, to clarify which resources should have MDM run on them. + @OperationParam(name= ProviderConstants.MDM_BATCH_RUN_RESOURCE_TYPE, min = 0 , max = 1) StringType theResourceType, @OperationParam(name= ProviderConstants.MDM_BATCH_RUN_CRITERIA,min = 0 , max = 1) StringType theCriteria, ServletRequestDetails theRequestDetails) { - String criteria = convertCriteriaToString(theCriteria); - long submittedCount = myMdmSubmitSvc.submitAllTargetTypesToEmpi(criteria); + String criteria = convertStringTypeToString(theCriteria); + String resourceType = convertStringTypeToString(theResourceType); + + long submittedCount; + if (resourceType != null) { + submittedCount = myMdmSubmitSvc.submitTargetTypeToEmpi(resourceType, criteria); + } else { + submittedCount = myMdmSubmitSvc.submitAllTargetTypesToEmpi(criteria); + + } return buildMdmOutParametersWithCount(submittedCount); } - private String convertCriteriaToString(StringType theCriteria) { + private String convertStringTypeToString(StringType theCriteria) { return theCriteria == null ? null : theCriteria.getValueAsString(); } + @Operation(name = ProviderConstants.OPERATION_MDM_SUBMIT, idempotent = false, type = Patient.class, returnParameters = { @OperationParam(name = ProviderConstants.OPERATION_MDM_BATCH_RUN_OUT_PARAM_SUBMIT_COUNT, type = IntegerType.class) }) @@ -244,7 +254,7 @@ public class EmpiProviderR4 extends BaseEmpiProvider { public Parameters empiBatchPatientType( @OperationParam(name = ProviderConstants.MDM_BATCH_RUN_CRITERIA) StringType theCriteria, RequestDetails theRequest) { - String criteria = convertCriteriaToString(theCriteria); + String criteria = convertStringTypeToString(theCriteria); long submittedCount = myMdmSubmitSvc.submitPatientTypeToMdm(criteria); return buildMdmOutParametersWithCount(submittedCount); } @@ -265,7 +275,7 @@ public class EmpiProviderR4 extends BaseEmpiProvider { public Parameters empiBatchPractitionerType( @OperationParam(name = ProviderConstants.MDM_BATCH_RUN_CRITERIA) StringType theCriteria, RequestDetails theRequest) { - String criteria = convertCriteriaToString(theCriteria); + String criteria = convertStringTypeToString(theCriteria); long submittedCount = myMdmSubmitSvc.submitPractitionerTypeToMdm(criteria); return buildMdmOutParametersWithCount(submittedCount); } 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 4e36ba1fc61..05a52cea317 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 @@ -92,4 +92,5 @@ public class ProviderConstants { public static final String MDM_BATCH_RUN_CRITERIA = "criteria" ; public static final String OPERATION_MDM_BATCH_RUN_OUT_PARAM_SUBMIT_COUNT = "submitted" ; public static final String OPERATION_MDM_CLEAR_OUT_PARAM_DELETED_COUNT = "deleted"; + public static final String MDM_BATCH_RUN_RESOURCE_TYPE = "resourceType"; }