The entity-relationship diagram below summarises the core healthcare data model introduced in V1__initial_schema.sql. Relationships are cardinality annotated so engineers can visualise the lifecycle of encounters, notes, and coding artefacts.
┌────────────────┐ ┌────────────────────┐
│ organizations │◄────►│ users │
└────────┬───────┘ └────────┬───────────┘
│ │ ▲
│ │ │
▼ ▼ │
┌────────────────┐ ┌────────────────────┐
│ patients │─────►│ encounters │
└────────┬───────┘ └───────┬────┬───────┘
│ │ │
│ │ └─────────────┐
│ │ ▼
│ │ ┌───────────────┐
▼ ▼ │ audio_record- │
┌────────────────┐ ┌────────────────┐ │ ings │
│ clinical_notes │◄────►│ diagnoses │ └────┬──────────┘
└───────┬────────┘ └────┬──────────┘ │
│ │ ▼
│ │ ┌────────────────┐
▼ ▼ │ transcripts │
┌───────────────┐ ┌────────────┐ └────┬───────────┘
│ note_sections │ │ procedures │ │
└───────────────┘ └────┬───────┘ ▼
│ ┌────────────────────┐
│ │ transcript_segments│
▼ └────────────────────┘
┌──────────────┐
│ icd10_codes │
└──────────────┘
┌──────────────┐
│ cpt_codes │
└──────────────┘
┌────────────────┐
│ audit_logs │◄─────────────────────────────┐
└────────────────┘ │
│
┌────────────────┐ │
│ helper funcs │ (set context, RLS, triggers) │
└────────────────┘ │
Key takeaways:
- Every
userbelongs to exactly oneorganization. Organization settings drive RLS policies. patientsare scoped to organisations and can experience manyencounters.- Each
encountercan have oneaudio_recording, multipletranscripts, one or moreclinical_notes, and billing artefacts (diagnoses,procedures). clinical_notesoptionally decompose into granularnote_sectionsfor subject/objective/etc sections.- Coding reference data (
icd10_codes,cpt_codes) remains independent but links to encounter artefacts via foreign keys. - All PHI tables are protected by audit triggers writing to
audit_logs, which is range-partitioned by month.