diff --git a/api/pom.xml b/api/pom.xml
index f119a5e..cc20907 100644
--- a/api/pom.xml
+++ b/api/pom.xml
@@ -145,6 +145,18 @@
provided
+
+ org.bahmni.module
+ fhir2Extension-api
+ provided
+
+
+
+ org.bahmni.module
+ fhir2Extension-omod
+ provided
+
+
org.bahmni.module
medication-administration-api
diff --git a/omod/pom.xml b/omod/pom.xml
index 8895021..11a3f26 100644
--- a/omod/pom.xml
+++ b/omod/pom.xml
@@ -123,6 +123,18 @@
provided
+
+ org.bahmni.module
+ fhir2Extension-api
+ provided
+
+
+
+ org.bahmni.module
+ fhir2Extension-omod
+ provided
+
+
org.openmrs.module
emrapi-api
diff --git a/omod/src/main/java/org/openmrs/module/ipd/events/ConfigLoader.java b/omod/src/main/java/org/openmrs/module/ipd/events/ConfigLoader.java
new file mode 100644
index 0000000..3b390fa
--- /dev/null
+++ b/omod/src/main/java/org/openmrs/module/ipd/events/ConfigLoader.java
@@ -0,0 +1,41 @@
+package org.openmrs.module.ipd.events;
+
+import com.fasterxml.jackson.core.type.TypeReference;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import lombok.extern.slf4j.Slf4j;
+import org.openmrs.module.ipd.events.model.ConfigDetail;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.core.io.FileSystemResource;
+import org.springframework.stereotype.Component;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+@Component
+@Slf4j
+public class ConfigLoader {
+ private List configs = new ArrayList<>();
+
+ private ObjectMapper objectMapper = new ObjectMapper();
+
+ @Value("${config-file.path}")
+ private String routeConfigurationFileLocation;
+
+ public List getConfigs() {
+ if (configs.isEmpty()) {
+ loadConfiguration();
+ }
+ return this.configs;
+ }
+
+ private void loadConfiguration() {
+ try {
+ File routeConfigurationFile = new FileSystemResource(routeConfigurationFileLocation).getFile();
+ this.configs = objectMapper.readValue(routeConfigurationFile, new TypeReference>() {});
+ } catch (IOException exception) {
+ log.error("Failed to load configuration for file : " + routeConfigurationFileLocation, exception);
+ }
+ }
+}
diff --git a/omod/src/main/java/org/openmrs/module/ipd/events/IPDEventManager.java b/omod/src/main/java/org/openmrs/module/ipd/events/IPDEventManager.java
new file mode 100644
index 0000000..7614774
--- /dev/null
+++ b/omod/src/main/java/org/openmrs/module/ipd/events/IPDEventManager.java
@@ -0,0 +1,36 @@
+package org.openmrs.module.ipd.events;
+
+import org.openmrs.module.ipd.events.factory.IPDEventFactory;
+import org.openmrs.module.ipd.events.handler.IPDEventHandler;
+import org.openmrs.module.ipd.events.model.IPDEvent;
+import org.openmrs.module.ipd.events.model.IPDEventType;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+@Component
+public class IPDEventManager {
+ @Autowired
+ ConfigLoader configLoader;
+
+ @Autowired
+ IPDEventFactory eventFactory;
+
+ public IPDEventType getEventTypeForEncounter(String type) {
+ switch (type) {
+ case "ADMISSION":
+ return IPDEventType.PATIENT_ADMIT;
+ case "SHIFT_START_TASK":
+ return IPDEventType.SHIFT_START_TASK;
+ case "ROLLOVER_TASK":
+ return IPDEventType.ROLLOVER_TASK;
+ default:
+ return null;
+ }
+ }
+
+ public void processEvent(IPDEvent event) {
+ IPDEventHandler handler = eventFactory.createEventHandler(event.getIpdEventType());
+ handler.handleEvent(event);
+ }
+
+}
diff --git a/omod/src/main/java/org/openmrs/module/ipd/events/IPDEventUtils.java b/omod/src/main/java/org/openmrs/module/ipd/events/IPDEventUtils.java
new file mode 100644
index 0000000..42abc30
--- /dev/null
+++ b/omod/src/main/java/org/openmrs/module/ipd/events/IPDEventUtils.java
@@ -0,0 +1,22 @@
+package org.openmrs.module.ipd.events;
+
+import org.openmrs.module.fhir2.model.FhirTask;
+import org.openmrs.module.fhirExtension.web.contract.TaskRequest;
+import org.openmrs.module.ipd.events.model.IPDEvent;
+
+import java.util.Date;
+
+public class IPDEventUtils {
+
+ public static TaskRequest createNonMedicationTaskRequest(IPDEvent ipdEvent, String name, String taskType) {
+ TaskRequest taskRequest = new TaskRequest();
+ taskRequest.setName(name);
+ taskRequest.setTaskType(taskType);
+ taskRequest.setEncounterUuid(ipdEvent.getEncounterUuid());
+ taskRequest.setPatientUuid(ipdEvent.getPatientUuid());
+ taskRequest.setRequestedStartTime(new Date());
+ taskRequest.setIntent(FhirTask.TaskIntent.ORDER);
+ taskRequest.setStatus(FhirTask.TaskStatus.REQUESTED);
+ return taskRequest;
+ }
+}
diff --git a/omod/src/main/java/org/openmrs/module/ipd/events/factory/IPDEventFactory.java b/omod/src/main/java/org/openmrs/module/ipd/events/factory/IPDEventFactory.java
new file mode 100644
index 0000000..690a467
--- /dev/null
+++ b/omod/src/main/java/org/openmrs/module/ipd/events/factory/IPDEventFactory.java
@@ -0,0 +1,8 @@
+package org.openmrs.module.ipd.events.factory;
+
+import org.openmrs.module.ipd.events.model.IPDEventType;
+import org.openmrs.module.ipd.events.handler.IPDEventHandler;
+
+public interface IPDEventFactory {
+ IPDEventHandler createEventHandler(IPDEventType eventType);
+}
\ No newline at end of file
diff --git a/omod/src/main/java/org/openmrs/module/ipd/events/factory/impl/IPDEventFactoryImpl.java b/omod/src/main/java/org/openmrs/module/ipd/events/factory/impl/IPDEventFactoryImpl.java
new file mode 100644
index 0000000..faf7ddb
--- /dev/null
+++ b/omod/src/main/java/org/openmrs/module/ipd/events/factory/impl/IPDEventFactoryImpl.java
@@ -0,0 +1,38 @@
+package org.openmrs.module.ipd.events.factory.impl;
+
+import org.openmrs.module.ipd.events.model.IPDEventType;
+import org.openmrs.module.ipd.events.factory.IPDEventFactory;
+import org.openmrs.module.ipd.events.handler.IPDEventHandler;
+import org.openmrs.module.ipd.events.handler.impl.PatientAdmitEventHandler;
+import org.openmrs.module.ipd.events.handler.impl.RolloverTaskEventHandler;
+import org.openmrs.module.ipd.events.handler.impl.ShiftStartTaskEventHandler;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+@Component
+public class IPDEventFactoryImpl implements IPDEventFactory {
+
+ @Autowired
+ PatientAdmitEventHandler patientAdmitEventHandler;
+
+ @Autowired
+ ShiftStartTaskEventHandler shiftStartTaskEventHandler;
+
+ @Autowired
+ RolloverTaskEventHandler rolloverTaskEventHandler;
+
+ @Override
+ public IPDEventHandler createEventHandler(IPDEventType eventType) {
+ switch (eventType) {
+ case PATIENT_ADMIT:
+ return patientAdmitEventHandler;
+ case SHIFT_START_TASK:
+ return shiftStartTaskEventHandler;
+ case ROLLOVER_TASK:
+ return rolloverTaskEventHandler;
+ default:
+ throw new IllegalArgumentException("Unsupported event type: " + eventType);
+ }
+ }
+
+}
diff --git a/omod/src/main/java/org/openmrs/module/ipd/events/handler/IPDEventHandler.java b/omod/src/main/java/org/openmrs/module/ipd/events/handler/IPDEventHandler.java
new file mode 100644
index 0000000..27b1cca
--- /dev/null
+++ b/omod/src/main/java/org/openmrs/module/ipd/events/handler/IPDEventHandler.java
@@ -0,0 +1,7 @@
+package org.openmrs.module.ipd.events.handler;
+
+import org.openmrs.module.ipd.events.model.IPDEvent;
+
+public interface IPDEventHandler {
+ void handleEvent(IPDEvent event);
+}
\ No newline at end of file
diff --git a/omod/src/main/java/org/openmrs/module/ipd/events/handler/impl/PatientAdmitEventHandler.java b/omod/src/main/java/org/openmrs/module/ipd/events/handler/impl/PatientAdmitEventHandler.java
new file mode 100644
index 0000000..e9717da
--- /dev/null
+++ b/omod/src/main/java/org/openmrs/module/ipd/events/handler/impl/PatientAdmitEventHandler.java
@@ -0,0 +1,52 @@
+package org.openmrs.module.ipd.events.handler.impl;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.openmrs.module.fhirExtension.model.Task;
+import org.openmrs.module.fhirExtension.service.TaskService;
+import org.openmrs.module.fhirExtension.web.contract.TaskRequest;
+import org.openmrs.module.fhirExtension.web.mapper.TaskMapper;
+import org.openmrs.module.ipd.events.ConfigLoader;
+import org.openmrs.module.ipd.events.IPDEventUtils;
+import org.openmrs.module.ipd.events.handler.IPDEventHandler;
+import org.openmrs.module.ipd.events.model.ConfigDetail;
+import org.openmrs.module.ipd.events.model.IPDEvent;
+import org.openmrs.module.ipd.events.model.TaskDetail;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import java.util.List;
+
+@Component
+public class PatientAdmitEventHandler implements IPDEventHandler {
+
+ private final Log log = LogFactory.getLog(this.getClass());
+
+ @Autowired
+ ConfigLoader configLoader;
+
+ @Autowired
+ private TaskMapper taskMapper;
+
+ @Autowired
+ private TaskService taskService;
+
+ @Override
+ public void handleEvent(IPDEvent event) {
+ List configList = configLoader.getConfigs();
+ ConfigDetail eventConfig = configList.stream()
+ .filter(config -> config.getType().equals(event.getIpdEventType().name()))
+ .findFirst()
+ .orElse(null);
+ if (eventConfig != null) {
+ for(TaskDetail taskDetail : eventConfig.getTasks()) {
+ TaskRequest taskRequest = IPDEventUtils.createNonMedicationTaskRequest(event, taskDetail.getName(), "nursing_activity_system");
+ Task task = taskMapper.fromRequest(taskRequest);
+ taskService.saveTask(task);
+ log.info("Task created " + taskDetail.getName());
+ }
+ }
+
+
+ }
+}
\ No newline at end of file
diff --git a/omod/src/main/java/org/openmrs/module/ipd/events/handler/impl/RolloverTaskEventHandler.java b/omod/src/main/java/org/openmrs/module/ipd/events/handler/impl/RolloverTaskEventHandler.java
new file mode 100644
index 0000000..71f0def
--- /dev/null
+++ b/omod/src/main/java/org/openmrs/module/ipd/events/handler/impl/RolloverTaskEventHandler.java
@@ -0,0 +1,29 @@
+package org.openmrs.module.ipd.events.handler.impl;
+
+import org.openmrs.module.ipd.events.ConfigLoader;
+import org.openmrs.module.ipd.events.model.ConfigDetail;
+import org.openmrs.module.ipd.events.model.IPDEvent;
+import org.openmrs.module.ipd.events.handler.IPDEventHandler;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import java.util.List;
+
+@Component
+public class RolloverTaskEventHandler implements IPDEventHandler {
+
+ @Autowired
+ ConfigLoader configLoader;
+
+ @Override
+ public void handleEvent(IPDEvent event) {
+ List configList = configLoader.getConfigs();
+ ConfigDetail eventConfig = configList.stream()
+ .filter(config -> config.getType().equals(event.getIpdEventType().name()))
+ .findFirst()
+ .orElse(null);
+ System.out.println("eventConfig type RolloverTaskEventHandler " + eventConfig.getType());
+ System.out.println("eventConfig tasks RolloverTaskEventHandler " + eventConfig.getTasks() + " size --- " + eventConfig.getTasks().size());
+ //create task based on configuration
+ }
+}
\ No newline at end of file
diff --git a/omod/src/main/java/org/openmrs/module/ipd/events/handler/impl/ShiftStartTaskEventHandler.java b/omod/src/main/java/org/openmrs/module/ipd/events/handler/impl/ShiftStartTaskEventHandler.java
new file mode 100644
index 0000000..603e59a
--- /dev/null
+++ b/omod/src/main/java/org/openmrs/module/ipd/events/handler/impl/ShiftStartTaskEventHandler.java
@@ -0,0 +1,28 @@
+package org.openmrs.module.ipd.events.handler.impl;
+
+import org.openmrs.module.ipd.events.ConfigLoader;
+import org.openmrs.module.ipd.events.model.ConfigDetail;
+import org.openmrs.module.ipd.events.model.IPDEvent;
+import org.openmrs.module.ipd.events.handler.IPDEventHandler;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import java.util.List;
+
+@Component
+public class ShiftStartTaskEventHandler implements IPDEventHandler {
+
+ @Autowired
+ ConfigLoader configLoader;
+
+ @Override
+ public void handleEvent(IPDEvent event) {
+ List configList = configLoader.getConfigs();
+ ConfigDetail eventConfig = configList.stream()
+ .filter(config -> config.getType().equals(event.getIpdEventType().name()))
+ .findFirst()
+ .orElse(null);
+
+ //create task based on configuration
+ }
+}
\ No newline at end of file
diff --git a/omod/src/main/java/org/openmrs/module/ipd/events/model/ConfigDetail.java b/omod/src/main/java/org/openmrs/module/ipd/events/model/ConfigDetail.java
new file mode 100644
index 0000000..8eae262
--- /dev/null
+++ b/omod/src/main/java/org/openmrs/module/ipd/events/model/ConfigDetail.java
@@ -0,0 +1,19 @@
+package org.openmrs.module.ipd.events.model;
+
+import com.fasterxml.jackson.annotation.JsonAutoDetect;
+import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+
+import java.util.List;
+
+@JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.ANY)
+@JsonIgnoreProperties(ignoreUnknown = true)
+@Getter
+@NoArgsConstructor
+@AllArgsConstructor
+public class ConfigDetail {
+ private String type;
+ private List tasks;
+}
diff --git a/omod/src/main/java/org/openmrs/module/ipd/events/model/IPDEvent.java b/omod/src/main/java/org/openmrs/module/ipd/events/model/IPDEvent.java
new file mode 100644
index 0000000..e812c49
--- /dev/null
+++ b/omod/src/main/java/org/openmrs/module/ipd/events/model/IPDEvent.java
@@ -0,0 +1,18 @@
+package org.openmrs.module.ipd.events.model;
+
+import com.fasterxml.jackson.annotation.JsonAutoDetect;
+import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+
+@JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.ANY)
+@JsonIgnoreProperties(ignoreUnknown = true)
+@Getter
+@NoArgsConstructor
+@AllArgsConstructor
+public class IPDEvent {
+ private String encounterUuid;
+ private String patientUuid;
+ private IPDEventType ipdEventType;
+}
diff --git a/omod/src/main/java/org/openmrs/module/ipd/events/model/IPDEventType.java b/omod/src/main/java/org/openmrs/module/ipd/events/model/IPDEventType.java
new file mode 100644
index 0000000..52196f0
--- /dev/null
+++ b/omod/src/main/java/org/openmrs/module/ipd/events/model/IPDEventType.java
@@ -0,0 +1,7 @@
+package org.openmrs.module.ipd.events.model;
+
+public enum IPDEventType {
+ PATIENT_ADMIT,
+ SHIFT_START_TASK,
+ ROLLOVER_TASK;
+}
diff --git a/omod/src/main/java/org/openmrs/module/ipd/events/model/TaskDetail.java b/omod/src/main/java/org/openmrs/module/ipd/events/model/TaskDetail.java
new file mode 100644
index 0000000..e5de905
--- /dev/null
+++ b/omod/src/main/java/org/openmrs/module/ipd/events/model/TaskDetail.java
@@ -0,0 +1,16 @@
+package org.openmrs.module.ipd.events.model;
+
+import com.fasterxml.jackson.annotation.JsonAutoDetect;
+import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+
+@JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.ANY)
+@JsonIgnoreProperties(ignoreUnknown = true)
+@Getter
+@NoArgsConstructor
+@AllArgsConstructor
+public class TaskDetail {
+ private String name;
+}
diff --git a/omod/src/main/java/org/openmrs/module/ipd/postprocessor/IPDTransactionHandler.java b/omod/src/main/java/org/openmrs/module/ipd/postprocessor/IPDTransactionHandler.java
index 81c74aa..82c9825 100644
--- a/omod/src/main/java/org/openmrs/module/ipd/postprocessor/IPDTransactionHandler.java
+++ b/omod/src/main/java/org/openmrs/module/ipd/postprocessor/IPDTransactionHandler.java
@@ -3,9 +3,12 @@
import org.openmrs.Encounter;
import org.openmrs.module.emrapi.encounter.domain.EncounterTransaction;
import org.openmrs.module.emrapi.encounter.postprocessor.EncounterTransactionHandler;
+import org.openmrs.module.ipd.events.model.IPDEvent;
import org.openmrs.module.ipd.service.IPDScheduleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
+import org.openmrs.module.ipd.events.model.IPDEventType;
+import org.openmrs.module.ipd.events.IPDEventManager;
@Component
public class IPDTransactionHandler implements EncounterTransactionHandler {
@@ -13,6 +16,9 @@ public class IPDTransactionHandler implements EncounterTransactionHandler {
@Autowired
IPDScheduleService ipdScheduleService;
+ @Autowired
+ IPDEventManager eventManager;
+
@Override
public void forRead(Encounter encounter, EncounterTransaction encounterTransaction) {
// No Implementation needed as of now
@@ -20,6 +26,11 @@ public void forRead(Encounter encounter, EncounterTransaction encounterTransacti
@Override
public void forSave(Encounter encounter, EncounterTransaction encounterTransaction) {
+ IPDEventType eventType = eventManager.getEventTypeForEncounter(encounter.getEncounterType().getName());
+ if (eventType != null) {
+ IPDEvent ipdEvent = new IPDEvent(encounter.getUuid(), encounter.getPatient().getUuid(), eventType);
+ eventManager.processEvent(ipdEvent);
+ }
ipdScheduleService.handlePostProcessEncounterTransaction(encounter,encounterTransaction);
}
}
diff --git a/omod/src/main/resources/application.properties b/omod/src/main/resources/application.properties
new file mode 100644
index 0000000..ed16b69
--- /dev/null
+++ b/omod/src/main/resources/application.properties
@@ -0,0 +1,3 @@
+
+# Route definitions
+config-file.path=/etc/bahmni_config/openmrs/apps/ipdDashboard/eventsConfig.json
\ No newline at end of file
diff --git a/omod/src/main/resources/config.xml b/omod/src/main/resources/config.xml
index 7c18b69..6a691b1 100644
--- a/omod/src/main/resources/config.xml
+++ b/omod/src/main/resources/config.xml
@@ -14,6 +14,7 @@
org.bahmni.module.bahmnicore
org.openmrs.module.bedmanagement
org.bahmni.module.medication-administration
+ org.bahmni.module.fhir2Extension
org.openmrs.module.ipd.api.IPDActivator
diff --git a/omod/src/main/resources/webModuleApplicationContext.xml b/omod/src/main/resources/webModuleApplicationContext.xml
index 82e84de..a12d5d4 100644
--- a/omod/src/main/resources/webModuleApplicationContext.xml
+++ b/omod/src/main/resources/webModuleApplicationContext.xml
@@ -8,4 +8,5 @@
+
diff --git a/pom.xml b/pom.xml
index 1a8a3be..65aaef0 100644
--- a/pom.xml
+++ b/pom.xml
@@ -47,7 +47,8 @@
-Xmx1024m
0.7.9
1.18.26
- 1.11.0
+ 2.0.0-SNAPSHOT
+ 1.3.0.ipd-SNAPSHOT
0.94-SNAPSHOT
1.32.0
@@ -197,6 +198,21 @@
provided
+
+ org.bahmni.module
+ fhir2Extension-api
+ ${fhir2ExtensionVersion}
+ provided
+
+
+
+
+ org.bahmni.module
+ fhir2Extension-omod
+ ${fhir2ExtensionVersion}
+ provided
+
+
org.bahmni.module
medication-administration-api