From d3201ecbdcfca65b19aa278e56b0d850b5475307 Mon Sep 17 00:00:00 2001 From: Sinan Date: Fri, 4 Oct 2024 07:09:56 +0530 Subject: [PATCH] medical history server side added --- .../repositories/IAppointmentRepository.ts | 2 +- .../repositories/AppointmentRepository.ts | 2 +- .../controllers/doctor/DoctorController.ts | 17 ++++++++++++++++- .../routers/doctor/AuthorizedRoutes.ts | 1 + server/src/use_case/doctor/GetPatientUseCase.ts | 8 +++++++- 5 files changed, 26 insertions(+), 4 deletions(-) diff --git a/server/src/domain/interface/repositories/IAppointmentRepository.ts b/server/src/domain/interface/repositories/IAppointmentRepository.ts index ae74fc16..18b9dae5 100644 --- a/server/src/domain/interface/repositories/IAppointmentRepository.ts +++ b/server/src/domain/interface/repositories/IAppointmentRepository.ts @@ -20,7 +20,7 @@ export default interface IAppointmentRepository extends IRepository | null>; + ): Promise>; findManyByIds(ids: string[]): Promise; findPatientsByDoctorId(doctorId:string, limit:number, offset:number):Promise>; } diff --git a/server/src/infrastructure/repositories/AppointmentRepository.ts b/server/src/infrastructure/repositories/AppointmentRepository.ts index 2de52446..6cd35b6e 100644 --- a/server/src/infrastructure/repositories/AppointmentRepository.ts +++ b/server/src/infrastructure/repositories/AppointmentRepository.ts @@ -138,7 +138,7 @@ export default class AppointmentRepository implements IAppointmentRepository { offset: number, limit: number, status?: AppointmentStatus - ): Promise | null> { + ): Promise> { const filter: { patientId: string; status?: AppointmentStatus } = { patientId }; if (status) { filter.status = status; diff --git a/server/src/presentation/controllers/doctor/DoctorController.ts b/server/src/presentation/controllers/doctor/DoctorController.ts index 2a33770e..d60a9dfc 100644 --- a/server/src/presentation/controllers/doctor/DoctorController.ts +++ b/server/src/presentation/controllers/doctor/DoctorController.ts @@ -16,10 +16,25 @@ export default class DoctorController { offset = isNaN(offset) || offset < 0 ? 0 : offset; limit = isNaN(limit) || limit < 0 ? 10 : Math.min(limit, 100); - const patients = await this.getPatientUseCase.exec(doctorId, limit, offset); + const patients = await this.getPatientUseCase.exec(doctorId, limit, offset); res.status(StatusCode.Success).json(patients); } catch (error) { next(error) } } + + async getMedicalHistory(req: CustomRequest, res: Response, next: NextFunction) { + try { + const patientId = req.params.patientId + let offset = +(req.query.offset as string); + let limit = +(req.query.limit as string); + + offset = isNaN(offset) || offset < 0 ? 0 : offset; + limit = isNaN(limit) || limit < 0 ? 10 : Math.min(limit, 100); + const history = await this.getPatientUseCase.getMedicalHistory(patientId, offset, limit); + res.status(StatusCode.Success).json(history); + } catch (error) { + next(error) + } + } } \ No newline at end of file diff --git a/server/src/presentation/routers/doctor/AuthorizedRoutes.ts b/server/src/presentation/routers/doctor/AuthorizedRoutes.ts index 843bb791..959da82a 100644 --- a/server/src/presentation/routers/doctor/AuthorizedRoutes.ts +++ b/server/src/presentation/routers/doctor/AuthorizedRoutes.ts @@ -13,6 +13,7 @@ const doctorUseCase = new GetPatientUseCaseDoctor(appointmentRepository, validat const doctorController = new DoctorController(doctorUseCase) router.get("/", doctorController.getPatients.bind(doctorController)); +router.get("/medical-history/:patientId", doctorController.getMedicalHistory.bind(doctorController)) export default router; \ No newline at end of file diff --git a/server/src/use_case/doctor/GetPatientUseCase.ts b/server/src/use_case/doctor/GetPatientUseCase.ts index ac9424cd..ceb37bee 100644 --- a/server/src/use_case/doctor/GetPatientUseCase.ts +++ b/server/src/use_case/doctor/GetPatientUseCase.ts @@ -1,6 +1,7 @@ -import IPatient from "../../domain/entities/IPatient"; import IAppointmentRepository from "../../domain/interface/repositories/IAppointmentRepository"; import IValidatorService from '../../domain/interface/services/IValidatorService' +import IAppointment from "../../domain/entities/IAppointment"; +import IPatient from "../../domain/entities/IPatient"; import { PaginatedResult } from "../../types"; export default class GetPatientUseCaseDoctor { @@ -13,4 +14,9 @@ export default class GetPatientUseCaseDoctor { this.validatorService.validateIdFormat(doctorId); return await this.appointmentRepository.findPatientsByDoctorId(doctorId, limit, offset); } + + async getMedicalHistory(patientId: string, offset: number, limit: number): Promise> { + this.validatorService.validateIdFormat(patientId) + return await this.appointmentRepository.findMayByPatientId(patientId, offset, limit) + } } \ No newline at end of file