From 3fc30f8e595253870f3770723dde79e458cf0bf3 Mon Sep 17 00:00:00 2001 From: andrei Date: Sun, 16 Mar 2025 16:59:39 +0500 Subject: [PATCH] =?UTF-8?q?=D1=81=D0=B4=D0=B5=D0=BB=D0=B0=20=D1=8D=D0=BD?= =?UTF-8?q?=D0=B4-=D0=BF=D0=BE=D0=B8=D0=BD=D1=82=D1=8B=20=D0=B4=D0=BB?= =?UTF-8?q?=D1=8F=20=D0=B7=D0=B0=D0=BF=D0=BB=D0=B0=D0=BD=D0=B8=D1=80=D0=BE?= =?UTF-8?q?=D0=B2=D0=B0=D0=BD=D0=BD=D1=8B=D1=85=20=D0=BF=D1=80=D0=B8=D0=B5?= =?UTF-8?q?=D0=BC=D0=BE=D0=B2,=20=D0=B0=20=D1=82=D0=B0=D0=BA=D0=B6=D0=B5?= =?UTF-8?q?=20=D0=B2=D1=8B=D0=BD=D0=B5=D1=81=20=D0=BF=D1=80=D0=B5=D1=84?= =?UTF-8?q?=D0=B8=D0=BA=D1=81=D1=8B=20=D1=80=D0=BE=D1=83=D1=82=D0=B5=D1=80?= =?UTF-8?q?=D0=BE=D0=B2=20=D0=B2=20main=20=D1=84=D0=B0=D0=B9=D0=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controllers/appointment_types_router.py | 2 +- api/app/controllers/appointments_router.py | 10 +-- api/app/controllers/lens_issues_router.py | 4 +- api/app/controllers/lens_types_router.py | 2 +- api/app/controllers/lenses_router.py | 10 +-- api/app/controllers/patients_router.py | 8 +- api/app/controllers/register_routes.py | 2 +- .../scheduled_appointments_router.py | 84 +++++++++++++++++++ api/app/controllers/set_content_router.py | 6 +- api/app/controllers/sets_router.py | 10 +-- .../scheduled_appointments_service.py | 76 ++++++++++++++++- api/app/main.py | 22 ++--- 12 files changed, 198 insertions(+), 38 deletions(-) create mode 100644 api/app/controllers/scheduled_appointments_router.py diff --git a/api/app/controllers/appointment_types_router.py b/api/app/controllers/appointment_types_router.py index 8245488..db11f84 100644 --- a/api/app/controllers/appointment_types_router.py +++ b/api/app/controllers/appointment_types_router.py @@ -10,7 +10,7 @@ router = APIRouter() @router.get( - "/appointment_types/", + "/", response_model=list[AppointmentTypeEntity], summary="Get all appointment types", description="Returns a list of all appointment types", diff --git a/api/app/controllers/appointments_router.py b/api/app/controllers/appointments_router.py index 06d89ac..f7f5a47 100644 --- a/api/app/controllers/appointments_router.py +++ b/api/app/controllers/appointments_router.py @@ -10,7 +10,7 @@ router = APIRouter() @router.get( - "/appointments/", + "/", response_model=list[AppointmentEntity], summary="Get all appointments", description="Returns a list of all appointments", @@ -24,7 +24,7 @@ async def get_all_appointments( @router.get( - "/appointments/doctor/{doctor_id}/", + "/doctor/{doctor_id}/", response_model=AppointmentEntity, summary="Get all appointments for doctor", description="Returns a list of appointments for doctor", @@ -39,7 +39,7 @@ async def get_all_appointments_by_doctor_id( @router.get( - "/appointments/patient/{patient_id}/", + "/patient/{patient_id}/", response_model=AppointmentEntity, summary="Get all appointments for patient", description="Returns a list of appointments for patient", @@ -54,7 +54,7 @@ async def get_all_appointments_by_patient_id( @router.post( - "/appointments/", + "/", response_model=AppointmentEntity, summary="Create appointment", description="Creates a new appointment", @@ -69,7 +69,7 @@ async def create_appointment( @router.put( - "/appointments/{appointment_id}/", + "/{appointment_id}/", response_model=AppointmentEntity, summary="Update appointment", description="Updates an existing appointment", diff --git a/api/app/controllers/lens_issues_router.py b/api/app/controllers/lens_issues_router.py index e5da17a..6945974 100644 --- a/api/app/controllers/lens_issues_router.py +++ b/api/app/controllers/lens_issues_router.py @@ -10,7 +10,7 @@ router = APIRouter() @router.get( - "/lens_issues/", + "/", response_model=list[LensIssueEntity], summary="Get all lens issues", description="Returns a list of all lens issues", @@ -24,7 +24,7 @@ async def get_all_lens_issues( @router.post( - "/lens_issues/", + "/", response_model=LensIssueEntity, summary="Create lens issue", description="Creates a new lens issue", diff --git a/api/app/controllers/lens_types_router.py b/api/app/controllers/lens_types_router.py index 1e92cd2..33aa21d 100644 --- a/api/app/controllers/lens_types_router.py +++ b/api/app/controllers/lens_types_router.py @@ -10,7 +10,7 @@ router = APIRouter() @router.get( - "/lens_types/", + "/", response_model=list[LensTypeEntity], summary="Get all lens types", description="Returns a list of all lens types", diff --git a/api/app/controllers/lenses_router.py b/api/app/controllers/lenses_router.py index 7eaafa6..1459489 100644 --- a/api/app/controllers/lenses_router.py +++ b/api/app/controllers/lenses_router.py @@ -10,7 +10,7 @@ router = APIRouter() @router.get( - "/lenses/", + "/", response_model=list[LensEntity], summary="Get all lenses", description="Returns a list of all lenses", @@ -24,7 +24,7 @@ async def get_all_lenses( @router.get( - "/lenses/not_issued/", + "/not_issued/", response_model=list[LensEntity], summary="Get all not issued lenses", description="Returns a list of all not issued lenses", @@ -38,7 +38,7 @@ async def get_all_not_issued_lenses( @router.post( - "/lenses/", + "/", response_model=LensEntity, summary="Create lens", description="Creates a new lens", @@ -53,7 +53,7 @@ async def create_lens( @router.put( - "/lenses/{lens_id}/", + "/{lens_id}/", response_model=LensEntity, summary="Update lens", description="Updates an existing lens", @@ -69,7 +69,7 @@ async def update_lens( @router.delete( - "/lenses/{lens_id}/", + "/{lens_id}/", response_model=LensEntity, summary="Delete lens", description="Deletes an existing lens", diff --git a/api/app/controllers/patients_router.py b/api/app/controllers/patients_router.py index d482b0e..fbcfa7e 100644 --- a/api/app/controllers/patients_router.py +++ b/api/app/controllers/patients_router.py @@ -10,7 +10,7 @@ router = APIRouter() @router.get( - "/patients/", + "/", response_model=list[PatientEntity], summary="Get all patients", description="Returns a list of all patients", @@ -24,7 +24,7 @@ async def get_all_patients( @router.post( - "/patients/", + "/", response_model=PatientEntity, summary="Create a new patient", description="Creates a new patient", @@ -39,7 +39,7 @@ async def create_patient( @router.put( - "/patients/{patient_id}/", + "/{patient_id}/", response_model=PatientEntity, summary="Update a patient", description="Updates a patient", @@ -55,7 +55,7 @@ async def update_patient( @router.delete( - "/patients/{patient_id}/", + "/{patient_id}/", response_model=PatientEntity, summary="Delete a patient", description="Deletes a patient", diff --git a/api/app/controllers/register_routes.py b/api/app/controllers/register_routes.py index 7d57b19..9414192 100644 --- a/api/app/controllers/register_routes.py +++ b/api/app/controllers/register_routes.py @@ -9,7 +9,7 @@ router = APIRouter() @router.post( - "/register/", + "/", response_model=dict, summary="User Registration", description="Performs user registration in the system", diff --git a/api/app/controllers/scheduled_appointments_router.py b/api/app/controllers/scheduled_appointments_router.py new file mode 100644 index 0000000..fb57b5c --- /dev/null +++ b/api/app/controllers/scheduled_appointments_router.py @@ -0,0 +1,84 @@ +from fastapi import APIRouter, Depends +from sqlalchemy.ext.asyncio import AsyncSession + +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), +): + scheduled_appointments_service = ScheduledAppointmentsService(db) + return await scheduled_appointments_service.get_all_scheduled_appointments() + + +@router.get( + "/doctor/{doctor_id}/", + response_model=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), +): + appointments_service = ScheduledAppointmentsService(db) + return await appointments_service.get_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), +): + appointments_service = ScheduledAppointmentsService(db) + return await appointments_service.get_scheduled_appointments_by_patient_id(patient_id) + + +@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) + + +@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) diff --git a/api/app/controllers/set_content_router.py b/api/app/controllers/set_content_router.py index 67cd0b6..3fca1d3 100644 --- a/api/app/controllers/set_content_router.py +++ b/api/app/controllers/set_content_router.py @@ -10,7 +10,7 @@ router = APIRouter() @router.get( - '/set_content/{set_id}/', + '/{set_id}/', response_model=list[SetContentEntity], summary='Get all set content by set ID', description='Returns a list of set content by set ID', @@ -25,7 +25,7 @@ async def get_set_content_by_set_id( @router.post( - '/set_content/{set_id}/', + '/{set_id}/', response_model=list[SetContentEntity], summary='Create a new set content by set_id', description='Create a new set content by set_id', @@ -41,7 +41,7 @@ async def create_set_content( @router.put( - '/set_content/{set_id}/', + '/{set_id}/', response_model=list[SetContentEntity], summary='Update a set content by set_id', description='Update a set content by set_id', diff --git a/api/app/controllers/sets_router.py b/api/app/controllers/sets_router.py index a4e7127..ad31091 100644 --- a/api/app/controllers/sets_router.py +++ b/api/app/controllers/sets_router.py @@ -11,7 +11,7 @@ router = APIRouter() @router.get( - '/sets/', + '/', response_model=list[SetEntity], summary='Get all sets', description='Returns a list of all sets', @@ -25,7 +25,7 @@ async def get_all_sets( @router.post( - '/sets/', + '/', response_model=SetEntity, summary='Create a new set', description='Create a new set', @@ -40,7 +40,7 @@ async def create_set( @router.put( - '/sets/{set_id}/', + '/{set_id}/', response_model=SetEntity, summary='Update a set', description='Update a set,' @@ -56,7 +56,7 @@ async def update_set( @router.post( - '/sets/append_lenses/{set_id}/', + '/append_lenses/{set_id}/', response_model=list[LensEntity], summary='Append content from set to lenses', description='Get all content from set, converting to lens and appending to database', @@ -71,7 +71,7 @@ async def append_lenses_set( @router.delete( - '/sets/{set_id}/', + '/{set_id}/', response_model=SetEntity, summary='Delete set', description='Delete an existing set', diff --git a/api/app/infrastructure/scheduled_appointments_service.py b/api/app/infrastructure/scheduled_appointments_service.py index 69c6007..039ef7d 100644 --- a/api/app/infrastructure/scheduled_appointments_service.py +++ b/api/app/infrastructure/scheduled_appointments_service.py @@ -63,7 +63,81 @@ class ScheduledAppointmentsService: for scheduled_appointment in scheduled_appointments ] - + async def create_scheduled_appointment(self, scheduled_appointment: ScheduledAppointmentEntity) -> Optional[ + ScheduledAppointmentEntity + ]: + patient = await self.patients_repository.get_by_id(scheduled_appointment.patient_id) + + if not patient: + raise HTTPException( + status_code=status.HTTP_400_BAD_REQUEST, + detail='The patient with this ID was not found', + ) + + doctor = await self.users_repository.get_by_id(scheduled_appointment.doctor_id) + + if not doctor: + raise HTTPException( + status_code=status.HTTP_400_BAD_REQUEST, + detail='The doctor/user with this ID was not found', + ) + + appointment_type = await self.appointment_types_repository.get_by_id(scheduled_appointment.type_id) + + if not appointment_type: + raise HTTPException( + status_code=status.HTTP_400_BAD_REQUEST, + detail='The appointment type with this ID was not found', + ) + + scheduled_appointment_model = self.entity_to_model(scheduled_appointment) + + await self.scheduled_appointment_repository.create(scheduled_appointment_model) + + return self.model_to_entity(scheduled_appointment_model) + + async def update_scheduled_appointment( + self, + scheduled_appointment_id: int, + scheduled_appointment: ScheduledAppointmentEntity + ) -> Optional[ScheduledAppointmentEntity]: + scheduled_appointment_model = await self.scheduled_appointment_repository.get_by_id(scheduled_appointment_id) + + if not scheduled_appointment_model: + raise HTTPException(status_code=status.HTTP_400_BAD_REQUEST, detail="Scheduled appointment not found") + + patient = await self.patients_repository.get_by_id(scheduled_appointment.patient_id) + + if not patient: + raise HTTPException( + status_code=status.HTTP_400_BAD_REQUEST, + detail='The patient with this ID was not found', + ) + + doctor = await self.users_repository.get_by_id(scheduled_appointment.doctor_id) + + if not doctor: + raise HTTPException( + status_code=status.HTTP_400_BAD_REQUEST, + detail='The doctor/user with this ID was not found', + ) + + appointment_type = await self.appointment_types_repository.get_by_id(scheduled_appointment.type_id) + + if not appointment_type: + raise HTTPException( + status_code=status.HTTP_400_BAD_REQUEST, + detail='The appointment type with this ID was not found', + ) + + scheduled_appointment_model.scheduled_datetime = scheduled_appointment.scheduled_datetime + scheduled_appointment_model.patient_id = scheduled_appointment.patient_id + scheduled_appointment_model.doctor_id = scheduled_appointment.doctor_id + scheduled_appointment_model.type_id = scheduled_appointment.type_id + + await self.scheduled_appointment_repository.update(scheduled_appointment_model) + + return self.model_to_entity(scheduled_appointment_model) @staticmethod def entity_to_model(scheduled_appointment: ScheduledAppointmentEntity) -> ScheduledAppointment: diff --git a/api/app/main.py b/api/app/main.py index 3a5e482..1d84a30 100644 --- a/api/app/main.py +++ b/api/app/main.py @@ -1,7 +1,7 @@ from fastapi import FastAPI from starlette.middleware.cors import CORSMiddleware -from app.controllers.appointment_types_router import router as appointment_types_router +from app.controllers.appointment_types_router import router as appointments_types_router from app.controllers.appointments_router import router as appointment_router from app.controllers.auth_router import router as auth_router from app.controllers.lens_issues_router import router as lens_issues_router @@ -9,6 +9,7 @@ from app.controllers.lens_types_router import router as lens_types_router from app.controllers.lenses_router import router as lenses_router from app.controllers.patients_router import router as patients_router from app.controllers.register_routes import router as register_router +from app.controllers.scheduled_appointments_router import router as scheduled_appointments_router from app.controllers.set_content_router import router as set_content_router from app.controllers.sets_router import router as sets_router from app.settings import settings @@ -25,16 +26,17 @@ def start_app(): allow_headers=['*'], ) + api_app.include_router(appointments_types_router, prefix=f'{settings.APP_PREFIX}/appointment_types', tags=['appointment_types']) + api_app.include_router(appointment_router, prefix=f'{settings.APP_PREFIX}/appointments', tags=['appointments']) api_app.include_router(auth_router, prefix=settings.APP_PREFIX, tags=['auth']) - api_app.include_router(register_router, prefix=settings.APP_PREFIX, tags=['register']) - api_app.include_router(patients_router, prefix=settings.APP_PREFIX, tags=['patients']) - api_app.include_router(lenses_router, prefix=settings.APP_PREFIX, tags=['lenses']) - api_app.include_router(lens_types_router, prefix=settings.APP_PREFIX, tags=['lens_types']) - api_app.include_router(sets_router, prefix=settings.APP_PREFIX, tags=['sets']) - api_app.include_router(set_content_router, prefix=settings.APP_PREFIX, tags=['set_content']) - api_app.include_router(lens_issues_router, prefix=settings.APP_PREFIX, tags=['lens_issue']) - api_app.include_router(appointment_types_router, prefix=settings.APP_PREFIX, tags=['appointment_types']) - api_app.include_router(appointment_router, prefix=settings.APP_PREFIX, tags=['appointments']) + api_app.include_router(lens_issues_router, prefix=f'{settings.APP_PREFIX}/lens_issue', tags=['lens_issue']) + api_app.include_router(lens_types_router, prefix=f'{settings.APP_PREFIX}/lens_types', tags=['lens_types']) + api_app.include_router(lenses_router, prefix=f'{settings.APP_PREFIX}/lenses', tags=['lenses']) + api_app.include_router(patients_router, prefix=f'{settings.APP_PREFIX}/patients', tags=['patients']) + api_app.include_router(register_router, prefix=f'{settings.APP_PREFIX}/register', tags=['register']) + api_app.include_router(scheduled_appointments_router, prefix=f'{settings.APP_PREFIX}/scheduled_appointments_router', tags=['scheduled_appointments_router']) + api_app.include_router(set_content_router, prefix=f'{settings.APP_PREFIX}/set_content', tags=['set_content']) + api_app.include_router(sets_router, prefix=f'{settings.APP_PREFIX}/sets', tags=['sets']) return api_app