-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BAH-3723|Kavitha| Event handling model & create task for admit event (#…
…48) * BAH-3723|Kavitha| add event handling model and create task for admit event * Kavitha| add null check for event type * Kavitha | update fhir2 extension module version
- Loading branch information
1 parent
c37c286
commit f219c9a
Showing
20 changed files
with
378 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
omod/src/main/java/org/openmrs/module/ipd/events/ConfigLoader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<ConfigDetail> configs = new ArrayList<>(); | ||
|
||
private ObjectMapper objectMapper = new ObjectMapper(); | ||
|
||
@Value("${config-file.path}") | ||
private String routeConfigurationFileLocation; | ||
|
||
public List<ConfigDetail> 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<List<ConfigDetail>>() {}); | ||
} catch (IOException exception) { | ||
log.error("Failed to load configuration for file : " + routeConfigurationFileLocation, exception); | ||
} | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
omod/src/main/java/org/openmrs/module/ipd/events/IPDEventManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
|
||
} |
22 changes: 22 additions & 0 deletions
22
omod/src/main/java/org/openmrs/module/ipd/events/IPDEventUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
omod/src/main/java/org/openmrs/module/ipd/events/factory/IPDEventFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} |
38 changes: 38 additions & 0 deletions
38
omod/src/main/java/org/openmrs/module/ipd/events/factory/impl/IPDEventFactoryImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} | ||
|
||
} |
7 changes: 7 additions & 0 deletions
7
omod/src/main/java/org/openmrs/module/ipd/events/handler/IPDEventHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} |
52 changes: 52 additions & 0 deletions
52
omod/src/main/java/org/openmrs/module/ipd/events/handler/impl/PatientAdmitEventHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<ConfigDetail> 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()); | ||
} | ||
} | ||
|
||
|
||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
omod/src/main/java/org/openmrs/module/ipd/events/handler/impl/RolloverTaskEventHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<ConfigDetail> 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 | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
.../src/main/java/org/openmrs/module/ipd/events/handler/impl/ShiftStartTaskEventHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<ConfigDetail> configList = configLoader.getConfigs(); | ||
ConfigDetail eventConfig = configList.stream() | ||
.filter(config -> config.getType().equals(event.getIpdEventType().name())) | ||
.findFirst() | ||
.orElse(null); | ||
|
||
//create task based on configuration | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
omod/src/main/java/org/openmrs/module/ipd/events/model/ConfigDetail.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<TaskDetail> tasks; | ||
} |
18 changes: 18 additions & 0 deletions
18
omod/src/main/java/org/openmrs/module/ipd/events/model/IPDEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} |
7 changes: 7 additions & 0 deletions
7
omod/src/main/java/org/openmrs/module/ipd/events/model/IPDEventType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package org.openmrs.module.ipd.events.model; | ||
|
||
public enum IPDEventType { | ||
PATIENT_ADMIT, | ||
SHIFT_START_TASK, | ||
ROLLOVER_TASK; | ||
} |
16 changes: 16 additions & 0 deletions
16
omod/src/main/java/org/openmrs/module/ipd/events/model/TaskDetail.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} |
Oops, something went wrong.