feat: new endpoints for agent
feat: new auth middleware for agent
This commit is contained in:
@@ -0,0 +1,15 @@
|
||||
from services.clinicServices import ClinicServices
|
||||
from services.clinicDoctorsServices import ClinicDoctorsServices
|
||||
|
||||
|
||||
class AgentServices:
|
||||
def __init__(self):
|
||||
self.clinicServices = ClinicServices()
|
||||
self.clinicDoctorService = ClinicDoctorsServices()
|
||||
|
||||
async def get_clinic_by_phone(self, phone: str):
|
||||
return await self.clinicServices.get_clinic_by_phone(phone)
|
||||
|
||||
|
||||
async def get_clinic_doctors_with_appointments(self, clinic_id: int):
|
||||
return await self.clinicDoctorService.get_clinic_doctors(clinic_id)
|
||||
@@ -53,7 +53,9 @@ class ClinicDoctorsServices:
|
||||
)
|
||||
|
||||
# check if clinic exists
|
||||
await self.clinic_services.get_clinic_by_id(user["created_clinics"][0]["id"])
|
||||
await self.clinic_services.get_clinic_by_id(
|
||||
user["created_clinics"][0]["id"]
|
||||
)
|
||||
|
||||
# exclude appointmentTypes from clinic_doctor
|
||||
clinic_doctor_db = ClinicDoctors(
|
||||
@@ -129,7 +131,6 @@ class ClinicDoctorsServices:
|
||||
if clinic_doctor is None:
|
||||
raise ResourceNotFoundException("Clinic doctor not found")
|
||||
|
||||
|
||||
# Update the existing object with new values
|
||||
update_data = clinic_doctor_data.model_dump(exclude_unset=True)
|
||||
|
||||
@@ -173,7 +174,7 @@ class ClinicDoctorsServices:
|
||||
finally:
|
||||
self.db.close()
|
||||
|
||||
async def get_doctor_status_count(self, clinic_id:int):
|
||||
async def get_doctor_status_count(self, clinic_id: int):
|
||||
try:
|
||||
# Query to count doctors by status
|
||||
status_counts = (
|
||||
@@ -198,14 +199,42 @@ class ClinicDoctorsServices:
|
||||
finally:
|
||||
self.db.close()
|
||||
|
||||
async def get_clinic_doctors(self,user, limit: int, offset: int, search: str = "", sort_by: str = DEFAULT_ORDER, sort_order: str = DEFAULT_ORDER_BY):
|
||||
async def get_clinic_doctors(
|
||||
self,
|
||||
clinic_id: int,
|
||||
limit: int | None = None,
|
||||
offset: int | None = None,
|
||||
search: str = "",
|
||||
sort_by: str = DEFAULT_ORDER,
|
||||
sort_order: str = DEFAULT_ORDER_BY,
|
||||
):
|
||||
try:
|
||||
response = await self._get_clinic_doctors(
|
||||
clinic_id, limit, offset, search, sort_by, sort_order
|
||||
)
|
||||
|
||||
return response
|
||||
except Exception as e:
|
||||
self.logger.error(e)
|
||||
raise e
|
||||
|
||||
async def _get_clinic_doctors(
|
||||
self,
|
||||
clinic_id: int,
|
||||
limit: int | None = None,
|
||||
offset: int | None = None,
|
||||
search: str = "",
|
||||
sort_by: str = DEFAULT_ORDER,
|
||||
sort_order: str = DEFAULT_ORDER_BY,
|
||||
):
|
||||
try:
|
||||
clinic_doctors_query = (
|
||||
self.db.query(ClinicDoctors)
|
||||
.filter(ClinicDoctors.clinic_id == user["created_clinics"][0]["id"])
|
||||
.filter(ClinicDoctors.clinic_id == clinic_id)
|
||||
.options(
|
||||
selectinload(ClinicDoctors.appointmentRelations)
|
||||
.selectinload(AppointmentRelations.masterAppointmentTypes)
|
||||
selectinload(ClinicDoctors.appointmentRelations).selectinload(
|
||||
AppointmentRelations.masterAppointmentTypes
|
||||
)
|
||||
)
|
||||
.order_by(
|
||||
getattr(ClinicDoctors, sort_by).desc()
|
||||
@@ -224,13 +253,16 @@ class ClinicDoctorsServices:
|
||||
ClinicDoctors.appointmentRelations.any(
|
||||
AppointmentRelations.masterAppointmentTypes.has(
|
||||
MasterAppointmentTypes.type.ilike(f"%{search}%")
|
||||
)
|
||||
)
|
||||
)
|
||||
),
|
||||
)
|
||||
)
|
||||
total = clinic_doctors_query.count()
|
||||
|
||||
clinic_doctors = clinic_doctors_query.limit(limit).offset(offset).all()
|
||||
if limit and offset:
|
||||
clinic_doctors_query = clinic_doctors_query.limit(limit).offset(offset)
|
||||
|
||||
clinic_doctors = clinic_doctors_query.all()
|
||||
|
||||
# Build response data manually to include appointment types
|
||||
response_data = []
|
||||
@@ -244,7 +276,7 @@ class ClinicDoctorsServices:
|
||||
id=relation.masterAppointmentTypes.id,
|
||||
type=relation.masterAppointmentTypes.type,
|
||||
create_time=relation.masterAppointmentTypes.create_time,
|
||||
update_time=relation.masterAppointmentTypes.update_time
|
||||
update_time=relation.masterAppointmentTypes.update_time,
|
||||
)
|
||||
)
|
||||
|
||||
@@ -256,7 +288,7 @@ class ClinicDoctorsServices:
|
||||
status=clinic_doctor.status,
|
||||
create_time=clinic_doctor.create_time,
|
||||
update_time=clinic_doctor.update_time,
|
||||
appointmentTypes=appointment_types
|
||||
appointmentTypes=appointment_types,
|
||||
)
|
||||
response_data.append(clinic_doctor_data)
|
||||
|
||||
|
||||
@@ -128,6 +128,23 @@ class ClinicServices:
|
||||
finally:
|
||||
self.db.close()
|
||||
|
||||
|
||||
async def get_clinic_by_phone(self, phone: str):
|
||||
try:
|
||||
clinic = self.db.query(Clinics).filter(Clinics.phone == phone).first()
|
||||
|
||||
if clinic is None:
|
||||
raise ResourceNotFoundException("Clinic not found")
|
||||
|
||||
clinic_response = Clinic.model_validate(clinic)
|
||||
|
||||
return clinic_response.model_dump(
|
||||
exclude={"creator", "abn_doc", "contract_doc", "logo"}
|
||||
)
|
||||
except Exception as e:
|
||||
DBExceptionHandler.handle_exception(e, context="getting clinic by phone")
|
||||
finally:
|
||||
self.db.close()
|
||||
|
||||
|
||||
async def get_clinic_files(self, clinic_id: int):
|
||||
|
||||
Reference in New Issue
Block a user