This commit is contained in:
2026-04-15 10:05:09 +07:00
parent 5388107e68
commit a9b157aee6
3 changed files with 136 additions and 98 deletions

View File

@ -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));
}
}