top of page

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

  1. Enable row-level security (RLS)

  2. Define roles (doctor, reception, pharmacy, admin, patient)

  3. Configure auth model (even if Wix handles login)

2️⃣ Core Tables (Do NOT skip order)

A. Patients (Master Profile)

  1. patients table

  2. UHID generator (EFC####)

  3. Demographics fields

  4. Master medical fields

  5. diagnosis_master_text

  6. Audit fields

  7. Indexes (uhid, mobile, first_name, last_name)

B. Diagnosis Registry

  1. diagnosis_master

  2. patient_master_diagnoses

  3. Unique constraint (patient_id + diagnosis_code)

  4. Index on diagnosis_code

C. Appointments (Scheduling only)

  1. appointments table

  2. Slot model

  3. Appointment status enum

  4. Index on date/time

D. Encounters (Medical Core Object)

  1. encounters table

  2. EID generator

  3. encounter_type enum

  4. status enum

  5. Index patient_id + start_time

E. Visits

  1. visits table

  2. VID generator

  3. Link visits → encounters

  4. visit_channel enum

F. Clinical Notes (Versioned)

  1. clinical_notes

  2. version logic

  3. status (DRAFT/SIGNED)

  4. signed_at

  5. Lock constraint after SIGNED

G. Prescriptions

  1. prescriptions

  2. prescription_items

  3. Versioning + locking rules

H. Billing Engine

  1. invoices

  2. invoice_no generator

  3. invoice status enum

  4. invoice_items

  5. Snapshot price fields

  6. DB constraint: cannot edit if PAID

I. Lab System

  1. lab_tests_master

  2. lab_orders

  3. Link lab_orders → encounters

  4. Snapshot price rule

J. Documents

  1. documents table

  2. doc_type enum

  3. versioning model

  4. Storage bucket structure

K. Teleconsult Infrastructure Tables

  1. tele_sessions

  2. store Twilio session metadata

  3. recording_url field

  4. consent flag

  5. 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.

  1. “Same encounter?” logic function

  2. “New encounter?” rule enforcement

  3. Invoice lifecycle guard function

  4. Payment lock function

  5. Snapshot pricing function

  6. Version increment function

  7. Master history auto-update function

  8. Diagnosis sync function

  9. Credit note logic function

  10. Tele-session logging function

Now backend is intelligent.

🖥 STAGE 3 — MINIMAL WIX UI (Week 4–5)

Now we touch frontend.

3A. Reception Console

  1. Patient search (UHID/mobile/name)

  2. Booking form

  3. Today list

  4. Walk-in toggle

  5. Collect payment button

3B. OPD Assistant

  1. Vitals page

  2. Ready-for-doctor signal

3C. Doctor Dashboard

  1. Encounter open/create

  2. Visit create

  3. Clinical note editor

  4. Diagnosis selector

  5. Rx entry

  6. Sign button

3D. Pharmacy

  1. Queue page

  2. Dispense qty adjust

  3. Finalize invoice

At this stage:
Eweb works internally for OPD.

📄 STAGE 4 — DOCUMENT ENGINE (Week 6–7)

  1. Prescription PDF template

  2. Invoice PDF template

  3. Certificate template base

  4. Google Docs OR server-renderer integration

  5. PDF storage logic

  6. Version stamping

  7. Immutability enforcement

  8. Full vs redacted Rx generation

Now medicolegal safety begins.

🧪 STAGE 5 — LAB INTEGRATION (Week 8)

  1. Metropolis catalog import

  2. Lab order UI

  3. Report vault upload

  4. Report linking

  5. Report timeline view

Now unnecessary repeat tests reduce.

📡 STAGE 6 — TELECONSULT MODULE (Week 9–10)

  1. Teleconsult booking type

  2. Twilio token generation endpoint

  3. Video room creation

  4. Chat channel

  5. Recording enable

  6. Recording metadata storage

  7. Tele encounter auto-create

  8. Tele Rx generation

  9. Tele invoice generation

  10. Consent flow enforcement

Now virtual care is production-ready.

📬 STAGE 7 — NOTIFICATIONS (Week 11)

  1. Portal bell system

  2. Doctor email hooks

  3. Patient email

  4. SMS fallback logic

  5. Deep-link routing

📁 STAGE 8 — PATIENT PORTAL (Week 12)

  1. Dashboard

  2. My Prescriptions

  3. My Reports

  4. My Invoices

  5. My Certificates

  6. Upload reports

  7. Access control

💊 STAGE 9 — PHARMACY INVENTORY (Week 13)

  1. Medicine master UI

  2. Batch tracking schema

  3. Expiry alerts

  4. Low-stock alert

🏥 STAGE 10 — DAYCARE EXPANSION (Week 14–15)

  1. Day-care encounter flow

  2. Nursing chart module

  3. Bed allocation

  4. Consolidated billing

  5. Day-care summary PDF

🔐 STAGE 11 — HARDENING & LOCKS (Week 16)

  1. RLS fine-tuning

  2. Role permission tests

  3. Race condition tests

  4. Idempotency tests

  5. Audit verification

  6. Backup simulation

  7. Performance indexing

  8. Error logging system

Now it is Everest-grade.

🧠 Final Chronology Summary

  1. Supabase tables

  2. Server logic

  3. Minimal UI

  4. Documents

  5. Labs

  6. Teleconsult

  7. Notifications

  8. Patient portal

  9. Inventory

  10. Day-care

  11. 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.

bottom of page