43 lines
1.4 KiB
Python
43 lines
1.4 KiB
Python
from typing import List
|
|
|
|
from sqlalchemy.orm import Session
|
|
|
|
from app.crud.base import CRUDBase
|
|
from app.models.doctor_schedule import DoctorSchedule, WeekDay
|
|
from app.schemas.doctor_schedule import DoctorScheduleCreate, DoctorScheduleUpdate
|
|
|
|
|
|
class CRUDDoctorSchedule(CRUDBase[DoctorSchedule, DoctorScheduleCreate, DoctorScheduleUpdate]):
|
|
def get_by_doctor(
|
|
self, db: Session, *, doctor_id: int, skip: int = 0, limit: int = 100
|
|
) -> List[DoctorSchedule]:
|
|
return (
|
|
db.query(DoctorSchedule)
|
|
.filter(DoctorSchedule.doctor_id == doctor_id)
|
|
.offset(skip)
|
|
.limit(limit)
|
|
.all()
|
|
)
|
|
|
|
def get_by_doctor_and_day(
|
|
self, db: Session, *, doctor_id: int, day: WeekDay
|
|
) -> List[DoctorSchedule]:
|
|
return (
|
|
db.query(DoctorSchedule)
|
|
.filter(DoctorSchedule.doctor_id == doctor_id, DoctorSchedule.day_of_week == day)
|
|
.all()
|
|
)
|
|
|
|
def get_available_doctors_by_day(
|
|
self, db: Session, *, day: WeekDay, skip: int = 0, limit: int = 100
|
|
) -> List[DoctorSchedule]:
|
|
return (
|
|
db.query(DoctorSchedule)
|
|
.filter(DoctorSchedule.day_of_week == day, DoctorSchedule.is_available)
|
|
.offset(skip)
|
|
.limit(limit)
|
|
.all()
|
|
)
|
|
|
|
|
|
doctor_schedule = CRUDDoctorSchedule(DoctorSchedule) |