Merge branch 'gg_20201105-remove-person-references' of github.com:jamesagnew/hapi-fhir into gg_20201105-remove-person-references

This commit is contained in:
Nick Goupinets 2020-11-13 16:57:23 -05:00
commit 176f7f0412
3 changed files with 48 additions and 9 deletions

View File

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

View File

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

View File

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