import { param, get, getFilterSchemaFor, } from '@loopback/rest'; import { CONTENT_TYPE, ErrorCodes, STATUS_CODE, } from '@sourcefuse-npm/alivio-lib'; import {authenticate, STRATEGY} from 'loopback4-authentication'; import {authorize} from 'loopback4-authorization'; import {MoodFactorLogsService} from '../services'; import {inject} from '@loopback/core'; import { CountSchema, Filter } from '@loopback/repository'; import { Appointment, PatientService } from '@sourcefuse-npm/patient-facade'; import moment from 'moment'; const alertsPath='alerts'; export class AlertController { constructor( @inject('services.MoodFactorLogsService') protected patientSvc: MoodFactorLogsService, @inject('services.PatientService') protected patientService: PatientService, ) {} @authenticate(STRATEGY.BEARER, { passReqToCallback: true, }) @authorize({permissions: ['*']}) @get(`${alertsPath}/dashboard-count`, { responses: { [STATUS_CODE.OK]: { description: 'Alerts model count', content: {[CONTENT_TYPE.JSON]: {schema: CountSchema}}, }, ...ErrorCodes, }, }) async getCareCentralCount( @param.header.string('Authorization') token?: string, @param.query.object('filter', getFilterSchemaFor(Appointment)) filter?: Filter, // sonarignore:start ): Promise { // sonarignore:end const responce={ upComingAppointmentCount:0, followupsCount:0, pendingTasksCount:0 }; const followupCount=await this.patientSvc.getFollowupAlertCount( token ); const pendingTasksCount=await this.patientSvc.getPendingTasklAlertCount( token ); const apptList= await this.patientService.getAllAppointments(filter, token); const currentTime = moment(new Date()).format('YYYY-MM-DDTHH:mm:ss.SSS[Z]'); const upComingAppoinments: Appointment[]=[]; const noFeedbackAppointments=apptList.filter(appt=>appt.status===null); noFeedbackAppointments.forEach(appointment=>{ //@ts-ignore if(appointment.apptDate>currentTime){ upComingAppoinments.push(appointment); } }); responce.followupsCount=followupCount.count; responce.pendingTasksCount=pendingTasksCount.count; responce.upComingAppointmentCount=upComingAppoinments.length ?? 0; return responce; } }