from __future__ import annotations import json import os from typing import List from logic import Medication STORE_PATH = os.environ.get("PILLPAL_STORE", "meds.json") def load_meds() -> List[Medication]: if not os.path.exists(STORE_PATH): return [] try: with open(STORE_PATH, "r", encoding="utf-8") as f: raw = json.load(f) except (json.JSONDecodeError, OSError): return [] return [Medication(**item) for item in raw] def save_meds(meds: List[Medication]) -> None: with open(STORE_PATH, "w", encoding="utf-8") as f: json.dump([m.to_dict() for m in meds], f, indent=2)