23 lines
936 B
Python
23 lines
936 B
Python
from __future__ import annotations
|
|
|
|
from sqlalchemy import Boolean, ForeignKey, Integer, String
|
|
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
|
|
|
from app.db.base import Base
|
|
from app.models.mixins import TimestampMixin
|
|
|
|
|
|
class Department(TimestampMixin, Base):
|
|
"""科室模型:维护病例、知识库和评分规则的科室分类。"""
|
|
|
|
__tablename__ = "departments"
|
|
|
|
id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
|
|
name: Mapped[str] = mapped_column(String(100), nullable=False)
|
|
code: Mapped[str] = mapped_column(String(50), nullable=False, unique=True, index=True)
|
|
parent_id: Mapped[int | None] = mapped_column(ForeignKey("departments.id"), nullable=True)
|
|
sort_order: Mapped[int] = mapped_column(Integer, default=0)
|
|
is_active: Mapped[bool] = mapped_column(Boolean, default=True)
|
|
|
|
parent: Mapped["Department | None"] = relationship(remote_side=[id])
|