Fix medication system and rename to Synculous.
- Add all 14 missing database tables (medications, med_logs, routines, etc.) - Rewrite medication scheduling: support specific days, every N days, as-needed (PRN) - Fix taken_times matching: match by created_at date, not scheduled_time string - Fix adherence calculation: taken / expected doses, not taken / (taken + skipped) - Add formatSchedule() helper for readable display - Update client types and API layer - Rename brilli-ins-client → synculous-client - Make client PWA: add manifest, service worker, icons - Bind dev server to 0.0.0.0 for network access - Fix SVG icon bugs in Icons.tsx - Add .dockerignore for client npm caching Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -21,23 +21,48 @@ POLL_INTERVAL = int(os.environ.get("POLL_INTERVAL", 60))
|
||||
def check_medication_reminders():
|
||||
"""Check for medications due now and send notifications."""
|
||||
try:
|
||||
from datetime import date as date_type
|
||||
meds = postgres.select("medications", where={"active": True})
|
||||
now = datetime.now()
|
||||
current_time = now.strftime("%H:%M")
|
||||
today = now.strftime("%Y-%m-%d")
|
||||
current_day = now.strftime("%a").lower() # "mon","tue", etc.
|
||||
today = now.date()
|
||||
today_str = today.isoformat()
|
||||
|
||||
for med in meds:
|
||||
freq = med.get("frequency", "daily")
|
||||
|
||||
# Skip as_needed -- no scheduled reminders for PRN
|
||||
if freq == "as_needed":
|
||||
continue
|
||||
|
||||
# Day-of-week check for specific_days
|
||||
if freq == "specific_days":
|
||||
days = med.get("days_of_week", [])
|
||||
if current_day not in days:
|
||||
continue
|
||||
|
||||
# Interval check for every_n_days
|
||||
if freq == "every_n_days":
|
||||
start = med.get("start_date")
|
||||
interval = med.get("interval_days")
|
||||
if start and interval:
|
||||
start_d = start if isinstance(start, date_type) else datetime.strptime(str(start), "%Y-%m-%d").date()
|
||||
if (today - start_d).days < 0 or (today - start_d).days % interval != 0:
|
||||
continue
|
||||
else:
|
||||
continue
|
||||
|
||||
# Time check
|
||||
times = med.get("times", [])
|
||||
if current_time not in times:
|
||||
continue
|
||||
|
||||
logs = postgres.select(
|
||||
"med_logs",
|
||||
where={"medication_id": med["id"]},
|
||||
)
|
||||
# Already taken today? Check by created_at date
|
||||
logs = postgres.select("med_logs", where={"medication_id": med["id"], "action": "taken"})
|
||||
already_taken = any(
|
||||
log.get("action") == "taken"
|
||||
and log.get("scheduled_time", "").startswith(today)
|
||||
log.get("scheduled_time") == current_time
|
||||
and str(log.get("created_at", ""))[:10] == today_str
|
||||
for log in logs
|
||||
)
|
||||
if already_taken:
|
||||
|
||||
Reference in New Issue
Block a user