import {inject} from '@loopback/core'; import { Count, CountSchema, } from '@loopback/repository'; import { post, param, get, getModelSchemaRef, patch, del, requestBody, } from '@loopback/rest'; import {STATUS_CODE, SuccessResponse} from '@sourcefuse-npm/alivio-lib'; import { AppointmentNote, PatientService } from '@sourcefuse-npm/patient-facade'; import {authenticate, STRATEGY} from 'loopback4-authentication'; import {authorize} from 'loopback4-authorization'; import {AppointmentHealth, AppointmentStatusModel} from '../models'; import {AppointmentFeedbackService} from '../services'; const appointmentsPath = '/appointments/{id}/health'; export class AppointmentFeedbackController { constructor( @inject('services.AppointmentFeedbackService') public appointmentFeedbackService: AppointmentFeedbackService, @inject('services.PatientService') protected patientService: PatientService, ) {} @authenticate(STRATEGY.BEARER, { passReqToCallback: true, }) @authorize({permissions: ['*']}) @post(`${appointmentsPath}`, { responses: { [STATUS_CODE.OK]: { description: 'Create AppointmentHealth model instance', content: { 'application/json': { schema: getModelSchemaRef(AppointmentHealth), }, }, }, }, }) async create( @requestBody({ content: { 'application/json': { schema: getModelSchemaRef(AppointmentHealth, { title: 'AppointmentHealth', }), }, }, }) appointmentHealth: Omit, @param.path.number('id') id: number, @param.header.string('Authorization') token: string, ): Promise { return this.appointmentFeedbackService.create( id, appointmentHealth, token, ); } @authenticate(STRATEGY.BEARER, { passReqToCallback: true, }) @authorize({permissions: ['*']}) @get(`${appointmentsPath}`, { responses: { [STATUS_CODE.OK]: { description: 'Array of AppointmentHealth model instances', content: { 'application/json': { schema: { type: 'array', items: getModelSchemaRef(AppointmentHealth, { includeRelations: true, }), }, }, }, }, }, }) async find( @param.path.number('id') id: number, @param.header.string('Authorization') token?: string, ): Promise { return this.appointmentFeedbackService.find(id, token); } @authenticate(STRATEGY.BEARER, { passReqToCallback: true, }) @authorize({permissions: ['*']}) @patch(`${appointmentsPath}`, { responses: { [STATUS_CODE.OK]: { description: 'AppointmentHealth PATCH success count', content: {'application/json': {schema: CountSchema}}, }, }, }) async updateAll( @requestBody({ content: { 'application/json': { schema: getModelSchemaRef(AppointmentHealth, {partial: true}), }, }, }) appointmentHealth: AppointmentHealth, @param.path.number('id') id: number, @param.header.string('Authorization') token?: string, ): Promise { return this.appointmentFeedbackService.updateAll( appointmentHealth, id, token, ); } @authenticate(STRATEGY.BEARER, { passReqToCallback: true, }) @authorize({permissions: ['*']}) @patch(`appointments/{id}/status`, { responses: { [STATUS_CODE.NO_CONTENT]: { description: 'Appointment status PUT success', }, }, }) async replaceById( @param.path.number('id') id: number, @requestBody() appointmentStatus: AppointmentStatusModel, @param.header.string('Authorization') token?: string, ): Promise { const statusUpdate : Partial={}; statusUpdate.status=appointmentStatus.status; await this.appointmentFeedbackService.updateAppoinmentStatus( id, statusUpdate, token, ); if(appointmentStatus.note){ const data={ note : appointmentStatus.note, title: appointmentStatus.title }; await this.patientService.createAppointmentNote( token, id, data as AppointmentNote, ); } return new SuccessResponse({ success: true, }); } @authenticate(STRATEGY.BEARER, { passReqToCallback: true, }) @authorize({permissions: ['*']}) @del(`${appointmentsPath}`, { responses: { [STATUS_CODE.NO_CONTENT]: { description: 'AppointmentHealth DELETE success', }, }, }) async deleteById( @param.path.number('id') id: number, @param.header.string('Authorization') token?: string, ): Promise { await this.appointmentFeedbackService.deleteById(id, token); } }