Comprehensive Technical Documentation & Architecture Reference
The Backend Electronic Medical Record (EMR) system is a robust, clinical application designed to support family-centered community healthcare. It serves as the primary system of record, hosting patient registration details, location hierarchies, doctor and provider scheduling, home visits, clinical consultations, billing, and system audit trails.
The backend is built as a web application that exposes administrative panels to clinic operators, care teams, and billing clerks, while also exposing standard REST APIs for bidirectional synchronization with offline-first Flutter mobile applications.
The application strictly enforces separation of concerns through clean design patterns.
To avoid thick controllers, the system isolates business rules inside dedicated Service classes under the app/Services/ directory. Controllers are responsible only for request validation, authorization checks, routing response models, and flash messaging, while services contain Eloquent queries, transaction wrappers, and state mutations.
Cross-cutting model functionalities are structured as Traits in the app/Traits/ directory:
HasUuid: Automatically registers boot listeners to assign a UUIDv4 string during model creation. This UUID is critical for offline-mobile synchronization as it acts as a immutable, globally unique lookup key, preventing primary key collisions when inserting records from mobile clients.
Auditable: Registers observers to automatically record database state changes. It logs the user who made the change, the event type (created, updated, deleted), the original values, the updated values, the active request URL, IP address, and client User-Agent. Sensitive columns (such as password and remember_token) are automatically filtered out.
The schema maps out clinical structures, administrative bounds, and geographical groupings. The key database tables and models are defined as follows:
| Model Name | Table Name | Core Responsibilities & Fields |
|---|---|---|
| User | users |
Standard authentication model. Belongs to many roles. Can be associated directly with a Family (as a contact) or a Doctor. |
| Doctor | doctors |
Represents medical practitioners. Contains specialty, active state, and links to assigned families and home_visits. |
| Family | families |
Household group profile. Tracks active/inactive status, socioeconomic parameters, water supply details, and dynamic health risk scores. |
| Patient | patients |
Detailed clinical file. Structured into 16 sections (details below). Belongs to a family household. |
| HomeVisit | home_visits |
Scheduling engine records. Statuses include: scheduled, completed, and missed. |
| Consultation | consultations |
Full clinical encounter log. Records vitals, pathological history, medications, vaccinations, and follow-up plans. |
| Payment | payments |
Billing transactions. Tracks mobile money provider (MTN, Airtel, Zamtel) and transaction reference. |
| Subscription | subscriptions |
Tracks subscription status and billing periods for families. |
| Attachment | attachments |
Polymorphic uploads (images, PDFs) linked to payments (receipts) or consultations (clinical files). |
To coordinate field health initiatives, locations are stored in a rigid parent-child hierarchy:
Families and Patients are assigned a village_id, placing them precisely within the administrative jurisdiction of specific clinics and health workers.
The Patient model features a massive schema designed to hold a complete, holistic health record:
A core feature of the EMR is the dynamic health score evaluation running inside the Family model's saving hook. Every time a family profile or a related patient file is updated, the system recalculates the family_health_score (a weighted cap value from 0 to 100) and updates the family_health_risk_level.
| Health Score Range | Risk Level Classification | Clinical Action Priority |
|---|---|---|
| 0 – 25 | Low Risk | Routine annual wellness check-up. |
| 26 – 50 | Moderate Risk | Bi-annual checkups, targeted health education. |
| 51 – 75 | High Risk | Quarterly visits, medical provider care coordination. |
| 76 – 100 | Very High Risk | Priority monthly clinical intervention and active follow-up. |
The backend secures routes and resources using role-based gates defined in AppServiceProvider and checked via Laravel's can: middleware or policy files.
Users with the family-contact role are logged in directly to a custom, self-service dashboard (dashboard.family-portal) instead of the admin dashboard. This portal lets them interact directly with their allocated care team and manages their billing.
VisitRequested notification to the practitioner.
DoctorContacted alert to the doctor.
PaymentSubmitted notification to the billing team.
RefillRequested notification.