Step 9:药品管理(IMP)

This commit is contained in:
Cheng Zhou
2025-12-16 19:26:45 +08:00
parent 566ebdf749
commit 882fcb0963
107 changed files with 855 additions and 1 deletions
+26
View File
@@ -0,0 +1,26 @@
import uuid
from datetime import datetime
from sqlalchemy import Boolean, DateTime, ForeignKey, String, Text, UniqueConstraint, func
from sqlalchemy.dialects.postgresql import UUID
from sqlalchemy.orm import Mapped, mapped_column
from app.db.base_class import Base
class ImpProduct(Base):
__tablename__ = "imp_products"
__table_args__ = (UniqueConstraint("study_id", "name", name="uq_imp_product_name"),)
id: Mapped[uuid.UUID] = mapped_column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
study_id: Mapped[uuid.UUID] = mapped_column(UUID(as_uuid=True), ForeignKey("studies.id"), index=True, nullable=False)
name: Mapped[str] = mapped_column(String(255), nullable=False)
form: Mapped[str | None] = mapped_column(String(100), nullable=True)
strength: Mapped[str | None] = mapped_column(String(100), nullable=True)
unit: Mapped[str] = mapped_column(String(50), nullable=False)
description: Mapped[str | None] = mapped_column(Text, nullable=True)
is_active: Mapped[bool] = mapped_column(Boolean, nullable=False, default=True)
created_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), nullable=False, server_default=func.now())
updated_at: Mapped[datetime] = mapped_column(
DateTime(timezone=True), nullable=False, server_default=func.now(), onupdate=func.now()
)