mariozabala / prescription
Medical prescription package
Requires
- php: ^8.1|^8.2|^8.3
- ext-json: *
- illuminate/support: ^10.0|^11.0|^12.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.23
- larastan/larastan: ^2.9|^3.0
- orchestra/testbench: ^8.9.0|^9.0|^10.0
- phpunit/phpunit: ^10.3.2|^11.0
This package is auto-updated.
Last update: 2026-08-23 18:04:03 UTC
README
A robust, developer-friendly Laravel package providing a RESTful API scaffolding for managing medical prescriptions, patients, and medications. Features layered architecture (Action/Manager + Repository pattern), automatic query caching with cache eviction, asynchronous queued email notifications, and automated audit logging.
Requirements
Ensure your environment satisfies the following minimum requirements:
| Dependency | Supported Versions |
|---|---|
| PHP | ^8.1 | ^8.2 | ^8.3 |
Laravel Framework (illuminate/support) |
^10.0 | ^11.0 | ^12.0 |
| Ext-JSON | * |
Installation
Install the package into your Laravel application via Composer:
composer require mariozabala/prescription
Note
VCS Repository Installation
If you are installing directly from a private or standalone Git repository before it is published to Packagist, add the VCS repository entry to your root composer.json:
{
"repositories": [
{
"type": "vcs",
"url": "https://github.com/mariozabala/prescriptions"
}
],
"require": {
"mariozabala/prescription": "^1.0"
}
}
1. Run Database Migrations
Run the package migrations to set up the patients, prescriptions, drugs, and audit log tables:
php artisan migrate
2. Publish Package Assets
Publish the configuration file to config/prescription.php:
php artisan vendor:publish --provider="MarioZabala\Prescription\PrescriptionServiceProvider" --tag="config"
Publish localization and language files:
php artisan vendor:publish --provider="MarioZabala\Prescription\PrescriptionServiceProvider" --tag="locale"
Configuration
The published configuration file is located at config/prescription.php:
<?php return [ /* |-------------------------------------------------------------------------- | Route Middleware |-------------------------------------------------------------------------- | | Define the middleware pipeline applied to all package API routes. | By default this is empty; for production APIs, attach your authentication | middleware (such as Sanctum or Passport) and rate limiting. | */ 'middleware' => [ 'api', 'auth:sanctum', ], /* |-------------------------------------------------------------------------- | Notification Emails |-------------------------------------------------------------------------- | | List of email addresses that will receive asynchronous notifications | whenever patient, prescription, or drug entities are created, updated, | or deleted. Leave empty to disable email notifications. | */ 'notificationEmails' => [ 'prescriptions-audit@hospital.org', ], ];
Localization & Translations
The package supports English (en) and Spanish (es) locales out of the box. Published language files are stored in lang/ (or resources/lang/ in earlier Laravel versions):
lang/
├── en/
│ └── prescription.php
└── es/
└── prescription.php
API Documentation
All routes are prefixed with /api and respect the middleware configured in config/prescription.php.
1. Patients (/api/patient)
Manage patient demographic and identification data.
| Method | Endpoint | Description | Status Code |
|---|---|---|---|
GET |
/api/patient |
Retrieve all patients (cached) | 200 OK |
POST |
/api/patient |
Create a new patient | 201 Created |
GET |
/api/patient/{id} |
Retrieve a single patient | 200 OK / 404 Not Found |
PUT |
/api/patient/{id} |
Update an existing patient | 200 OK / 400 Bad Request |
DELETE |
/api/patient/{id} |
Delete a patient | 200 OK / 400 Bad Request |
GET |
/api/patient/filter |
Query patients by attributes (name, lastname, id_card) |
200 OK |
Create / Update Request Body (POST /api/patient, PUT /api/patient/{id})
{
"name": "Jane",
"lastname": "Doe",
"id_card": "12345678X"
}
Example Filter Request
GET /api/patient/filter?lastname=Doe&id_card=12345678X HTTP/1.1
2. Prescriptions (/api/prescription)
Manage medical prescriptions associated with patients.
| Method | Endpoint | Description | Status Code |
|---|---|---|---|
GET |
/api/prescription |
Retrieve all prescriptions (cached) | 200 OK |
POST |
/api/prescription |
Create a new prescription | 201 Created |
GET |
/api/prescription/{id} |
Retrieve a prescription with patient details | 200 OK / 404 Not Found |
PUT |
/api/prescription/{id} |
Reassign prescription to another patient | 200 OK / 400 Bad Request |
DELETE |
/api/prescription/{id} |
Delete a prescription and associated drugs | 200 OK / 400 Bad Request |
GET |
/api/prescription/filter |
Query prescriptions by patient_id |
200 OK |
Create / Update Request Body (POST /api/prescription, PUT /api/prescription/{id})
{
"patient_id": 1
}
3. Drugs (/api/drug)
Manage medications and dosages attached to prescriptions.
| Method | Endpoint | Description | Status Code |
|---|---|---|---|
GET |
/api/drug |
Retrieve all medications (cached) | 200 OK |
POST |
/api/drug |
Add a medication to a prescription | 201 Created |
GET |
/api/drug/{id} |
Retrieve details for a specific medication | 200 OK / 404 Not Found |
PUT |
/api/drug/{id} |
Update medication dosage or code | 200 OK / 400 Bad Request |
DELETE |
/api/drug/{id} |
Remove a medication | 200 OK / 400 Bad Request |
GET |
/api/drug/filter |
Filter by prescription_id, name, or code |
200 OK |
Create / Update Request Body (POST /api/drug, PUT /api/drug/{id})
{
"prescription_id": 1,
"name": "Amoxicillin",
"code": 1234567,
"posology": "500mg orally every 8 hours for 7 days"
}
Architectural Highlights
- Action / Manager Pattern: Business operations are encapsulated into dedicated Manager classes (
CreatePatient,FilterDrugs, etc.). - Repository & Caching Layer: Repositories abstract persistence logic and utilize automated Cache invalidation on all write operations (
create,update,delete). - Audit Trail: Dispatched events trigger auditor listeners that record full JSON snapshots of operations in
patient_logs,prescription_logs, anddrug_logs. - Asynchronous Notifications: Email listeners implement
ShouldQueueto ensure HTTP API responses remain non-blocking.
Testing & Quality Assurance
Run the test suite and static analysis locally or in Docker:
# Execute PHPUnit test suite ./vendor/bin/phpunit tests # Execute PHPStan static analysis ./vendor/bin/phpstan analyse --memory-limit=2G # Execute code formatting fixer ./vendor/bin/php-cs-fixer fix src --verbose --diff # Or run the integrated fixer script inside Docker docker exec prescriptions-dev ./fixer.sh
Disclaimer & Compliance
Warning
Healthcare Data Privacy & Regulatory Notice
This package provides an architectural blueprint and API scaffolding for educational, evaluation, and integration purposes.
When deploying applications handling real Protected Health Information (PHI) or Personally Identifiable Information (PII), developers and system administrators are solely responsible for ensuring compliance with applicable healthcare regulations:
- GDPR & LOPDGDD (European Union & Spain)
- HIPAA / HITECH (United States)
Production Hardening Recommendations:
- Field-Level Encryption: Encrypt sensitive patient identification columns (e.g.,
id_card,name,lastname) at rest using Laravel's$casts = ['id_card' => 'encrypted']. - Authentication & RBAC: Enforce granular Role-Based Access Control (e.g.
spatie/laravel-permission) on all prescription write and audit endpoints. - Audit Log Protection: Store audit logs in immutable or append-only storage for regulatory compliance.
- TLS/HTTPS: Enforce HTTPS with HSTS across all API transport layers.
License
This package is open-sourced software licensed under the MIT License.