Merge branch 'main' of https://git.shiblysolution.id/SAUDE-TL/service-master-data into main
This commit is contained in:
@ -109,11 +109,7 @@ export class QueueMonitoringController {
|
|||||||
ro.registration_status,
|
ro.registration_status,
|
||||||
ro."roomId",
|
ro."roomId",
|
||||||
ro.updated_at,
|
ro.updated_at,
|
||||||
TRIM(CONCAT(
|
p.full_name AS fullname_patient
|
||||||
COALESCE(p."first_name", ''),
|
|
||||||
' ',
|
|
||||||
COALESCE(p."last_name", '')
|
|
||||||
)) AS "fullname_patient"
|
|
||||||
FROM emr.emr_registration_outpatient ro
|
FROM emr.emr_registration_outpatient ro
|
||||||
LEFT JOIN emr.emr_registrations r ON ro."registrationId" = r.id
|
LEFT JOIN emr.emr_registrations r ON ro."registrationId" = r.id
|
||||||
LEFT JOIN emr.emr_patients p ON r."patientId" = p.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) => ({
|
queueMonitoring.rooms = queueMonitoring.rooms.map((room: any) => ({
|
||||||
...room,
|
...room,
|
||||||
queues: queuesByRoom[room.id] || []
|
queues: queuesByRoom[room.id] || []
|
||||||
}));
|
}));
|
||||||
|
|
||||||
const currentQueues: any[] = [];
|
const latestOnGoing = allQueues
|
||||||
|
.filter((q: any) => q.registration_status === 'ON GOING')
|
||||||
queueMonitoring.rooms.forEach((room: any) => {
|
.reduce((latest: any, current: any) => {
|
||||||
const roomQueues = allQueues.filter((queue: any) => queue.roomId === room.id);
|
const latestDate = new Date(latest?.updated_at || latest?.updatedAt || 0);
|
||||||
|
const currentDate = new Date(current?.updated_at || current?.updatedAt || 0);
|
||||||
const onGoingQueues = roomQueues.filter((q: any) => q.registration_status === 'ON GOING');
|
return currentDate > latestDate ? current : latest;
|
||||||
|
}, undefined);
|
||||||
if (onGoingQueues.length > 0) {
|
|
||||||
const latestOnGoing = onGoingQueues.reduce((latest: any, current: any) => {
|
(queueMonitoring as any).currentQueue = latestOnGoing
|
||||||
const latestDate = new Date(latest.updated_at || latest.updatedAt || 0);
|
? {
|
||||||
const currentDate = new Date(current.updated_at || current.updatedAt || 0);
|
room: roomIdToRoomObj[latestOnGoing.roomId]?.room || null,
|
||||||
return currentDate > latestDate ? current : latest;
|
id: latestOnGoing.id,
|
||||||
});
|
qeue_number: latestOnGoing.qeue_number,
|
||||||
|
registration_status: latestOnGoing.registration_status,
|
||||||
currentQueues.push({
|
fullname_patient: latestOnGoing.fullname_patient,
|
||||||
room: room.room || room.name || room.roomName,
|
|
||||||
code: room.code,
|
|
||||||
qeue_number: latestOnGoing.qeue_number,
|
|
||||||
fullname_patient: latestOnGoing.fullname_patient,
|
|
||||||
status: latestOnGoing.registration_status,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
});
|
: null;
|
||||||
|
|
||||||
(queueMonitoring as any).currentQueues = currentQueues;
|
|
||||||
} catch (queryError: any) {
|
} catch (queryError: any) {
|
||||||
log.warn(`Failed to fetch queue data from emr.emr_registration_outpatient: ${queryError.message}`);
|
log.warn(`Failed to fetch queue data from emr.emr_registration_outpatient: ${queryError.message}`);
|
||||||
queueMonitoring.rooms = queueMonitoring.rooms.map((room: any) => ({
|
queueMonitoring.rooms = queueMonitoring.rooms.map((room: any) => ({
|
||||||
...room,
|
...room,
|
||||||
queues: []
|
queues: []
|
||||||
}));
|
}));
|
||||||
(queueMonitoring as any).currentQueues = [];
|
(queueMonitoring as any).currentQueue = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user