首次提交by MimoCode
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
from app.models.user import User
|
||||
from app.models.medicine import Medicine
|
||||
from app.models.batch import Batch
|
||||
from app.models.category import Category
|
||||
from app.models.audit_log import AuditLog
|
||||
from app.models.notification import Notification
|
||||
from app.models.setting import Setting
|
||||
|
||||
__all__ = [
|
||||
"User",
|
||||
"Medicine",
|
||||
"Batch",
|
||||
"Category",
|
||||
"AuditLog",
|
||||
"Notification",
|
||||
"Setting"
|
||||
]
|
||||
@@ -0,0 +1,23 @@
|
||||
from sqlalchemy import Column, Integer, String, Text, ForeignKey, DateTime
|
||||
from sqlalchemy.orm import relationship
|
||||
from datetime import datetime
|
||||
|
||||
from app.database import Base
|
||||
|
||||
|
||||
class AuditLog(Base):
|
||||
__tablename__ = "audit_logs"
|
||||
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
medicine_id = Column(Integer, ForeignKey("medicines.id"), nullable=False, index=True)
|
||||
batch_id = Column(Integer, ForeignKey("batches.id"))
|
||||
user_id = Column(Integer, ForeignKey("users.id"))
|
||||
action = Column(String(50), nullable=False)
|
||||
quantity_change = Column(Integer, nullable=False)
|
||||
quantity_after = Column(Integer, nullable=False)
|
||||
remark = Column(Text)
|
||||
created_at = Column(DateTime, default=datetime.utcnow)
|
||||
|
||||
medicine = relationship("Medicine", back_populates="audit_logs")
|
||||
batch = relationship("Batch", back_populates="audit_logs")
|
||||
user = relationship("User", back_populates="audit_logs")
|
||||
@@ -0,0 +1,23 @@
|
||||
from sqlalchemy import Column, Integer, String, Date, Boolean, ForeignKey, DateTime
|
||||
from sqlalchemy.orm import relationship
|
||||
from datetime import datetime
|
||||
|
||||
from app.database import Base
|
||||
|
||||
|
||||
class Batch(Base):
|
||||
__tablename__ = "batches"
|
||||
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
medicine_id = Column(Integer, ForeignKey("medicines.id"), nullable=False, index=True)
|
||||
batch_no = Column(String(100))
|
||||
production_date = Column(Date)
|
||||
expiry_date = Column(Date, nullable=False)
|
||||
quantity = Column(Integer, nullable=False, default=0)
|
||||
location = Column(String(200))
|
||||
is_expired = Column(Boolean, default=False)
|
||||
created_at = Column(DateTime, default=datetime.utcnow)
|
||||
updated_at = Column(DateTime, default=datetime.utcnow, onupdate=datetime.utcnow)
|
||||
|
||||
medicine = relationship("Medicine", back_populates="batches")
|
||||
audit_logs = relationship("AuditLog", back_populates="batch")
|
||||
@@ -0,0 +1,22 @@
|
||||
from sqlalchemy import Column, Integer, String, ForeignKey, DateTime
|
||||
from sqlalchemy.orm import relationship
|
||||
from datetime import datetime
|
||||
|
||||
from app.database import Base
|
||||
|
||||
|
||||
class Category(Base):
|
||||
__tablename__ = "categories"
|
||||
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
name = Column(String(100), nullable=False)
|
||||
parent_id = Column(Integer, ForeignKey("categories.id"))
|
||||
level = Column(Integer, nullable=False, default=1)
|
||||
icon = Column(String(50))
|
||||
sort_order = Column(Integer, default=0)
|
||||
created_at = Column(DateTime, default=datetime.utcnow)
|
||||
updated_at = Column(DateTime, default=datetime.utcnow, onupdate=datetime.utcnow)
|
||||
|
||||
parent = relationship("Category", remote_side=[id])
|
||||
children = relationship("Category", back_populates="parent")
|
||||
medicines = relationship("Medicine", back_populates="category")
|
||||
@@ -0,0 +1,35 @@
|
||||
from sqlalchemy import Column, Integer, String, Text, ForeignKey, DateTime, JSON
|
||||
from sqlalchemy.orm import relationship
|
||||
from datetime import datetime
|
||||
|
||||
from app.database import Base
|
||||
|
||||
|
||||
class Medicine(Base):
|
||||
__tablename__ = "medicines"
|
||||
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
name = Column(String(200), nullable=False, index=True)
|
||||
generic_name = Column(String(200), index=True)
|
||||
brand_name = Column(String(200))
|
||||
manufacturer = Column(String(200))
|
||||
specification = Column(String(200))
|
||||
category_id = Column(Integer, ForeignKey("categories.id"))
|
||||
description = Column(Text)
|
||||
indications = Column(Text)
|
||||
adult_dose = Column(Text)
|
||||
child_dose = Column(Text)
|
||||
contraindications = Column(Text)
|
||||
notes = Column(Text)
|
||||
image_front_path = Column(String(500))
|
||||
image_expiry_path = Column(String(500))
|
||||
image_leaflet_paths = Column(JSON)
|
||||
expiry_grace_days = Column(Integer, default=0)
|
||||
created_by = Column(Integer, ForeignKey("users.id"))
|
||||
created_at = Column(DateTime, default=datetime.utcnow)
|
||||
updated_at = Column(DateTime, default=datetime.utcnow, onupdate=datetime.utcnow)
|
||||
|
||||
category = relationship("Category", back_populates="medicines")
|
||||
creator = relationship("User", back_populates="medicines")
|
||||
batches = relationship("Batch", back_populates="medicine", cascade="all, delete-orphan")
|
||||
audit_logs = relationship("AuditLog", back_populates="medicine")
|
||||
@@ -0,0 +1,20 @@
|
||||
from sqlalchemy import Column, Integer, String, Boolean, Text, ForeignKey, DateTime
|
||||
from sqlalchemy.orm import relationship
|
||||
from datetime import datetime
|
||||
|
||||
from app.database import Base
|
||||
|
||||
|
||||
class Notification(Base):
|
||||
__tablename__ = "notifications"
|
||||
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
type = Column(String(50), nullable=False)
|
||||
title = Column(String(200), nullable=False)
|
||||
content = Column(Text, nullable=False)
|
||||
is_read = Column(Boolean, default=False)
|
||||
user_id = Column(Integer, ForeignKey("users.id"))
|
||||
related_id = Column(Integer)
|
||||
created_at = Column(DateTime, default=datetime.utcnow)
|
||||
|
||||
user = relationship("User", back_populates="notifications")
|
||||
@@ -0,0 +1,14 @@
|
||||
from sqlalchemy import Column, Integer, String, Text, DateTime
|
||||
from datetime import datetime
|
||||
|
||||
from app.database import Base
|
||||
|
||||
|
||||
class Setting(Base):
|
||||
__tablename__ = "settings"
|
||||
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
key = Column(String(100), unique=True, index=True, nullable=False)
|
||||
value = Column(Text)
|
||||
description = Column(String(500))
|
||||
updated_at = Column(DateTime, default=datetime.utcnow, onupdate=datetime.utcnow)
|
||||
@@ -0,0 +1,24 @@
|
||||
from sqlalchemy import Column, Integer, String, Boolean, DateTime
|
||||
from sqlalchemy.orm import relationship
|
||||
from datetime import datetime
|
||||
|
||||
from app.database import Base
|
||||
|
||||
|
||||
class User(Base):
|
||||
__tablename__ = "users"
|
||||
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
username = Column(String(50), unique=True, index=True, nullable=False)
|
||||
password_hash = Column(String(255), nullable=False)
|
||||
role = Column(String(20), nullable=False, default="user")
|
||||
display_name = Column(String(100))
|
||||
email = Column(String(100))
|
||||
notification_level = Column(String(20), default="normal")
|
||||
is_active = Column(Boolean, default=True)
|
||||
created_at = Column(DateTime, default=datetime.utcnow)
|
||||
updated_at = Column(DateTime, default=datetime.utcnow, onupdate=datetime.utcnow)
|
||||
|
||||
medicines = relationship("Medicine", back_populates="creator")
|
||||
audit_logs = relationship("AuditLog", back_populates="user")
|
||||
notifications = relationship("Notification", back_populates="user")
|
||||
Reference in New Issue
Block a user