Clinical Schema
Purpose: Patient care, clinical documentation, AI-assisted care, and FHIR-aligned clinical resources Tenant Scoped: Yes (all tables) RLS Enabled: Yes
Overview
The clinical schema contains all patient care data aligned with FHIR R4 resources. It supports:
- Longitudinal Health Record (LHR) as a computed view
- Episode of Care for treatment programs
- Multi-practitioner encounters
- Care Plans with versioning
- AI-Assisted Care (transcription, suggestions)
Entities
Patients
Entity: Patient
Purpose: Individual receiving healthcare services (FHIR: Patient)
Attributes:
| Attribute | Type | Required | Description |
|---|---|---|---|
| id | UUID | Yes | Primary identifier |
| tenant_id | UUID | Yes | Owning tenant |
| mrn | String | No | Medical Record Number (facility-specific) |
| abha_id | String | No | ABHA identifier (India) |
| first_name | String | Yes | First name |
| last_name | String | No | Last name |
| display_name | String | No | Preferred display name |
| gender | Enum | No | male, female, other, unknown |
| birth_date | Date | No | Date of birth |
| deceased | Boolean | No | Deceased status |
| deceased_date | Date | No | Date of death |
| marital_status | Enum | No | single, married, divorced, widowed |
| photo_url | String | No | Patient photo |
| String | No | Email address | |
| phone | String | No | Primary phone |
| address | JSONB | No | Address information |
| emergency_contact | JSONB | No | Emergency contact details |
| communication_preferences | JSONB | No | Language, contact preferences |
| is_active | Boolean | Yes | Active patient |
Emergency Contact Structure:
{
"name": "Jane Doe",
"relationship": "spouse",
"phone": "+919876543210",
"email": "jane@example.com"
}Relationships:
- Belongs to: Tenant
- Has many: PatientFacilities, EpisodesOfCare, Encounters, Conditions, Observations
- Has many: MedicationRequests, CarePlans, Goals, Appointments
FHIR Mapping: Patient resource
Entity: PatientFacility
Purpose: Links patients to facilities they receive care at
Attributes:
| Attribute | Type | Required | Description |
|---|---|---|---|
| id | UUID | Yes | Primary identifier |
| tenant_id | UUID | Yes | Owning tenant |
| patient_id | UUID | Yes | Patient reference |
| facility_id | UUID | Yes | Facility reference |
| facility_mrn | String | No | Facility-specific MRN |
| registration_date | Date | No | First registration |
| is_primary | Boolean | No | Primary facility |
| is_active | Boolean | Yes | Active registration |
Relationships:
- Belongs to: Tenant, Patient, Facility
Episodes of Care
Entity: EpisodeOfCare
Purpose: Treatment program container spanning multiple encounters (FHIR: EpisodeOfCare)
Attributes:
| Attribute | Type | Required | Description |
|---|---|---|---|
| id | UUID | Yes | Primary identifier |
| tenant_id | UUID | Yes | Owning tenant |
| patient_id | UUID | Yes | Patient reference |
| facility_id | UUID | Yes | Managing facility |
| managing_practitioner_id | UUID | No | Primary practitioner |
| status | Enum | Yes | planned, waitlist, active, onhold, finished, cancelled |
| type | Enum | No | Episode type (rehabilitation, chronic_care, mental_health, etc.) |
| diagnosis_codes | JSONB | No | Primary diagnoses for this episode |
| period_start | Date | No | Episode start date |
| period_end | Date | No | Episode end date |
| description | Text | No | Episode description |
Status Lifecycle:
planned --> waitlist --> active <--> onhold --> finished
\--> cancelledType Values:
rehabilitation- Post-surgical or injury recoverychronic_care- Chronic disease managementmental_health- Mental health treatment programmaternity- Pregnancy and postnatal careoncology- Cancer treatment programpreventive- Preventive care programacute- Acute care episode
Relationships:
- Belongs to: Tenant, Patient, Facility, Practitioner
- Has many: Encounters, TreatmentGoals, ProgressNotes
- Referenced by: CarePlans
FHIR Mapping: EpisodeOfCare resource
Entity: TreatmentGoal
Purpose: Goals specific to an episode of care
Attributes:
| Attribute | Type | Required | Description |
|---|---|---|---|
| id | UUID | Yes | Primary identifier |
| tenant_id | UUID | Yes | Owning tenant |
| episode_of_care_id | UUID | Yes | Parent episode |
| description | Text | Yes | Goal description |
| target_date | Date | No | Target completion date |
| status | Enum | Yes | proposed, planned, accepted, active, achieved, cancelled |
| priority | Enum | No | high, medium, low |
| outcome | Text | No | Outcome description |
Relationships:
- Belongs to: Tenant, EpisodeOfCare
Entity: ProgressNote
Purpose: Progress notes within an episode
Attributes:
| Attribute | Type | Required | Description |
|---|---|---|---|
| id | UUID | Yes | Primary identifier |
| tenant_id | UUID | Yes | Owning tenant |
| episode_of_care_id | UUID | Yes | Parent episode |
| encounter_id | UUID | No | Related encounter |
| author_id | UUID | Yes | Note author (practitioner) |
| note_date | Timestamp | Yes | Note date/time |
| content | Text | Yes | Note content |
| note_type | Enum | No | progress, assessment, plan, summary |
Relationships:
- Belongs to: Tenant, EpisodeOfCare, Encounter, Practitioner
Encounters
Entity: Encounter
Purpose: Clinical visit or interaction (FHIR: Encounter)
Attributes:
| Attribute | Type | Required | Description |
|---|---|---|---|
| id | UUID | Yes | Primary identifier |
| tenant_id | UUID | Yes | Owning tenant |
| patient_id | UUID | Yes | Patient reference |
| facility_id | UUID | Yes | Facility where encounter occurs |
| episode_of_care_id | UUID | No | Parent episode (optional) |
| status | Enum | Yes | planned, arrived, triaged, in-progress, onleave, finished, cancelled |
| class | Enum | Yes | ambulatory, inpatient, emergency, virtual, home |
| type | Enum | No | consultation, follow_up, procedure, therapy, etc. |
| priority | Enum | No | routine, urgent, emergency |
| period_start | Timestamp | No | Start time |
| period_end | Timestamp | No | End time |
| reason_codes | JSONB | No | Reason for visit |
| diagnosis_codes | JSONB | No | Encounter diagnoses |
| hospitalization | JSONB | No | Admission details (inpatient) |
| service_type_id | UUID | No | Healthcare service reference |
Class Values:
ambulatory- OPD, clinic visitinpatient- Hospital admissionemergency- Emergency departmentvirtual- Telemedicine consultationhome- Home visit
Hospitalization Structure (for inpatient):
{
"admit_source": "emergency",
"re_admission": false,
"diet_preference": "vegetarian",
"special_arrangement": ["wheelchair"],
"discharge_disposition": "home"
}Relationships:
- Belongs to: Tenant, Patient, Facility, EpisodeOfCare, HealthcareService
- Has many: EncounterParticipants, Observations, MedicationRequests, ServiceRequests
- Has many: TranscriptionSessions, AiSuggestions
FHIR Mapping: Encounter resource
Entity: EncounterParticipant
Purpose: Practitioners involved in an encounter (multi-practitioner support)
Attributes:
| Attribute | Type | Required | Description |
|---|---|---|---|
| id | UUID | Yes | Primary identifier |
| tenant_id | UUID | Yes | Owning tenant |
| encounter_id | UUID | Yes | Encounter reference |
| practitioner_id | UUID | Yes | Practitioner reference |
| role | Enum | Yes | primary, consultant, assistant, observer |
| period_start | Timestamp | No | Participation start |
| period_end | Timestamp | No | Participation end |
Role Values:
primary- Primary/attending practitionerconsultant- Consulting specialistassistant- Assisting practitionerobserver- Observer (training, etc.)
Relationships:
- Belongs to: Tenant, Encounter, Practitioner
FHIR Mapping: Encounter.participant
Clinical Data
Entity: Condition
Purpose: Diagnoses and problems (FHIR: Condition)
Attributes:
| Attribute | Type | Required | Description |
|---|---|---|---|
| id | UUID | Yes | Primary identifier |
| tenant_id | UUID | Yes | Owning tenant |
| patient_id | UUID | Yes | Patient reference |
| encounter_id | UUID | No | Diagnosing encounter |
| recorder_id | UUID | No | Recording practitioner |
| clinical_status | Enum | Yes | active, recurrence, relapse, inactive, remission, resolved |
| verification_status | Enum | No | unconfirmed, provisional, differential, confirmed |
| category | Enum | No | problem_list_item, encounter_diagnosis |
| severity | Enum | No | mild, moderate, severe |
| code | JSONB | Yes | Diagnosis code (ICD, SNOMED) |
| body_site | JSONB | No | Affected body site |
| onset_date | Date | No | When condition started |
| abatement_date | Date | No | When condition ended |
| recorded_date | Date | No | When recorded |
| note | Text | No | Additional notes |
Code Structure:
{
"system": "icd-10",
"code": "E11.9",
"display": "Type 2 diabetes mellitus without complications"
}Relationships:
- Belongs to: Tenant, Patient, Encounter, Practitioner
- References: reference.icd_codes, reference.snomed_concepts
FHIR Mapping: Condition resource
Entity: Observation
Purpose: Vitals, measurements, and clinical findings (FHIR: Observation)
Attributes:
| Attribute | Type | Required | Description |
|---|---|---|---|
| id | UUID | Yes | Primary identifier |
| tenant_id | UUID | Yes | Owning tenant |
| patient_id | UUID | Yes | Patient reference |
| encounter_id | UUID | No | Related encounter |
| performer_id | UUID | No | Performing practitioner |
| status | Enum | Yes | registered, preliminary, final, amended, cancelled |
| category | Enum | Yes | vital_signs, laboratory, imaging, social_history, exam |
| code | JSONB | Yes | Observation type (LOINC, SNOMED) |
| value | JSONB | Yes | Observation value |
| interpretation | Enum | No | normal, abnormal, critical_low, critical_high |
| effective_date | Timestamp | Yes | When observed |
| issued | Timestamp | No | When result issued |
| note | Text | No | Additional notes |
| reference_range | JSONB | No | Normal range |
| body_site | JSONB | No | Body site |
| method | String | No | Observation method |
Value Structure (varies by type):
// Quantity
{ "type": "quantity", "value": 120, "unit": "mmHg" }
// String
{ "type": "string", "value": "Normal breath sounds" }
// CodeableConcept
{ "type": "code", "system": "snomed", "code": "17621005", "display": "Normal" }
// Boolean
{ "type": "boolean", "value": true }Common Vital Signs:
- Blood Pressure (systolic/diastolic)
- Heart Rate
- Temperature
- Respiratory Rate
- Oxygen Saturation
- Height, Weight, BMI
Relationships:
- Belongs to: Tenant, Patient, Encounter, Practitioner
- References: reference.lab_tests, reference.snomed_concepts
FHIR Mapping: Observation resource
Entity: AllergyIntolerance
Purpose: Patient allergies and intolerances (FHIR: AllergyIntolerance)
Attributes:
| Attribute | Type | Required | Description |
|---|---|---|---|
| id | UUID | Yes | Primary identifier |
| tenant_id | UUID | Yes | Owning tenant |
| patient_id | UUID | Yes | Patient reference |
| encounter_id | UUID | No | Recording encounter |
| recorder_id | UUID | No | Recording practitioner |
| clinical_status | Enum | Yes | active, inactive, resolved |
| verification_status | Enum | No | unconfirmed, confirmed, refuted |
| type | Enum | No | allergy, intolerance |
| category | Enum | No | food, medication, environment, biologic |
| criticality | Enum | No | low, high, unable_to_assess |
| code | JSONB | Yes | Substance/allergen |
| onset_date | Date | No | When allergy started |
| recorded_date | Date | No | When recorded |
| reactions | JSONB | No | Reaction details |
| note | Text | No | Additional notes |
Reactions Structure:
[
{
"substance": "Penicillin",
"manifestation": ["Hives", "Difficulty breathing"],
"severity": "severe",
"onset": "immediate"
}
]Relationships:
- Belongs to: Tenant, Patient, Encounter, Practitioner
FHIR Mapping: AllergyIntolerance resource
Medications
Entity: MedicationRequest
Purpose: Prescriptions and medication orders (FHIR: MedicationRequest)
Attributes:
| Attribute | Type | Required | Description |
|---|---|---|---|
| id | UUID | Yes | Primary identifier |
| tenant_id | UUID | Yes | Owning tenant |
| patient_id | UUID | Yes | Patient reference |
| encounter_id | UUID | No | Prescribing encounter |
| requester_id | UUID | Yes | Prescribing practitioner |
| status | Enum | Yes | active, on-hold, cancelled, completed, stopped, draft |
| intent | Enum | Yes | proposal, plan, order, original-order, reflex-order |
| priority | Enum | No | routine, urgent, asap, stat |
| medication | JSONB | Yes | Medication details |
| dosage_instruction | JSONB | Yes | Dosage instructions |
| dispense_request | JSONB | No | Dispensing details |
| substitution_allowed | Boolean | No | Generic substitution allowed |
| reason_code | JSONB | No | Reason for medication |
| authored_on | Timestamp | Yes | When prescribed |
| validity_period_start | Date | No | Prescription start |
| validity_period_end | Date | No | Prescription end |
| note | Text | No | Additional instructions |
Medication Structure:
{
"drug_id": "uuid",
"name": "Metformin 500mg",
"generic_name": "Metformin Hydrochloride",
"form": "tablet",
"strength": "500mg"
}Dosage Instruction Structure:
{
"sequence": 1,
"text": "Take 1 tablet twice daily with meals",
"timing": {
"frequency": 2,
"period": 1,
"period_unit": "day"
},
"route": "oral",
"dose_quantity": {
"value": 1,
"unit": "tablet"
},
"as_needed": false,
"duration": {
"value": 30,
"unit": "day"
}
}Relationships:
- Belongs to: Tenant, Patient, Encounter, Practitioner
- References: reference.drugs
FHIR Mapping: MedicationRequest resource
Care Planning
Entity: CarePlan
Purpose: Treatment and care planning (FHIR: CarePlan)
Attributes:
| Attribute | Type | Required | Description |
|---|---|---|---|
| id | UUID | Yes | Primary identifier |
| tenant_id | UUID | Yes | Owning tenant |
| patient_id | UUID | Yes | Patient reference |
| encounter_id | UUID | No | Creating encounter |
| episode_of_care_id | UUID | No | Related episode |
| author_id | UUID | No | Plan author |
| status | Enum | Yes | draft, active, on-hold, revoked, completed |
| intent | Enum | Yes | proposal, plan, order |
| category | Enum | No | assess-plan, orders, overall-plan |
| title | String | No | Plan title |
| description | Text | No | Plan description |
| period_start | Date | No | Plan start date |
| period_end | Date | No | Plan end date |
| activities | JSONB | No | Planned activities |
| addresses | JSONB | No | Conditions addressed |
| version | Integer | Yes | Version number (default: 1) |
| replaces_id | UUID | No | Previous version reference |
| created_at | Timestamp | Yes | Creation timestamp |
Activities Structure:
[
{
"detail": {
"kind": "ServiceRequest",
"code": "Physical therapy",
"status": "scheduled",
"scheduled": "2024-02-01",
"performer_id": "uuid"
}
},
{
"detail": {
"kind": "MedicationRequest",
"code": "Pain management",
"status": "in-progress"
}
}
]Versioning Pattern:
- New versions created via
replaces_idchain - Old versions remain immutable
- Only one version can be
activeat a time
Relationships:
- Belongs to: Tenant, Patient, Encounter, EpisodeOfCare, Practitioner
- Has many: Goals
- Self-referential: replaces_id for version chain
FHIR Mapping: CarePlan resource
Entity: Goal
Purpose: Patient health goals (FHIR: Goal)
Attributes:
| Attribute | Type | Required | Description |
|---|---|---|---|
| id | UUID | Yes | Primary identifier |
| tenant_id | UUID | Yes | Owning tenant |
| patient_id | UUID | Yes | Patient reference |
| care_plan_id | UUID | No | Related care plan |
| expressed_by_id | UUID | No | Who expressed goal |
| lifecycle_status | Enum | Yes | proposed, planned, accepted, active, on-hold, completed, cancelled |
| achievement_status | Enum | No | in-progress, improving, worsening, no-change, achieved, not-achieved |
| priority | Enum | No | high, medium, low |
| category | Enum | No | dietary, safety, behavioral, physiotherapy |
| description | Text | Yes | Goal description |
| start_date | Date | No | Target start |
| target | JSONB | No | Target measures |
| status_date | Date | No | Last status update |
| status_reason | Text | No | Reason for current status |
| note | Text | No | Additional notes |
Target Structure:
{
"measure": "HbA1c",
"detail": {
"type": "quantity",
"value": 6.5,
"comparator": "<=",
"unit": "%"
},
"due_date": "2024-06-01"
}Relationships:
- Belongs to: Tenant, Patient, CarePlan, Practitioner
FHIR Mapping: Goal resource
Orders and Results
Entity: ServiceRequest
Purpose: Lab orders, imaging orders, referrals (FHIR: ServiceRequest)
Attributes:
| Attribute | Type | Required | Description |
|---|---|---|---|
| id | UUID | Yes | Primary identifier |
| tenant_id | UUID | Yes | Owning tenant |
| patient_id | UUID | Yes | Patient reference |
| encounter_id | UUID | No | Ordering encounter |
| requester_id | UUID | Yes | Ordering practitioner |
| status | Enum | Yes | draft, active, on-hold, revoked, completed |
| intent | Enum | Yes | proposal, plan, order, original-order |
| priority | Enum | No | routine, urgent, asap, stat |
| category | Enum | Yes | laboratory, imaging, procedure, referral, consultation |
| code | JSONB | Yes | Service/test code |
| order_detail | JSONB | No | Additional order details |
| quantity | Integer | No | Number of repetitions |
| occurrence | JSONB | No | When service should occur |
| authored_on | Timestamp | Yes | When ordered |
| reason_code | JSONB | No | Reason for order |
| supporting_info | JSONB | No | Additional clinical context |
| specimen | JSONB | No | Specimen requirements |
| note | Text | No | Additional instructions |
Relationships:
- Belongs to: Tenant, Patient, Encounter, Practitioner
- Has many: DiagnosticReports
- References: reference.lab_tests, reference.procedures
FHIR Mapping: ServiceRequest resource
Entity: DiagnosticReport
Purpose: Lab results, imaging results (FHIR: DiagnosticReport)
Attributes:
| Attribute | Type | Required | Description |
|---|---|---|---|
| id | UUID | Yes | Primary identifier |
| tenant_id | UUID | Yes | Owning tenant |
| patient_id | UUID | Yes | Patient reference |
| encounter_id | UUID | No | Related encounter |
| service_request_id | UUID | No | Original order |
| performer_id | UUID | No | Performing lab/center |
| status | Enum | Yes | registered, partial, preliminary, final, amended, cancelled |
| category | Enum | Yes | laboratory, radiology, pathology, cardiology |
| code | JSONB | Yes | Report type |
| effective_date | Timestamp | No | Clinically relevant time |
| issued | Timestamp | No | When report issued |
| results | JSONB | No | Observation references |
| conclusion | Text | No | Clinical conclusion |
| conclusion_code | JSONB | No | Coded conclusions |
| presented_form | JSONB | No | Attached reports/images |
| note | Text | No | Additional comments |
Results Structure (links to Observations):
[
{ "observation_id": "uuid", "name": "Hemoglobin", "value": "14.5 g/dL" },
{ "observation_id": "uuid", "name": "WBC Count", "value": "7500 /uL" }
]Relationships:
- Belongs to: Tenant, Patient, Encounter, ServiceRequest
- Has many: Observations
FHIR Mapping: DiagnosticReport resource
Appointments
Entity: Appointment
Purpose: Scheduled clinical appointments (FHIR: Appointment)
Attributes:
| Attribute | Type | Required | Description |
|---|---|---|---|
| id | UUID | Yes | Primary identifier |
| tenant_id | UUID | Yes | Owning tenant |
| patient_id | UUID | Yes | Patient reference |
| facility_id | UUID | Yes | Facility reference |
| practitioner_id | UUID | No | Practitioner reference |
| service_id | UUID | No | Healthcare service |
| status | Enum | Yes | proposed, pending, booked, arrived, fulfilled, cancelled, noshow |
| service_type | Enum | No | consultation, follow_up, procedure, therapy |
| appointment_type | Enum | No | routine, walk_in, checkup, emergency |
| reason_code | JSONB | No | Reason for appointment |
| priority | Integer | No | Priority (1-10) |
| start | Timestamp | Yes | Start time |
| end | Timestamp | No | End time |
| slot_id | UUID | No | Booked slot reference |
| created | Timestamp | Yes | When booked |
| cancellation_reason | Text | No | If cancelled |
| patient_instruction | Text | No | Instructions for patient |
| note | Text | No | Additional notes |
Relationships:
- Belongs to: Tenant, Patient, Facility, Practitioner, HealthcareService
- Has one: Encounter (created on arrival)
FHIR Mapping: Appointment resource
AI-Assisted Care
Entity: TranscriptionSession
Purpose: AI Scribe transcription sessions linked to encounters
Attributes:
| Attribute | Type | Required | Description |
|---|---|---|---|
| id | UUID | Yes | Primary identifier |
| tenant_id | UUID | Yes | Owning tenant |
| encounter_id | UUID | Yes | Related encounter |
| practitioner_id | UUID | Yes | Conducting practitioner |
| status | Enum | Yes | recording, processing, completed, failed |
| started_at | Timestamp | Yes | Session start |
| ended_at | Timestamp | No | Session end |
| duration_seconds | Integer | No | Total duration |
| audio_url | String | No | Audio recording URL |
| language | String | No | Transcription language |
| ai_provider | Enum | No | openai, anthropic, google |
| ai_model | String | No | Model used |
| raw_transcript | Text | No | Raw transcription |
| processed_transcript | JSONB | No | Structured transcript |
| confidence_score | Decimal | No | Overall confidence (0.0-1.0) |
| error_message | Text | No | If failed |
Processed Transcript Structure:
{
"segments": [
{
"speaker": "practitioner",
"start_time": 0,
"end_time": 5.5,
"text": "How are you feeling today?",
"confidence": 0.95
},
{
"speaker": "patient",
"start_time": 6.0,
"end_time": 12.0,
"text": "I've been having headaches for the past week.",
"confidence": 0.92
}
],
"summary": "Patient presents with one-week history of headaches..."
}Relationships:
- Belongs to: Tenant, Encounter, Practitioner
- Has many: AiSuggestions
Entity: AiSuggestion
Purpose: AI-generated clinical suggestions (CDS)
Attributes:
| Attribute | Type | Required | Description |
|---|---|---|---|
| id | UUID | Yes | Primary identifier |
| tenant_id | UUID | Yes | Owning tenant |
| encounter_id | UUID | Yes | Related encounter |
| transcription_session_id | UUID | No | Source transcription |
| suggestion_type | Enum | Yes | diagnosis, medication, order, observation, care_plan, goal |
| category | Enum | No | clinical, documentation, administrative |
| content | JSONB | Yes | Suggestion content |
| confidence_score | Decimal | No | AI confidence (0.0-1.0) |
| status | Enum | Yes | pending, accepted, rejected, modified |
| reviewed_by_id | UUID | No | Reviewing practitioner |
| reviewed_at | Timestamp | No | Review timestamp |
| modification_note | Text | No | If modified, what changed |
| source_reference | JSONB | No | Source evidence |
| created_resource_id | UUID | No | If accepted, created resource ID |
| created_resource_type | String | No | Type of created resource |
Content Structure (varies by type):
// Diagnosis suggestion
{
"type": "diagnosis",
"icd_code": "G43.909",
"display": "Migraine, unspecified, not intractable",
"confidence": 0.85,
"evidence": ["Patient reports recurring headaches", "Photophobia mentioned"]
}
// Medication suggestion
{
"type": "medication",
"drug_name": "Sumatriptan",
"dosage": "50mg",
"frequency": "as needed",
"confidence": 0.78,
"rationale": "First-line treatment for acute migraine"
}Status Flow:
pending --> accepted --> (creates resource)
\--> rejected
\--> modified --> (creates modified resource)Relationships:
- Belongs to: Tenant, Encounter, TranscriptionSession, Practitioner
- Creates: Conditions, MedicationRequests, ServiceRequests, Observations, CarePlans, Goals
Schema Diagram
+---------------+
| patients |
+---------------+
|
+---------------------------------------------+
| | |
| 1:N | 1:N | 1:N
v v v
+---------------+ +---------------+ +---------------+
| patient_ | | episodes_of_ | | appointments |
| facilities | | care | +---------------+
+---------------+ +---------------+
|
| 1:N
v
+---------------+ +---------------+
| encounters |------>| encounter_ |
+---------------+ | participants |
| +---------------+
|
+--------------------+--------------------+
| | | | |
v v v v v
+----------+ +----------+ +------+ +--------+ +-------------+
|conditions| |observa- | |medica| |service_| |transcription|
| | |tions | |tion_ | |requests| |_sessions |
+----------+ +----------+ |reqs | +--------+ +-------------+
+------+ | |
v v
+----------+ +----------+
|diagnostic| |ai_ |
|_reports | |suggestions|
+----------+ +----------+
+---------------+ +---------------+
| care_plans |------>| goals |
+---------------+ +---------------+
|
| (replaces_id)
v
+---------------+
| care_plans | (previous version)
+---------------+FHIR Resource Mapping
| Internal Entity | FHIR Resource | Notes |
|---|---|---|
| Patient | Patient | Core patient identity |
| EpisodeOfCare | EpisodeOfCare | Treatment program container |
| Encounter | Encounter | Clinical visit/interaction |
| EncounterParticipant | Encounter.participant | Multi-practitioner support |
| Condition | Condition | Diagnoses and problems |
| Observation | Observation | Vitals, labs, findings |
| AllergyIntolerance | AllergyIntolerance | Allergies and intolerances |
| MedicationRequest | MedicationRequest | Prescriptions |
| CarePlan | CarePlan | Treatment planning |
| Goal | Goal | Patient goals |
| ServiceRequest | ServiceRequest | Lab/imaging orders |
| DiagnosticReport | DiagnosticReport | Results |
| Appointment | Appointment | Scheduled visits |
| TranscriptionSession | N/A | AI Scribe (platform-specific) |
| AiSuggestion | N/A | CDS suggestions (platform-specific) |
RLS Policies
-- All clinical tables: tenant isolation
CREATE POLICY tenant_isolation ON clinical.patients
USING (tenant_id = current_setting('app.current_tenant_id')::uuid);
CREATE POLICY tenant_isolation ON clinical.encounters
USING (tenant_id = current_setting('app.current_tenant_id')::uuid);
-- Similar policies for all tenant-scoped tablesLHR (Longitudinal Health Record) Implementation
The LHR is NOT stored as a table. It is a computed view aggregated on demand from:
- Patient demographics
- Conditions (problem list)
- Medications (active prescriptions)
- Observations (vitals history)
- Allergies
- Care Plans
- Encounters (grouped by Episode)
- Goals
LHR Computation Pattern:
LHR = aggregate(
patient.demographics,
conditions.where(clinical_status: active),
medication_requests.where(status: active),
observations.recent(90.days),
allergy_intolerances.all,
care_plans.where(status: active),
encounters.grouped_by(episode_of_care),
goals.where(lifecycle_status: active)
)Reference: Clinical Data Hierarchy