This commit is contained in:
Rayhan Ardiansyah
2026-03-03 16:05:33 +07:00

View File

@ -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,44 +140,42 @@ 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);
(queueMonitoring as any).currentQueue = 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) => ({
...room,
queues: []
}));
(queueMonitoring as any).currentQueues = [];
(queueMonitoring as any).currentQueue = null;
}
}