feat(surgery_room): add new settings resource of surgery room
This commit is contained in:
290
src/controllers/surgery_room.ts
Normal file
290
src/controllers/surgery_room.ts
Normal file
@ -0,0 +1,290 @@
|
|||||||
|
import { Paging, Room, SurgeryRoom } from "entity";
|
||||||
|
import { NextFunction, Response } from "express";
|
||||||
|
import { Request } from "express-jwt";
|
||||||
|
import Joi from "joi";
|
||||||
|
import { ILogObj, Logger } from "tslog";
|
||||||
|
import CommonHelper from "../helpers/common";
|
||||||
|
import { ReturnHelper } from "../helpers/express/return";
|
||||||
|
import { OrmHelper } from "../helpers/orm";
|
||||||
|
import { Language } from "../langs/lang";
|
||||||
|
import { RoomModel } from "../model/room";
|
||||||
|
import { SurgeryRoomModel } from "../model/surgery_room";
|
||||||
|
|
||||||
|
const log: Logger<ILogObj> = new Logger({
|
||||||
|
name: "[SurgeryRoomController]",
|
||||||
|
type: "pretty",
|
||||||
|
});
|
||||||
|
|
||||||
|
export class SurgeryRoomController {
|
||||||
|
static async list(req: Request, res: Response, next: NextFunction): Promise<void | Response> {
|
||||||
|
/*
|
||||||
|
#swagger.tags = ['Surgery Room']
|
||||||
|
#swagger.security = [{
|
||||||
|
"bearerAuth": []
|
||||||
|
}]
|
||||||
|
#swagger.parameters['filter'] = {
|
||||||
|
description:'',
|
||||||
|
in: 'query',
|
||||||
|
type: 'string'
|
||||||
|
}
|
||||||
|
#swagger.parameters['limit'] = {
|
||||||
|
in: 'query',
|
||||||
|
required: true,
|
||||||
|
type: 'number'
|
||||||
|
}
|
||||||
|
#swagger.parameters['page'] = {
|
||||||
|
in: 'query',
|
||||||
|
required: true,
|
||||||
|
type: 'number'
|
||||||
|
}
|
||||||
|
#swagger.parameters['with_deleted'] = {
|
||||||
|
in: 'query',
|
||||||
|
required: true,
|
||||||
|
type: 'boolean'
|
||||||
|
}
|
||||||
|
#swagger.parameters['order_field'] = {
|
||||||
|
in: 'query',
|
||||||
|
required: true,
|
||||||
|
type: 'string'
|
||||||
|
}
|
||||||
|
#swagger.parameters['order_direction'] = {
|
||||||
|
in: 'query',
|
||||||
|
required: true,
|
||||||
|
schema: {
|
||||||
|
'@enum': ['ASC', 'DESC']
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
try {
|
||||||
|
const schema = Joi.object().keys({
|
||||||
|
filter: Joi.string().allow("").optional().label("Filter"),
|
||||||
|
page: Joi.number().required().min(1).label("Page"),
|
||||||
|
limit: Joi.number().required().min(1).label("Limit"),
|
||||||
|
with_deleted: Joi.bool().required().label("With Deleted"),
|
||||||
|
order_field: Joi.string().required().label("Order Field"),
|
||||||
|
order_direction: Joi.string().allow("asc", "desc").required().label("Order Direction"),
|
||||||
|
});
|
||||||
|
|
||||||
|
const param: Paging = await schema.validateAsync(req.query);
|
||||||
|
const offset = (param.page - 1) * param.limit;
|
||||||
|
const filter = JSON.parse(param.filter);
|
||||||
|
const query = await SurgeryRoomModel.list(filter);
|
||||||
|
const limit = param.limit;
|
||||||
|
|
||||||
|
const res_count = query;
|
||||||
|
const res_list = query
|
||||||
|
.leftJoinAndSelect("SurgeryRoom.room", "room")
|
||||||
|
.leftJoinAndSelect("room.serviceclass", "service_class")
|
||||||
|
.orderBy("SurgeryRoom." + param.order_field, param.order_direction)
|
||||||
|
.offset(offset)
|
||||||
|
.limit(limit);
|
||||||
|
|
||||||
|
if (param.with_deleted) {
|
||||||
|
res_count.withDeleted();
|
||||||
|
res_list.withDeleted();
|
||||||
|
}
|
||||||
|
|
||||||
|
const current_page = param.page;
|
||||||
|
const total_count_data = await res_count.getCount();
|
||||||
|
const list_data = await res_list.getMany();
|
||||||
|
const count_data = CommonHelper.countObject(list_data);
|
||||||
|
|
||||||
|
return ReturnHelper.successResponselist(res, 200, Language.lang.success_view, count_data, current_page, total_count_data, list_data);
|
||||||
|
} catch (e: unknown) {
|
||||||
|
log.error(e);
|
||||||
|
const err = e as Error;
|
||||||
|
|
||||||
|
return ReturnHelper.errorResponse(res, 400, 401, Language.lang.failed_view, err.message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static async create(req: Request, res: Response, next: NextFunction): Promise<void | Response> {
|
||||||
|
/*
|
||||||
|
#swagger.tags = ['Surgery Room']
|
||||||
|
#swagger.security = [{
|
||||||
|
"bearerAuth": []
|
||||||
|
}]
|
||||||
|
#swagger.requestBody = {
|
||||||
|
required: true,
|
||||||
|
content: {
|
||||||
|
"application/json": {
|
||||||
|
schema: {
|
||||||
|
$ref: "#/components/schemas/surgery_room"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
try {
|
||||||
|
const schema = Joi.object().keys({
|
||||||
|
room_id: Joi.string().uuid().required().label("Room ID"),
|
||||||
|
name: Joi.string().required().label("Name"),
|
||||||
|
});
|
||||||
|
|
||||||
|
const param = await schema.validateAsync(req.body);
|
||||||
|
|
||||||
|
let room: Room = await RoomModel.list({ id: param.room_id }).then((q) => q.getOne());
|
||||||
|
if (!room) throw { message: "Room " + Language.lang.failed_not_found };
|
||||||
|
|
||||||
|
const data = new SurgeryRoom();
|
||||||
|
data.room = room;
|
||||||
|
data.name = param.name;
|
||||||
|
data.created_by = req.auth?.data.name;
|
||||||
|
|
||||||
|
await OrmHelper.DB.manager.save(data);
|
||||||
|
|
||||||
|
return ReturnHelper.successResponseAny(res, 200, Language.lang.success_insert, data);
|
||||||
|
} catch (e: unknown) {
|
||||||
|
log.error(e);
|
||||||
|
const err = e as Error;
|
||||||
|
|
||||||
|
return ReturnHelper.errorResponse(res, 400, 401, Language.lang.failed_insert, err.message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static async detail(req: Request, res: Response, next: NextFunction): Promise<Response> {
|
||||||
|
/*
|
||||||
|
#swagger.tags = ['Surgery Room']
|
||||||
|
#swagger.security = [{
|
||||||
|
"bearerAuth": []
|
||||||
|
}]
|
||||||
|
#swagger.parameters['id'] = {
|
||||||
|
in: 'path',
|
||||||
|
description: 'Surgery Room ID.',
|
||||||
|
required: true,
|
||||||
|
type: 'string'
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
try {
|
||||||
|
const schema = Joi.object().keys({
|
||||||
|
id: Joi.string().required().label("ID"),
|
||||||
|
});
|
||||||
|
|
||||||
|
let param: any = await schema.validateAsync(req.params);
|
||||||
|
|
||||||
|
let data = await SurgeryRoomModel.list({ "SurgeryRoom.id": param.id }).then((q) =>
|
||||||
|
q //
|
||||||
|
.leftJoinAndSelect("SurgeryRoom.room", "room")
|
||||||
|
.getOne(),
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!data) throw { message: "Surgery Room " + Language.lang.failed_not_found };
|
||||||
|
|
||||||
|
return ReturnHelper.successResponseAny(res, 200, Language.lang.success_view, data);
|
||||||
|
} catch (e: unknown) {
|
||||||
|
log.error(e);
|
||||||
|
const err = e as Error;
|
||||||
|
|
||||||
|
return ReturnHelper.errorResponse(res, 500, 402, Language.lang.failed_view, err.message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static async update(req: Request, res: Response, next: NextFunction): Promise<void | Response> {
|
||||||
|
/*
|
||||||
|
#swagger.tags = ['Surgery Room']
|
||||||
|
#swagger.security = [{
|
||||||
|
"bearerAuth": []
|
||||||
|
}]
|
||||||
|
#swagger.parameters['id'] = {
|
||||||
|
description:'',
|
||||||
|
in: 'path',
|
||||||
|
type: 'string'
|
||||||
|
}
|
||||||
|
#swagger.requestBody = {
|
||||||
|
required: true,
|
||||||
|
content: {
|
||||||
|
"application/json": {
|
||||||
|
schema: {
|
||||||
|
$ref: "#/components/schemas/surgery_room"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
const queryRunner = OrmHelper.DB.createQueryRunner();
|
||||||
|
await queryRunner.startTransaction();
|
||||||
|
|
||||||
|
try {
|
||||||
|
req.body.id = req.params["id"];
|
||||||
|
|
||||||
|
const schema = Joi.object().keys({
|
||||||
|
id: Joi.string().required().label("Surgery Room ID"),
|
||||||
|
room_id: Joi.string().uuid().required().label("Room ID"),
|
||||||
|
name: Joi.string().required().label("Name"),
|
||||||
|
});
|
||||||
|
|
||||||
|
let param: any = await schema.validateAsync(req.body);
|
||||||
|
|
||||||
|
let surgeryRoom: SurgeryRoom = await SurgeryRoomModel.list({ id: param.id }).then((q) => q.getOne());
|
||||||
|
if (!surgeryRoom) throw { message: "Surgery Room " + Language.lang.failed_not_found };
|
||||||
|
|
||||||
|
let room: Room = await RoomModel.list({ id: param.room_id }).then((q) => q.getOne());
|
||||||
|
if (!room) throw { message: "Room " + Language.lang.failed_not_found };
|
||||||
|
|
||||||
|
surgeryRoom.room = room;
|
||||||
|
surgeryRoom.name = param.name;
|
||||||
|
surgeryRoom.updated_by = req.auth?.data.name;
|
||||||
|
|
||||||
|
await queryRunner.manager.save(surgeryRoom);
|
||||||
|
|
||||||
|
await queryRunner.commitTransaction();
|
||||||
|
|
||||||
|
return ReturnHelper.successResponseAny(res, 200, Language.lang.success_update, surgeryRoom);
|
||||||
|
} catch (e: unknown) {
|
||||||
|
await queryRunner.rollbackTransaction();
|
||||||
|
log.error(e);
|
||||||
|
const err = e as Error;
|
||||||
|
return ReturnHelper.errorResponse(res, 400, 401, Language.lang.failed_view, err.message);
|
||||||
|
} finally {
|
||||||
|
await queryRunner.release();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static async delete(req: Request, res: Response, next: NextFunction): Promise<Response> {
|
||||||
|
/*
|
||||||
|
#swagger.tags = ['Surgery Room']
|
||||||
|
#swagger.security = [{
|
||||||
|
"bearerAuth": []
|
||||||
|
}]
|
||||||
|
#swagger.parameters['id'] = {
|
||||||
|
in: 'path',
|
||||||
|
description: 'Surgery Room ID.',
|
||||||
|
required: true,
|
||||||
|
type: 'string'
|
||||||
|
}
|
||||||
|
#swagger.parameters['hard'] = {
|
||||||
|
in: 'path',
|
||||||
|
description: 'Is Hard Delete',
|
||||||
|
required: false,
|
||||||
|
type: 'boolean'
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
try {
|
||||||
|
const schema = Joi.object().keys({
|
||||||
|
id: Joi.string().uuid().required().label("ID"),
|
||||||
|
hard: Joi.bool().optional().allow("").label("Is hard delete?"),
|
||||||
|
});
|
||||||
|
|
||||||
|
const param: { id: string; hard: boolean } = await schema.validateAsync(req.params);
|
||||||
|
|
||||||
|
const repo = OrmHelper.DB.getRepository(SurgeryRoom);
|
||||||
|
|
||||||
|
const affected = (!param.hard ? await repo.softDelete({ id: param.id }) : await repo.delete({ id: param.id })).affected ?? 0;
|
||||||
|
|
||||||
|
if (affected > 0) {
|
||||||
|
return ReturnHelper.successResponseAny(res, 200, Language.lang.success_delete, {});
|
||||||
|
} else {
|
||||||
|
return ReturnHelper.errorResponse(res, 404, 401, Language.lang.failed_not_found, "");
|
||||||
|
}
|
||||||
|
} catch (e: unknown) {
|
||||||
|
log.error(e);
|
||||||
|
const err = e as Error;
|
||||||
|
|
||||||
|
return ReturnHelper.errorResponse(res, 500, 402, Language.lang.failed_delete, err.message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,7 +1,7 @@
|
|||||||
import config from "config";
|
import config from "config";
|
||||||
import { DataSource } from "typeorm";
|
import { DataSource } from "typeorm";
|
||||||
import { ILogObj, Logger } from "tslog";
|
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, Currency, InpatientRoom, PatientGuarantor, InitialStock, DoctorItem, DoctorItemPackage, UserToRoom, RoomToPharmacy, PlanningVerificator, ScheduleSeries, ScheduleException, CardType, PaymentMethod, FosterCareHistory } from "entity";
|
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, Currency, InpatientRoom, SurgeryRoom, PatientGuarantor, InitialStock, DoctorItem, DoctorItemPackage, UserToRoom, RoomToPharmacy, PlanningVerificator, ScheduleSeries, ScheduleException, CardType, PaymentMethod, FosterCareHistory } from "entity";
|
||||||
|
|
||||||
export class OrmHelper {
|
export class OrmHelper {
|
||||||
static DB: DataSource = null;
|
static DB: DataSource = null;
|
||||||
@ -60,6 +60,7 @@ export class OrmHelper {
|
|||||||
Unit,
|
Unit,
|
||||||
Currency,
|
Currency,
|
||||||
InpatientRoom,
|
InpatientRoom,
|
||||||
|
SurgeryRoom,
|
||||||
ItemCategory,
|
ItemCategory,
|
||||||
ItemStatus,
|
ItemStatus,
|
||||||
UsageInstructions,
|
UsageInstructions,
|
||||||
|
|||||||
27
src/model/surgery_room.ts
Normal file
27
src/model/surgery_room.ts
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
import { SurgeryRoom } from "entity";
|
||||||
|
import { SelectQueryBuilder } from "typeorm";
|
||||||
|
import CommonHelper from "../helpers/common";
|
||||||
|
import { OrmHelper } from "../helpers/orm";
|
||||||
|
|
||||||
|
export class SurgeryRoomModel {
|
||||||
|
static async list(filter = {}): Promise<SelectQueryBuilder<any>> {
|
||||||
|
const repo = OrmHelper.DB.getRepository(SurgeryRoom);
|
||||||
|
let whereAttr = [];
|
||||||
|
let whereVal: any = {};
|
||||||
|
if (filter) {
|
||||||
|
whereAttr = [...whereAttr, ...CommonHelper.handleQueryFilter(filter).whereAttr];
|
||||||
|
whereVal = {
|
||||||
|
...whereVal,
|
||||||
|
...CommonHelper.handleQueryFilter(filter).whereVal,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
var query = null;
|
||||||
|
query = repo.createQueryBuilder();
|
||||||
|
if (whereAttr.length != 0) {
|
||||||
|
query = query.where(whereAttr.join(" and "), whereVal);
|
||||||
|
}
|
||||||
|
|
||||||
|
return query;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -67,6 +67,7 @@ import { RegionController } from "../controllers/region";
|
|||||||
import { ResponsiblePartyConsentController } from "../controllers/responsiblepartyconsent";
|
import { ResponsiblePartyConsentController } from "../controllers/responsiblepartyconsent";
|
||||||
import { CurrencyController } from "../controllers/currency";
|
import { CurrencyController } from "../controllers/currency";
|
||||||
import { InpatientRoomController } from "../controllers/inpatient_room";
|
import { InpatientRoomController } from "../controllers/inpatient_room";
|
||||||
|
import { SurgeryRoomController } from "../controllers/surgery_room";
|
||||||
import { FosterCareHistoryController } from "../controllers/fostercarehistory";
|
import { FosterCareHistoryController } from "../controllers/fostercarehistory";
|
||||||
|
|
||||||
export class RoutePrivate {
|
export class RoutePrivate {
|
||||||
@ -328,6 +329,12 @@ export class RoutePrivate {
|
|||||||
app.put("/api/inpatient-room/update/:id", InpatientRoomController.update);
|
app.put("/api/inpatient-room/update/:id", InpatientRoomController.update);
|
||||||
app.delete("/api/inpatient-room/delete/:id/:hard", InpatientRoomController.delete);
|
app.delete("/api/inpatient-room/delete/:id/:hard", InpatientRoomController.delete);
|
||||||
|
|
||||||
|
app.get("/api/surgery-room/list", SurgeryRoomController.list);
|
||||||
|
app.post("/api/surgery-room/create", SurgeryRoomController.create);
|
||||||
|
app.get("/api/surgery-room/detail/:id", SurgeryRoomController.detail);
|
||||||
|
app.put("/api/surgery-room/update/:id", SurgeryRoomController.update);
|
||||||
|
app.delete("/api/surgery-room/delete/:id/:hard", SurgeryRoomController.delete);
|
||||||
|
|
||||||
app.get("/api/pharmacy/item-category/list", ItemCategoryController.list);
|
app.get("/api/pharmacy/item-category/list", ItemCategoryController.list);
|
||||||
app.get("/api/pharmacy/item-category/export", ItemCategoryController.export);
|
app.get("/api/pharmacy/item-category/export", ItemCategoryController.export);
|
||||||
app.post("/api/pharmacy/item-category/create", ItemCategoryController.create);
|
app.post("/api/pharmacy/item-category/create", ItemCategoryController.create);
|
||||||
|
|||||||
@ -37,6 +37,10 @@ const doc = {
|
|||||||
$name: "Name",
|
$name: "Name",
|
||||||
$number_of_bed: 1,
|
$number_of_bed: 1,
|
||||||
},
|
},
|
||||||
|
surgery_room: {
|
||||||
|
$room_id: "34fdda87-9b42-44d3-8cab-2f2032481d42",
|
||||||
|
$name: "Name",
|
||||||
|
},
|
||||||
menu: {
|
menu: {
|
||||||
$module: "Dashboard",
|
$module: "Dashboard",
|
||||||
$name: "Dashboard",
|
$name: "Dashboard",
|
||||||
|
|||||||
Reference in New Issue
Block a user