-
Notifications
You must be signed in to change notification settings - Fork 1
Show lab prescription taken from Analyse form to lab order form for a specific patient #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Dutervil
wants to merge
1
commit into
main
Choose a base branch
from
HAI-1062
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
6 changes: 6 additions & 0 deletions
6
omod/src/main/java/org/openmrs/module/pihapps/constant/AppConstant.java
This file contains hidden or 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,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"; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
| } | ||
This file contains hidden or 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
11 changes: 11 additions & 0 deletions
11
omod/src/main/java/org/openmrs/module/pihapps/service/LabPrescriptionService.java
This file contains hidden or 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,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); | ||
| } |
90 changes: 90 additions & 0 deletions
90
omod/src/main/java/org/openmrs/module/pihapps/service/impl/LabPrescriptionServiceImpl.java
This file contains hidden or 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,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; | ||
| } | ||
|
|
||
|
|
||
| } |
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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