From 00a9975bc7dfd39c809429c6b92bedf91af68637 Mon Sep 17 00:00:00 2001 From: Ritesh Ghiya Date: Wed, 30 Aug 2023 17:27:56 +0530 Subject: [PATCH] [ Ritesh ] | BAH-3191 - PR Feedback incorporated. --- .../bahmni/module/events/api/listener/PatientAdvice.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/api/src/main/java/org/bahmni/module/events/api/listener/PatientAdvice.java b/api/src/main/java/org/bahmni/module/events/api/listener/PatientAdvice.java index e5567e8..7c45fd8 100644 --- a/api/src/main/java/org/bahmni/module/events/api/listener/PatientAdvice.java +++ b/api/src/main/java/org/bahmni/module/events/api/listener/PatientAdvice.java @@ -1,5 +1,6 @@ package org.bahmni.module.events.api.listener; +import com.google.common.collect.Sets; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.bahmni.module.events.api.model.BahmniEventType; @@ -15,6 +16,7 @@ import java.lang.reflect.Method; import java.util.HashMap; import java.util.Map; +import java.util.Set; import static org.bahmni.module.events.api.model.BahmniEventType.BAHMNI_PATIENT_CREATED; import static org.bahmni.module.events.api.model.BahmniEventType.BAHMNI_PATIENT_UPDATED; @@ -25,6 +27,7 @@ public class PatientAdvice implements AfterReturningAdvice, MethodBeforeAdvice { private final BahmniEventPublisher eventPublisher; private final ThreadLocal> threadLocal = new ThreadLocal<>(); private final String PATIENT_ID_KEY = "patientId"; + private final Set adviceMethodNames = Sets.newHashSet("savePatient"); public PatientAdvice() { this.eventPublisher = Context.getRegisteredComponent("bahmniEventPublisher", BahmniEventPublisher.class); @@ -36,7 +39,7 @@ public PatientAdvice(BahmniEventPublisher bahmniEventPublisher) { @Override public void afterReturning(Object returnValue, Method method, Object[] arguments, Object target) { - if (method.getName().equals("savePatient")) { + if (adviceMethodNames.contains(method.getName())) { Map patientInfo = threadLocal.get(); BahmniEventType eventType = patientInfo != null && patientInfo.get(PATIENT_ID_KEY) == null ? BAHMNI_PATIENT_CREATED : BAHMNI_PATIENT_UPDATED; threadLocal.remove(); @@ -53,7 +56,7 @@ public void afterReturning(Object returnValue, Method method, Object[] arguments @Override public void before(Method method, Object[] objects, Object o) { - if (method.getName().equals("savePatient")) { + if (adviceMethodNames.contains(method.getName())) { Patient patient = (Patient) objects[0]; Map patientInfo = new HashMap<>(1);