diff --git a/hapi-fhir-jpaserver-empi/src/main/java/ca/uhn/fhir/jpa/empi/config/EmpiConsumerConfig.java b/hapi-fhir-jpaserver-empi/src/main/java/ca/uhn/fhir/jpa/empi/config/EmpiConsumerConfig.java index 496d860923e..7c64c923d59 100644 --- a/hapi-fhir-jpaserver-empi/src/main/java/ca/uhn/fhir/jpa/empi/config/EmpiConsumerConfig.java +++ b/hapi-fhir-jpaserver-empi/src/main/java/ca/uhn/fhir/jpa/empi/config/EmpiConsumerConfig.java @@ -214,7 +214,7 @@ public class EmpiConsumerConfig { } @Bean - EmpiResourceFilteringSvc empiMessageFilteringSvc() { + EmpiResourceFilteringSvc empiResourceFilteringSvc() { return new EmpiResourceFilteringSvc(); } } diff --git a/hapi-fhir-jpaserver-empi/src/main/java/ca/uhn/fhir/jpa/empi/svc/EmpiResourceFilteringSvc.java b/hapi-fhir-jpaserver-empi/src/main/java/ca/uhn/fhir/jpa/empi/svc/EmpiResourceFilteringSvc.java index f455ef59eff..83f61422153 100644 --- a/hapi-fhir-jpaserver-empi/src/main/java/ca/uhn/fhir/jpa/empi/svc/EmpiResourceFilteringSvc.java +++ b/hapi-fhir-jpaserver-empi/src/main/java/ca/uhn/fhir/jpa/empi/svc/EmpiResourceFilteringSvc.java @@ -32,7 +32,7 @@ public class EmpiResourceFilteringSvc { * If the payload has no attributes that appear in the Candidate Search Params, processing should be skipped, as there is not * sufficient information to perform meaningful EMPI processing. (For example, how can EMPI processing occur on a patient that has _no_ attributes?) * - * @param theMessage the message provided by the EMPI channel. + * @param theResource the resource that you wish to check against EMPI rules. * * @return whether or not EMPI processing should proceed */ @@ -41,7 +41,7 @@ public class EmpiResourceFilteringSvc { List candidateSearchParams = empiSettings.getEmpiRules().getCandidateSearchParams(); boolean containsValueForSomeSearchParam = candidateSearchParams.stream() - .filter(csp -> searchParamIsValidForType(csp, resourceType)) + .filter(csp -> myEmpiSearchParamSvc.searchParamTypeIsValidForResourceType(csp.getResourceType(), resourceType)) .flatMap(csp -> csp.getSearchParams().stream()) .map(searchParam -> myEmpiSearchParamSvc.getValueFromResourceForSearchParam(theResource, searchParam)) .anyMatch(valueList -> !valueList.isEmpty()); @@ -49,9 +49,4 @@ public class EmpiResourceFilteringSvc { ourLog.debug("Is {} suitable for EMPI processing? : {}", theResource.getId(), containsValueForSomeSearchParam); return containsValueForSomeSearchParam; } - - private boolean searchParamIsValidForType(EmpiResourceSearchParamJson theSearchParamJson, String theResourceType) { - return theSearchParamJson.getResourceType().equalsIgnoreCase(theResourceType) || theSearchParamJson.getResourceType().equalsIgnoreCase("*"); - - } } diff --git a/hapi-fhir-jpaserver-empi/src/main/java/ca/uhn/fhir/jpa/empi/svc/EmpiSearchParamSvc.java b/hapi-fhir-jpaserver-empi/src/main/java/ca/uhn/fhir/jpa/empi/svc/EmpiSearchParamSvc.java index b9fd9747aa3..9c033f4df6b 100644 --- a/hapi-fhir-jpaserver-empi/src/main/java/ca/uhn/fhir/jpa/empi/svc/EmpiSearchParamSvc.java +++ b/hapi-fhir-jpaserver-empi/src/main/java/ca/uhn/fhir/jpa/empi/svc/EmpiSearchParamSvc.java @@ -87,10 +87,20 @@ public class EmpiSearchParamSvc implements ISearchParamRetriever { spMap = mapFromCriteria(theTargetType, theCriteria); } return spMap; - } + } - public ISearchBuilder generateSearchBuilderForType(String theTargetType) { + public ISearchBuilder generateSearchBuilderForType(String theTargetType) { IFhirResourceDao resourceDao = myDaoRegistry.getResourceDao(theTargetType); return mySearchBuilderFactory.newSearchBuilder(resourceDao, theTargetType, resourceDao.getResourceType()); } + + /** + * Will return true if the types match, or the search param type is '*', otherwise false. + * @param theSearchParamType + * @param theResourceType + * @return + */ + public boolean searchParamTypeIsValidForResourceType(String theSearchParamType, String theResourceType) { + return theSearchParamType.equalsIgnoreCase(theResourceType) || theSearchParamType.equalsIgnoreCase("*"); + } } diff --git a/hapi-fhir-jpaserver-empi/src/test/java/ca/uhn/fhir/jpa/empi/svc/EmpiResourceFilteringSvcTest.java b/hapi-fhir-jpaserver-empi/src/test/java/ca/uhn/fhir/jpa/empi/svc/EmpiResourceFilteringSvcTest.java index 0b4ae216b44..f0fbf66dca9 100644 --- a/hapi-fhir-jpaserver-empi/src/test/java/ca/uhn/fhir/jpa/empi/svc/EmpiResourceFilteringSvcTest.java +++ b/hapi-fhir-jpaserver-empi/src/test/java/ca/uhn/fhir/jpa/empi/svc/EmpiResourceFilteringSvcTest.java @@ -13,7 +13,7 @@ import static org.hamcrest.Matchers.is; class EmpiResourceFilteringSvcTest extends BaseEmpiR4Test { @Autowired - private EmpiResourceFilteringSvc myEmpiMessageFilteringSvc; + private EmpiResourceFilteringSvc myEmpiResourceFilteringSvc; @Test public void testFilterResourcesWhichHaveNoRelevantAttributes() { @@ -21,7 +21,7 @@ class EmpiResourceFilteringSvcTest extends BaseEmpiR4Test { patient.setDeceased(new BooleanType(true)); //EMPI rules defined do not care about the deceased attribute. //SUT - boolean shouldBeProcessed = myEmpiMessageFilteringSvc.shouldBeProcessed(patient); + boolean shouldBeProcessed = myEmpiResourceFilteringSvc.shouldBeProcessed(patient); assertThat(shouldBeProcessed, is(equalTo(false))); } @@ -32,7 +32,7 @@ class EmpiResourceFilteringSvcTest extends BaseEmpiR4Test { patient.addIdentifier().setValue("Hey I'm an ID! rules defined in empi-rules.json care about me!"); //SUT - boolean shouldBeProcessed = myEmpiMessageFilteringSvc.shouldBeProcessed(patient); + boolean shouldBeProcessed = myEmpiResourceFilteringSvc.shouldBeProcessed(patient); assertThat(shouldBeProcessed, is(equalTo(true))); }