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..21924dcbb1
--- /dev/null
+++ b/bahmnicore-api/src/main/java/org/bahmni/module/bahmnicore/events/BahmniEvent.java
@@ -0,0 +1,35 @@
+package org.bahmni.module.bahmnicore.events;
+
+import org.openmrs.api.context.UserContext;
+import org.springframework.stereotype.Component;
+
+import java.time.LocalDateTime;
+
+@Component
+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 UserContext getUserContext() {
+ return userContext;
+ }
+ public String getEventId() {
+ return eventId;
+ }
+ public BahmniEventType getEventType() {
+ return eventType;
+ }
+ public String getPayloadId() {
+ return payloadId;
+ }
+
+ public LocalDateTime getPublishedDateTime() {
+ return publishedDateTime;
+ }
+}
+
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..bbda65c16e
--- /dev/null
+++ b/bahmnicore-api/src/main/java/org/bahmni/module/bahmnicore/events/EncounterEvent.java
@@ -0,0 +1,29 @@
+package org.bahmni.module.bahmnicore.events;
+
+import org.openmrs.Encounter;
+import org.openmrs.Patient;
+import org.openmrs.api.context.Context;
+import org.springframework.stereotype.Component;
+
+import java.time.LocalDateTime;
+import java.util.UUID;
+
+@Component
+public class EncounterEvent extends BahmniEvent {
+
+ private Encounter encounter;
+
+ public void createEncounterEvent(BahmniEventType eventType, Encounter encounter) {
+ this.eventType = eventType;
+ this.encounter = encounter;
+ this.eventId = UUID.randomUUID().toString();
+ this.payloadId = encounter.getUuid();
+ this.publishedDateTime = LocalDateTime.now();
+ this.userContext= Context.getUserContext();
+ }
+
+ 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..a0901bba25
--- /dev/null
+++ b/bahmnicore-api/src/main/java/org/bahmni/module/bahmnicore/events/PatientEvent.java
@@ -0,0 +1,28 @@
+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;
+
+@Component
+public class PatientEvent extends BahmniEvent {
+
+ private Patient patient;
+
+ public void createPatientEvent(BahmniEventType eventType, Patient patient) {
+ this.eventType = eventType;
+ this.patient = patient;
+ this.eventId = UUID.randomUUID().toString();
+ this.payloadId = patient.getUuid();
+ this.publishedDateTime = LocalDateTime.now();
+ this.userContext= Context.getUserContext();
+ }
+
+ 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..8b0bde10b1
--- /dev/null
+++ b/bahmnicore-api/src/main/java/org/bahmni/module/bahmnicore/events/advice/EncounterAdvice.java
@@ -0,0 +1,62 @@
+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 EncounterEvent encounterEvent;
+ private final ThreadLocal