diff --git a/src/controllers/responsiblepartyconsent.ts b/src/controllers/responsiblepartyconsent.ts new file mode 100644 index 0000000..e61759e --- /dev/null +++ b/src/controllers/responsiblepartyconsent.ts @@ -0,0 +1,121 @@ +import { ResponsiblePartyConsent } from "entity"; +import { NextFunction, Response } from "express"; +import { Request } from "express-jwt"; +import Joi from "joi"; +import { ILogObj, Logger } from "tslog"; +import { ReturnHelper } from "../helpers/express/return"; +import { Language } from "../langs/lang"; +import { OrmHelper } from "../helpers/orm"; +import moment from "moment"; + +const log: Logger = new Logger({ + name: "[ResponsiblePartyConsentController]", + type: "pretty", +}); + +export class ResponsiblePartyConsentController { + static async body(req: Request, res: Response, next: NextFunction): Promise { + /* + #swagger.tags = ['Responsible Party Consent'] + #swagger.security = [{ "bearerAuth": [] }] + */ + try { + const data = await OrmHelper.DB.getRepository(ResponsiblePartyConsent) + .createQueryBuilder("ResponsiblePartyConsent") + .getMany(); + + const count_data = data.length; + const current_page = 1; + const total_count_data = count_data; + const mapped_data = data; + + return ReturnHelper.successResponselist(res, 200, Language.lang.success_view, count_data, current_page, total_count_data, mapped_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 { + /* + #swagger.tags = ['Responsible Party Consent'] + #swagger.security = [{ "bearerAuth": [] }] + #swagger.requestBody = { required: true, content: { "application/json": { schema: { $ref: "#/components/schemas/responsiblepartyconsent" } } } } + */ + const queryRunner = OrmHelper.DB.createQueryRunner(); + await queryRunner.startTransaction(); + try { + const schema = Joi.object().keys({ + bodytext: Joi.string().required().label("Body Text"), + }); + + let param: any = await schema.validateAsync(req.body); + + const existing = await OrmHelper.DB.getRepository(ResponsiblePartyConsent) + .createQueryBuilder("ResponsiblePartyConsent") + .getOne(); + + if (existing) { + await queryRunner.rollbackTransaction(); + return ReturnHelper.errorResponse(res, 400, 400, "Data already exists", "Responsible Party Consent already exists"); + } + + let responsiblepartyconsent = new ResponsiblePartyConsent(); + responsiblepartyconsent.body = param.bodytext; + responsiblepartyconsent.created_by = req.auth?.data.name; + responsiblepartyconsent.updated_by = req.auth?.data.name; + await queryRunner.manager.save(responsiblepartyconsent); + + await queryRunner.commitTransaction(); + return ReturnHelper.successResponseAny(res, 200, Language.lang.success_insert, responsiblepartyconsent); + } 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 update(req: Request, res: Response, next: NextFunction): Promise { + /* + #swagger.tags = ['Responsible Party Consent'] + #swagger.security = [{ "bearerAuth": [] }] + #swagger.parameters['id'] = { in: 'path', type: 'string' } + #swagger.requestBody = { required: true, content: { "application/json": { schema: { $ref: "#/components/schemas/responsiblepartyconsent" } } } } + */ + const queryRunner = OrmHelper.DB.createQueryRunner(); + await queryRunner.startTransaction(); + try { + req.body.id = req.params["id"]; + const schema = Joi.object().keys({ + id: Joi.string().uuid().required().label("Room ID"), + bodytext: Joi.string().required().label("Body Text"), + }); + let param: any = await schema.validateAsync(req.body); + + let responsiblepartyconsent = await OrmHelper.DB.getRepository(ResponsiblePartyConsent) + .createQueryBuilder("Room") + .where("Room.id = :id", { id: param.id }) + .getOne(); + if (!responsiblepartyconsent) throw { message: "Responsible Party Consent " + Language.lang.failed_not_found }; + + responsiblepartyconsent.body = param.bodytext; + responsiblepartyconsent.updated_by = req.auth?.data.name; + responsiblepartyconsent.updated_at = moment().toDate(); + await queryRunner.manager.save(responsiblepartyconsent); + + await queryRunner.commitTransaction(); + return ReturnHelper.successResponseAny(res, 200, Language.lang.success_update, responsiblepartyconsent); + } 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(); + } + } +} diff --git a/src/helpers/orm.ts b/src/helpers/orm.ts index 71d99ee..e0cd5c4 100644 --- a/src/helpers/orm.ts +++ b/src/helpers/orm.ts @@ -1,7 +1,7 @@ import config from 'config'; import { DataSource } from "typeorm"; import { ILogObj, Logger } from 'tslog'; -import { 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 { 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' export class OrmHelper { static DB: DataSource = null @@ -54,7 +54,8 @@ export class OrmHelper { CardType, PaymentMethod, RegistrationFee, - RefferalHospital,Province,City,Subdistrict,Ward + RefferalHospital,Province,City,Subdistrict,Ward, + ResponsiblePartyConsent ], subscribers: [], migrations: [], diff --git a/src/routes/private.ts b/src/routes/private.ts index 4ae2351..4472f22 100644 --- a/src/routes/private.ts +++ b/src/routes/private.ts @@ -64,6 +64,7 @@ import { CardTypeController } from '../controllers/card_type'; import { PaymentMethodController } from '../controllers/payment-method'; import { RegistrationFeeController } from '../controllers/registrationfee'; import { RegionController } from '../controllers/region'; +import { ResponsiblePartyConsentController } from '../controllers/responsiblepartyconsent'; export class RoutePrivate { static setup(app: express.Application) { @@ -490,5 +491,9 @@ export class RoutePrivate { app.get('/api/region/city/:province_code', RegionController.city) app.get('/api/region/subdistrict/:city_code', RegionController.subdistrict) app.get('/api/region/ward/:subdistric_code', RegionController.ward) + + app.get('/api/responsible-party-consent/body', ResponsiblePartyConsentController.body) + app.post('/api/responsible-party-consent/create', ResponsiblePartyConsentController.create) + app.put('/api/responsible-party-consent/update/:id', ResponsiblePartyConsentController.update) } } diff --git a/src/swagger/builder.js b/src/swagger/builder.js index 4a92c69..71e22b8 100644 --- a/src/swagger/builder.js +++ b/src/swagger/builder.js @@ -472,6 +472,9 @@ const doc = { serviceFareUpdate: { $fare: 100000, }, + responsiblepartyconsent:{ + $bodytext: "string" + } }, parameters: {}, securitySchemes: {