visus-plus/api/app/domain/models/scheduled_appointments.py

23 lines
1.1 KiB
Python

from sqlalchemy import Column, Integer, ForeignKey, DateTime, Boolean
from sqlalchemy.orm import relationship
from sqlalchemy.sql import func
from app.domain.models.base import BaseModel
from app.settings import settings
class ScheduledAppointment(BaseModel):
__tablename__ = 'scheduled_appointments'
__table_args__ = {"schema": settings.SCHEMA}
scheduled_datetime = Column(DateTime, nullable=False, server_default=func.now())
is_canceled = Column(Boolean, nullable=False, default=False, server_default='false')
patient_id = Column(Integer, ForeignKey(f'{settings.SCHEMA}.patients.id', ondelete='CASCADE'), nullable=False)
doctor_id = Column(Integer, ForeignKey(f'{settings.SCHEMA}.users.id', ondelete='SET NULL'), nullable=True)
type_id = Column(Integer, ForeignKey(f'{settings.SCHEMA}.appointment_types.id', ondelete='CASCADE'), nullable=False)
patient = relationship('Patient', back_populates='scheduled_appointments')
doctor = relationship('User', back_populates='scheduled_appointments')
type = relationship('AppointmentType', back_populates='scheduled_appointments')