import { inject } from '@loopback/core'; import { getModelSchemaRef, RestBindings, requestBody , Request, post} from '@loopback/rest'; import { PermissionKey, ErrorCodes, STATUS_CODE, CONTENT_TYPE } from '@sourcefuse-npm/alivio-lib'; import { PatientService, Prescription, PrescriptionMedicinesController, } from '@sourcefuse-npm/patient-facade'; import { authenticate, STRATEGY } from 'loopback4-authentication'; import { authorize } from 'loopback4-authorization'; import { AppointmentFeedbackService } from '../services'; const baseUrl = '/prescriptions'; export class PrescriptionAPIController extends PrescriptionMedicinesController { constructor( @inject('services.PatientService') protected patientService: PatientService, @inject('services.AppointmentFeedbackService') public appointmentFeedbackService: AppointmentFeedbackService, ) { super(patientService); } @authenticate(STRATEGY.BEARER, { passReqToCallback: true, }) @authorize({ permissions: [ PermissionKey.CreatePrescriptionMeds, PermissionKey.CreatePrescription, ], }) @post(baseUrl, { responses: { ...ErrorCodes, [STATUS_CODE.OK]: { description: 'Prescription model instance', content: { [CONTENT_TYPE.JSON]: { schema: getModelSchemaRef(Prescription), }, }, }, }, }) async createPrescription( @inject(RestBindings.Http.REQUEST) request: Request, @requestBody({ content: { [CONTENT_TYPE.JSON]: { schema: getModelSchemaRef(Prescription, {exclude: ['id']}), }, }, }) prescriptionMedicines: Omit, ): Promise { const result= await this.patientService.createPatientPrescriptions( `${request.headers.authorization}`, prescriptionMedicines, ); this.appointmentFeedbackService.updatePrescriptionStatus(prescriptionMedicines.patientId,`${request.headers.authorization}`); return result; } }