ui update and some backend functionality adding in accordance with research on adhd and ux design

This commit is contained in:
2026-02-14 17:21:37 -06:00
parent 4d3a9fbd54
commit fb480eacb2
32 changed files with 9549 additions and 248 deletions

View File

@@ -11,6 +11,7 @@ import jwt
from psycopg2.extras import Json
import core.auth as auth
import core.postgres as postgres
import core.tz as tz
def _get_user_uuid(token):
@@ -72,7 +73,7 @@ def _compute_next_dose_date(med):
interval = med.get("interval_days")
if not interval:
return None
return (date.today() + timedelta(days=interval)).isoformat()
return (tz.user_today() + timedelta(days=interval)).isoformat()
def _count_expected_doses(med, period_start, days):
@@ -162,7 +163,7 @@ def register(app):
# Compute next_dose_date for interval meds
if data.get("frequency") == "every_n_days" and data.get("start_date") and data.get("interval_days"):
start = datetime.strptime(data["start_date"], "%Y-%m-%d").date()
today = date.today()
today = tz.user_today()
if start > today:
row["next_dose_date"] = data["start_date"]
else:
@@ -322,8 +323,8 @@ def register(app):
return flask.jsonify({"error": "unauthorized"}), 401
meds = postgres.select("medications", where={"user_uuid": user_uuid, "active": True})
now = datetime.now()
today = date.today()
now = tz.user_now()
today = now.date()
today_str = today.isoformat()
current_day = now.strftime("%a").lower() # "mon","tue", etc.
current_hour = now.hour
@@ -361,7 +362,7 @@ def register(app):
if current_hour >= 22:
tomorrow = today + timedelta(days=1)
tomorrow_str = tomorrow.isoformat()
tomorrow_day = (now + timedelta(days=1)).strftime("%a").lower()
tomorrow_day = tomorrow.strftime("%a").lower()
for med in meds:
if med["id"] in seen_med_ids:
continue
@@ -398,7 +399,7 @@ def register(app):
if current_hour < 2:
yesterday = today - timedelta(days=1)
yesterday_str = yesterday.isoformat()
yesterday_day = (now - timedelta(days=1)).strftime("%a").lower()
yesterday_day = yesterday.strftime("%a").lower()
for med in meds:
if med["id"] in seen_med_ids:
continue
@@ -443,7 +444,7 @@ def register(app):
return flask.jsonify({"error": "unauthorized"}), 401
num_days = flask.request.args.get("days", 30, type=int)
meds = postgres.select("medications", where={"user_uuid": user_uuid, "active": True})
today = date.today()
today = tz.user_today()
period_start = today - timedelta(days=num_days)
period_start_str = period_start.isoformat()
@@ -485,7 +486,7 @@ def register(app):
if not med:
return flask.jsonify({"error": "not found"}), 404
num_days = flask.request.args.get("days", 30, type=int)
today = date.today()
today = tz.user_today()
period_start = today - timedelta(days=num_days)
period_start_str = period_start.isoformat()
@@ -542,7 +543,7 @@ def register(app):
if not user_uuid:
return flask.jsonify({"error": "unauthorized"}), 401
days_ahead = flask.request.args.get("days_ahead", 7, type=int)
cutoff = (datetime.now() + timedelta(days=days_ahead)).strftime("%Y-%m-%d")
cutoff = (tz.user_today() + timedelta(days=days_ahead)).isoformat()
meds = postgres.select(
"medications",
where={"user_uuid": user_uuid},