Authentication
All endpoints require:- Middleware:
auth,verified
Authorization
Access to prescriptions is controlled by theauthorizeAccess() method with role-based rules:
- Admin: Full access to all prescriptions
- Doctor: Access to prescriptions from their own consultations
- Patient: Access to their own prescriptions only
- Receptionist: Full access (for distributing prescriptions to patients)
Endpoints
Download Prescription
Path Parameters
Prescription ID
Response
Returns a downloadable PDF file with filename format:receta-Juan Perez-20260304.pdf
Headers
Preview Prescription
Path Parameters
Prescription ID
Response
Returns a PDF stream for inline browser viewing.Headers
Authorization Logic
The controller validates access using the following logic:Admin Role
Doctor Role
Patient Role
Receptionist Role
PDF Generation
Prescriptions are generated using theGeneratePrescriptionPdfAction action class.
Required Relationships
Before generating the PDF, the consultation relationship must be loaded:Prescription Data Structure
Prescription model with relationships
Prescription ID
Associated consultation ID
Patient ID
Patient information (name, document ID, etc.)
Prescribing doctor ID
Doctor information (name, credentials)
General prescription instructions
Prescription creation timestamp
Implementation Details
- Source:
app/Http/Controllers/PrescriptionController.php - Routes:
/prescriptions/{prescription}/downloadand/prescriptions/{prescription}/preview - Uses action class:
GeneratePrescriptionPdfAction - Soft deletes enabled on Prescription model
- Relationships:
consultation,patient,doctor
Security Considerations
- Server-Side Validation: All access checks are performed server-side before PDF generation
- Consultation Loading: The consultation relationship must be loaded for doctor ownership validation
- Patient Matching: Patient role access requires matching the patient record linked to the user account
- No Direct Database IDs in URLs: Uses route model binding for secure ID resolution
Use Cases
Doctor Workflow
- Create consultation with prescription data via Consultation Controller
- Preview prescription:
GET /prescriptions/{id}/preview - Share download link with patient
Patient Workflow
- View consultation history on patient portal
- Download prescription:
GET /prescriptions/{id}/download - Print or save PDF for pharmacy
Receptionist Workflow
- Access patient record
- Print prescription:
GET /prescriptions/{id}/download - Provide physical copy to patient
Error Responses
403 Forbidden
404 Not Found
Returned when prescription ID doesn’t exist or has been soft deleted.Related Resources
- Consultation Controller - Create consultations with prescriptions
- Patient Controller - View patient prescription history