fix(schedule): calendar add doctor filter

This commit is contained in:
avicenan
2026-04-20 11:59:58 +07:00
parent 344c27be86
commit 2d0438535a

View File

@ -74,6 +74,7 @@ export class ScheduleModel {
}
const filterRoomId = filterObj && filterObj.roomId !== "" && filterObj.roomId !== null && filterObj.roomId !== undefined ? String(filterObj.roomId) : "";
const filterDoctorId = filterObj && filterObj.doctorId !== "" && filterObj.doctorId !== null && filterObj.doctorId !== undefined ? String(filterObj.doctorId) : "";
const page = options.page ?? 1;
const limit = options.limit ?? 10;
@ -83,10 +84,8 @@ export class ScheduleModel {
const roomQuery = query
.select(["Room.id", "Room.room", "Room.code", "Room.picture", "Room.location", "Room.status", "Department.name"])
.leftJoin("Room.department", "Department")
.where("Department.name = :departmentName", { departmentName: "Outpatient" });
if (filterRoomId !== "") {
roomQuery.andWhere("Room.id = :roomId", { roomId: filterRoomId });
}
.where("Department.name = :departmentName", { departmentName: "Outpatient" })
.andWhere(filterRoomId !== "" ? "Room.id = :roomId" : "1=1", { roomId: filterRoomId });
const roomTotalCount = await roomQuery
.getCount();
@ -103,6 +102,7 @@ export class ScheduleModel {
.andWhere("ScheduleSeries.start_date <= :rangeEndDate", { rangeEndDate: dayjs(rangeEnd).format("YYYY-MM-DD") })
.andWhere("(ScheduleSeries.until_date IS NULL OR ScheduleSeries.until_date >= :rangeStartDate)", { rangeStartDate: dayjs(rangeStart).format("YYYY-MM-DD") })
.andWhere("ScheduleSeries.deleted_at IS NULL")
.andWhere(filterDoctorId !== "" ? "ScheduleSeries.doctor_id = :doctorId" : "1=1", { doctorId: filterDoctorId })
.orderBy("ScheduleSeries.start_time", "ASC")
.getMany();