Spaces:
Sleeping
Sleeping
File size: 2,902 Bytes
e2daa68 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 | from sqlalchemy import Column, Integer, String, Float, DateTime, ForeignKey, Enum as SQLEnum
from sqlalchemy.orm import relationship
from datetime import datetime
from app.database import Base
import enum
class ItemType(str, enum.Enum):
GROCERY = "grocery"
MEDICATION = "medication"
SUPPLEMENT = "supplement"
class InventoryStatus(str, enum.Enum):
NORMAL = "normal"
LOW = "low"
OUT = "out"
class UserMedicationProfile(Base):
__tablename__ = "user_medication_profiles"
id = Column(Integer, primary_key=True, index=True)
user_id = Column(String, index=True, default="default_user")
allergies = Column(String, nullable=True)
dose_events = relationship("DoseEvent", back_populates="profile")
medication_items = relationship("MedicationItem", back_populates="profile")
class DoseEvent(Base):
__tablename__ = "dose_events"
id = Column(Integer, primary_key=True, index=True)
user_id = Column(String, index=True, default="default_user")
profile_id = Column(Integer, ForeignKey("user_medication_profiles.id"))
item_name = Column(String, index=True)
amount_mg = Column(Float)
timestamp = Column(DateTime, default=datetime.utcnow)
source = Column(String, default="manual")
profile = relationship("UserMedicationProfile", back_populates="dose_events")
class MedicationItem(Base):
__tablename__ = "medication_items"
id = Column(Integer, primary_key=True, index=True)
user_id = Column(String, index=True, default="default_user")
profile_id = Column(Integer, ForeignKey("user_medication_profiles.id"))
display_name = Column(String, index=True)
strength = Column(String, nullable=True)
form = Column(String, nullable=True)
indication_plain = Column(String, nullable=True)
instructions_plain = Column(String, nullable=True)
warnings_plain = Column(String, nullable=True)
barcode = Column(String, nullable=True)
last_reviewed = Column(DateTime, default=datetime.utcnow)
max_daily_dose_mg = Column(Float, nullable=True)
profile = relationship("UserMedicationProfile", back_populates="medication_items")
inventory_links = relationship("InventoryItem", back_populates="linked_item")
class InventoryItem(Base):
__tablename__ = "inventory_items"
id = Column(Integer, primary_key=True, index=True)
user_id = Column(String, index=True, default="default_user")
name = Column(String, index=True)
type = Column(SQLEnum(ItemType), default=ItemType.GROCERY)
linked_item_id = Column(Integer, ForeignKey("medication_items.id"), nullable=True)
quantity_estimate = Column(Integer, default=1)
last_purchased_at = Column(DateTime, default=datetime.utcnow)
status = Column(SQLEnum(InventoryStatus), default=InventoryStatus.NORMAL)
linked_item = relationship("MedicationItem", back_populates="inventory_links") |