Overview
The Prescriptions module manages medication documentation in Nguhöe EHR. Prescriptions are created from consultations and can be previewed or downloaded as professional PDF documents using the dompdf library.All authenticated users can access prescriptions based on their role. The system enforces strict access control to ensure privacy.
Prescription Data Model
Core Fields
| Field | Type | Description |
|---|---|---|
consultation_id | foreign key | Link to the consultation |
patient_id | foreign key | Reference to patient |
doctor_id | foreign key | Reference to prescribing doctor |
items | JSON array | Medication items with dosage |
general_instructions | text | General instructions for all medications |
Medication Items Structure
Theitems field is a JSON array containing medication details:
The items array is automatically cast to/from JSON by Laravel’s Eloquent (Prescription.php:22-24).
Creating Prescriptions
Prescriptions are created automatically when a consultation includes prescription items:CreateConsultationAction handles prescription creation:
- Consultation is created
- If prescription items exist, create prescription
- Link prescription to consultation, patient, and doctor
Prescription Item Fields
medication (required)
medication (required)
Name and strength of the medicationExamples:
- “Metformina 850mg”
- “Losartan 50mg”
- “Omeprazol 20mg”
dosage (required)
dosage (required)
Amount to take per doseExamples:
- “1 tableta”
- “2 cápsulas”
- “10 ml”
frequency (optional)
frequency (optional)
How often to take the medicationExamples:
- “Cada 8 horas”
- “Dos veces al día”
- “Una vez al día en ayunas”
duration (optional)
duration (optional)
How long to continue treatmentExamples:
- “7 días”
- “1 mes”
- “Uso continuo”
PDF Generation with dompdf
Prescriptions are rendered as professional PDF documents using the dompdf library.Preview Prescription
Display the prescription PDF in the browser: Route:prescriptions.preview → PrescriptionController@showEndpoint:
GET /prescriptions/{prescription}/preview
Download Prescription
Download the prescription as a PDF file: Route:prescriptions.download → PrescriptionController@downloadEndpoint:
GET /prescriptions/{prescription}/download
Filenames are automatically generated with patient name and date:
receta-Juan-Perez-20260304.pdfGeneratePrescriptionPdfAction
TheGeneratePrescriptionPdfAction class handles PDF generation:
- Loads prescription with patient and doctor data
- Renders a Blade template with prescription details
- Converts HTML to PDF using dompdf
- Returns the PDF object for streaming or downloading
Access Control
Strict access control ensures prescription privacy (PrescriptionController.php:14-42):Admin
Admin
- View and download all prescriptions
- Full access to preview and PDF generation
Doctor
Doctor
- View and download only prescriptions they created
- Access through consultation link
Patient
Patient
- View and download only their own prescriptions
- Access through patient portal
Receptionist
Receptionist
- View and download all prescriptions
- Needed for printing and delivery to patients
Patient Portal Access
Patients can view their prescriptions through the dedicated portal: Route:patient.prescriptions → PatientPortalController@prescriptionsEndpoint:
GET /my-prescriptions
- View list of all their prescriptions
- Preview prescriptions in browser
- Download prescription PDFs
- See which doctor prescribed each medication
Relationships
Database Schema
UI Workflow
Example Usage
Creating a Multi-Item Prescription
Accessing Prescription Data
Best Practices
Complete Information
Always include medication, dosage, and frequency for patient safety
Clear Instructions
Use plain language that patients can understand
Duration Specified
Always specify how long to take the medication
General Instructions
Add important warnings or follow-up instructions