125 lines
4.8 KiB
Python
125 lines
4.8 KiB
Python
from typing import Optional
|
|
from fastapi import APIRouter, Depends, Query
|
|
from sqlalchemy.ext.asyncio import AsyncSession
|
|
from datetime import date
|
|
|
|
from app.database.session import get_db
|
|
from app.domain.entities.scheduled_appointment import ScheduledAppointmentEntity
|
|
from app.infrastructure.dependencies import get_current_user
|
|
from app.infrastructure.scheduled_appointments_service import ScheduledAppointmentsService
|
|
|
|
router = APIRouter()
|
|
|
|
|
|
@router.get(
|
|
"/",
|
|
response_model=list[ScheduledAppointmentEntity],
|
|
summary="Get all scheduled appointments",
|
|
description="Returns a list of all scheduled appointments",
|
|
)
|
|
async def get_all_scheduled_appointments(
|
|
db: AsyncSession = Depends(get_db),
|
|
user=Depends(get_current_user),
|
|
start_date: date | None = Query(None, description="Start date for filtering (YYYY-MM-DD)"),
|
|
end_date: date | None = Query(None, description="End date for filtering (YYYY-MM-DD)"),
|
|
):
|
|
scheduled_appointments_service = ScheduledAppointmentsService(db)
|
|
return await scheduled_appointments_service.get_all_scheduled_appointments(start_date=start_date, end_date=end_date)
|
|
|
|
|
|
@router.get(
|
|
"/doctor/{doctor_id}/",
|
|
response_model=list[ScheduledAppointmentEntity],
|
|
summary="Get all scheduled appointments for doctor",
|
|
description="Returns a list of scheduled appointments for doctor",
|
|
)
|
|
async def get_all_scheduled_appointments_by_doctor_id(
|
|
doctor_id: int,
|
|
db: AsyncSession = Depends(get_db),
|
|
user=Depends(get_current_user),
|
|
start_date: date | None = Query(None, description="Start date for filtering (YYYY-MM-DD)"),
|
|
end_date: date | None = Query(None, description="End date for filtering (YYYY-MM-DD)"),
|
|
):
|
|
appointments_service = ScheduledAppointmentsService(db)
|
|
return await appointments_service.get_scheduled_appointments_by_doctor_id(doctor_id, start_date=start_date,
|
|
end_date=end_date)
|
|
|
|
|
|
@router.get(
|
|
"/doctor/{doctor_id}/upcoming/",
|
|
response_model=list[ScheduledAppointmentEntity],
|
|
summary="Get upcoming scheduled appointments for doctor",
|
|
description="Returns the next 5 upcoming scheduled appointments for doctor",
|
|
)
|
|
async def get_upcoming_scheduled_appointments_by_doctor_id(
|
|
doctor_id: int,
|
|
db: AsyncSession = Depends(get_db),
|
|
user=Depends(get_current_user),
|
|
):
|
|
appointments_service = ScheduledAppointmentsService(db)
|
|
return await appointments_service.get_upcoming_scheduled_appointments_by_doctor_id(doctor_id)
|
|
|
|
|
|
@router.get(
|
|
"/patient/{patient_id}/",
|
|
response_model=ScheduledAppointmentEntity,
|
|
summary="Get all scheduled appointments for patient",
|
|
description="Returns a list of scheduled appointments for patient",
|
|
)
|
|
async def get_all_appointments_by_patient_id(
|
|
patient_id: int,
|
|
db: AsyncSession = Depends(get_db),
|
|
user=Depends(get_current_user),
|
|
start_date: date | None = Query(None, description="Start date for filtering (YYYY-MM-DD)"),
|
|
end_date: date | None = Query(None, description="End date for filtering (YYYY-MM-DD)"),
|
|
):
|
|
appointments_service = ScheduledAppointmentsService(db)
|
|
return await appointments_service.get_scheduled_appointments_by_patient_id(patient_id, start_date=start_date,
|
|
end_date=end_date)
|
|
|
|
|
|
@router.post(
|
|
"/",
|
|
response_model=ScheduledAppointmentEntity,
|
|
summary="Create appointment",
|
|
description="Creates a new appointment",
|
|
)
|
|
async def create_appointment(
|
|
appointment: ScheduledAppointmentEntity,
|
|
db: AsyncSession = Depends(get_db),
|
|
user=Depends(get_current_user),
|
|
):
|
|
appointment_service = ScheduledAppointmentsService(db)
|
|
return await appointment_service.create_scheduled_appointment(appointment, user.id)
|
|
|
|
|
|
@router.post(
|
|
"/{appointment_id}/cancel/",
|
|
response_model=Optional[ScheduledAppointmentEntity],
|
|
summary="Cancel scheduled appointment",
|
|
description="Cancel scheduled appointment",
|
|
)
|
|
async def cancel_appointment(
|
|
appointment_id: int,
|
|
db: AsyncSession = Depends(get_db),
|
|
user=Depends(get_current_user),
|
|
):
|
|
appointment_service = ScheduledAppointmentsService(db)
|
|
return await appointment_service.cancel_scheduled_appointment(appointment_id, user.id)
|
|
|
|
|
|
@router.put(
|
|
"/{appointment_id}/",
|
|
response_model=ScheduledAppointmentEntity,
|
|
summary="Update appointment",
|
|
description="Updates an existing appointment",
|
|
)
|
|
async def update_appointment(
|
|
appointment_id: int,
|
|
appointment: ScheduledAppointmentEntity,
|
|
db: AsyncSession = Depends(get_db),
|
|
user=Depends(get_current_user),
|
|
):
|
|
appointment_service = ScheduledAppointmentsService(db)
|
|
return await appointment_service.update_scheduled_appointment(appointment_id, appointment)
|