From ab8c5d1a7d321c939aa455bd53557c01be6fab4f Mon Sep 17 00:00:00 2001
From: anubhavBeehyv <123312249+anubhavBeehyv@users.noreply.github.com>
Date: Fri, 20 Oct 2023 11:15:32 +0530
Subject: [PATCH] BAH-2962 | Added sms sending functionality . (#231)
* Added SMS sending functionality on patient registration.
---
bahmnicore-api/pom.xml | 4 +
.../module/bahmnicore/events/BahmniEvent.java | 26 +++++++
.../bahmnicore/events/BahmniEventType.java | 16 ++++
.../bahmnicore/events/EncounterEvent.java | 19 +++++
.../bahmnicore/events/PatientEvent.java | 24 ++++++
.../events/advice/EncounterAdvice.java | 61 +++++++++++++++
.../events/advice/PatientAdvice.java | 61 +++++++++++++++
.../PatientSmsEventListener.java | 78 +++++++++++++++++++
.../eventPublisher/BahmniEventPublisher.java | 21 +++++
.../util/BahmniAsyncThreadExecutor.java | 28 +++++++
...java => EmailCommunicationController.java} | 9 +--
bahmnicore-omod/src/main/resources/config.xml | 21 ++++-
pom.xml | 2 +-
13 files changed, 361 insertions(+), 9 deletions(-)
create mode 100644 bahmnicore-api/src/main/java/org/bahmni/module/bahmnicore/events/BahmniEvent.java
create mode 100644 bahmnicore-api/src/main/java/org/bahmni/module/bahmnicore/events/BahmniEventType.java
create mode 100644 bahmnicore-api/src/main/java/org/bahmni/module/bahmnicore/events/EncounterEvent.java
create mode 100644 bahmnicore-api/src/main/java/org/bahmni/module/bahmnicore/events/PatientEvent.java
create mode 100644 bahmnicore-api/src/main/java/org/bahmni/module/bahmnicore/events/advice/EncounterAdvice.java
create mode 100644 bahmnicore-api/src/main/java/org/bahmni/module/bahmnicore/events/advice/PatientAdvice.java
create mode 100644 bahmnicore-api/src/main/java/org/bahmni/module/bahmnicore/events/eventListener/PatientSmsEventListener.java
create mode 100644 bahmnicore-api/src/main/java/org/bahmni/module/bahmnicore/events/eventPublisher/BahmniEventPublisher.java
create mode 100644 bahmnicore-api/src/main/java/org/bahmni/module/bahmnicore/util/BahmniAsyncThreadExecutor.java
rename bahmnicore-omod/src/main/java/org/bahmni/module/bahmnicore/web/v1_0/controller/{TransmissionController.java => EmailCommunicationController.java} (93%)
diff --git a/bahmnicore-api/pom.xml b/bahmnicore-api/pom.xml
index 2b447e3a7e..4aaf0cf22a 100644
--- a/bahmnicore-api/pom.xml
+++ b/bahmnicore-api/pom.xml
@@ -83,6 +83,10 @@
joda-time
2.0
+
+ org.bahmni.module
+ communication-api
+
org.bahmni.module
bahmni-emr-api
diff --git a/bahmnicore-api/src/main/java/org/bahmni/module/bahmnicore/events/BahmniEvent.java b/bahmnicore-api/src/main/java/org/bahmni/module/bahmnicore/events/BahmniEvent.java
new file mode 100644
index 0000000000..1681c1e017
--- /dev/null
+++ b/bahmnicore-api/src/main/java/org/bahmni/module/bahmnicore/events/BahmniEvent.java
@@ -0,0 +1,26 @@
+package org.bahmni.module.bahmnicore.events;
+
+import org.openmrs.api.context.Context;
+import org.openmrs.api.context.UserContext;
+
+import java.time.LocalDateTime;
+import java.util.UUID;
+
+public class BahmniEvent {
+
+ private static final long version = 1L;
+ public UserContext userContext;
+ public String eventId;
+ public BahmniEventType eventType;
+ public String payloadId;
+ public LocalDateTime publishedDateTime;
+
+ public BahmniEvent(BahmniEventType bahmniEventType) {
+ this.eventType = bahmniEventType;
+ this.eventId = UUID.randomUUID().toString();
+ this.publishedDateTime = LocalDateTime.now();
+ this.userContext= Context.getUserContext();
+ this.payloadId="";
+ }
+}
+
diff --git a/bahmnicore-api/src/main/java/org/bahmni/module/bahmnicore/events/BahmniEventType.java b/bahmnicore-api/src/main/java/org/bahmni/module/bahmnicore/events/BahmniEventType.java
new file mode 100644
index 0000000000..0f2dd642ce
--- /dev/null
+++ b/bahmnicore-api/src/main/java/org/bahmni/module/bahmnicore/events/BahmniEventType.java
@@ -0,0 +1,16 @@
+package org.bahmni.module.bahmnicore.events;
+
+public enum BahmniEventType {
+ BAHMNI_PATIENT_CREATED("bahmni-patient"),
+ BAHMNI_PATIENT_UPDATED("bahmni-patient"),
+ BAHMNI_ENCOUNTER_CREATED("bahmni-encounter"),
+ BAHMNI_ENCOUNTER_UPDATED("bahmni-encounter");
+
+ private final String topic;
+ BahmniEventType(String topic) {
+ this.topic = topic;
+ }
+ public String topic() {
+ return topic;
+ }
+}
\ No newline at end of file
diff --git a/bahmnicore-api/src/main/java/org/bahmni/module/bahmnicore/events/EncounterEvent.java b/bahmnicore-api/src/main/java/org/bahmni/module/bahmnicore/events/EncounterEvent.java
new file mode 100644
index 0000000000..a3b0107902
--- /dev/null
+++ b/bahmnicore-api/src/main/java/org/bahmni/module/bahmnicore/events/EncounterEvent.java
@@ -0,0 +1,19 @@
+package org.bahmni.module.bahmnicore.events;
+
+import org.openmrs.Encounter;
+
+public class EncounterEvent extends BahmniEvent {
+
+ private Encounter encounter;
+
+ public EncounterEvent(BahmniEventType bahmniEventType, Encounter encounter) {
+ super(bahmniEventType);
+ this.encounter = encounter;
+ this.payloadId=encounter.getUuid();
+ }
+
+ public Encounter getEncounter() {
+ return encounter;
+ }
+}
+
diff --git a/bahmnicore-api/src/main/java/org/bahmni/module/bahmnicore/events/PatientEvent.java b/bahmnicore-api/src/main/java/org/bahmni/module/bahmnicore/events/PatientEvent.java
new file mode 100644
index 0000000000..dba79af640
--- /dev/null
+++ b/bahmnicore-api/src/main/java/org/bahmni/module/bahmnicore/events/PatientEvent.java
@@ -0,0 +1,24 @@
+package org.bahmni.module.bahmnicore.events;
+
+import org.openmrs.Patient;
+import org.openmrs.api.context.Context;
+import org.springframework.stereotype.Component;
+
+import java.time.LocalDateTime;
+import java.util.UUID;
+
+public class PatientEvent extends BahmniEvent {
+
+ private Patient patient;
+
+ public PatientEvent(BahmniEventType bahmniEventType, Patient patient) {
+ super(bahmniEventType);
+ this.patient = patient;
+ this.payloadId=patient.getUuid();
+ }
+
+ public Patient getPatient() {
+ return patient;
+ }
+}
+
diff --git a/bahmnicore-api/src/main/java/org/bahmni/module/bahmnicore/events/advice/EncounterAdvice.java b/bahmnicore-api/src/main/java/org/bahmni/module/bahmnicore/events/advice/EncounterAdvice.java
new file mode 100644
index 0000000000..649a21f563
--- /dev/null
+++ b/bahmnicore-api/src/main/java/org/bahmni/module/bahmnicore/events/advice/EncounterAdvice.java
@@ -0,0 +1,61 @@
+package org.bahmni.module.bahmnicore.events.advice;
+
+import com.google.common.collect.Sets;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+import org.bahmni.module.bahmnicore.events.BahmniEventType;
+import org.bahmni.module.bahmnicore.events.EncounterEvent;
+import org.bahmni.module.bahmnicore.events.eventPublisher.BahmniEventPublisher;
+import org.openmrs.Encounter;
+import org.openmrs.api.context.Context;
+import org.springframework.aop.AfterReturningAdvice;
+import org.springframework.aop.MethodBeforeAdvice;
+
+import java.lang.reflect.Method;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+
+import static org.bahmni.module.bahmnicore.events.BahmniEventType.BAHMNI_ENCOUNTER_CREATED;
+import static org.bahmni.module.bahmnicore.events.BahmniEventType.BAHMNI_ENCOUNTER_UPDATED;
+
+
+public class EncounterAdvice implements AfterReturningAdvice, MethodBeforeAdvice {
+
+ private final Logger log = LogManager.getLogger(this.getClass());
+ private final BahmniEventPublisher eventPublisher;
+ private final ThreadLocal