CPOE Data Specifications

CPOE Data Specifications

Shared Entity References

This module references the following shared entities defined in their owning modules. CPOE does not redefine these tables — it uses foreign-key references only.

Shared Entity Owning Module Table(s) FK Used in CPOE
Patients ehr-patient-mgmt patients, patient_demographics, patient_identifiers patients.patient_id
Providers ehr-patient-mgmt providers, provider_credentials providers.provider_id
Encounters scheduling encounters, encounter_details encounters.encounter_id
Users & Auth ehr-patient-mgmt users, roles, permissions users.user_id
Facilities ehr-patient-mgmt facilities, departments, locations facilities.facility_id
Payers policy-contract-mgmt payers, insurance_plans payers.payer_id

Entity Relationship Diagram

erDiagram patients ||--o{ medication_orders : "has" patients ||--o{ laboratory_orders : "has" patients ||--o{ imaging_orders : "has" providers ||--o{ medication_orders : "orders" providers ||--o{ laboratory_orders : "orders" providers ||--o{ imaging_orders : "orders" encounters ||--o{ medication_orders : "during" encounters ||--o{ laboratory_orders : "during" encounters ||--o{ imaging_orders : "during" medication_orders ||--o{ clinical_alerts : "triggers" medication_orders ||--o{ order_audit_log : "tracked by" medication_orders ||--o| pending_pharmacy_queue : "queued in" laboratory_orders ||--o{ clinical_alerts : "triggers" laboratory_orders ||--o{ order_audit_log : "tracked by" imaging_orders ||--o{ clinical_alerts : "triggers" imaging_orders ||--o{ order_audit_log : "tracked by" medication_master ||--o{ medication_orders : "referenced by" order_sets ||--o{ order_set_items : "contains" order_sets ||--o{ order_set_executions : "executed as" medication_orders }o--o{ controlled_substance_inventory : "tracked in" medication_orders { bigint order_id PK bigint patient_id FK bigint encounter_id FK bigint ordering_provider_id FK bigint medication_id FK } laboratory_orders { bigint order_id PK bigint patient_id FK bigint encounter_id FK bigint ordering_provider_id FK } imaging_orders { bigint order_id PK bigint patient_id FK bigint encounter_id FK bigint ordering_provider_id FK } medication_master { bigint medication_id PK } clinical_alerts { bigint alert_id PK bigint order_id FK } order_audit_log { bigint audit_id PK bigint order_id FK bigint user_id FK } controlled_substance_inventory { bigint inventory_id PK bigint medication_id FK bigint facility_id FK }

Table Definitions

medication_orders

Purpose: Stores all medication orders placed through CPOE. Includes UAE controlled substance metadata for CDa/CDb prescriptions (Federal Decree-Law No. 30/2021).

Field Name Data Type Nullable Default Validation Description
order_id BIGINT NO GENERATED ALWAYS AS IDENTITY PK Primary key
patient_id BIGINT NO FK → patients.patient_id Patient receiving medication
encounter_id BIGINT NO FK → encounters.encounter_id Encounter context
ordering_provider_id BIGINT NO FK → providers.provider_id Ordering provider
medication_id BIGINT NO FK → medication_master.medication_id Medication ordered
order_type VARCHAR(20) NO 'inpatient' IN ('inpatient', 'outpatient', 'discharge') Order context
order_status VARCHAR(20) NO 'draft' IN ('draft', 'pending', 'active', 'completed', 'discontinued', 'cancelled') Current status
order_source VARCHAR(20) NO 'direct' IN ('direct', 'verbal', 'telephone', 'order_set') How order was entered
dose DECIMAL(10,3) NO > 0 Dose amount
dose_unit VARCHAR(20) NO FK → dose_units.code Unit of dose (mg, mL, units)
route VARCHAR(50) NO FK → medication_routes.code Route of administration
frequency VARCHAR(50) NO FK → order_frequencies.code Dosing frequency
duration_value INT YES > 0 if provided Duration numeric value
duration_unit VARCHAR(20) YES IN ('days', 'weeks', 'months') Duration time unit
prn_flag BOOLEAN NO FALSE PRN (as-needed) flag
prn_indication VARCHAR(200) YES Required if prn_flag = TRUE PRN reason
sig TEXT NO Full directions for patient
indication_code VARCHAR(10) YES ICD-10-AM format Clinical indication
indication_text VARCHAR(500) YES Indication free text
priority VARCHAR(20) NO 'routine' IN ('stat', 'asap', 'today', 'routine') Order priority
start_datetime TIMESTAMP NO CURRENT_TIMESTAMP When to start
stop_datetime TIMESTAMP YES > start_datetime When to stop
order_datetime TIMESTAMP NO CURRENT_TIMESTAMP When order was placed
signed_datetime TIMESTAMP YES order_datetime When order was signed
signed_by BIGINT YES FK → users.user_id Signing user
cosign_required BOOLEAN NO FALSE Requires co-signature
cosign_by BIGINT YES FK → users.user_id Co-signing provider
cosign_datetime TIMESTAMP YES When co-signed
discontinue_datetime TIMESTAMP YES order_datetime When discontinued
discontinue_reason TEXT YES Required if status = 'discontinued' Discontinuation reason
cancel_reason TEXT YES Required if status = 'cancelled' Cancellation reason
entered_by BIGINT YES FK → users.user_id Nurse/clerk for verbal orders
is_controlled_substance BOOLEAN NO FALSE UAE MOH controlled substance
controlled_class VARCHAR(20) YES IN ('CDa-Narcotic', 'CDa-Psychotropic', 'CDb') UAE controlled class
uae_legal_schedule VARCHAR(10) YES IN ('Schedule 1''Schedule 9') UAE Decree-Law 30/2021 schedule
uep_required BOOLEAN NO FALSE Must submit to MOH UEP
uep_prescription_id VARCHAR(50) YES ID returned by MOH UEP
uep_submission_status VARCHAR(20) YES IN ('pending', 'submitted', 'approved', 'rejected') UEP status
uep_submission_datetime TIMESTAMP YES UEP submission time
special_prescription_number VARCHAR(30) YES Required for CDa Serialised form number
prescriber_controlled_auth BOOLEAN YES Prescriber has CS authorisation
dual_verification_by BIGINT YES FK → users.user_id Pharmacist dual verification
dual_verification_datetime TIMESTAMP YES Dual verification time
override_flags JSONB YES CDS override details
formulary_status VARCHAR(20) YES IN ('preferred', 'non-preferred', 'not-covered') Formulary tier
estimated_cost_aed DECIMAL(10,2) YES Estimated cost in AED
alerts_overridden INT NO 0 ≥ 0 Count of overridden CDS alerts
order_set_execution_id BIGINT YES FK → order_set_executions.execution_id If from order set
created_by BIGINT NO FK → users.user_id Creator
created_at TIMESTAMP NO CURRENT_TIMESTAMP Created timestamp
updated_by BIGINT YES FK → users.user_id Last updater
updated_at TIMESTAMP YES Last update timestamp

SQL DDL

SQL
CREATE TABLE medication_orders (
  order_id BIGINT PRIMARY KEY GENERATED ALWAYS AS IDENTITY,
  patient_id BIGINT NOT NULL,
  encounter_id BIGINT NOT NULL,
  ordering_provider_id BIGINT NOT NULL,
  medication_id BIGINT NOT NULL,
  order_type VARCHAR(20) NOT NULL DEFAULT 'inpatient',
  order_status VARCHAR(20) NOT NULL DEFAULT 'draft',
  order_source VARCHAR(20) NOT NULL DEFAULT 'direct',
  dose DECIMAL(10,3) NOT NULL,
  dose_unit VARCHAR(20) NOT NULL,
  route VARCHAR(50) NOT NULL,
  frequency VARCHAR(50) NOT NULL,
  duration_value INT,
  duration_unit VARCHAR(20),
  prn_flag BOOLEAN NOT NULL DEFAULT FALSE,
  prn_indication VARCHAR(200),
  sig TEXT NOT NULL,
  indication_code VARCHAR(10),
  indication_text VARCHAR(500),
  priority VARCHAR(20) NOT NULL DEFAULT 'routine',
  start_datetime TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
  stop_datetime TIMESTAMP,
  order_datetime TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
  signed_datetime TIMESTAMP,
  signed_by BIGINT,
  cosign_required BOOLEAN NOT NULL DEFAULT FALSE,
  cosign_by BIGINT,
  cosign_datetime TIMESTAMP,
  discontinue_datetime TIMESTAMP,
  discontinue_reason TEXT,
  cancel_reason TEXT,
  entered_by BIGINT,
  is_controlled_substance BOOLEAN NOT NULL DEFAULT FALSE,
  controlled_class VARCHAR(20),
  uae_legal_schedule VARCHAR(10),
  uep_required BOOLEAN NOT NULL DEFAULT FALSE,
  uep_prescription_id VARCHAR(50),
  uep_submission_status VARCHAR(20),
  uep_submission_datetime TIMESTAMP,
  special_prescription_number VARCHAR(30),
  prescriber_controlled_auth BOOLEAN,
  dual_verification_by BIGINT,
  dual_verification_datetime TIMESTAMP,
  override_flags JSONB,
  formulary_status VARCHAR(20),
  estimated_cost_aed DECIMAL(10,2),
  alerts_overridden INT NOT NULL DEFAULT 0,
  order_set_execution_id BIGINT,
  created_by BIGINT NOT NULL,
  created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
  updated_by BIGINT,
  updated_at TIMESTAMP,

  CONSTRAINT fk_mo_patient FOREIGN KEY (patient_id) REFERENCES patients(patient_id),
  CONSTRAINT fk_mo_encounter FOREIGN KEY (encounter_id) REFERENCES encounters(encounter_id),
  CONSTRAINT fk_mo_provider FOREIGN KEY (ordering_provider_id) REFERENCES providers(provider_id),
  CONSTRAINT fk_mo_medication FOREIGN KEY (medication_id) REFERENCES medication_master(medication_id),
  CONSTRAINT fk_mo_signed_by FOREIGN KEY (signed_by) REFERENCES users(user_id),
  CONSTRAINT fk_mo_cosign_by FOREIGN KEY (cosign_by) REFERENCES users(user_id),
  CONSTRAINT fk_mo_entered_by FOREIGN KEY (entered_by) REFERENCES users(user_id),
  CONSTRAINT fk_mo_dual_verif FOREIGN KEY (dual_verification_by) REFERENCES users(user_id),
  CONSTRAINT fk_mo_created_by FOREIGN KEY (created_by) REFERENCES users(user_id),
  CONSTRAINT fk_mo_order_set FOREIGN KEY (order_set_execution_id) REFERENCES order_set_executions(execution_id),
  CONSTRAINT chk_order_type CHECK (order_type IN ('inpatient', 'outpatient', 'discharge')),
  CONSTRAINT chk_order_status CHECK (order_status IN ('draft', 'pending', 'active', 'completed', 'discontinued', 'cancelled')),
  CONSTRAINT chk_order_source CHECK (order_source IN ('direct', 'verbal', 'telephone', 'order_set')),
  CONSTRAINT chk_priority CHECK (priority IN ('stat', 'asap', 'today', 'routine')),
  CONSTRAINT chk_stop_after_start CHECK (stop_datetime IS NULL OR stop_datetime > start_datetime),
  CONSTRAINT chk_prn_indication CHECK (prn_flag = FALSE OR prn_indication IS NOT NULL),
  CONSTRAINT chk_controlled_class CHECK (
    is_controlled_substance = FALSE
    OR controlled_class IN ('CDa-Narcotic', 'CDa-Psychotropic', 'CDb')
  ),
  CONSTRAINT chk_uae_schedule CHECK (
    is_controlled_substance = FALSE
    OR uae_legal_schedule IN (
      'Schedule 1', 'Schedule 2', 'Schedule 3',
      'Schedule 4', 'Schedule 5', 'Schedule 6',
      'Schedule 7', 'Schedule 8', 'Schedule 9'
    )
  ),
  CONSTRAINT chk_uep_required CHECK (
    is_controlled_substance = FALSE OR uep_required = TRUE
  ),
  CONSTRAINT chk_self_prescribe CHECK (
    is_controlled_substance = FALSE
    OR dual_verification_by IS NULL
    OR ordering_provider_id != dual_verification_by
  ),
  CONSTRAINT chk_discontinue_reason CHECK (
    order_status != 'discontinued' OR discontinue_reason IS NOT NULL
  ),
  CONSTRAINT chk_cancel_reason CHECK (
    order_status != 'cancelled' OR cancel_reason IS NOT NULL
  )
);

CREATE INDEX idx_mo_patient ON medication_orders(patient_id);
CREATE INDEX idx_mo_provider ON medication_orders(ordering_provider_id);
CREATE INDEX idx_mo_encounter ON medication_orders(encounter_id);
CREATE INDEX idx_mo_status ON medication_orders(order_status);
CREATE INDEX idx_mo_datetime ON medication_orders(order_datetime);
CREATE INDEX idx_mo_active ON medication_orders(patient_id, order_status)
  WHERE order_status = 'active';
CREATE INDEX idx_mo_controlled ON medication_orders(is_controlled_substance, uep_submission_status)
  WHERE is_controlled_substance = TRUE;

FHIR Mapping: MedicationRequest

CPOE Field FHIR Path Notes
order_id MedicationRequest.id
patient_id MedicationRequest.subject Reference(Patient)
encounter_id MedicationRequest.encounter Reference(Encounter)
ordering_provider_id MedicationRequest.requester Reference(Practitioner)
medication_idrxnorm_code MedicationRequest.medicationCodeableConcept.coding System: http://www.nlm.nih.gov/research/umls/rxnorm
order_status MedicationRequest.status Mapping: draft→draft, pending→active, active→active, completed→completed, discontinued→stopped, cancelled→cancelled
dose + dose_unit MedicationRequest.dosageInstruction.doseAndRate.doseQuantity UCUM units
route MedicationRequest.dosageInstruction.route SNOMED CT coded
frequency MedicationRequest.dosageInstruction.timing FHIR Timing
prn_flag MedicationRequest.dosageInstruction.asNeededBoolean
prn_indication MedicationRequest.dosageInstruction.asNeededCodeableConcept SNOMED CT if coded
indication_code MedicationRequest.reasonCode ICD-10-AM
priority MedicationRequest.priority routine | urgent | asap | stat
sig MedicationRequest.dosageInstruction.text
order_source = 'verbal' MedicationRequest.reportedBoolean = true

laboratory_orders

Purpose: Stores all laboratory orders placed through CPOE.

Field Name Data Type Nullable Default Validation Description
order_id BIGINT NO GENERATED ALWAYS AS IDENTITY PK Primary key
patient_id BIGINT NO FK → patients.patient_id Patient
encounter_id BIGINT NO FK → encounters.encounter_id Encounter
ordering_provider_id BIGINT NO FK → providers.provider_id Ordering provider
loinc_code VARCHAR(20) NO LOINC format LOINC observation code
test_name VARCHAR(200) NO Lab test display name
cpt_code VARCHAR(10) YES CPT format Billing code
specimen_type VARCHAR(50) NO SNOMED CT coded Specimen type
order_status VARCHAR(20) NO 'pending' IN ('pending', 'collected', 'in-process', 'completed', 'cancelled') Status
order_source VARCHAR(20) NO 'direct' IN ('direct', 'verbal', 'telephone', 'order_set') Entry source
priority VARCHAR(20) NO 'routine' IN ('stat', 'today', 'routine') Priority
collection_datetime TIMESTAMP YES Requested collection time
collected_datetime TIMESTAMP YES Actual collection time
fasting_required BOOLEAN NO FALSE Fasting requirement
clinical_indication VARCHAR(10) YES ICD-10-AM Diagnosis code
clinical_indication_text VARCHAR(500) YES Free text indication
special_instructions TEXT YES Additional instructions
is_panel BOOLEAN NO FALSE Is part of a panel order
panel_name VARCHAR(100) YES Panel name if applicable
order_datetime TIMESTAMP NO CURRENT_TIMESTAMP Order placed time
signed_datetime TIMESTAMP YES Order signed time
signed_by BIGINT YES FK → users.user_id Signing user
result_datetime TIMESTAMP YES Result available time
order_set_execution_id BIGINT YES FK → order_set_executions.execution_id If from order set
created_by BIGINT NO FK → users.user_id Creator
created_at TIMESTAMP NO CURRENT_TIMESTAMP Created
updated_by BIGINT YES FK → users.user_id Updater
updated_at TIMESTAMP YES Updated

SQL DDL

SQL
CREATE TABLE laboratory_orders (
  order_id BIGINT PRIMARY KEY GENERATED ALWAYS AS IDENTITY,
  patient_id BIGINT NOT NULL,
  encounter_id BIGINT NOT NULL,
  ordering_provider_id BIGINT NOT NULL,
  loinc_code VARCHAR(20) NOT NULL,
  test_name VARCHAR(200) NOT NULL,
  cpt_code VARCHAR(10),
  specimen_type VARCHAR(50) NOT NULL,
  order_status VARCHAR(20) NOT NULL DEFAULT 'pending',
  order_source VARCHAR(20) NOT NULL DEFAULT 'direct',
  priority VARCHAR(20) NOT NULL DEFAULT 'routine',
  collection_datetime TIMESTAMP,
  collected_datetime TIMESTAMP,
  fasting_required BOOLEAN NOT NULL DEFAULT FALSE,
  clinical_indication VARCHAR(10),
  clinical_indication_text VARCHAR(500),
  special_instructions TEXT,
  is_panel BOOLEAN NOT NULL DEFAULT FALSE,
  panel_name VARCHAR(100),
  order_datetime TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
  signed_datetime TIMESTAMP,
  signed_by BIGINT,
  result_datetime TIMESTAMP,
  order_set_execution_id BIGINT,
  created_by BIGINT NOT NULL,
  created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
  updated_by BIGINT,
  updated_at TIMESTAMP,

  CONSTRAINT fk_lo_patient FOREIGN KEY (patient_id) REFERENCES patients(patient_id),
  CONSTRAINT fk_lo_encounter FOREIGN KEY (encounter_id) REFERENCES encounters(encounter_id),
  CONSTRAINT fk_lo_provider FOREIGN KEY (ordering_provider_id) REFERENCES providers(provider_id),
  CONSTRAINT fk_lo_signed_by FOREIGN KEY (signed_by) REFERENCES users(user_id),
  CONSTRAINT fk_lo_created_by FOREIGN KEY (created_by) REFERENCES users(user_id),
  CONSTRAINT fk_lo_order_set FOREIGN KEY (order_set_execution_id) REFERENCES order_set_executions(execution_id),
  CONSTRAINT chk_lo_status CHECK (order_status IN ('pending', 'collected', 'in-process', 'completed', 'cancelled')),
  CONSTRAINT chk_lo_source CHECK (order_source IN ('direct', 'verbal', 'telephone', 'order_set')),
  CONSTRAINT chk_lo_priority CHECK (priority IN ('stat', 'today', 'routine'))
);

CREATE INDEX idx_lo_patient ON laboratory_orders(patient_id);
CREATE INDEX idx_lo_encounter ON laboratory_orders(encounter_id);
CREATE INDEX idx_lo_status ON laboratory_orders(order_status);
CREATE INDEX idx_lo_datetime ON laboratory_orders(order_datetime);
CREATE INDEX idx_lo_loinc ON laboratory_orders(loinc_code);

FHIR Mapping: ServiceRequest

CPOE Field FHIR Path Notes
order_id ServiceRequest.id
patient_id ServiceRequest.subject Reference(Patient)
encounter_id ServiceRequest.encounter Reference(Encounter)
ordering_provider_id ServiceRequest.requester Reference(Practitioner)
loinc_code ServiceRequest.code.coding System: http://loinc.org
specimen_type ServiceRequest.specimen SNOMED CT
order_status ServiceRequest.status active | completed | revoked
priority ServiceRequest.priority routine | urgent | asap | stat
clinical_indication ServiceRequest.reasonCode ICD-10-AM

imaging_orders

Purpose: Stores all imaging / radiology orders placed through CPOE.

Field Name Data Type Nullable Default Validation Description
order_id BIGINT NO GENERATED ALWAYS AS IDENTITY PK Primary key
patient_id BIGINT NO FK → patients.patient_id Patient
encounter_id BIGINT NO FK → encounters.encounter_id Encounter
ordering_provider_id BIGINT NO FK → providers.provider_id Ordering provider
cpt_code VARCHAR(10) NO CPT format Procedure code
snomed_code VARCHAR(20) YES SNOMED CT Clinical procedure code
exam_name VARCHAR(200) NO Exam display name
modality VARCHAR(20) NO IN ('XR', 'CT', 'MRI', 'US', 'NM', 'IR', 'PET', 'FLUORO') Imaging modality
body_part VARCHAR(100) NO SNOMED CT coded Anatomical region
laterality VARCHAR(10) YES IN ('left', 'right', 'bilateral') Side
contrast_required BOOLEAN NO FALSE Contrast study
contrast_type VARCHAR(50) YES Iodinated / gadolinium / oral / rectal
exam_protocol VARCHAR(200) YES Protocol details (views, phases)
order_status VARCHAR(20) NO 'pending' IN ('pending', 'scheduled', 'in-progress', 'completed', 'cancelled') Status
order_source VARCHAR(20) NO 'direct' IN ('direct', 'verbal', 'telephone', 'order_set') Entry source
priority VARCHAR(20) NO 'routine' IN ('stat', 'urgent', 'routine') Priority
clinical_indication VARCHAR(10) NO ICD-10-AM Diagnosis code
clinical_question TEXT NO Clinical question for radiologist
pregnancy_status VARCHAR(20) YES IN ('not-pregnant', 'pregnant', 'unknown', 'not-applicable') Pregnancy attestation
portable_flag BOOLEAN NO FALSE Portable / bedside exam
scheduled_datetime TIMESTAMP YES Scheduled exam time
performed_datetime TIMESTAMP YES Actual exam time
appropriateness_score VARCHAR(30) YES ACR score if checked
cumulative_dose_msv DECIMAL(8,2) YES Estimated radiation dose
order_datetime TIMESTAMP NO CURRENT_TIMESTAMP Order placed
signed_datetime TIMESTAMP YES Order signed
signed_by BIGINT YES FK → users.user_id Signer
report_datetime TIMESTAMP YES Report available
order_set_execution_id BIGINT YES FK → order_set_executions.execution_id If from order set
created_by BIGINT NO FK → users.user_id Creator
created_at TIMESTAMP NO CURRENT_TIMESTAMP Created
updated_by BIGINT YES FK → users.user_id Updater
updated_at TIMESTAMP YES Updated

SQL DDL

SQL
CREATE TABLE imaging_orders (
  order_id BIGINT PRIMARY KEY GENERATED ALWAYS AS IDENTITY,
  patient_id BIGINT NOT NULL,
  encounter_id BIGINT NOT NULL,
  ordering_provider_id BIGINT NOT NULL,
  cpt_code VARCHAR(10) NOT NULL,
  snomed_code VARCHAR(20),
  exam_name VARCHAR(200) NOT NULL,
  modality VARCHAR(20) NOT NULL,
  body_part VARCHAR(100) NOT NULL,
  laterality VARCHAR(10),
  contrast_required BOOLEAN NOT NULL DEFAULT FALSE,
  contrast_type VARCHAR(50),
  exam_protocol VARCHAR(200),
  order_status VARCHAR(20) NOT NULL DEFAULT 'pending',
  order_source VARCHAR(20) NOT NULL DEFAULT 'direct',
  priority VARCHAR(20) NOT NULL DEFAULT 'routine',
  clinical_indication VARCHAR(10) NOT NULL,
  clinical_question TEXT NOT NULL,
  pregnancy_status VARCHAR(20),
  portable_flag BOOLEAN NOT NULL DEFAULT FALSE,
  scheduled_datetime TIMESTAMP,
  performed_datetime TIMESTAMP,
  appropriateness_score VARCHAR(30),
  cumulative_dose_msv DECIMAL(8,2),
  order_datetime TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
  signed_datetime TIMESTAMP,
  signed_by BIGINT,
  report_datetime TIMESTAMP,
  order_set_execution_id BIGINT,
  created_by BIGINT NOT NULL,
  created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
  updated_by BIGINT,
  updated_at TIMESTAMP,

  CONSTRAINT fk_io_patient FOREIGN KEY (patient_id) REFERENCES patients(patient_id),
  CONSTRAINT fk_io_encounter FOREIGN KEY (encounter_id) REFERENCES encounters(encounter_id),
  CONSTRAINT fk_io_provider FOREIGN KEY (ordering_provider_id) REFERENCES providers(provider_id),
  CONSTRAINT fk_io_signed_by FOREIGN KEY (signed_by) REFERENCES users(user_id),
  CONSTRAINT fk_io_created_by FOREIGN KEY (created_by) REFERENCES users(user_id),
  CONSTRAINT fk_io_order_set FOREIGN KEY (order_set_execution_id) REFERENCES order_set_executions(execution_id),
  CONSTRAINT chk_io_modality CHECK (modality IN ('XR', 'CT', 'MRI', 'US', 'NM', 'IR', 'PET', 'FLUORO')),
  CONSTRAINT chk_io_status CHECK (order_status IN ('pending', 'scheduled', 'in-progress', 'completed', 'cancelled')),
  CONSTRAINT chk_io_source CHECK (order_source IN ('direct', 'verbal', 'telephone', 'order_set')),
  CONSTRAINT chk_io_priority CHECK (priority IN ('stat', 'urgent', 'routine')),
  CONSTRAINT chk_io_laterality CHECK (laterality IS NULL OR laterality IN ('left', 'right', 'bilateral')),
  CONSTRAINT chk_io_pregnancy CHECK (pregnancy_status IS NULL OR pregnancy_status IN ('not-pregnant', 'pregnant', 'unknown', 'not-applicable'))
);

CREATE INDEX idx_io_patient ON imaging_orders(patient_id);
CREATE INDEX idx_io_encounter ON imaging_orders(encounter_id);
CREATE INDEX idx_io_status ON imaging_orders(order_status);
CREATE INDEX idx_io_modality ON imaging_orders(modality);
CREATE INDEX idx_io_datetime ON imaging_orders(order_datetime);

medication_master

Purpose: Reference table of all available medications. Includes UAE-specific controlled substance classification and EDE registration status.

SQL
CREATE TABLE medication_master (
  medication_id BIGINT PRIMARY KEY GENERATED ALWAYS AS IDENTITY,
  generic_name VARCHAR(200) NOT NULL,
  brand_name VARCHAR(200),
  rxnorm_code VARCHAR(20) NOT NULL UNIQUE,
  atc_code VARCHAR(10),
  drug_class VARCHAR(100) NOT NULL,
  available_strengths JSONB,
  available_forms JSONB,
  is_formulary BOOLEAN NOT NULL DEFAULT TRUE,
  formulary_tier VARCHAR(20),
  is_controlled_substance BOOLEAN NOT NULL DEFAULT FALSE,
  controlled_class VARCHAR(20),
  uae_legal_schedule VARCHAR(10),
  uep_required BOOLEAN NOT NULL DEFAULT FALSE,
  ede_registered BOOLEAN NOT NULL DEFAULT FALSE,
  ede_registration_number VARCHAR(50),
  formulary_alternatives JSONB,
  max_dose_per_day DECIMAL(10,3),
  max_dose_unit VARCHAR(20),
  renal_adjustment_required BOOLEAN NOT NULL DEFAULT FALSE,
  pediatric_dosing_available BOOLEAN NOT NULL DEFAULT FALSE,
  active_flag BOOLEAN NOT NULL DEFAULT TRUE,
  created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
  updated_at TIMESTAMP,

  CONSTRAINT chk_mm_controlled_class CHECK (
    is_controlled_substance = FALSE
    OR controlled_class IN ('CDa-Narcotic', 'CDa-Psychotropic', 'CDb')
  ),
  CONSTRAINT chk_mm_uae_schedule CHECK (
    is_controlled_substance = FALSE
    OR uae_legal_schedule IN (
      'Schedule 1', 'Schedule 2', 'Schedule 3',
      'Schedule 4', 'Schedule 5', 'Schedule 6',
      'Schedule 7', 'Schedule 8', 'Schedule 9'
    )
  ),
  CONSTRAINT chk_mm_uep CHECK (
    is_controlled_substance = FALSE OR uep_required = TRUE
  )
);

CREATE INDEX idx_mm_rxnorm ON medication_master(rxnorm_code);
CREATE INDEX idx_mm_generic ON medication_master(generic_name);
CREATE INDEX idx_mm_controlled ON medication_master(is_controlled_substance)
  WHERE is_controlled_substance = TRUE;
CREATE INDEX idx_mm_active ON medication_master(active_flag)
  WHERE active_flag = TRUE;

Terminology Bindings:

  • RxNorm: Primary medication identifier (rxnorm_code) — system: http://www.nlm.nih.gov/research/umls/rxnorm
  • ATC: WHO Anatomical Therapeutic Chemical code (atc_code) — system: http://www.whocc.no/atc
  • SNOMED CT: Drug class categorisation — mapped from drug_class
  • FHIR ValueSet: http://hl7.org/fhir/ValueSet/medication-codes

clinical_alerts

Purpose: Records all CDS alerts fired during order entry and their responses.

SQL
CREATE TABLE clinical_alerts (
  alert_id BIGINT PRIMARY KEY GENERATED ALWAYS AS IDENTITY,
  order_id BIGINT NOT NULL,
  order_table VARCHAR(30) NOT NULL,
  alert_type VARCHAR(50) NOT NULL,
  severity VARCHAR(20) NOT NULL,
  alert_message TEXT NOT NULL,
  interacting_entity VARCHAR(200),
  recommended_action TEXT,
  alert_datetime TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
  alert_response VARCHAR(30),
  override_reason_code VARCHAR(30),
  override_reason_text TEXT,
  response_user_id BIGINT,
  response_datetime TIMESTAMP,

  CONSTRAINT chk_ca_order_table CHECK (
    order_table IN ('medication_orders', 'laboratory_orders', 'imaging_orders')
  ),
  CONSTRAINT chk_ca_type CHECK (
    alert_type IN ('drug-allergy', 'drug-drug', 'dose-range', 'duplicate-therapy',
                   'renal-dosing', 'formulary', 'duplicate-test', 'pregnancy',
                   'appropriateness', 'contrast-safety', 'radiation-dose',
                   'controlled-substance', 'insurance-auth')
  ),
  CONSTRAINT chk_ca_severity CHECK (
    severity IN ('contraindicated', 'severe', 'major', 'moderate', 'minor', 'informational')
  ),
  CONSTRAINT chk_ca_response CHECK (
    alert_response IS NULL
    OR alert_response IN ('cancelled', 'overridden', 'accepted-alternative', 'acknowledged', 'co-signed')
  ),
  CONSTRAINT chk_ca_override_reason CHECK (
    alert_response != 'overridden'
    OR override_reason_code IN (
      'CLIN_NECESSITY', 'PRIOR_TOLERANCE', 'SHORT_DURATION',
      'ALLERGY_UNCERTAIN', 'NO_ALTERNATIVE', 'SPECIALIST_CONSULT',
      'PATIENT_PREFERENCE', 'INCORRECT_ALERT'
    )
  )
);

CREATE INDEX idx_ca_order ON clinical_alerts(order_id, order_table);
CREATE INDEX idx_ca_type ON clinical_alerts(alert_type, severity);
CREATE INDEX idx_ca_response ON clinical_alerts(alert_response);
CREATE INDEX idx_ca_datetime ON clinical_alerts(alert_datetime);

order_audit_log

Purpose: Immutable audit trail for all CPOE order lifecycle events. Required by UAE PDPL, ADHICS V2, and NABIDH.

SQL
CREATE TABLE order_audit_log (
  audit_id BIGINT PRIMARY KEY GENERATED ALWAYS AS IDENTITY,
  order_id BIGINT NOT NULL,
  order_table VARCHAR(30) NOT NULL,
  action VARCHAR(30) NOT NULL,
  user_id BIGINT NOT NULL,
  action_datetime TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
  workstation_id VARCHAR(50),
  ip_address INET,
  session_id VARCHAR(100),
  old_values JSONB,
  new_values JSONB,
  override_reason TEXT,
  alert_type VARCHAR(50),
  notes TEXT,

  CONSTRAINT fk_oal_user FOREIGN KEY (user_id) REFERENCES users(user_id),
  CONSTRAINT chk_oal_order_table CHECK (
    order_table IN ('medication_orders', 'laboratory_orders', 'imaging_orders')
  ),
  CONSTRAINT chk_oal_action CHECK (
    action IN ('created', 'signed', 'co-signed', 'modified', 'cancelled',
               'discontinued', 'transmitted', 'acknowledged', 'overridden',
               'uep-submitted', 'uep-approved', 'uep-rejected',
               'dual-verified', 'verbal-entered', 'break-the-glass')
  )
);

CREATE INDEX idx_oal_order ON order_audit_log(order_id, order_table);
CREATE INDEX idx_oal_user ON order_audit_log(user_id);
CREATE INDEX idx_oal_action ON order_audit_log(action, action_datetime);
CREATE INDEX idx_oal_datetime ON order_audit_log(action_datetime);

Retention: 2 years online, 5 years archived (ADHICS V2 / NESA T10). Audit log records must be immutable — no UPDATE or DELETE operations permitted.


pending_pharmacy_queue

Purpose: Working queue for pharmacy to verify and process medication orders.

SQL
CREATE TABLE pending_pharmacy_queue (
  queue_id BIGINT PRIMARY KEY GENERATED ALWAYS AS IDENTITY,
  order_id BIGINT NOT NULL UNIQUE,
  priority VARCHAR(20) NOT NULL,
  queue_status VARCHAR(30) NOT NULL DEFAULT 'pending',
  is_controlled_substance BOOLEAN NOT NULL DEFAULT FALSE,
  received_datetime TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
  assigned_pharmacist_id BIGINT,
  verified_datetime TIMESTAMP,
  verified_by BIGINT,
  dispensed_datetime TIMESTAMP,
  dispensed_by BIGINT,
  rejection_reason TEXT,
  notes TEXT,

  CONSTRAINT fk_ppq_order FOREIGN KEY (order_id) REFERENCES medication_orders(order_id),
  CONSTRAINT fk_ppq_assigned FOREIGN KEY (assigned_pharmacist_id) REFERENCES users(user_id),
  CONSTRAINT fk_ppq_verified FOREIGN KEY (verified_by) REFERENCES users(user_id),
  CONSTRAINT chk_ppq_status CHECK (
    queue_status IN ('pending', 'in-review', 'verified', 'dispensed',
                     'rejected', 'on-hold', 'cancelled')
  ),
  CONSTRAINT chk_ppq_priority CHECK (priority IN ('stat', 'asap', 'today', 'routine'))
);

CREATE INDEX idx_ppq_status ON pending_pharmacy_queue(queue_status, priority);
CREATE INDEX idx_ppq_controlled ON pending_pharmacy_queue(is_controlled_substance)
  WHERE is_controlled_substance = TRUE;

order_sets

Purpose: Master definition of re-usable order set templates.

SQL
CREATE TABLE order_sets (
  order_set_id BIGINT PRIMARY KEY GENERATED ALWAYS AS IDENTITY,
  set_name VARCHAR(200) NOT NULL,
  set_code VARCHAR(50) NOT NULL UNIQUE,
  description TEXT,
  clinical_category VARCHAR(100),
  target_diagnoses JSONB,
  approved_by VARCHAR(200),
  approved_datetime TIMESTAMP,
  review_due_date DATE,
  active_flag BOOLEAN NOT NULL DEFAULT TRUE,
  version INT NOT NULL DEFAULT 1,
  facility_id BIGINT,
  created_by BIGINT NOT NULL,
  created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
  updated_at TIMESTAMP,

  CONSTRAINT fk_os_facility FOREIGN KEY (facility_id) REFERENCES facilities(facility_id),
  CONSTRAINT fk_os_created_by FOREIGN KEY (created_by) REFERENCES users(user_id)
);

order_set_items

Purpose: Individual order line items within an order set template.

SQL
CREATE TABLE order_set_items (
  item_id BIGINT PRIMARY KEY GENERATED ALWAYS AS IDENTITY,
  order_set_id BIGINT NOT NULL,
  item_type VARCHAR(20) NOT NULL,
  display_order INT NOT NULL,
  item_name VARCHAR(200) NOT NULL,
  default_values JSONB NOT NULL,
  is_required BOOLEAN NOT NULL DEFAULT FALSE,
  is_conditional BOOLEAN NOT NULL DEFAULT FALSE,
  condition_expression TEXT,
  time_offset_minutes INT DEFAULT 0,

  CONSTRAINT fk_osi_set FOREIGN KEY (order_set_id) REFERENCES order_sets(order_set_id),
  CONSTRAINT chk_osi_type CHECK (
    item_type IN ('medication', 'laboratory', 'imaging', 'nursing', 'dietary', 'consult')
  )
);

CREATE INDEX idx_osi_set ON order_set_items(order_set_id, display_order);

order_set_executions

Purpose: Tracks each time an order set is executed for a patient.

SQL
CREATE TABLE order_set_executions (
  execution_id BIGINT PRIMARY KEY GENERATED ALWAYS AS IDENTITY,
  order_set_id BIGINT NOT NULL,
  patient_id BIGINT NOT NULL,
  encounter_id BIGINT NOT NULL,
  executed_by BIGINT NOT NULL,
  executed_datetime TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
  items_selected INT NOT NULL,
  items_total INT NOT NULL,
  items_modified INT NOT NULL DEFAULT 0,

  CONSTRAINT fk_ose_set FOREIGN KEY (order_set_id) REFERENCES order_sets(order_set_id),
  CONSTRAINT fk_ose_patient FOREIGN KEY (patient_id) REFERENCES patients(patient_id),
  CONSTRAINT fk_ose_encounter FOREIGN KEY (encounter_id) REFERENCES encounters(encounter_id),
  CONSTRAINT fk_ose_user FOREIGN KEY (executed_by) REFERENCES users(user_id)
);

controlled_substance_inventory

Purpose: Perpetual inventory tracking for all controlled substances (CDa and CDb) as required by MOH Federal Decree-Law No. 30/2021.

SQL
CREATE TABLE controlled_substance_inventory (
  inventory_id BIGINT PRIMARY KEY GENERATED ALWAYS AS IDENTITY,
  medication_id BIGINT NOT NULL,
  facility_id BIGINT NOT NULL,
  controlled_class VARCHAR(20) NOT NULL,
  uae_legal_schedule VARCHAR(10) NOT NULL,
  transaction_type VARCHAR(20) NOT NULL,
  quantity DECIMAL(10,2) NOT NULL,
  balance_after DECIMAL(10,2) NOT NULL,
  lot_number VARCHAR(50),
  expiry_date DATE,
  source_document VARCHAR(100),
  order_id BIGINT,
  witnessed_by BIGINT,
  performed_by BIGINT NOT NULL,
  performed_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
  notes TEXT,

  CONSTRAINT fk_csi_medication FOREIGN KEY (medication_id) REFERENCES medication_master(medication_id),
  CONSTRAINT fk_csi_facility FOREIGN KEY (facility_id) REFERENCES facilities(facility_id),
  CONSTRAINT fk_csi_order FOREIGN KEY (order_id) REFERENCES medication_orders(order_id),
  CONSTRAINT fk_csi_witnessed FOREIGN KEY (witnessed_by) REFERENCES users(user_id),
  CONSTRAINT fk_csi_performed FOREIGN KEY (performed_by) REFERENCES users(user_id),
  CONSTRAINT chk_csi_class CHECK (controlled_class IN ('CDa-Narcotic', 'CDa-Psychotropic', 'CDb')),
  CONSTRAINT chk_csi_schedule CHECK (
    uae_legal_schedule IN (
      'Schedule 1', 'Schedule 2', 'Schedule 3',
      'Schedule 4', 'Schedule 5', 'Schedule 6',
      'Schedule 7', 'Schedule 8', 'Schedule 9'
    )
  ),
  CONSTRAINT chk_csi_transaction CHECK (
    transaction_type IN ('receipt', 'dispensing', 'return', 'disposal', 'adjustment')
  ),
  CONSTRAINT chk_disposal_witness CHECK (
    transaction_type != 'disposal' OR witnessed_by IS NOT NULL
  )
);

CREATE INDEX idx_csi_reporting ON controlled_substance_inventory(
  facility_id, controlled_class, transaction_type, performed_at
);
CREATE INDEX idx_csi_medication ON controlled_substance_inventory(medication_id);
CREATE INDEX idx_csi_balance ON controlled_substance_inventory(medication_id, facility_id);

Retention: Controlled substance records must be retained perpetually (Federal Decree-Law 30/2021). Archive after 10 years but never delete.


Reference Tables Summary

Table Purpose Source Standard Sample Size
order_frequencies Dosing frequencies (QD, BID, TID, Q6H, PRN, etc.) Institution-defined ~30 entries
medication_routes Routes of administration (PO, IV, IM, SC, topical, etc.) SNOMED CT ~25 entries
dose_units Units (mg, g, mL, mcg, units, mEq, etc.) UCUM ~20 entries
interaction_severity CDS alert severity levels Institution-defined 6 levels
override_reason_codes Standard override justifications Institution-defined 8 codes
imaging_modalities XR, CT, MRI, US, NM, IR, PET, FLUORO DICOM 8 entries

See 06-master-data.md for detailed reference data specifications and setup sequences.


Terminology Binding Summary

Standard CPOE Usage Tables Field(s)
RxNorm Medication identification medication_master, medication_orders rxnorm_code
LOINC Laboratory test identification laboratory_orders loinc_code
CPT Procedure / imaging / billing codes imaging_orders, laboratory_orders cpt_code
SNOMED CT Routes, specimen types, body parts, clinical terms Multiple route, specimen_type, body_part, snomed_code
ICD-10-AM Clinical indications medication_orders, laboratory_orders, imaging_orders indication_code, clinical_indication
ATC Drug classification medication_master atc_code
UCUM Units of measure (for FHIR) Mapped from dose_unit
content/clinical/cpoe/03-data-specifications.md Generated 2026-02-20 22:54