Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion api/src/main/resources/messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,5 @@ pihapps.orderReason=Order reason
pihapps.status=Status
pihapps.discontinue=Discontinue
pihapps.discontinueOrder=Discontinue order
pihapps.discontinueReason=Discontinue reason
pihapps.discontinueReason=Discontinue reason
pihapps.addLabOrders.ExamstoOrder=Exams to Order
3 changes: 2 additions & 1 deletion api/src/main/resources/messages_fr.properties
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,5 @@ pihapps.return=Retourner
pihapps.status=État
pihapps.discontinue=Interrompre
pihapps.discontinueOrder=Interrompre l'ordonnance
pihapps.discontinueReason=Raison d'interrompre
pihapps.discontinueReason=Raison d'interrompre
pihapps.addLabOrders.ExamstoOrder=Examens � commander
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like the wrong character encoding is set in your IDE - properties files must be set to UTF-8

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package org.openmrs.module.pihapps.constant;

public class AppConstant {
public static final String LAB_TEST_ORDERED_MAPPING = "10745";
public static final String LAB_TEST_ORDERED_MAPPING_SOURCE = "PIH";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will not be true across all of PIH, so we may need another way to model this, perhaps as global properties

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,21 @@
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.openmrs.Concept;
import org.openmrs.ConceptAnswer;
import org.openmrs.Patient;
import org.openmrs.*;
import org.openmrs.api.ConceptService;
import org.openmrs.api.ObsService;
import org.openmrs.module.emrapi.patient.PatientDomainWrapper;
import org.openmrs.module.pihapps.PihAppsUtils;
import org.openmrs.module.pihapps.service.LabPrescriptionService;
import org.openmrs.module.pihapps.service.impl.LabPrescriptionServiceImpl;
import org.openmrs.ui.framework.UiUtils;
import org.openmrs.ui.framework.annotation.InjectBeans;
import org.openmrs.ui.framework.annotation.SpringBean;
import org.openmrs.ui.framework.page.PageModel;
import org.openmrs.util.ConfigUtil;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;

public class LabOrderPageController {

Expand All @@ -29,7 +27,9 @@ public void get(PageModel model, UiUtils ui,
@InjectBeans PatientDomainWrapper patientDomainWrapper,
@RequestParam(value = "patient") Patient patient,
@RequestParam(value = "returnUrl", required = false) String returnUrl,
@SpringBean("conceptService") ConceptService conceptService) {
@SpringBean("conceptService") ConceptService conceptService,
@SpringBean LabPrescriptionService labPrescriptionService
) {

String labSetProp = ConfigUtil.getGlobalProperty("orderentryowa.labOrderablesConceptSet");
Concept labSet = conceptService.getConceptByReference(labSetProp);
Expand Down Expand Up @@ -65,8 +65,10 @@ else if (reasonConcept.getAnswers() != null && !reasonConcept.getAnswers().isEmp
}
}
}

// Get lab prescriptions for this patient
List<String> labPrescriptions = labPrescriptionService.getLabPrescriptions(patient);
patientDomainWrapper.setPatient(patient);
model.addAttribute("labPrescriptions", labPrescriptions);
model.addAttribute("patient", patientDomainWrapper);
model.addAttribute("labSet", labSet);
model.addAttribute("orderReasonsMap", orderReasonsMap);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package org.openmrs.module.pihapps.service;

import org.openmrs.Patient;


import java.util.List;

public interface LabPrescriptionService {
// Returns a list of lab prescriptions for the given patient.
List<String> getLabPrescriptions(Patient patient);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
package org.openmrs.module.pihapps.service.impl;

import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.BooleanUtils;
import org.openmrs.*;
import org.openmrs.api.ConceptService;
import org.openmrs.api.ObsService;
import org.openmrs.api.OrderService;
import org.openmrs.api.context.Context;
import org.openmrs.api.db.hibernate.HibernateUtil;
import org.openmrs.module.pihapps.service.LabPrescriptionService;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import java.util.*;
import java.util.stream.Collectors;

import static org.openmrs.module.pihapps.constant.AppConstant.LAB_TEST_ORDERED_MAPPING;
import static org.openmrs.module.pihapps.constant.AppConstant.LAB_TEST_ORDERED_MAPPING_SOURCE;

@Service
@Slf4j
public class LabPrescriptionServiceImpl implements LabPrescriptionService {
private final OrderService orderService;
private final ConceptService conceptService;
private final ObsService obsService;

public LabPrescriptionServiceImpl(
@Qualifier("orderService") OrderService orderService,
@Qualifier("conceptService") ConceptService conceptService,
@Qualifier("obsService") ObsService obsService ) {
this.orderService = orderService;
this.conceptService = conceptService;
this.obsService = obsService;
}

@Override
public List<String> getLabPrescriptions(Patient patient) {

// This list is to store the lab exam name;
List<String> labTests = new ArrayList<>();
Concept concept = conceptService.getConceptByMapping(LAB_TEST_ORDERED_MAPPING, LAB_TEST_ORDERED_MAPPING_SOURCE);

if (concept == null) {
return Collections.emptyList();
}

// Get obs
List<Obs> observations = obsService.getObservationsByPersonAndConcept(patient, concept);
observations.sort(Comparator.comparing(Obs::getObsDatetime).reversed());
Locale userLocale = Context.getLocale();


// Get lab test names and store in list
for (Obs obs : observations) {
if (obs.getValueCoded() != null) {
labTests.add(obs.getValueCoded().getName(userLocale).getName());
}
}

// Get RECEIVED orders
List<TestOrder> labOrders = getLabOrders(patient);
Set<String> receivedOrderNames = labOrders.stream()
.map(order -> order.getConcept().getName(userLocale).getName())
.collect(Collectors.toSet());


// Filter out names that already exist in received orders
List<String> filteredLabTests = labTests.stream()
.filter(name -> !receivedOrderNames.contains(name))
.collect(Collectors.toList());

// If all lab prescriptions are already received, return empty list
return filteredLabTests.isEmpty() ? Collections.emptyList() : filteredLabTests;
}

// This method is to get all RECEIVED orders for a patient.
private List<TestOrder> getLabOrders(Patient patient) {
List<TestOrder> labOrders = new ArrayList<>();
for (Order order : orderService.getAllOrdersByPatient(patient)) {
order = HibernateUtil.getRealObjectFromProxy(order);
if (order instanceof TestOrder && BooleanUtils.isNotTrue(order.getVoided())) {
labOrders.add((TestOrder) order);
}
}
return labOrders;
}


}
56 changes: 54 additions & 2 deletions omod/src/main/webapp/pages/labs/labOrder.gsp
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,37 @@ ${ui.includeFragment("coreapps", "patientHeader", [patient: patient.patient])}
</script>

<style>
legend {
.lab-buttons {
display: flex;
flex-wrap: wrap;
gap: 8px;
margin-top: 10px;
margin-bottom: 10px;
padding: 10px;
border-radius: 6px;
border: 1px solid darkgrey;
}
.lab-order-entry h5{
font-size: 14px;
font-weight: 600;

}
.lab-buttons button {
padding: 6px 12px;
font-size: 14px;
border-radius: 6px;
border: 1px solid #fd7e14;
color: darkgrey;
cursor: pointer;
transition: background-color 0.2s, transform 0.2s;
}

.lab-buttons button:hover {
background-color: #0056b3;
transform: translateY(-2px);
}

legend {
text-align: left;
padding: 0 10px;
font-weight: 300;
Expand Down Expand Up @@ -360,7 +390,29 @@ ${ui.includeFragment("coreapps", "patientHeader", [patient: patient.patient])}

<% } else { %>

<div class="row">
<%
// Check if there is at least one non-empty lab prescription
def hasData = labPrescriptions.any { it?.trim() }
if (hasData) {
%>

<fieldset class="lab-buttons">
<legend><h5>${ui.message("pihapps.addLabOrders.ExamstoOrder")}</h5></legend>
<% labPrescriptions.each { lab ->
if (lab?.trim()) {
%>
<button type="button">
${lab}
</button>
<% } } %>
</fieldset>
<%
} // end if hasData
%>



<div class="row">
<div class="col-12 col-sm-4 col-md-5 lab-category">
<ul>
<% labSet.setMembers.each { category -> %>
Expand Down