Skip to content

Commit

Permalink
medical history server side added
Browse files Browse the repository at this point in the history
  • Loading branch information
sinanptm committed Oct 4, 2024
1 parent c333a31 commit d3201ec
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export default interface IAppointmentRepository extends IRepository<IAppointment
offset: number,
limit: number,
status?: AppointmentStatus
): Promise<PaginatedResult<IAppointment> | null>;
): Promise<PaginatedResult<IAppointment>>;
findManyByIds(ids: string[]): Promise<IAppointment[] | null>;
findPatientsByDoctorId(doctorId:string, limit:number, offset:number):Promise<PaginatedResult<IPatient>>;
}
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ export default class AppointmentRepository implements IAppointmentRepository {
offset: number,
limit: number,
status?: AppointmentStatus
): Promise<PaginatedResult<IAppointment> | null> {
): Promise<PaginatedResult<IAppointment>> {
const filter: { patientId: string; status?: AppointmentStatus } = { patientId };
if (status) {
filter.status = status;
Expand Down
17 changes: 16 additions & 1 deletion server/src/presentation/controllers/doctor/DoctorController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}
1 change: 1 addition & 0 deletions server/src/presentation/routers/doctor/AuthorizedRoutes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
8 changes: 7 additions & 1 deletion server/src/use_case/doctor/GetPatientUseCase.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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<PaginatedResult<IAppointment>> {
this.validatorService.validateIdFormat(patientId)
return await this.appointmentRepository.findMayByPatientId(patientId, offset, limit)
}
}

0 comments on commit d3201ec

Please sign in to comment.