Now we move from “what to build” to in what exact order to build.
If Supabase is the spine (and it must be), then the rule is:
🔒 Backend integrity first
🎯 Then lifecycle logic
🖥 Then minimal UI
📄 Then documents
📡 Then teleconsult + communication
📊 Then analytics
No feature-first chaos. No UI-first temptation.
Below is the correct chronological build order for Eweb.
🏗 STAGE 1 — SUPABASE FOUNDATION (Week 1–2)
Nothing visible. Only structural spine.
1️⃣ Create Supabase project
-
Enable row-level security (RLS)
-
Define roles (doctor, reception, pharmacy, admin, patient)
-
Configure auth model (even if Wix handles login)
2️⃣ Core Tables (Do NOT skip order)
A. Patients (Master Profile)
-
patients table
-
UHID generator (EFC####)
-
Demographics fields
-
Master medical fields
-
diagnosis_master_text
-
Audit fields
-
Indexes (uhid, mobile, first_name, last_name)
B. Diagnosis Registry
-
diagnosis_master
-
patient_master_diagnoses
-
Unique constraint (patient_id + diagnosis_code)
-
Index on diagnosis_code
C. Appointments (Scheduling only)
-
appointments table
-
Slot model
-
Appointment status enum
-
Index on date/time
D. Encounters (Medical Core Object)
-
encounters table
-
EID generator
-
encounter_type enum
-
status enum
-
Index patient_id + start_time
E. Visits
-
visits table
-
VID generator
-
Link visits → encounters
-
visit_channel enum
F. Clinical Notes (Versioned)
-
clinical_notes
-
version logic
-
status (DRAFT/SIGNED)
-
signed_at
-
Lock constraint after SIGNED
G. Prescriptions
-
prescriptions
-
prescription_items
-
Versioning + locking rules
H. Billing Engine
-
invoices
-
invoice_no generator
-
invoice status enum
-
invoice_items
-
Snapshot price fields
-
DB constraint: cannot edit if PAID
I. Lab System
-
lab_tests_master
-
lab_orders
-
Link lab_orders → encounters
-
Snapshot price rule
J. Documents
-
documents table
-
doc_type enum
-
versioning model
-
Storage bucket structure
K. Teleconsult Infrastructure Tables
-
tele_sessions
-
store Twilio session metadata
-
recording_url field
-
consent flag
-
Link tele_session → visit
👉 At this point:
Supabase spine is complete.
No UI yet.
Everything enforced at DB layer.
🧠 STAGE 2 — BUSINESS RULE LOGIC (Week 3)
Now implement server-side functions.
-
“Same encounter?” logic function
-
“New encounter?” rule enforcement
-
Invoice lifecycle guard function
-
Payment lock function
-
Snapshot pricing function
-
Version increment function
-
Master history auto-update function
-
Diagnosis sync function
-
Credit note logic function
-
Tele-session logging function
Now backend is intelligent.
🖥 STAGE 3 — MINIMAL WIX UI (Week 4–5)
Now we touch frontend.
3A. Reception Console
-
Patient search (UHID/mobile/name)
-
Booking form
-
Today list
-
Walk-in toggle
-
Collect payment button
3B. OPD Assistant
-
Vitals page
-
Ready-for-doctor signal
3C. Doctor Dashboard
-
Encounter open/create
-
Visit create
-
Clinical note editor
-
Diagnosis selector
-
Rx entry
-
Sign button
3D. Pharmacy
-
Queue page
-
Dispense qty adjust
-
Finalize invoice
At this stage:
Eweb works internally for OPD.
📄 STAGE 4 — DOCUMENT ENGINE (Week 6–7)
-
Prescription PDF template
-
Invoice PDF template
-
Certificate template base
-
Google Docs OR server-renderer integration
-
PDF storage logic
-
Version stamping
-
Immutability enforcement
-
Full vs redacted Rx generation
Now medicolegal safety begins.
🧪 STAGE 5 — LAB INTEGRATION (Week 8)
-
Metropolis catalog import
-
Lab order UI
-
Report vault upload
-
Report linking
-
Report timeline view
Now unnecessary repeat tests reduce.
📡 STAGE 6 — TELECONSULT MODULE (Week 9–10)
-
Teleconsult booking type
-
Twilio token generation endpoint
-
Video room creation
-
Chat channel
-
Recording enable
-
Recording metadata storage
-
Tele encounter auto-create
-
Tele Rx generation
-
Tele invoice generation
-
Consent flow enforcement
Now virtual care is production-ready.
📬 STAGE 7 — NOTIFICATIONS (Week 11)
-
Portal bell system
-
Doctor email hooks
-
Patient email
-
SMS fallback logic
-
Deep-link routing
📁 STAGE 8 — PATIENT PORTAL (Week 12)
-
Dashboard
-
My Prescriptions
-
My Reports
-
My Invoices
-
My Certificates
-
Upload reports
-
Access control
💊 STAGE 9 — PHARMACY INVENTORY (Week 13)
-
Medicine master UI
-
Batch tracking schema
-
Expiry alerts
-
Low-stock alert
🏥 STAGE 10 — DAYCARE EXPANSION (Week 14–15)
-
Day-care encounter flow
-
Nursing chart module
-
Bed allocation
-
Consolidated billing
-
Day-care summary PDF
🔐 STAGE 11 — HARDENING & LOCKS (Week 16)
-
RLS fine-tuning
-
Role permission tests
-
Race condition tests
-
Idempotency tests
-
Audit verification
-
Backup simulation
-
Performance indexing
-
Error logging system
Now it is Everest-grade.
🧠 Final Chronology Summary
-
Supabase tables
-
Server logic
-
Minimal UI
-
Documents
-
Labs
-
Teleconsult
-
Notifications
-
Patient portal
-
Inventory
-
Day-care
-
Hardening
If we follow this chronology strictly,
you will never need to rewrite your schema.
Next time you’re at your PC,
we start with:
👉 Stage 1, Step 4 — Designing the patients table properly.
And from there, everything cascades correctly.
