From 996e5ad76859d715702fdde9469be969a35d1cfc Mon Sep 17 00:00:00 2001 From: mozzy11 Date: Fri, 20 Jun 2025 12:23:49 +0300 Subject: [PATCH 1/2] switch from IsantePlus ID to Isante ID --- .../api/LabIntegrationReportsConstants.java | 2 +- .../api/reports/LabResultDataSetEvaluator.java | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/api/src/main/java/org/openmrs/module/labintegration/api/LabIntegrationReportsConstants.java b/api/src/main/java/org/openmrs/module/labintegration/api/LabIntegrationReportsConstants.java index 27637b6..bd39113 100644 --- a/api/src/main/java/org/openmrs/module/labintegration/api/LabIntegrationReportsConstants.java +++ b/api/src/main/java/org/openmrs/module/labintegration/api/LabIntegrationReportsConstants.java @@ -10,7 +10,7 @@ public final class LabIntegrationReportsConstants { public static final String LOCATION_ISANTE_CODE_UUID = "0e52924e-4ebb-40ba-9b83-b198b532653b"; - public static final String ISANTEPLUS_IDENDTIFIER_TYPE_UUID = "05a29f94-c0ed-11e2-94be-8c13b969e334"; + public static final String ISANTEPLUS_IDENDTIFIER_TYPE_UUID = "0e0c7cc2-3491-4675-b705-746e372ff346"; private LabIntegrationReportsConstants() { } diff --git a/api/src/main/java/org/openmrs/module/labintegration/api/reports/LabResultDataSetEvaluator.java b/api/src/main/java/org/openmrs/module/labintegration/api/reports/LabResultDataSetEvaluator.java index ccdb62c..e4a5f02 100644 --- a/api/src/main/java/org/openmrs/module/labintegration/api/reports/LabResultDataSetEvaluator.java +++ b/api/src/main/java/org/openmrs/module/labintegration/api/reports/LabResultDataSetEvaluator.java @@ -99,7 +99,10 @@ public DataSet evaluate(DataSetDefinition dataSetDefinition, EvaluationContext e value = obs.getPerson().getPersonName().getFullName(); break; case COLUMN_ISANTEPLUS_ID: - value = getPatientIdentifier(obs.getPersonId()); + String locationCode = locationCodeCache.containsKey(obs.getEncounter().getLocation()) + ? locationCodeCache.get(obs.getEncounter().getLocation()) + : ""; + value = getPatientIdentifier(obs.getPersonId(), locationCode); break; case COLUMN_DATE_ORDERED: value = obs.getEncounter().getEncounterDatetime(); @@ -147,12 +150,12 @@ protected String extractLocationCode(Obs obs, Map locationCode return null; } - protected String getPatientIdentifier(Integer personId) { + protected String getPatientIdentifier(Integer personId, String locationCode) { PatientService patientService = Context.getPatientService(); Patient patient = patientService.getPatient(personId); PatientIdentifierType pit = patientService.getPatientIdentifierTypeByUuid(ISANTEPLUS_IDENDTIFIER_TYPE_UUID); patient.getPatientIdentifier(pit); PatientIdentifier pid = patient.getPatientIdentifier(pit); - return pid != null ? pid.getIdentifier() : ""; + return pid != null ? pid.getIdentifier() : locationCode + '4' + personId; } } From a6438ccd4f9fc6220653d33d2355cd60fd6298df Mon Sep 17 00:00:00 2001 From: mozzy11 Date: Tue, 15 Jul 2025 18:13:13 +0300 Subject: [PATCH 2/2] LNSP report should correctly parse start and end end dates --- .../impl/LabIntegrationReportServiceImpl.java | 50 +++++++++++++++---- .../reports/LabResultDataSetEvaluator.java | 8 ++- 2 files changed, 48 insertions(+), 10 deletions(-) diff --git a/api/src/main/java/org/openmrs/module/labintegration/api/impl/LabIntegrationReportServiceImpl.java b/api/src/main/java/org/openmrs/module/labintegration/api/impl/LabIntegrationReportServiceImpl.java index 22bf3d4..7baeb07 100644 --- a/api/src/main/java/org/openmrs/module/labintegration/api/impl/LabIntegrationReportServiceImpl.java +++ b/api/src/main/java/org/openmrs/module/labintegration/api/impl/LabIntegrationReportServiceImpl.java @@ -14,6 +14,7 @@ import java.util.ArrayList; import java.util.Arrays; +import java.util.Calendar; import java.util.Collections; import java.util.Comparator; import java.util.Date; @@ -29,7 +30,11 @@ public class LabIntegrationReportServiceImpl extends BaseOpenmrsService implements LabIntegrationReportService { @Override - public List getLabResults(Date startDate, Date endDate) { + public List getLabResults(Date inputStartDate, Date inputEndDate) { + + Date startDate = getStartOfDay(inputStartDate); + Date endDate = getEndOfDay(inputEndDate); + ConceptService conceptService = Context.getConceptService(); ObsService obsService = Context.getObsService(); ObsSelector obsSelector = new ObsSelector(); @@ -52,7 +57,7 @@ public List getLabResults(Date startDate, Date endDate) { } List orders = obsService.getObservations(null, null, orderConcepts, null, null, null, null, null, null, - startDate, endDate, false, null); + startDate, endDate, false); Set persons = new LinkedHashSet<>(orders.size()); Set resultTests = new LinkedHashSet<>(orders.size()); @@ -70,9 +75,14 @@ public List getLabResults(Date startDate, Date endDate) { if (freeTextResults != null) { resultTests.add(freeTextResults); } - List testResults = obsService.getObservations(new ArrayList<>(persons), new ArrayList<>(resultEncounters), - new ArrayList<>(resultTests), null, null, null, Arrays.asList("obsDatetime desc", "obsId asc"), null, null, null, - null, false); + List testResults = new ArrayList<>(); + + if (!persons.isEmpty() && !resultEncounters.isEmpty()) { + testResults = obsService.getObservations(new ArrayList<>(persons), new ArrayList<>(resultEncounters), + new ArrayList<>(resultTests), null, null, null, Arrays.asList("obsDatetime desc", "obsId asc"), null, null, + startDate, endDate, false); + + } Set resultEncounterIds = resultEncounters.stream().map(Encounter::getId).collect(Collectors.toSet()); @@ -89,10 +99,12 @@ public List getLabResults(Date startDate, Date endDate) { orderPersons.add(order.getPerson()); orderEncounters.add(order.getEncounter()); } - - List orderResults = obsService.getObservations(new ArrayList<>(orderPersons), new ArrayList<>(orderEncounters), - Collections.singletonList(labOrderConcept), null, null, null, Arrays.asList("obsDatetime desc", "obsId asc"), - null, null, null, null, false); + List orderResults = new ArrayList<>(); + if (!orderPersons.isEmpty() && !orderEncounters.isEmpty()) { + orderResults = obsService.getObservations(new ArrayList<>(orderPersons), new ArrayList<>(orderEncounters), + Collections.singletonList(labOrderConcept), null, null, null, Arrays.asList("obsDatetime desc", "obsId asc"), + null, null, startDate, endDate, false); + } if (testResults != null) { if (orderResults != null) { @@ -117,4 +129,24 @@ private Obs translateToDisplayResultTest(Obs obs) { displayResult.setValueText(""); return displayResult; } + + public static Date getStartOfDay(Date date) { + Calendar cal = Calendar.getInstance(); + cal.setTime(date); + cal.set(Calendar.HOUR_OF_DAY, 0); + cal.set(Calendar.MINUTE, 0); + cal.set(Calendar.SECOND, 0); + cal.set(Calendar.MILLISECOND, 0); + return cal.getTime(); + } + + public static Date getEndOfDay(Date date) { + Calendar cal = Calendar.getInstance(); + cal.setTime(date); + cal.set(Calendar.HOUR_OF_DAY, 23); + cal.set(Calendar.MINUTE, 59); + cal.set(Calendar.SECOND, 59); + cal.set(Calendar.MILLISECOND, 999); + return cal.getTime(); + } } diff --git a/api/src/main/java/org/openmrs/module/labintegration/api/reports/LabResultDataSetEvaluator.java b/api/src/main/java/org/openmrs/module/labintegration/api/reports/LabResultDataSetEvaluator.java index e4a5f02..460d9e6 100644 --- a/api/src/main/java/org/openmrs/module/labintegration/api/reports/LabResultDataSetEvaluator.java +++ b/api/src/main/java/org/openmrs/module/labintegration/api/reports/LabResultDataSetEvaluator.java @@ -1,6 +1,7 @@ package org.openmrs.module.labintegration.api.reports; import org.openmrs.Concept; +import org.openmrs.ConceptNumeric; import org.openmrs.Location; import org.openmrs.LocationAttribute; import org.openmrs.Obs; @@ -114,7 +115,7 @@ public DataSet evaluate(DataSetDefinition dataSetDefinition, EvaluationContext e value = obs.getObsDatetime(); break; case COLUMN_RESULT: - value = obsValueConverter.convert(obs); + value = obsValueConverter.convert(obs) + getUnits(obs); break; } if (value != null) { @@ -158,4 +159,9 @@ protected String getPatientIdentifier(Integer personId, String locationCode) { PatientIdentifier pid = patient.getPatientIdentifier(pit); return pid != null ? pid.getIdentifier() : locationCode + '4' + personId; } + + protected String getUnits(Obs obs) { + ConceptNumeric conceptNumeric = Context.getConceptService().getConceptNumeric(obs.getConcept().getId()); + return conceptNumeric != null && obs.getValueNumeric() != null ? " " + conceptNumeric.getUnits() : ""; + } }