From 2ef5960c8cf5e8f89f375755a35e0e46bbc5bb14 Mon Sep 17 00:00:00 2001 From: makombe Date: Wed, 13 Mar 2024 17:12:56 +0300 Subject: [PATCH] (fix):Filter Queue Entries to return count of those waiting for a service --- .../module/queue/web/QueueEntryMetricRestController.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/omod/src/main/java/org/openmrs/module/queue/web/QueueEntryMetricRestController.java b/omod/src/main/java/org/openmrs/module/queue/web/QueueEntryMetricRestController.java index 7267b2d..949e9cf 100644 --- a/omod/src/main/java/org/openmrs/module/queue/web/QueueEntryMetricRestController.java +++ b/omod/src/main/java/org/openmrs/module/queue/web/QueueEntryMetricRestController.java @@ -15,6 +15,7 @@ import java.util.Arrays; import java.util.List; import java.util.Map; +import java.util.stream.Collectors; import org.openmrs.module.queue.api.QueueServicesWrapper; import org.openmrs.module.queue.api.search.QueueEntrySearchCriteria; @@ -71,8 +72,12 @@ public Object handleRequest(HttpServletRequest request) { ret.add(COUNT, services.getQueueEntryService().getCountOfQueueEntries(criteria).intValue()); } else { List queueEntries = services.getQueueEntryService().getQueueEntries(criteria); + // Filter queueEntries where ended_at is null. The count should be for those waiting for a service + List filteredQueueEntries = queueEntries.stream().filter(entry -> entry.getEndedAt() == null) + .collect(Collectors.toList()); + if (metrics.isEmpty() || metrics.contains(COUNT)) { - ret.add(COUNT, queueEntries.size()); + ret.add(COUNT, filteredQueueEntries.size()); } if (metrics.isEmpty() || metrics.contains(AVERAGE_WAIT_TIME)) { ret.add(AVERAGE_WAIT_TIME, QueueUtils.computeAverageWaitTimeInMinutes(queueEntries));