fix medical form
This commit is contained in:
@ -57,9 +57,9 @@ export class FileController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Validate file type
|
// Validate file type
|
||||||
const allowedMimes = ['image/jpeg', 'image/jpg', 'image/png', 'image/webp'];
|
const allowedMimes = ['image/jpeg', 'image/jpg', 'image/png', 'image/webp', 'image/svg+xml', 'image/svg'];
|
||||||
if (!allowedMimes.includes(file.mimetype)) {
|
if (!allowedMimes.includes(file.mimetype)) {
|
||||||
return ReturnHelper.errorResponse(res, 400, 400, Language.lang.failed_insert, "Invalid file type. Only JPG, PNG, and WEBP are allowed");
|
return ReturnHelper.errorResponse(res, 400, 400, Language.lang.failed_insert, "Invalid file type. Only JPG, PNG, WEBP, and SVG are allowed");
|
||||||
}
|
}
|
||||||
const ext = file.name.split('.');
|
const ext = file.name.split('.');
|
||||||
const name = uuidv4() + '.' + ext[ext.length - 1];
|
const name = uuidv4() + '.' + ext[ext.length - 1];
|
||||||
@ -190,6 +190,7 @@ export class FileController {
|
|||||||
webp: "image/webp",
|
webp: "image/webp",
|
||||||
gif: "image/gif",
|
gif: "image/gif",
|
||||||
pdf: "application/pdf",
|
pdf: "application/pdf",
|
||||||
|
svg: "image/svg+xml",
|
||||||
};
|
};
|
||||||
|
|
||||||
const contentType = mimeMap[ext ?? ""] ?? "application/octet-stream";
|
const contentType = mimeMap[ext ?? ""] ?? "application/octet-stream";
|
||||||
|
|||||||
@ -80,8 +80,11 @@ export class MedicalFormController {
|
|||||||
await queryRunner.startTransaction();
|
await queryRunner.startTransaction();
|
||||||
try {
|
try {
|
||||||
const schema = Joi.object().keys({
|
const schema = Joi.object().keys({
|
||||||
|
title: Joi.string().max(256).required().label("Title"),
|
||||||
name: Joi.string().max(256).required().label("Name"),
|
name: Joi.string().max(256).required().label("Name"),
|
||||||
description: Joi.string().max(512).required().label("Description"),
|
description: Joi.string().max(512).required().label("Description"),
|
||||||
|
picture: Joi.string().max(512).allow("").optional().label("Picture"),
|
||||||
|
status: Joi.string().max(64).required().label("Status"),
|
||||||
});
|
});
|
||||||
|
|
||||||
let param: any = await schema.validateAsync(req.body);
|
let param: any = await schema.validateAsync(req.body);
|
||||||
@ -91,8 +94,11 @@ export class MedicalFormController {
|
|||||||
if (exist) throw { message: "Medical Form " + Language.lang.failed_duplicate };
|
if (exist) throw { message: "Medical Form " + Language.lang.failed_duplicate };
|
||||||
|
|
||||||
let medicalForm = new MedicalForm();
|
let medicalForm = new MedicalForm();
|
||||||
|
medicalForm.title = param.title;
|
||||||
medicalForm.name = param.name;
|
medicalForm.name = param.name;
|
||||||
medicalForm.description = param.description;
|
medicalForm.description = param.description;
|
||||||
|
medicalForm.picture = param.picture || null;
|
||||||
|
medicalForm.status = param.status;
|
||||||
medicalForm.created_by = req.auth.data.name;
|
medicalForm.created_by = req.auth.data.name;
|
||||||
medicalForm.updated_by = req.auth.data.name;
|
medicalForm.updated_by = req.auth.data.name;
|
||||||
await queryRunner.manager.save(medicalForm);
|
await queryRunner.manager.save(medicalForm);
|
||||||
@ -150,8 +156,11 @@ export class MedicalFormController {
|
|||||||
|
|
||||||
const schema = Joi.object().keys({
|
const schema = Joi.object().keys({
|
||||||
id: Joi.string().uuid().required().label("Medical Form ID"),
|
id: Joi.string().uuid().required().label("Medical Form ID"),
|
||||||
|
title: Joi.string().max(256).required().label("Title"),
|
||||||
name: Joi.string().max(256).required().label("Name"),
|
name: Joi.string().max(256).required().label("Name"),
|
||||||
description: Joi.string().max(512).required().label("Description"),
|
description: Joi.string().max(512).required().label("Description"),
|
||||||
|
picture: Joi.string().max(512).allow("").optional().label("Picture"),
|
||||||
|
status: Joi.string().max(64).required().label("Status"),
|
||||||
});
|
});
|
||||||
|
|
||||||
let param: any = await schema.validateAsync(req.body);
|
let param: any = await schema.validateAsync(req.body);
|
||||||
@ -164,8 +173,11 @@ export class MedicalFormController {
|
|||||||
|
|
||||||
if (!medicalForm) throw { message: "Medical Form " + Language.lang.failed_not_found };
|
if (!medicalForm) throw { message: "Medical Form " + Language.lang.failed_not_found };
|
||||||
|
|
||||||
|
medicalForm.title = param.title;
|
||||||
medicalForm.name = param.name;
|
medicalForm.name = param.name;
|
||||||
medicalForm.description = param.description;
|
medicalForm.description = param.description;
|
||||||
|
medicalForm.picture = param.picture || null;
|
||||||
|
medicalForm.status = param.status;
|
||||||
medicalForm.updated_by = req.auth.data.name;
|
medicalForm.updated_by = req.auth.data.name;
|
||||||
await queryRunner.manager.save(medicalForm);
|
await queryRunner.manager.save(medicalForm);
|
||||||
|
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
import { Room, Paging, Service } from "entity";
|
import { Room, Paging, Service, MedicalForm } from "entity";
|
||||||
import { NextFunction, Response } from "express";
|
import { NextFunction, Response } from "express";
|
||||||
import { Request } from "express-jwt";
|
import { Request } from "express-jwt";
|
||||||
import Joi from "joi";
|
import Joi from "joi";
|
||||||
@ -15,7 +15,7 @@ import fileUpload from "express-fileupload";
|
|||||||
import { v4 as uuidv4 } from "uuid";
|
import { v4 as uuidv4 } from "uuid";
|
||||||
import fs from "fs";
|
import fs from "fs";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
import { Brackets } from "typeorm";
|
import { Brackets, In } from "typeorm";
|
||||||
import config from "../../config/stag.json";
|
import config from "../../config/stag.json";
|
||||||
|
|
||||||
const log: Logger<ILogObj> = new Logger({
|
const log: Logger<ILogObj> = new Logger({
|
||||||
@ -78,6 +78,7 @@ export class RoomController {
|
|||||||
const res_list = query
|
const res_list = query
|
||||||
.leftJoinAndSelect("Room.department", "department")
|
.leftJoinAndSelect("Room.department", "department")
|
||||||
.leftJoinAndSelect("Room.serviceclass", "serviceclass")
|
.leftJoinAndSelect("Room.serviceclass", "serviceclass")
|
||||||
|
.leftJoinAndSelect("Room.medical_forms", "medical_forms")
|
||||||
.orderBy("Room." + param.order_field, param.order_direction)
|
.orderBy("Room." + param.order_field, param.order_direction)
|
||||||
.offset(offset)
|
.offset(offset)
|
||||||
.limit(param.limit);
|
.limit(param.limit);
|
||||||
@ -167,6 +168,7 @@ export class RoomController {
|
|||||||
location: Joi.string().required().label("Location"),
|
location: Joi.string().required().label("Location"),
|
||||||
floor: Joi.number().required().label("Floor"),
|
floor: Joi.number().required().label("Floor"),
|
||||||
picture: Joi.string().required().label("picture"),
|
picture: Joi.string().required().label("picture"),
|
||||||
|
medical_forms: Joi.array().items(Joi.string().uuid()).optional().label("Medical Forms"),
|
||||||
});
|
});
|
||||||
|
|
||||||
let param: any = await schema.validateAsync(req.body);
|
let param: any = await schema.validateAsync(req.body);
|
||||||
@ -180,6 +182,12 @@ export class RoomController {
|
|||||||
let serviceclass = await ServiceClassModel.list({ id: param.serviceclass }).then((q) => q.getOne());
|
let serviceclass = await ServiceClassModel.list({ id: param.serviceclass }).then((q) => q.getOne());
|
||||||
if (!serviceclass) throw { message: "Class not found" };
|
if (!serviceclass) throw { message: "Class not found" };
|
||||||
|
|
||||||
|
let medicalForms: MedicalForm[] = [];
|
||||||
|
if (param.medical_forms && param.medical_forms.length > 0) {
|
||||||
|
medicalForms = await queryRunner.manager.getRepository(MedicalForm).find({ where: { id: In(param.medical_forms) } });
|
||||||
|
if (medicalForms.length !== param.medical_forms.length) throw { message: "Medical Form not found" };
|
||||||
|
}
|
||||||
|
|
||||||
let room = new Room();
|
let room = new Room();
|
||||||
room.room = param.room;
|
room.room = param.room;
|
||||||
room.code = param.code;
|
room.code = param.code;
|
||||||
@ -190,6 +198,7 @@ export class RoomController {
|
|||||||
room.location = param.location;
|
room.location = param.location;
|
||||||
room.picture = param.picture;
|
room.picture = param.picture;
|
||||||
room.floor = param.floor;
|
room.floor = param.floor;
|
||||||
|
room.medical_forms = medicalForms;
|
||||||
room.created_by = req.auth?.data.name;
|
room.created_by = req.auth?.data.name;
|
||||||
room.updated_by = req.auth?.data.name;
|
room.updated_by = req.auth?.data.name;
|
||||||
await queryRunner.manager.save(room);
|
await queryRunner.manager.save(room);
|
||||||
@ -217,7 +226,7 @@ export class RoomController {
|
|||||||
id: Joi.string().uuid().required().label("Room Id"),
|
id: Joi.string().uuid().required().label("Room Id"),
|
||||||
});
|
});
|
||||||
let param: any = await schema.validateAsync(req.params);
|
let param: any = await schema.validateAsync(req.params);
|
||||||
let room = await RoomModel.list({ "Room.id": param.id }).then((q) => q.leftJoinAndSelect("Room.department", "department").leftJoinAndSelect("Room.serviceclass", "serviceclass").getOne());
|
let room = await RoomModel.list({ "Room.id": param.id }).then((q) => q.leftJoinAndSelect("Room.department", "department").leftJoinAndSelect("Room.serviceclass", "serviceclass").leftJoinAndSelect("Room.medical_forms", "medical_forms").getOne());
|
||||||
if (!room) throw { message: "Room Not Found" };
|
if (!room) throw { message: "Room Not Found" };
|
||||||
return ReturnHelper.successResponseAny(res, 200, Language.lang.success_view, room);
|
return ReturnHelper.successResponseAny(res, 200, Language.lang.success_view, room);
|
||||||
} catch (e: unknown) {
|
} catch (e: unknown) {
|
||||||
@ -249,6 +258,7 @@ export class RoomController {
|
|||||||
status: Joi.string().required().label("Status"),
|
status: Joi.string().required().label("Status"),
|
||||||
location: Joi.string().required().label("Location"),
|
location: Joi.string().required().label("Location"),
|
||||||
picture: Joi.string().required().label("picture"),
|
picture: Joi.string().required().label("picture"),
|
||||||
|
medical_forms: Joi.array().items(Joi.string().uuid()).optional().label("Medical Forms"),
|
||||||
});
|
});
|
||||||
let param: any = await schema.validateAsync(req.body);
|
let param: any = await schema.validateAsync(req.body);
|
||||||
|
|
||||||
@ -264,6 +274,12 @@ export class RoomController {
|
|||||||
let room = await RoomModel.list({ "Room.id": param.id }).then((q) => q.getOne());
|
let room = await RoomModel.list({ "Room.id": param.id }).then((q) => q.getOne());
|
||||||
if (!room) throw { message: "Room " + Language.lang.failed_not_found };
|
if (!room) throw { message: "Room " + Language.lang.failed_not_found };
|
||||||
|
|
||||||
|
let medicalForms: MedicalForm[] = [];
|
||||||
|
if (param.medical_forms && param.medical_forms.length > 0) {
|
||||||
|
medicalForms = await queryRunner.manager.getRepository(MedicalForm).find({ where: { id: In(param.medical_forms) } });
|
||||||
|
if (medicalForms.length !== param.medical_forms.length) throw { message: "Medical Form not found" };
|
||||||
|
}
|
||||||
|
|
||||||
room.room = param.room;
|
room.room = param.room;
|
||||||
room.code = param.code;
|
room.code = param.code;
|
||||||
room.description = param.description || null;
|
room.description = param.description || null;
|
||||||
@ -273,6 +289,7 @@ export class RoomController {
|
|||||||
room.floor = param.floor;
|
room.floor = param.floor;
|
||||||
room.location = param.location;
|
room.location = param.location;
|
||||||
room.picture = param.picture;
|
room.picture = param.picture;
|
||||||
|
room.medical_forms = medicalForms;
|
||||||
room.updated_by = req.auth?.data.name;
|
room.updated_by = req.auth?.data.name;
|
||||||
await queryRunner.manager.save(room);
|
await queryRunner.manager.save(room);
|
||||||
|
|
||||||
@ -400,9 +417,9 @@ export class RoomController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Validate file type
|
// Validate file type
|
||||||
const allowedMimes = ["image/jpeg", "image/jpg", "image/png", "image/webp"];
|
const allowedMimes = ["image/jpeg", "image/jpg", "image/png", "image/webp", "image/svg+xml", "image/svg"];
|
||||||
if (!allowedMimes.includes(file.mimetype)) {
|
if (!allowedMimes.includes(file.mimetype)) {
|
||||||
return ReturnHelper.errorResponse(res, 400, 400, Language.lang.failed_insert, "Invalid file type. Only JPG, PNG, and WEBP are allowed");
|
return ReturnHelper.errorResponse(res, 400, 400, Language.lang.failed_insert, "Invalid file type. Only JPG, PNG, WEBP, and SVG are allowed");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Normalize path
|
// Normalize path
|
||||||
|
|||||||
@ -132,6 +132,7 @@ const doc = {
|
|||||||
$status: "Y",
|
$status: "Y",
|
||||||
$location: "Room location",
|
$location: "Room location",
|
||||||
$picture: "Room picture name",
|
$picture: "Room picture name",
|
||||||
|
medical_forms: ["uuid-string"],
|
||||||
},
|
},
|
||||||
room_number: {
|
room_number: {
|
||||||
$number: "101",
|
$number: "101",
|
||||||
@ -215,8 +216,11 @@ const doc = {
|
|||||||
$status: { "@enum": ["Y", "N"] },
|
$status: { "@enum": ["Y", "N"] },
|
||||||
},
|
},
|
||||||
medical_form: {
|
medical_form: {
|
||||||
|
$title: "Form title",
|
||||||
$name: "Form name",
|
$name: "Form name",
|
||||||
$description: "Form description",
|
$description: "Form description",
|
||||||
|
picture: "Form picture path",
|
||||||
|
$status: "Y",
|
||||||
},
|
},
|
||||||
referenceRange: {
|
referenceRange: {
|
||||||
$gender: { "@enum": ["male", "female"] },
|
$gender: { "@enum": ["male", "female"] },
|
||||||
|
|||||||
Reference in New Issue
Block a user