-
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.
Merge pull request #49 from Bahmni/create-shift-scheduler
Create shift scheduler
- Loading branch information
Showing
26 changed files
with
302 additions
and
106 deletions.
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
4 changes: 2 additions & 2 deletions
4
...enmrs/module/ipd/events/ConfigLoader.java → ...s/module/ipd/api/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
10 changes: 5 additions & 5 deletions
10
...rs/module/ipd/events/IPDEventManager.java → ...odule/ipd/api/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
4 changes: 2 additions & 2 deletions
4
...nmrs/module/ipd/events/IPDEventUtils.java → .../module/ipd/api/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
8 changes: 8 additions & 0 deletions
8
api/src/main/java/org/openmrs/module/ipd/api/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.api.events.factory; | ||
|
||
import org.openmrs.module.ipd.api.events.model.IPDEventType; | ||
import org.openmrs.module.ipd.api.events.handler.IPDEventHandler; | ||
|
||
public interface IPDEventFactory { | ||
IPDEventHandler createEventHandler(IPDEventType eventType); | ||
} |
14 changes: 7 additions & 7 deletions
14
...nts/factory/impl/IPDEventFactoryImpl.java → ...nts/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
7 changes: 7 additions & 0 deletions
7
api/src/main/java/org/openmrs/module/ipd/api/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.api.events.handler; | ||
|
||
import org.openmrs.module.ipd.api.events.model.IPDEvent; | ||
|
||
public interface IPDEventHandler { | ||
void handleEvent(IPDEvent event); | ||
} |
14 changes: 7 additions & 7 deletions
14
...andler/impl/PatientAdmitEventHandler.java → ...andler/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
54 changes: 54 additions & 0 deletions
54
...rc/main/java/org/openmrs/module/ipd/api/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,54 @@ | ||
package org.openmrs.module.ipd.api.events.handler.impl; | ||
|
||
import org.openmrs.module.fhir2.model.FhirTask; | ||
import org.openmrs.module.fhirExtension.dao.TaskRequestedPeriodDao; | ||
import org.openmrs.module.fhirExtension.model.FhirTaskRequestedPeriod; | ||
import org.openmrs.module.fhirExtension.model.Task; | ||
import org.openmrs.module.fhirExtension.service.TaskService; | ||
import org.openmrs.module.ipd.api.events.ConfigLoader; | ||
import org.openmrs.module.ipd.api.events.handler.IPDEventHandler; | ||
import org.openmrs.module.ipd.api.events.model.ConfigDetail; | ||
import org.openmrs.module.ipd.api.events.model.IPDEvent; | ||
import org.openmrs.module.ipd.api.events.model.TaskDetail; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Date; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
@Component | ||
public class RolloverTaskEventHandler implements IPDEventHandler { | ||
|
||
@Autowired | ||
ConfigLoader configLoader; | ||
@Autowired | ||
private TaskService taskService; | ||
@Autowired | ||
private TaskRequestedPeriodDao taskRequestedPeriodDao; | ||
private static final String TASK_STATUS = "REQUESTED"; | ||
|
||
@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); | ||
|
||
List<String> taskNames = eventConfig.getTasks().stream() | ||
.map(TaskDetail::getName) | ||
.collect(Collectors.toList()); | ||
List<Task> rolloverTasks = taskService.searchTasks(taskNames, FhirTask.TaskStatus.REQUESTED); | ||
List<FhirTaskRequestedPeriod> fhirTaskRequestedPeriods = new ArrayList<FhirTaskRequestedPeriod>(); | ||
for (Task task : rolloverTasks) { | ||
if (task.getFhirTaskRequestedPeriod() != null) { | ||
FhirTaskRequestedPeriod fhirTaskRequestedPeriod = task.getFhirTaskRequestedPeriod(); | ||
fhirTaskRequestedPeriod.setRequestedStartTime(new Date()); | ||
fhirTaskRequestedPeriods.add(fhirTaskRequestedPeriod); | ||
} | ||
} | ||
taskRequestedPeriodDao.update(fhirTaskRequestedPeriods); | ||
} | ||
} |
60 changes: 60 additions & 0 deletions
60
.../main/java/org/openmrs/module/ipd/api/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,60 @@ | ||
package org.openmrs.module.ipd.api.events.handler.impl; | ||
|
||
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.api.events.ConfigLoader; | ||
import org.openmrs.module.ipd.api.events.IPDEventUtils; | ||
import org.openmrs.module.ipd.api.events.handler.IPDEventHandler; | ||
import org.openmrs.module.ipd.api.events.model.ConfigDetail; | ||
import org.openmrs.module.ipd.api.events.model.IPDEvent; | ||
import org.openmrs.module.ipd.api.events.model.TaskDetail; | ||
import org.openmrs.module.ipd.api.model.AdmittedPatient; | ||
import org.openmrs.module.ipd.api.service.WardService; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
@Component | ||
public class ShiftStartTaskEventHandler implements IPDEventHandler { | ||
|
||
@Autowired | ||
ConfigLoader configLoader; | ||
@Autowired | ||
private TaskMapper taskMapper; | ||
@Autowired | ||
private TaskService taskService; | ||
@Autowired | ||
private WardService wardService; | ||
|
||
@Override | ||
public void handleEvent(IPDEvent event) { | ||
List<AdmittedPatient> admittedPatients = wardService.getAdmittedPatients(); | ||
ConfigDetail eventConfig = getEventConfig(event); | ||
List<Task> tasks = new ArrayList<Task>(); | ||
for(AdmittedPatient admittedPatient: admittedPatients){ | ||
String patientUuid = admittedPatient.getBedPatientAssignment().getPatient().getUuid(); | ||
IPDEvent ipdEvent = new IPDEvent(null, patientUuid, event.getIpdEventType()); | ||
for(TaskDetail taskDetail : eventConfig.getTasks()) { | ||
TaskRequest taskRequest = IPDEventUtils.createNonMedicationTaskRequest(ipdEvent, taskDetail.getName(), "nursing_activity_system"); | ||
Task task = taskMapper.fromRequest(taskRequest); | ||
tasks.add(task); | ||
} | ||
} | ||
if(tasks.size() > 0){ | ||
taskService.saveTask(tasks); | ||
} | ||
} | ||
|
||
private ConfigDetail getEventConfig(IPDEvent event){ | ||
List<ConfigDetail> configList = configLoader.getConfigs(); | ||
ConfigDetail eventConfig = configList.stream() | ||
.filter(config -> config.getType().equals(event.getIpdEventType().name())) | ||
.findFirst() | ||
.orElse(null); | ||
return eventConfig; | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...module/ipd/events/model/ConfigDetail.java → ...le/ipd/api/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
2 changes: 1 addition & 1 deletion
2
...mrs/module/ipd/events/model/IPDEvent.java → ...module/ipd/api/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
2 changes: 1 addition & 1 deletion
2
...module/ipd/events/model/IPDEventType.java → ...le/ipd/api/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
2 changes: 1 addition & 1 deletion
2
...s/module/ipd/events/model/TaskDetail.java → ...dule/ipd/api/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
30 changes: 30 additions & 0 deletions
30
api/src/main/java/org/openmrs/module/ipd/api/scheduler/tasks/RollOverNonMedicationTasks.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,30 @@ | ||
package org.openmrs.module.ipd.api.scheduler.tasks; | ||
|
||
import org.openmrs.module.ipd.api.events.IPDEventManager; | ||
import org.openmrs.module.ipd.api.events.model.IPDEvent; | ||
import org.openmrs.module.ipd.api.events.model.IPDEventType; | ||
import org.openmrs.scheduler.tasks.AbstractTask; | ||
import org.springframework.context.ApplicationContext; | ||
import org.springframework.context.ApplicationContextAware; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
public class RollOverNonMedicationTasks extends AbstractTask implements ApplicationContextAware { | ||
|
||
private static ApplicationContext context; | ||
|
||
@Override | ||
public void execute() { | ||
IPDEventManager eventManager = context.getBean(IPDEventManager.class); | ||
IPDEventType eventType = eventManager.getEventTypeForEncounter(String.valueOf(IPDEventType.ROLLOVER_TASK)); | ||
if (eventType != null) { | ||
IPDEvent ipdEvent = new IPDEvent(null, null, eventType); | ||
eventManager.processEvent(ipdEvent); | ||
} | ||
} | ||
|
||
@Override | ||
public void setApplicationContext(ApplicationContext applicationContext) { | ||
this.context = applicationContext; | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
api/src/main/java/org/openmrs/module/ipd/api/scheduler/tasks/ShiftStartTasks.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.api.scheduler.tasks; | ||
|
||
import org.openmrs.module.ipd.api.events.IPDEventManager; | ||
import org.openmrs.module.ipd.api.events.model.IPDEvent; | ||
import org.openmrs.module.ipd.api.events.model.IPDEventType; | ||
import org.openmrs.scheduler.tasks.AbstractTask; | ||
import org.springframework.context.ApplicationContext; | ||
import org.springframework.context.ApplicationContextAware; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
public class ShiftStartTasks extends AbstractTask implements ApplicationContextAware { | ||
|
||
private static ApplicationContext context; | ||
@Override | ||
public void execute() { | ||
IPDEventManager eventManager = context.getBean(IPDEventManager.class); | ||
IPDEventType eventType = eventManager.getEventTypeForEncounter(String.valueOf(IPDEventType.SHIFT_START_TASK)); | ||
if (eventType != null) { | ||
IPDEvent ipdEvent = new IPDEvent(null, null, eventType); | ||
eventManager.processEvent(ipdEvent); | ||
} | ||
} | ||
|
||
@Override | ||
public void setApplicationContext(ApplicationContext applicationContext) { | ||
this.context = applicationContext; | ||
} | ||
} |
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
Oops, something went wrong.