From 3cad1a646cf61a4b8caf8ee8923a838ef7750a50 Mon Sep 17 00:00:00 2001 From: avicenan Date: Mon, 2 Mar 2026 20:37:15 +0700 Subject: [PATCH 1/2] fix(queue): recent queue order --- src/controllers/queue_monitoring.ts | 54 +++++++++++++---------------- 1 file changed, 25 insertions(+), 29 deletions(-) diff --git a/src/controllers/queue_monitoring.ts b/src/controllers/queue_monitoring.ts index 3e942b9..6783947 100644 --- a/src/controllers/queue_monitoring.ts +++ b/src/controllers/queue_monitoring.ts @@ -109,11 +109,7 @@ export class QueueMonitoringController { ro.registration_status, ro."roomId", ro.updated_at, - TRIM(CONCAT( - COALESCE(p."first_name", ''), - ' ', - COALESCE(p."last_name", '') - )) AS "fullname_patient" + p.full_name AS fullname_patient FROM emr.emr_registration_outpatient ro LEFT JOIN emr.emr_registrations r ON ro."registrationId" = r.id LEFT JOIN emr.emr_patients p ON r."patientId" = p.id @@ -144,37 +140,37 @@ export class QueueMonitoringController { }); } }); + + // room lookup + const roomIdToRoomObj: { [key: string]: any } = {}; + queueMonitoring.rooms.forEach((room: any) => { + roomIdToRoomObj[room.id] = room; + }); queueMonitoring.rooms = queueMonitoring.rooms.map((room: any) => ({ ...room, queues: queuesByRoom[room.id] || [] })); - const currentQueues: any[] = []; - - queueMonitoring.rooms.forEach((room: any) => { - const roomQueues = allQueues.filter((queue: any) => queue.roomId === room.id); - - const onGoingQueues = roomQueues.filter((q: any) => q.registration_status === 'ON GOING'); - - if (onGoingQueues.length > 0) { - const latestOnGoing = onGoingQueues.reduce((latest: any, current: any) => { - const latestDate = new Date(latest.updated_at || latest.updatedAt || 0); - const currentDate = new Date(current.updated_at || current.updatedAt || 0); - return currentDate > latestDate ? current : latest; - }); - - currentQueues.push({ - room: room.room || room.name || room.roomName, - code: room.code, - qeue_number: latestOnGoing.qeue_number, - fullname_patient: latestOnGoing.fullname_patient, - status: latestOnGoing.registration_status, - }); + const latestOnGoing = allQueues + .filter((q: any) => q.registration_status === 'ON GOING') + .reduce((latest: any, current: any) => { + const latestDate = new Date(latest?.updated_at || latest?.updatedAt || 0); + const currentDate = new Date(current?.updated_at || current?.updatedAt || 0); + return currentDate > latestDate ? current : latest; + }, undefined); + + console.log("latestOnGoing", latestOnGoing); + + (queueMonitoring as any).currentQueues = latestOnGoing + ? { + room: roomIdToRoomObj[latestOnGoing.roomId]?.room || null, + id: latestOnGoing.id, + qeue_number: latestOnGoing.qeue_number, + registration_status: latestOnGoing.registration_status, + fullname_patient: latestOnGoing.fullname_patient, } - }); - - (queueMonitoring as any).currentQueues = currentQueues; + : null; } catch (queryError: any) { log.warn(`Failed to fetch queue data from emr.emr_registration_outpatient: ${queryError.message}`); queueMonitoring.rooms = queueMonitoring.rooms.map((room: any) => ({ From 505dfbdc9844b0ca89a2c24243b4aec7b8fe2536 Mon Sep 17 00:00:00 2001 From: avicenan Date: Mon, 2 Mar 2026 20:41:50 +0700 Subject: [PATCH 2/2] fix --- src/controllers/queue_monitoring.ts | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/controllers/queue_monitoring.ts b/src/controllers/queue_monitoring.ts index 6783947..f780937 100644 --- a/src/controllers/queue_monitoring.ts +++ b/src/controllers/queue_monitoring.ts @@ -160,9 +160,7 @@ export class QueueMonitoringController { return currentDate > latestDate ? current : latest; }, undefined); - console.log("latestOnGoing", latestOnGoing); - - (queueMonitoring as any).currentQueues = latestOnGoing + (queueMonitoring as any).currentQueue = latestOnGoing ? { room: roomIdToRoomObj[latestOnGoing.roomId]?.room || null, id: latestOnGoing.id, @@ -177,7 +175,7 @@ export class QueueMonitoringController { ...room, queues: [] })); - (queueMonitoring as any).currentQueues = []; + (queueMonitoring as any).currentQueue = null; } }