Kulcare Docs
DeveloperCare plansCare planBackend

Prescription Entity Relationship Diagram (ERD)

Overview

This document provides a comprehensive Entity Relationship Diagram (ERD) for the prescription system and its associated tables within the Kulcare platform. The prescription system serves as the central hub for patient healthcare data, connecting encounters, medications, problems, vitals, and FHIR-compliant health records.

Table of Contents

  1. Core Prescription Tables
  2. FHIR Compliance Tables
  3. Patient Health Data Tables
  4. Template and Configuration Tables
  5. Supporting Tables
  6. Complete ERD Diagram
  7. Key Relationships
  8. Migration Notes

Core Prescription Tables

Primary Entity Relationship


Prescription Components

Prescription Details Tables


FHIR Compliance Tables

FHIR Resources Linked to Prescriptions


Patient Health Data Tables

Patient Medicines and Problems


Template and Configuration Tables

Doctor Templates


Supporting Tables

Orders, Documents, and Sharing


Complete ERD Diagram

High-Level System Overview


Key Relationships

1. Prescription Central Hub

  • Prescriptions serve as the central entity connecting all healthcare data
  • Links to Doctors, Patients, Clinics, and ClinicPatients
  • Polymorphic association with events (usually Appointments)

2. Prescription Components

  • PrescriptionMedicines: Medications prescribed during encounter
  • PrescriptionComplaints: Chief complaints reported by patient
  • PrescriptionTestLists: Ordered laboratory tests and investigations
  • PrescriptionProcedures: Procedures performed or recommended
  • PrescriptionAdvices: General advice given to patient
  • PrescriptionDiets: Dietary recommendations

3. Patient Health Records

  • PatientMedicines: Long-term medication records with alerts
  • PatientProblems: Ongoing health conditions and problems
  • PatientVitals: Vital signs recorded during visits

4. FHIR Compliance

  • ClinicalImpressions: FHIR-compliant clinical assessments
  • MedicationRequests: FHIR medication prescriptions
  • ServiceRequests: FHIR service and test orders
  • ClinicalObservations: FHIR clinical observations
  • DiagnosticReports: FHIR diagnostic reports
  • CarePlans: FHIR care coordination plans (created for chronic conditions)

5. Templates and Configuration

  • DoctorPrescriptionTemplates: Reusable prescription templates
  • BasicVitals: Vital sign configurations with normal ranges
  • VitalNormalRanges: Age and gender-specific normal ranges

6. Supporting Systems

  • PharmacyOrders: Prescription fulfillment tracking
  • LabOrders: Laboratory test order tracking
  • Documents: Prescription documents and files
  • SharedPrescriptions: Prescription sharing functionality
  • SystemLogs: Audit trail for all prescription activities

7. FHIR Care Plan Creation

  • CarePlans are automatically created during prescription finalization for patients with chronic conditions
  • Links directly to the prescription that triggered the care plan creation
  • Chronic Condition Criteria: Patient problems with status ['chronic', 'active'] and severity ['high', 'critical']
  • FHIR Compliance: Follows FHIR CarePlan structure with goals, activities, and care team coordination
  • Traceability: prescription_id provides direct link to triggering prescription for audit and context

Migration Notes

Table Renaming (Careplan → Prescription)

The following tables were renamed during the careplan-to-prescription migration:

Old Table NameNew Table Name
careplansprescriptions
careplan_medicinesprescription_medicines
careplan_complaintsprescription_complaints
careplan_test_listsprescription_test_lists
careplan_testsprescription_tests
careplan_proceduresprescription_procedures
careplan_advicesprescription_advices
careplan_dietsprescription_diets
doctor_careplan_templatesdoctor_prescription_templates
careplan_template_medicinesprescription_template_medicines
careplan_template_test_listsprescription_template_test_lists
careplan_template_testsprescription_template_tests

Foreign Key Updates

  • All careplan_id columns renamed to prescription_id
  • Polymorphic references updated from 'Careplan' to 'Prescription'
  • Foreign key constraints maintained during migration

Backward Compatibility

  • SystemLog constants preserved as CAREPLAN_* for audit compatibility
  • Some settings preserved as send_careplan_sms for mobile app compatibility
  • All model associations updated to use new foreign keys

Usage Examples

Creating a Complete Prescription

# Create prescription with all components
prescription = Prescription.create!(
  doctor: doctor,
  patient: patient,
  clinic_patient: clinic_patient,
  clinic: clinic,
  diagnosis: ["Hypertension", "Type 2 Diabetes"],
  observations: "Patient stable, BP elevated",
  is_final: false
)

# Add medicines
prescription.prescription_medicines.create!(
  medicine_name: "Metformin",
  dosage: ["B", "D"],
  frequency: "BID",
  duration_unit: "30",
  duration_frequency: "DAYS"
)

# Add complaints
prescription.prescription_complaints.create!(
  name: "Headache",
  description: "Persistent headache for 3 days"
)

# Finalize prescription (triggers FHIR resource creation)
prescription.update!(is_final: true)

Querying Patient Health Data

# Get all prescriptions for a patient
patient.prescriptions.final.order_by_latest

# Get current medications
patient.patient_medicines.active

# Get active problems
patient.patient_problems.active

# Get recent vitals
patient.patient_vitals.joins(:basic_vital)
  .where(created_at: 1.month.ago..Time.current)

This ERD provides a comprehensive view of the prescription system's data architecture, enabling effective development, maintenance, and extension of the healthcare platform's core functionality.

On this page