update
This commit is contained in:
@ -1,4 +1,4 @@
|
||||
import { QueueMonitoring, Paging } from "entity";
|
||||
import { QueueMonitoring, Paging, QueueMonitoringRooms, Status } from "entity";
|
||||
import { NextFunction, Response } from "express";
|
||||
import { Request } from "express-jwt";
|
||||
import Joi from "joi";
|
||||
@ -86,22 +86,19 @@ export class QueueMonitoringController {
|
||||
|
||||
const param: any = await schema.validateAsync(req.params);
|
||||
|
||||
const queueMonitoring = await QueueMonitoringModel.list({ "QueueMonitoring.slug": param.slug }).then((q) =>
|
||||
q.leftJoinAndSelect("QueueMonitoring.rooms", "rooms").leftJoinAndSelect("rooms.department", "department").getOne()
|
||||
);
|
||||
const queueMonitoring = await QueueMonitoringModel.list({ "QueueMonitoring.slug": param.slug }).then((q) => q.leftJoinAndSelect("QueueMonitoring.rooms", "rooms").leftJoinAndSelect("rooms.department", "department").getOne());
|
||||
|
||||
if (!queueMonitoring) throw { message: "Queue Monitoring Not Found" };
|
||||
|
||||
|
||||
if (queueMonitoring.rooms && queueMonitoring.rooms.length > 0) {
|
||||
try {
|
||||
const roomIds = queueMonitoring.rooms.map((room: any) => room.id);
|
||||
const today = moment().format("YYYY-MM-DD");
|
||||
|
||||
|
||||
const placeholders = roomIds.map((_: any, index: number) => `$${index + 1}`).join(", ");
|
||||
const dateParamIndex = roomIds.length + 1;
|
||||
const queryParams = [...roomIds, today];
|
||||
|
||||
|
||||
const queueQuery = `
|
||||
SELECT
|
||||
ro.id,
|
||||
@ -122,9 +119,9 @@ export class QueueMonitoringController {
|
||||
ELSE 2 END,
|
||||
ro.qeue_number ASC
|
||||
`;
|
||||
|
||||
|
||||
const allQueues = await OrmHelper.DB.manager.query(queueQuery, queryParams);
|
||||
|
||||
|
||||
const queuesByRoom: { [key: string]: any[] } = {};
|
||||
allQueues.forEach((queue: any) => {
|
||||
const roomId = queue.roomId;
|
||||
@ -136,7 +133,7 @@ export class QueueMonitoringController {
|
||||
id: queue.id,
|
||||
qeue_number: queue.qeue_number,
|
||||
registration_status: queue.registration_status,
|
||||
fullname_patient: queue.fullname_patient
|
||||
fullname_patient: queue.fullname_patient,
|
||||
});
|
||||
}
|
||||
});
|
||||
@ -146,14 +143,14 @@ export class QueueMonitoringController {
|
||||
queueMonitoring.rooms.forEach((room: any) => {
|
||||
roomIdToRoomObj[room.id] = room;
|
||||
});
|
||||
|
||||
|
||||
queueMonitoring.rooms = queueMonitoring.rooms.map((room: any) => ({
|
||||
...room,
|
||||
queues: queuesByRoom[room.id] || []
|
||||
queues: queuesByRoom[room.id] || [],
|
||||
}));
|
||||
|
||||
|
||||
const latestOnGoing = allQueues
|
||||
.filter((q: any) => q.registration_status === 'ON GOING')
|
||||
.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);
|
||||
@ -162,25 +159,25 @@ export class QueueMonitoringController {
|
||||
|
||||
(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,
|
||||
}
|
||||
room: roomIdToRoomObj[latestOnGoing.roomId]?.room || null,
|
||||
id: latestOnGoing.id,
|
||||
qeue_number: latestOnGoing.qeue_number,
|
||||
registration_status: latestOnGoing.registration_status,
|
||||
fullname_patient: latestOnGoing.fullname_patient,
|
||||
}
|
||||
: 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: []
|
||||
queues: [],
|
||||
}));
|
||||
(queueMonitoring as any).currentQueue = null;
|
||||
}
|
||||
}
|
||||
|
||||
const responseData = {
|
||||
...queueMonitoring
|
||||
...queueMonitoring,
|
||||
};
|
||||
|
||||
return ReturnHelper.successResponseAny(res, 200, Language.lang.success_view, responseData);
|
||||
@ -209,24 +206,29 @@ export class QueueMonitoringController {
|
||||
|
||||
let param: any = await schema.validateAsync(req.body);
|
||||
|
||||
let rooms: any[] = [];
|
||||
if (param.room_ids && param.room_ids.length > 0) {
|
||||
for (const roomId of param.room_ids) {
|
||||
const room = await RoomModel.list({ id: roomId }).then((q) => q.getOne());
|
||||
if (!room) throw { message: `Room with id ${roomId} not found` };
|
||||
rooms.push(room);
|
||||
}
|
||||
}
|
||||
|
||||
let queueMonitoring = new QueueMonitoring();
|
||||
queueMonitoring.slug = param.slug;
|
||||
queueMonitoring.name = param.name;
|
||||
queueMonitoring.rooms = rooms;
|
||||
queueMonitoring.status = param.status;
|
||||
queueMonitoring.created_by = req.auth.data.name;
|
||||
queueMonitoring.updated_by = req.auth.data.name;
|
||||
await queryRunner.manager.save(queueMonitoring);
|
||||
|
||||
if (param.room_ids && param.room_ids.length > 0) {
|
||||
for (const roomId of param.room_ids) {
|
||||
const room = await RoomModel.list({ id: roomId }).then((q) => q.getOne());
|
||||
if (!room) throw { message: `Room with id ${roomId} not found` };
|
||||
|
||||
let queueMonitoringRooms = new QueueMonitoringRooms();
|
||||
queueMonitoringRooms.queue_monitoring = queueMonitoring;
|
||||
queueMonitoringRooms.room = room;
|
||||
queueMonitoringRooms.status = param.status;
|
||||
queueMonitoringRooms.created_by = req.auth.data.name;
|
||||
queueMonitoringRooms.updated_by = req.auth.data.name;
|
||||
await queryRunner.manager.save(queueMonitoringRooms);
|
||||
}
|
||||
}
|
||||
|
||||
await queryRunner.commitTransaction();
|
||||
|
||||
return ReturnHelper.successResponseAny(res, 200, Language.lang.success_insert, queueMonitoring);
|
||||
@ -253,8 +255,7 @@ export class QueueMonitoringController {
|
||||
|
||||
let param: any = await schema.validateAsync(req.params);
|
||||
|
||||
let queueMonitoring = await QueueMonitoringModel.list({ "QueueMonitoring.id": param.id })
|
||||
.then((q) => q.leftJoinAndSelect("QueueMonitoring.rooms", "rooms").leftJoinAndSelect("rooms.department", "department").getOne());
|
||||
let queueMonitoring = await QueueMonitoringModel.list({ "QueueMonitoring.id": param.id }).then((q) => q.leftJoinAndSelect("QueueMonitoring.rooms", "rooms").leftJoinAndSelect("rooms.department", "department").getOne());
|
||||
|
||||
if (!queueMonitoring) throw { message: "Queue Monitoring Not Found" };
|
||||
|
||||
|
||||
Reference in New Issue
Block a user