feat: appointment relation table
fix: relations for clinic doc and clinic
This commit is contained in:
parent
c235196990
commit
dabc7dd308
|
|
@ -5,7 +5,7 @@ from fastapi.security import HTTPBearer
|
|||
# Import the security scheme
|
||||
bearer_scheme = HTTPBearer(scheme_name="Bearer Authentication")
|
||||
|
||||
from .endpoints import clinics, doctors, calender, appointments, patients, admin, auth, s3, users
|
||||
from .endpoints import clinics, doctors, calender, appointments, patients, admin, auth, s3, users, clinicDoctor
|
||||
|
||||
api_router = APIRouter()
|
||||
# api_router.include_router(twilio.router, prefix="/twilio")
|
||||
|
|
@ -14,6 +14,7 @@ api_router.include_router(doctors.router, prefix="/doctors", tags=["doctors"])
|
|||
api_router.include_router(calender.router, prefix="/calender", tags=["calender"])
|
||||
api_router.include_router(appointments.router, prefix="/appointments", tags=["appointments"])
|
||||
api_router.include_router(patients.router, prefix="/patients", tags=["patients"])
|
||||
|
||||
api_router.include_router(
|
||||
admin.router,
|
||||
prefix="/admin",
|
||||
|
|
@ -22,3 +23,4 @@ api_router.include_router(
|
|||
api_router.include_router(auth.router, prefix="/auth", tags=["auth"])
|
||||
api_router.include_router(s3.router, dependencies=[Depends(auth_required)], prefix="/s3", tags=["s3"])
|
||||
api_router.include_router(users.router, prefix="/users", tags=["users"], dependencies=[Depends(auth_required)])
|
||||
api_router.include_router(clinicDoctor.router, prefix="/clinic-doctors", tags=["clinic-doctors"], dependencies=[Depends(auth_required)])
|
||||
|
|
|
|||
|
|
@ -0,0 +1,23 @@
|
|||
from fastapi import APIRouter
|
||||
from schemas.ApiResponse import ApiResponse
|
||||
from schemas.CreateSchemas import ClinicDoctorCreate
|
||||
from schemas.UpdateSchemas import ClinicDoctorUpdate
|
||||
from services.clinicDoctorsServices import ClinicDoctorsServices
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
|
||||
@router.post("/clinic-doctor")
|
||||
def create_clinic_doctor(clinic_doctor: ClinicDoctorCreate):
|
||||
clinic_doctor = ClinicDoctorsServices().create_clinic_doctor(clinic_doctor)
|
||||
return ApiResponse(data=clinic_doctor, message="Clinic doctor created successfully")
|
||||
|
||||
@router.put("/clinic-doctor/{clinic_doctor_id}")
|
||||
def update_clinic_doctor(clinic_doctor_id: int, clinic_doctor: ClinicDoctorUpdate):
|
||||
clinic_doctor = ClinicDoctorsServices().update_clinic_doctor(clinic_doctor)
|
||||
return ApiResponse(data=clinic_doctor, message="Clinic doctor updated successfully")
|
||||
|
||||
@router.delete("/clinic-doctor/{clinic_doctor_id}")
|
||||
def delete_clinic_doctor(clinic_doctor_id: int):
|
||||
ClinicDoctorsServices().delete_clinic_doctor(clinic_doctor_id)
|
||||
return ApiResponse(data="OK", message="Clinic doctor deleted successfully")
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
"""appointment relation table
|
||||
|
||||
Revision ID: a3a9b7d17bdd
|
||||
Revises: 827c736d4aeb
|
||||
Create Date: 2025-05-13 11:09:24.512689
|
||||
|
||||
"""
|
||||
from typing import Sequence, Union
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision: str = 'a3a9b7d17bdd'
|
||||
down_revision: Union[str, None] = '827c736d4aeb'
|
||||
branch_labels: Union[str, Sequence[str], None] = None
|
||||
depends_on: Union[str, Sequence[str], None] = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
"""Upgrade schema."""
|
||||
op.add_column('clinic_doctors', sa.Column('clinic_id', sa.Integer(), nullable=True))
|
||||
op.create_foreign_key(None, 'clinic_doctors', 'clinics', ['clinic_id'], ['id'])
|
||||
# ### end Alembic commands ###
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
"""Downgrade schema."""
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.drop_constraint(None, 'clinic_doctors', type_='foreignkey')
|
||||
op.drop_column('clinic_doctors', 'clinic_id')
|
||||
# ### end Alembic commands ###
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
from sqlalchemy import Column, ForeignKey, Integer
|
||||
from database import Base
|
||||
from .CustomBase import CustomBase
|
||||
from sqlalchemy.orm import relationship
|
||||
|
||||
class AppointmentRelations(Base, CustomBase):
|
||||
__tablename__ = "appointment_relations"
|
||||
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
appointment_type_id = Column(Integer, ForeignKey("master_appointment_types.id"))
|
||||
clinic_doctor_id = Column(Integer, ForeignKey("clinic_doctors.id"))
|
||||
|
||||
clinicDoctors = relationship("ClinicDoctors", back_populates="appointmentRelations")
|
||||
masterAppointmentTypes = relationship("MasterAppointmentTypes", back_populates="appointmentRelations")
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
from sqlalchemy import Column, Enum, Integer, String, ForeignKey,Table
|
||||
from database import Base
|
||||
from enums.enums import ClinicUserRoles, ClinicDoctorStatus
|
||||
from .CustomBase import CustomBase
|
||||
from sqlalchemy.orm import relationship
|
||||
|
||||
class ClinicDoctors(Base, CustomBase):
|
||||
__tablename__ = "clinic_doctors"
|
||||
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
name = Column(String)
|
||||
role = Column(Enum(ClinicUserRoles))
|
||||
status = Column(Enum(ClinicDoctorStatus))
|
||||
|
||||
appointmentRelations = relationship("AppointmentRelations", back_populates="clinicDoctors")
|
||||
clinic_id = Column(Integer, ForeignKey("clinics.id"))
|
||||
clinic = relationship("Clinics", back_populates="clinicDoctors")
|
||||
|
|
@ -42,3 +42,4 @@ class Clinics(Base, CustomBase):
|
|||
|
||||
|
||||
doctors = relationship("Doctors", back_populates="clinic")
|
||||
clinicDoctors = relationship("ClinicDoctors", back_populates="clinic")
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
from sqlalchemy import Column, Integer, String
|
||||
from database import Base
|
||||
from .CustomBase import CustomBase
|
||||
from sqlalchemy.orm import relationship
|
||||
|
||||
class MasterAppointmentTypes(Base, CustomBase):
|
||||
__tablename__ = "master_appointment_types"
|
||||
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
type = Column(String)
|
||||
|
||||
appointmentRelations = relationship("AppointmentRelations", back_populates="masterAppointmentTypes")
|
||||
clinicDoctors = relationship("ClinicDoctors", back_populates="masterAppointmentTypes")
|
||||
|
|
@ -4,6 +4,9 @@ from .Doctors import Doctors
|
|||
from .Patients import Patients
|
||||
from .Appointments import Appointments
|
||||
from .Calendar import Calenders
|
||||
from .AppointmentRelations import AppointmentRelations
|
||||
from .MasterAppointmentTypes import MasterAppointmentTypes
|
||||
from .ClinicDoctors import ClinicDoctors
|
||||
|
||||
__all__ = [
|
||||
"Users",
|
||||
|
|
@ -12,4 +15,7 @@ __all__ = [
|
|||
"Patients",
|
||||
"Appointments",
|
||||
"Calenders",
|
||||
"AppointmentRelations",
|
||||
"MasterAppointmentTypes",
|
||||
"ClinicDoctors",
|
||||
]
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
from datetime import datetime
|
||||
from typing import List, Optional
|
||||
from pydantic import BaseModel, EmailStr
|
||||
from enums.enums import AppointmentStatus, ClinicUserRoles, UserType, Integration
|
||||
from enums.enums import AppointmentStatus, ClinicDoctorStatus, ClinicDoctorType, ClinicUserRoles, UserType, Integration
|
||||
|
||||
|
||||
# Base schemas (shared attributes for create/read operations)
|
||||
|
|
@ -69,4 +69,10 @@ class UserBase(BaseModel):
|
|||
email: EmailStr
|
||||
password: str
|
||||
clinicRole: Optional[ClinicUserRoles] = None
|
||||
userType: Optional[UserType] = None
|
||||
userType: Optional[UserType] = None
|
||||
|
||||
|
||||
class ClinicDoctorBase(BaseModel):
|
||||
name: str
|
||||
role: ClinicDoctorType
|
||||
status: ClinicDoctorStatus
|
||||
|
|
@ -37,3 +37,7 @@ class UserCreate(BaseModel):
|
|||
user: UserBase
|
||||
# Clinic data sent from frontend
|
||||
clinic: ClinicBase
|
||||
|
||||
|
||||
class ClinicDoctorCreate(ClinicDoctorBase):
|
||||
pass
|
||||
|
|
|
|||
|
|
@ -12,6 +12,16 @@ class Clinic(ClinicBase):
|
|||
class Config:
|
||||
orm_mode = True
|
||||
|
||||
|
||||
class ClinicDoctorResponse(ClinicDoctorBase):
|
||||
id: int
|
||||
create_time: datetime
|
||||
update_time: datetime
|
||||
|
||||
class Config:
|
||||
orm_mode = True
|
||||
|
||||
|
||||
class UserResponse(UserBase):
|
||||
id: int
|
||||
create_time: datetime
|
||||
|
|
@ -124,3 +134,12 @@ class AppointmentDetailed(AppointmentSchema):
|
|||
|
||||
doctor: Doctor
|
||||
patient: Patient
|
||||
|
||||
|
||||
class ClinicDoctor(ClinicDoctorBase):
|
||||
id: int
|
||||
create_time: datetime
|
||||
update_time: datetime
|
||||
|
||||
class Config:
|
||||
orm_mode = True
|
||||
|
|
@ -44,3 +44,7 @@ class UserUpdate(BaseModel):
|
|||
userType: Optional[UserType] = None
|
||||
profile_pic: Optional[str] = None
|
||||
password: Optional[str] = None
|
||||
|
||||
|
||||
class ClinicDoctorUpdate(ClinicDoctorBase):
|
||||
pass
|
||||
|
|
|
|||
|
|
@ -0,0 +1,21 @@
|
|||
from schemas.CreateSchemas import ClinicDoctorCreate
|
||||
from schemas.UpdateSchemas import ClinicDoctorUpdate
|
||||
from database import get_db
|
||||
from models import ClinicDoctors
|
||||
|
||||
class ClinicDoctorsServices:
|
||||
def __init__(self):
|
||||
self.db = next(get_db())
|
||||
|
||||
def create_clinic_doctor(self, clinic_doctor: ClinicDoctorCreate):
|
||||
clinic_doctor = ClinicDoctors(**clinic_doctor.dict())
|
||||
self.db.add(clinic_doctor)
|
||||
self.db.commit()
|
||||
self.db.refresh(clinic_doctor)
|
||||
return clinic_doctor
|
||||
|
||||
def update_clinic_doctor(self, clinic_doctor_id: int, clinic_doctor: ClinicDoctorUpdate):
|
||||
pass
|
||||
|
||||
def delete_clinic_doctor(self, clinic_doctor_id: int):
|
||||
pass
|
||||
Loading…
Reference in New Issue