Skip to content

Commit

Permalink
[ Ritesh ] | BAH-3191 - PR Feedback incorporated.
Browse files Browse the repository at this point in the history
  • Loading branch information
riteshghiya90 committed Sep 1, 2023
1 parent 724198e commit 00a9975
Showing 1 changed file with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand All @@ -25,6 +27,7 @@ public class PatientAdvice implements AfterReturningAdvice, MethodBeforeAdvice {
private final BahmniEventPublisher eventPublisher;
private final ThreadLocal<Map<String,Integer>> threadLocal = new ThreadLocal<>();
private final String PATIENT_ID_KEY = "patientId";
private final Set<String> adviceMethodNames = Sets.newHashSet("savePatient");

public PatientAdvice() {
this.eventPublisher = Context.getRegisteredComponent("bahmniEventPublisher", BahmniEventPublisher.class);
Expand All @@ -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<String, Integer> patientInfo = threadLocal.get();
BahmniEventType eventType = patientInfo != null && patientInfo.get(PATIENT_ID_KEY) == null ? BAHMNI_PATIENT_CREATED : BAHMNI_PATIENT_UPDATED;
threadLocal.remove();
Expand All @@ -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<String, Integer> patientInfo = new HashMap<>(1);
Expand Down

0 comments on commit 00a9975

Please sign in to comment.