update
This commit is contained in:
@ -22,7 +22,7 @@
|
||||
"database": {
|
||||
"engine": "postgres",
|
||||
"host": "127.0.0.1",
|
||||
"port": "15432",
|
||||
"port": "1520",
|
||||
"username": "saude_stag",
|
||||
"password": "gM*#o>3W4&5X",
|
||||
"database": "saude_stag",
|
||||
|
||||
@ -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" };
|
||||
|
||||
|
||||
@ -1,70 +1,107 @@
|
||||
import config from 'config';
|
||||
import config from "config";
|
||||
import { DataSource } from "typeorm";
|
||||
import { ILogObj, Logger } from 'tslog';
|
||||
import { ResponsiblePartyConsent,Province,City,Subdistrict,Ward, RefferalHospital,RegistrationFee,FareType, RoomStock, Administrativu, Aldeia, District, Menu, Munisipo, Suco, Application, Nationality, Diagnosis, DiagnosticProcedure, Room, ServiceType, ServiceClass, Service, ServiceFare, ServicePackage, Department, DoctorSchedule, MeasurementUnit, ReferenceRange, QueueMonitoring, ExaminationDetail, ExaminationType, User, UserRole, HrmsEmployee, HrmsDepartment, HrmsPosition, HrmsShift, HospitalInformation, ItemOrigin, ItemType, ItemTypeDetail, Unit, ItemCategory, ItemStatus, UsageInstructions, UsageTime, ItemClass, ItemClassDetail, GenericName, Factory, Supplier, FactoryToSupplier, ItemMaster, ItemGroup, PharmacyInfo, ItemPrice, SellingPricePercentage, PatientGroup, PatientGuarantor, InitialStock, DoctorItem, DoctorItemPackage, UserToRoom, RoomToPharmacy, PlanningVerificator, ScheduleSeries, ScheduleException, CardType, PaymentMethod } from 'entity'
|
||||
import { ILogObj, Logger } from "tslog";
|
||||
import { ResponsiblePartyConsent, Province, City, Subdistrict, Ward, RefferalHospital, RegistrationFee, FareType, RoomStock, Administrativu, Aldeia, District, Menu, Munisipo, Suco, Application, Nationality, Diagnosis, DiagnosticProcedure, Room, ServiceType, ServiceClass, Service, ServiceFare, ServicePackage, Department, DoctorSchedule, MeasurementUnit, ReferenceRange, QueueMonitoring, QueueMonitoringRooms, ExaminationDetail, ExaminationType, User, UserRole, HrmsEmployee, HrmsDepartment, HrmsPosition, HrmsShift, HospitalInformation, ItemOrigin, ItemType, ItemTypeDetail, Unit, ItemCategory, ItemStatus, UsageInstructions, UsageTime, ItemClass, ItemClassDetail, GenericName, Factory, Supplier, FactoryToSupplier, ItemMaster, ItemGroup, PharmacyInfo, ItemPrice, SellingPricePercentage, PatientGroup, PatientGuarantor, InitialStock, DoctorItem, DoctorItemPackage, UserToRoom, RoomToPharmacy, PlanningVerificator, ScheduleSeries, ScheduleException, CardType, PaymentMethod } from "entity";
|
||||
|
||||
export class OrmHelper {
|
||||
static DB: DataSource = null
|
||||
static DB: DataSource = null;
|
||||
|
||||
static setup() {
|
||||
const log: Logger<ILogObj> = new Logger({ name: '[OrmHelper]', type: 'pretty' });
|
||||
static setup() {
|
||||
const log: Logger<ILogObj> = new Logger({ name: "[OrmHelper]", type: "pretty" });
|
||||
|
||||
const engine: 'mysql' | 'postgres' = config.get("database.engine")
|
||||
const engine: "mysql" | "postgres" = config.get("database.engine");
|
||||
|
||||
OrmHelper.DB = new DataSource({
|
||||
type: engine,
|
||||
host: config.get("database.host"),
|
||||
port: Number(config.get("database.port")),
|
||||
username: String(config.get("database.username")),
|
||||
password: String(config.get("database.password")),
|
||||
database: String(config.get("database.database")),
|
||||
synchronize: true,
|
||||
logging: config.get('database.logging'),
|
||||
entities: [Menu, Administrativu, Aldeia, District, Munisipo, Suco, Application, Nationality, Diagnosis, DiagnosticProcedure, Room, ServiceType, ServiceClass, Service, ServiceFare, ServicePackage, Department, DoctorSchedule, MeasurementUnit, ReferenceRange, QueueMonitoring, ExaminationDetail, ExaminationType, User, UserRole, HrmsEmployee, HrmsDepartment, HrmsPosition, HrmsShift, HospitalInformation, ItemGroup,
|
||||
ItemOrigin,
|
||||
ItemType,
|
||||
ItemTypeDetail,
|
||||
Unit,
|
||||
ItemCategory,
|
||||
ItemStatus,
|
||||
UsageInstructions,
|
||||
UsageTime,
|
||||
ItemClass,
|
||||
ItemClassDetail,
|
||||
GenericName,
|
||||
Factory,
|
||||
Supplier,
|
||||
FactoryToSupplier,
|
||||
ItemMaster,
|
||||
PharmacyInfo,
|
||||
ItemPrice,
|
||||
SellingPricePercentage,
|
||||
PatientGroup,
|
||||
PatientGuarantor,
|
||||
InitialStock,
|
||||
DoctorItem,
|
||||
DoctorItemPackage,
|
||||
UserToRoom,
|
||||
RoomToPharmacy,
|
||||
PlanningVerificator,
|
||||
RoomStock,
|
||||
ScheduleSeries,
|
||||
ScheduleException,
|
||||
FareType,
|
||||
CardType,
|
||||
PaymentMethod,
|
||||
RegistrationFee,
|
||||
RefferalHospital,Province,City,Subdistrict,Ward,
|
||||
ResponsiblePartyConsent
|
||||
],
|
||||
subscribers: [],
|
||||
migrations: [],
|
||||
})
|
||||
OrmHelper.DB = new DataSource({
|
||||
type: engine,
|
||||
host: config.get("database.host"),
|
||||
port: Number(config.get("database.port")),
|
||||
username: String(config.get("database.username")),
|
||||
password: String(config.get("database.password")),
|
||||
database: String(config.get("database.database")),
|
||||
synchronize: true,
|
||||
logging: config.get("database.logging"),
|
||||
entities: [
|
||||
//
|
||||
Menu,
|
||||
Administrativu,
|
||||
Aldeia,
|
||||
District,
|
||||
Munisipo,
|
||||
Suco,
|
||||
Application,
|
||||
Nationality,
|
||||
Diagnosis,
|
||||
DiagnosticProcedure,
|
||||
Room,
|
||||
ServiceType,
|
||||
ServiceClass,
|
||||
Service,
|
||||
ServiceFare,
|
||||
ServicePackage,
|
||||
Department,
|
||||
DoctorSchedule,
|
||||
MeasurementUnit,
|
||||
ReferenceRange,
|
||||
QueueMonitoring,
|
||||
QueueMonitoringRooms,
|
||||
ExaminationDetail,
|
||||
ExaminationType,
|
||||
User,
|
||||
UserRole,
|
||||
HrmsEmployee,
|
||||
HrmsDepartment,
|
||||
HrmsPosition,
|
||||
HrmsShift,
|
||||
HospitalInformation,
|
||||
ItemGroup,
|
||||
ItemOrigin,
|
||||
ItemType,
|
||||
ItemTypeDetail,
|
||||
Unit,
|
||||
ItemCategory,
|
||||
ItemStatus,
|
||||
UsageInstructions,
|
||||
UsageTime,
|
||||
ItemClass,
|
||||
ItemClassDetail,
|
||||
GenericName,
|
||||
Factory,
|
||||
Supplier,
|
||||
FactoryToSupplier,
|
||||
ItemMaster,
|
||||
PharmacyInfo,
|
||||
ItemPrice,
|
||||
SellingPricePercentage,
|
||||
PatientGroup,
|
||||
PatientGuarantor,
|
||||
InitialStock,
|
||||
DoctorItem,
|
||||
DoctorItemPackage,
|
||||
UserToRoom,
|
||||
RoomToPharmacy,
|
||||
PlanningVerificator,
|
||||
RoomStock,
|
||||
ScheduleSeries,
|
||||
ScheduleException,
|
||||
FareType,
|
||||
CardType,
|
||||
PaymentMethod,
|
||||
RegistrationFee,
|
||||
RefferalHospital,
|
||||
Province,
|
||||
City,
|
||||
Subdistrict,
|
||||
Ward,
|
||||
ResponsiblePartyConsent,
|
||||
],
|
||||
subscribers: [],
|
||||
migrations: [],
|
||||
});
|
||||
|
||||
OrmHelper.DB.initialize()
|
||||
.then(() => {
|
||||
// here you can start to work with your database
|
||||
})
|
||||
.catch((error: any) => log.error(error))
|
||||
}
|
||||
}
|
||||
OrmHelper.DB.initialize()
|
||||
.then(() => {
|
||||
// here you can start to work with your database
|
||||
})
|
||||
.catch((error: any) => log.error(error));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user