DeveloperCare plansBackend
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
- Core Prescription Tables
- FHIR Compliance Tables
- Patient Health Data Tables
- Template and Configuration Tables
- Supporting Tables
- Complete ERD Diagram
- Key Relationships
- 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_idprovides 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 Name | New Table Name |
|---|---|
careplans | prescriptions |
careplan_medicines | prescription_medicines |
careplan_complaints | prescription_complaints |
careplan_test_lists | prescription_test_lists |
careplan_tests | prescription_tests |
careplan_procedures | prescription_procedures |
careplan_advices | prescription_advices |
careplan_diets | prescription_diets |
doctor_careplan_templates | doctor_prescription_templates |
careplan_template_medicines | prescription_template_medicines |
careplan_template_test_lists | prescription_template_test_lists |
careplan_template_tests | prescription_template_tests |
Foreign Key Updates
- All
careplan_idcolumns renamed toprescription_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_smsfor 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.