Skip to content

Commit

Permalink
Nursing task enhancement (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
abinaya-u authored Jan 22, 2024
1 parent c9f4bc0 commit 1361ee7
Show file tree
Hide file tree
Showing 13 changed files with 48 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public interface SlotDAO {

List<Slot> getSlotsByPatientAndVisitAndServiceType(Reference subject, Visit visit, Concept serviceType);

List<Slot> getSlotsBySubjectReferenceIdAndForTheGivenTimeFrame(Reference subject, LocalDateTime localStartDate, LocalDateTime localEndDate);
List<Slot> getSlotsBySubjectReferenceIdAndForTheGivenTimeFrame(Reference subject, LocalDateTime localStartDate, LocalDateTime localEndDate, Visit visit);

List<Slot> getSlotsBySubjectIncludingAdministeredTimeFrame(Reference subject, LocalDateTime localStartDate, LocalDateTime localEndDate);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,15 @@ public List<Slot> getSlotsByPatientAndVisitAndServiceType(Reference subject, Vis
return query.getResultList();
}
@Override
public List<Slot> getSlotsBySubjectReferenceIdAndForTheGivenTimeFrame(Reference subject, LocalDateTime localStartDate, LocalDateTime localEndDate) {
public List<Slot> getSlotsBySubjectReferenceIdAndForTheGivenTimeFrame(Reference subject, LocalDateTime localStartDate, LocalDateTime localEndDate, Visit visit){
Query query = sessionFactory.getCurrentSession()
.createQuery("FROM Slot slot WHERE slot.schedule.subject=:subject and (slot.startDateTime BETWEEN :startDate and :endDate) and slot.voided=0");
.createQuery("FROM Slot slot WHERE slot.schedule.subject=:subject and (slot.startDateTime BETWEEN :startDate and :endDate) and slot.voided=0 and slot.schedule.visit=:visit");

query.setParameter("subject", subject);
query.setParameter("startDate", localStartDate);
query.setParameter("endDate", localEndDate);
query.setParameter("visit", visit);


return query.getResultList();
}
Expand Down
3 changes: 3 additions & 0 deletions api/src/main/java/org/openmrs/module/ipd/api/model/Slot.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ public enum SlotStatus {
@JoinColumn(name = "medication_administration_id", referencedColumnName = "medication_administration_id")
private MedicationAdministration medicationAdministration;

@Column(name = "comments")
private String notes;

public Boolean isStopped() {
return this.status !=null && this.status == SlotStatus.STOPPED;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public interface SlotService extends OpenmrsService {

List<Slot> getSlotsByPatientAndVisitAndServiceType(Reference subject, Visit visit, Concept serviceType);

List<Slot> getSlotsBySubjectReferenceIdAndForTheGivenTimeFrame(Reference reference, LocalDateTime localStartDate, LocalDateTime localEndDate);
List<Slot> getSlotsBySubjectReferenceIdAndForTheGivenTimeFrame(Reference reference, LocalDateTime localStartDate, LocalDateTime localEndDate, Visit visit);

List<Slot> getSlotsBySubjectReferenceIncludingAdministeredTimeFrame(Reference subject, LocalDateTime localStartDate, LocalDateTime localEndDate);
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ public List<Slot> getSlotsByPatientAndVisitAndServiceType(Reference subject, Vis
return slotDAO.getSlotsByPatientAndVisitAndServiceType(subject, visit, serviceType);
}
@Override
public List<Slot> getSlotsBySubjectReferenceIdAndForTheGivenTimeFrame(Reference subject, LocalDateTime localStartDate, LocalDateTime localEndDate) {
return slotDAO.getSlotsBySubjectReferenceIdAndForTheGivenTimeFrame(subject, localStartDate, localEndDate);
public List<Slot> getSlotsBySubjectReferenceIdAndForTheGivenTimeFrame(Reference subject, LocalDateTime localStartDate, LocalDateTime localEndDate, Visit visit){
return slotDAO.getSlotsBySubjectReferenceIdAndForTheGivenTimeFrame(subject, localStartDate, localEndDate, visit);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public class DrugOrderScheduleResponse {
private List<Long> remainingDaySlotsStartTime;
private Long slotStartTime;
private Boolean medicationAdministrationStarted;
private String notes;

public static DrugOrderScheduleResponse createFrom(DrugOrderSchedule drugOrderSchedule){
return DrugOrderScheduleResponse.builder().
Expand All @@ -24,6 +25,7 @@ public static DrugOrderScheduleResponse createFrom(DrugOrderSchedule drugOrderSc
remainingDaySlotsStartTime(drugOrderSchedule.getRemainingDaySlotsStartTime()).
slotStartTime(drugOrderSchedule.getSlotStartTime()).
medicationAdministrationStarted(drugOrderSchedule.getSlots().stream().anyMatch(slot -> slot.getMedicationAdministration() != null)).
notes(drugOrderSchedule.getNotes()).
build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public class MedicationSlotResponse {
private long startTime;
private Object order;
private Object medicationAdministration;
private String notes;

public static MedicationSlotResponse createFrom(Slot slot) {
return MedicationSlotResponse.builder()
Expand All @@ -36,6 +37,7 @@ public static MedicationSlotResponse createFrom(Slot slot) {
.startTime(convertLocalDateTimeToUTCEpoc(slot.getStartDateTime()))
.order(ConversionUtil.convertToRepresentation(slot.getOrder(), Representation.FULL))
.medicationAdministration(MedicationAdministrationResponse.createFrom((slot.getMedicationAdministration())))
.notes(slot.getNotes())
.build();
}

Expand All @@ -49,6 +51,7 @@ public static MedicationSlotResponse createFrom(Slot slot, Representation rep) {
.status(slot.getStatus().name())
.startTime(convertLocalDateTimeToUTCEpoc(slot.getStartDateTime()))
.medicationAdministration(MedicationAdministrationResponse.createFrom((slot.getMedicationAdministration())))
.notes(slot.getNotes())
.build();
}
return MedicationSlotResponse.createFrom(slot);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
package org.openmrs.module.ipd.controller;

import com.google.common.collect.Lists;
import lombok.extern.slf4j.Slf4j;
import org.openmrs.Patient;
import org.openmrs.Visit;
import org.openmrs.api.PatientService;
import org.openmrs.api.VisitService;
import org.openmrs.module.ipd.api.model.Schedule;
import org.openmrs.module.ipd.api.model.Slot;
import org.openmrs.module.ipd.api.util.DateTimeUtil;
import org.openmrs.module.ipd.api.util.IPDConstants;
import org.openmrs.module.ipd.api.service.ScheduleService;
import org.openmrs.module.ipd.contract.MedicationScheduleResponse;
import org.openmrs.module.ipd.contract.MedicationSlotResponse;
import org.openmrs.module.ipd.contract.ScheduleMedicationRequest;
Expand All @@ -19,7 +24,6 @@
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
Expand All @@ -36,10 +40,16 @@
public class IPDScheduleController extends BaseRestController {

private final IPDScheduleService ipdScheduleService;
private final VisitService visitService;
private final PatientService patientService;
private final ScheduleService scheduleService;

@Autowired
public IPDScheduleController(IPDScheduleService ipdScheduleService) {
public IPDScheduleController(IPDScheduleService ipdScheduleService, VisitService visitService, PatientService patientService, ScheduleService scheduleService) {
this.ipdScheduleService = ipdScheduleService;
this.visitService = visitService;
this.patientService = patientService;
this.scheduleService = scheduleService;
}

@RequestMapping(value = "type/medication", method = RequestMethod.POST)
Expand Down Expand Up @@ -76,8 +86,10 @@ public ResponseEntity<Object> getMedicationSlotsByDate(@RequestParam(value = "pa
LocalDateTime localStartDate = convertEpocUTCToLocalTimeZone(startTime);
LocalDateTime localEndDate = convertEpocUTCToLocalTimeZone(endTime);
Boolean considerAdministeredTime = view!=null & IPDConstants.IPD_VIEW_DRUG_CHART.equals(view);
List<Slot> slots = ipdScheduleService.getMedicationSlotsForTheGivenTimeFrame(patientUuid, localStartDate, localEndDate,considerAdministeredTime);
return new ResponseEntity<>(constructResponse(slots), OK);
Patient patient = patientService.getPatientByUuid(patientUuid);
Visit visit = visitService.getActiveVisitsByPatient(patient).get(0);
List<Slot> slots = ipdScheduleService.getMedicationSlotsForTheGivenTimeFrame(patientUuid, localStartDate, localEndDate,considerAdministeredTime, visit);
return new ResponseEntity<>(constructResponse(slots, visit), OK);
}
throw new Exception();
} catch (Exception e) {
Expand Down Expand Up @@ -107,7 +119,12 @@ public ResponseEntity<Object> getMedicationSlotsByOrderUuids(@RequestParam(value
}
}

private List<MedicationScheduleResponse> constructResponse(List<Slot> slots) {

private List<MedicationScheduleResponse> constructResponse(List<Slot> slots, Visit visit) {
Schedule schedule = scheduleService.getScheduleByVisit(visit);
if(slots.isEmpty() && schedule != null){
return Lists.newArrayList(createFrom(schedule, slots));
}
Map<Schedule, List<Slot>> slotsBySchedule = slots.stream().collect(Collectors.groupingBy(Slot::getSchedule));
return slotsBySchedule.entrySet().stream().map(entry -> createFrom(entry.getKey(), entry.getValue())).collect(Collectors.toList());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public SlotFactory(BedManagementService bedManagementService, ConceptService con

public List<Slot> createSlotsForMedicationFrom(Schedule savedSchedule, List<LocalDateTime> slotsStartTime,
Order drugOrder, MedicationAdministration medicationAdministration,
Slot.SlotStatus status, ServiceType serviceType) {
Slot.SlotStatus status, ServiceType serviceType, String comments) {

return slotsStartTime.stream().map(slotStartTime -> {
Slot slot = new Slot();
Expand All @@ -57,6 +57,7 @@ public List<Slot> createSlotsForMedicationFrom(Schedule savedSchedule, List<Loca
slot.setStartDateTime(slotStartTime);
slot.setStatus(status);
slot.setMedicationAdministration(medicationAdministration);
slot.setNotes(comments);
return slot;
}).collect(Collectors.toList());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ public class DrugOrderSchedule {
private List<Long> remainingDaySlotsStartTime;
private Long slotStartTime;
private List<Slot> slots;

private String notes;
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.openmrs.module.ipd.service;

import org.openmrs.Visit;
import org.openmrs.Encounter;
import org.openmrs.module.emrapi.encounter.domain.EncounterTransaction;
import org.openmrs.module.ipd.api.model.Schedule;
Expand All @@ -17,6 +18,6 @@ public interface IPDScheduleService {
List<Slot> getMedicationSlots(String patientUuid, ServiceType serviceType);
List<Slot> getMedicationSlots(String patientUuid, ServiceType serviceType, List<String> orderUuids);
Schedule updateMedicationSchedule(ScheduleMedicationRequest scheduleMedicationRequest);
List<Slot> getMedicationSlotsForTheGivenTimeFrame(String patientUuid, LocalDateTime localStartDate, LocalDateTime localEndDate,Boolean considerAdministeredTime);
List<Slot> getMedicationSlotsForTheGivenTimeFrame(String patientUuid, LocalDateTime localStartDate, LocalDateTime localEndDate,Boolean considerAdministeredTime, Visit visit);
void handlePostProcessEncounterTransaction(Encounter encounter, EncounterTransaction encounterTransaction);
}
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public org.hl7.fhir.r4.model.MedicationAdministration saveAdhocMedicationAdminis
slotsStartTime.add(DateTimeUtil.convertEpocUTCToLocalTimeZone(medicationAdministrationRequest.getAdministeredDateTime()));
ServiceType serviceType = openmrsMedicationAdministration.getDrugOrder() == null ? ServiceType.EMERGENCY_MEDICATION_REQUEST : ServiceType.AS_NEEDED_MEDICATION_REQUEST;
slotFactory.createSlotsForMedicationFrom(schedule, slotsStartTime, openmrsMedicationAdministration.getDrugOrder(),
openmrsMedicationAdministration, Slot.SlotStatus.COMPLETED, serviceType)
openmrsMedicationAdministration, Slot.SlotStatus.COMPLETED, serviceType,"")
.forEach(slotService::saveSlot);
return medicationAdministration;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public Schedule saveMedicationSchedule(ScheduleMedicationRequest scheduleMedicat
}
DrugOrder order = (DrugOrder) orderService.getOrderByUuid(scheduleMedicationRequest.getOrderUuid());
List<LocalDateTime> slotsStartTime = slotTimeCreationService.createSlotsStartTimeFrom(scheduleMedicationRequest, order);
slotFactory.createSlotsForMedicationFrom(savedSchedule, slotsStartTime, order, null, SCHEDULED, ServiceType.MEDICATION_REQUEST)
slotFactory.createSlotsForMedicationFrom(savedSchedule, slotsStartTime, order, null, SCHEDULED, ServiceType.MEDICATION_REQUEST, scheduleMedicationRequest.getComments())
.forEach(slotService::saveSlot);

return savedSchedule;
Expand Down Expand Up @@ -115,14 +115,14 @@ private void voidExistingMedicationSlotsForOrder(String patientUuid,String order


@Override
public List<Slot> getMedicationSlotsForTheGivenTimeFrame(String patientUuid, LocalDateTime localStartDate, LocalDateTime localEndDate,Boolean considerAdministeredTime) {
public List<Slot> getMedicationSlotsForTheGivenTimeFrame(String patientUuid, LocalDateTime localStartDate, LocalDateTime localEndDate, Boolean considerAdministeredTime, Visit visit) {
Optional<Reference> subjectReference = referenceService.getReferenceByTypeAndTargetUUID(Patient.class.getTypeName(), patientUuid);
if(!subjectReference.isPresent())
return Collections.emptyList();
if (considerAdministeredTime) {
return slotService.getSlotsBySubjectReferenceIncludingAdministeredTimeFrame(subjectReference.get(), localStartDate, localEndDate);
}
return slotService.getSlotsBySubjectReferenceIdAndForTheGivenTimeFrame(subjectReference.get(), localStartDate,localEndDate);
return slotService.getSlotsBySubjectReferenceIdAndForTheGivenTimeFrame(subjectReference.get(), localStartDate,localEndDate, visit);
}

@Override
Expand Down

0 comments on commit 1361ee7

Please sign in to comment.