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:
2026-02-13 03:23:38 -06:00
parent 3e1134575b
commit 97a166f5aa
47 changed files with 5231 additions and 61 deletions

View File

@@ -20,11 +20,125 @@ CREATE TABLE IF NOT EXISTS notifications (
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
-- Add your domain tables below
-- Example:
-- CREATE TABLE IF NOT EXISTS examples (
-- id UUID PRIMARY KEY,
-- user_uuid UUID REFERENCES users(id) ON DELETE CASCADE,
-- name VARCHAR(255) NOT NULL,
-- created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
-- );
-- ── Routines ────────────────────────────────────────────────
CREATE TABLE IF NOT EXISTS routines (
id UUID PRIMARY KEY,
user_uuid UUID REFERENCES users(id) ON DELETE CASCADE,
name VARCHAR(255) NOT NULL,
description TEXT,
icon VARCHAR(100),
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
CREATE TABLE IF NOT EXISTS routine_steps (
id UUID PRIMARY KEY,
routine_id UUID REFERENCES routines(id) ON DELETE CASCADE,
name VARCHAR(255) NOT NULL,
duration_minutes INTEGER,
position INTEGER NOT NULL,
instructions TEXT,
step_type VARCHAR(50) DEFAULT 'generic',
media_url TEXT
);
CREATE TABLE IF NOT EXISTS routine_sessions (
id UUID PRIMARY KEY,
routine_id UUID REFERENCES routines(id) ON DELETE CASCADE,
user_uuid UUID REFERENCES users(id) ON DELETE CASCADE,
status VARCHAR(20) DEFAULT 'active',
current_step_index INTEGER DEFAULT 0,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
paused_at TIMESTAMP,
completed_at TIMESTAMP,
abort_reason TEXT,
actual_duration_minutes INTEGER
);
CREATE TABLE IF NOT EXISTS routine_schedules (
id UUID PRIMARY KEY,
routine_id UUID REFERENCES routines(id) ON DELETE CASCADE,
days JSON DEFAULT '[]',
time VARCHAR(5),
remind BOOLEAN DEFAULT FALSE
);
CREATE TABLE IF NOT EXISTS routine_session_notes (
id UUID PRIMARY KEY,
session_id UUID REFERENCES routine_sessions(id) ON DELETE CASCADE,
step_index INTEGER,
note TEXT,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
CREATE TABLE IF NOT EXISTS routine_templates (
id UUID PRIMARY KEY,
name VARCHAR(255) NOT NULL,
description TEXT,
icon VARCHAR(100),
created_by_admin BOOLEAN DEFAULT FALSE
);
CREATE TABLE IF NOT EXISTS routine_template_steps (
id UUID PRIMARY KEY,
template_id UUID REFERENCES routine_templates(id) ON DELETE CASCADE,
name VARCHAR(255) NOT NULL,
instructions TEXT,
step_type VARCHAR(50) DEFAULT 'generic',
duration_minutes INTEGER,
media_url TEXT,
position INTEGER NOT NULL
);
CREATE TABLE IF NOT EXISTS routine_tags (
id UUID PRIMARY KEY,
name VARCHAR(255) NOT NULL,
color VARCHAR(20) DEFAULT '#888888'
);
CREATE TABLE IF NOT EXISTS routine_routine_tags (
routine_id UUID REFERENCES routines(id) ON DELETE CASCADE,
tag_id UUID REFERENCES routine_tags(id) ON DELETE CASCADE,
PRIMARY KEY (routine_id, tag_id)
);
CREATE TABLE IF NOT EXISTS routine_streaks (
id UUID PRIMARY KEY,
user_uuid UUID REFERENCES users(id) ON DELETE CASCADE,
routine_id UUID REFERENCES routines(id) ON DELETE CASCADE,
current_streak INTEGER DEFAULT 0,
longest_streak INTEGER DEFAULT 0,
last_completed_date DATE
);
-- ── Medications ─────────────────────────────────────────────
CREATE TABLE IF NOT EXISTS medications (
id UUID PRIMARY KEY,
user_uuid UUID REFERENCES users(id) ON DELETE CASCADE,
name VARCHAR(255) NOT NULL,
dosage VARCHAR(100) NOT NULL,
unit VARCHAR(50) NOT NULL,
frequency VARCHAR(50) NOT NULL,
times JSON DEFAULT '[]',
days_of_week JSON DEFAULT '[]',
interval_days INTEGER,
start_date DATE,
next_dose_date DATE,
notes TEXT,
active BOOLEAN DEFAULT TRUE,
quantity_remaining INTEGER,
refill_date DATE,
pharmacy_notes TEXT,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
CREATE TABLE IF NOT EXISTS med_logs (
id UUID PRIMARY KEY,
medication_id UUID REFERENCES medications(id) ON DELETE CASCADE,
user_uuid UUID REFERENCES users(id) ON DELETE CASCADE,
action VARCHAR(20) NOT NULL,
scheduled_time VARCHAR(5),
notes TEXT,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);