diff --git a/hapi-fhir-jpaserver-empi/src/main/java/ca/uhn/fhir/jpa/empi/broker/EmpiMessageHandler.java b/hapi-fhir-jpaserver-empi/src/main/java/ca/uhn/fhir/jpa/empi/broker/EmpiMessageHandler.java index f98b563fda2..6c97cccbf14 100644 --- a/hapi-fhir-jpaserver-empi/src/main/java/ca/uhn/fhir/jpa/empi/broker/EmpiMessageHandler.java +++ b/hapi-fhir-jpaserver-empi/src/main/java/ca/uhn/fhir/jpa/empi/broker/EmpiMessageHandler.java @@ -28,6 +28,7 @@ import ca.uhn.fhir.interceptor.api.HookParams; import ca.uhn.fhir.interceptor.api.IInterceptorBroadcaster; import ca.uhn.fhir.interceptor.api.Pointcut; import ca.uhn.fhir.jpa.empi.svc.EmpiMatchLinkSvc; +import ca.uhn.fhir.jpa.empi.svc.EmpiMessageFilteringSvc; import ca.uhn.fhir.jpa.subscription.model.ResourceModifiedJsonMessage; import ca.uhn.fhir.jpa.subscription.model.ResourceModifiedMessage; import ca.uhn.fhir.rest.server.TransactionLogMessages; @@ -50,6 +51,8 @@ public class EmpiMessageHandler implements MessageHandler { private IInterceptorBroadcaster myInterceptorBroadcaster; @Autowired private FhirContext myFhirContext; + @Autowired + private EmpiMessageFilteringSvc myEmpiResourceFileringSvc; @Override public void handleMessage(Message theMessage) throws MessagingException { @@ -62,13 +65,14 @@ public class EmpiMessageHandler implements MessageHandler { ResourceModifiedMessage msg = ((ResourceModifiedJsonMessage) theMessage).getPayload(); try { - matchEmpiAndUpdateLinks(msg); + if (myEmpiResourceFileringSvc.shouldBeProcessed(msg)) { + matchEmpiAndUpdateLinks(msg); + } } catch (Exception e) { ourLog.error("Failed to handle EMPI Matching Resource:", e); throw e; } } - public void matchEmpiAndUpdateLinks(ResourceModifiedMessage theMsg) { String resourceType = theMsg.getId(myFhirContext).getResourceType(); validateResourceType(resourceType); 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 31da550d51a..22914903141 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 @@ -47,6 +47,7 @@ import ca.uhn.fhir.jpa.empi.svc.EmpiLinkSvcImpl; import ca.uhn.fhir.jpa.empi.svc.EmpiLinkUpdaterSvcImpl; import ca.uhn.fhir.jpa.empi.svc.EmpiMatchFinderSvcImpl; import ca.uhn.fhir.jpa.empi.svc.EmpiMatchLinkSvc; +import ca.uhn.fhir.jpa.empi.svc.EmpiMessageFilteringSvc; import ca.uhn.fhir.jpa.empi.svc.EmpiPersonDeletingSvc; import ca.uhn.fhir.jpa.empi.svc.EmpiPersonMergerSvcImpl; import ca.uhn.fhir.jpa.empi.svc.EmpiResetSvcImpl; @@ -211,4 +212,9 @@ public class EmpiConsumerConfig { EmpiLinkDeleteSvc empiLinkDeleteSvc() { return new EmpiLinkDeleteSvc(); } + + @Bean + EmpiMessageFilteringSvc empiMessageFilteringSvc() { + return new EmpiMessageFilteringSvc(); + } } diff --git a/hapi-fhir-jpaserver-empi/src/main/java/ca/uhn/fhir/jpa/empi/svc/EmpiMessageFilteringSvc.java b/hapi-fhir-jpaserver-empi/src/main/java/ca/uhn/fhir/jpa/empi/svc/EmpiMessageFilteringSvc.java new file mode 100644 index 00000000000..00c1ae0556c --- /dev/null +++ b/hapi-fhir-jpaserver-empi/src/main/java/ca/uhn/fhir/jpa/empi/svc/EmpiMessageFilteringSvc.java @@ -0,0 +1,25 @@ +package ca.uhn.fhir.jpa.empi.svc; + +import ca.uhn.fhir.empi.api.IEmpiSettings; +import ca.uhn.fhir.empi.rules.json.EmpiResourceSearchParamJson; +import ca.uhn.fhir.jpa.subscription.model.ResourceModifiedMessage; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.List; + +@Service +public class EmpiMessageFilteringSvc { + + @Autowired + private IEmpiSettings empiSettings; + + @Autowired + EmpiSearchParamSvc myEmpiSearchParamSvc; + + public boolean shouldBeProcessed(ResourceModifiedMessage theMsg) { + List candidateSearchParams = empiSettings.getEmpiRules().getCandidateSearchParams(); + List valuesFromResourceForSearchParam = myEmpiSearchParamSvc.getValueFromResourceForSearchParam(theResource, searchParam); + + } +} diff --git a/hapi-fhir-jpaserver-empi/src/test/java/ca/uhn/fhir/jpa/empi/interceptor/EmpiStorageInterceptorIT.java b/hapi-fhir-jpaserver-empi/src/test/java/ca/uhn/fhir/jpa/empi/interceptor/EmpiStorageInterceptorIT.java index c2ac7766a1b..5d8ab026733 100644 --- a/hapi-fhir-jpaserver-empi/src/test/java/ca/uhn/fhir/jpa/empi/interceptor/EmpiStorageInterceptorIT.java +++ b/hapi-fhir-jpaserver-empi/src/test/java/ca/uhn/fhir/jpa/empi/interceptor/EmpiStorageInterceptorIT.java @@ -104,7 +104,7 @@ public class EmpiStorageInterceptorIT extends BaseEmpiR4Test { @Test public void testCreatingPersonWithInsufficentEMPIAttributesIsNotEMPIProcessed() throws InterruptedException { - myEmpiHelper.createWithLatch(new Patient()); + myEmpiHelper.doCreateResource(new Patient(), true); assertLinkCount(0); } @@ -112,7 +112,6 @@ public class EmpiStorageInterceptorIT extends BaseEmpiR4Test { public void testCreatingPatientWithOneOrMoreMatchingAttributesIsEMPIProcessed() throws InterruptedException { myEmpiHelper.createWithLatch(buildPaulPatient()); assertLinkCount(1); - } @Test