Skip to content

API Overview

The CPR backend exposes a RESTful JSON API under /api/v1. All endpoints require authentication via Laravel Sanctum unless noted otherwise.

Base URL

http://localhost:8000/api/v1     # Development
https://your-domain.com/api/v1   # Production

Required Headers

http
Content-Type: application/json
Accept: application/json
Authorization: Bearer {token}
X-Branch-Id: {branch_id}          # Required for branch-scoped routes

Response Format

Success Response

json
{
  "message": "Patient created successfully",
  "data": {
    "id": 1,
    "pin": "MAIN-000123",
    "first_name": "Juan",
    "last_name": "Dela Cruz"
  }
}

Paginated Response

json
{
  "data": [...],
  "links": {
    "first": "/api/v1/patients?page=1",
    "last": "/api/v1/patients?page=5",
    "prev": null,
    "next": "/api/v1/patients?page=2"
  },
  "meta": {
    "current_page": 1,
    "from": 1,
    "last_page": 5,
    "per_page": 15,
    "to": 15,
    "total": 72
  }
}

Error Response

json
{
  "message": "The given data was invalid.",
  "errors": {
    "email": ["The email must be a valid email address."]
  }
}

HTTP Status Codes

CodeDescription
200Success
201Resource created
400Missing branch context
401Unauthenticated (invalid/missing token)
403Forbidden (no permission or branch access)
404Resource not found
422Validation errors
429Rate limit exceeded
500Server error

Endpoint Groups

Public (No Auth Required)

MethodEndpointDescription
GET/public/healthHealth check

Authentication

MethodEndpointDescription
POST/auth/loginLogin
POST/auth/logoutLogout
GET/auth/profileGet profile
PUT/auth/profileUpdate profile
POST/auth/switch-branchSwitch branch
GET/auth/branchesList user's branches
POST/auth/reset-codeRequest reset code
POST/auth/verify-codeVerify reset code
POST/auth/reset-passwordReset password

Branch-Scoped Routes (Require X-Branch-Id header)

Patient Management

MethodEndpointDescription
GET/patientsList patients (paginated, searchable)
POST/patientsCreate patient
GET/patients/searchSearch patients
GET/patients/exportExport patients
GET/patients/{id}Get patient
PUT/patients/{id}Update patient
DELETE/patients/{id}Delete patient
GET/patient-visitsList visits
POST/patient-visitsCreate visit
GET/PUT/DELETE/patient-visits/{id}CRUD visit
GET/POST/PUT/DELETE/patient-visit-plans/{id}CRUD visit plans
GET/POST/PUT/DELETE/patient-visit-prescribed-medicines/{id}CRUD prescriptions
GET/POST/PUT/DELETE/complaints/{id}CRUD complaints
GET/POST/PUT/DELETE/medical-certificates/{id}CRUD certificates

Clinical Examinations (all CRUD)

EndpointExam Type
/visual-acuitiesVisual Acuity
/refractionsRefraction
/tonometriesTonometry
/slit-lampsSlit Lamp
/funduscopiesFunduscopy
/gonioscopiesGonioscopy
/corneal-topographiesCorneal Topography
/amsler-gridsAmsler Grid
/eomsExtraocular Muscles
/exophthalmometriesExophthalmometry
/lacrimal-irrigationsLacrimal Irrigation
/radiologiesRadiology
/gross-examinationsGross Examination
/indirect-ophthalmoscopiesIndirect Ophthalmoscopy

Billing & Queue

MethodEndpointDescription
GET/POST/patients/{id}/billing-transactionsPatient billing
GET/PUT/DELETE/patients/{id}/billing-transactions/{txn}Manage transaction
POST/queue/visitsCreate queue visit
GET/queue/branch-services/{id}/queueGet service queue
POST/queue/branch-services/{id}/queueCreate queue ticket
PUT/queue/queue-tickets/{id}/callCall ticket
PUT/queue/queue-tickets/{id}/serveServe ticket
PUT/queue/queue-tickets/{id}/completeComplete ticket
PUT/queue/queue-tickets/{id}/skipSkip ticket
PUT/queue/queue-tickets/{id}/no-showMark no-show
POST/queue/queue-tickets/{id}/transferTransfer ticket

Dashboard

MethodEndpointDescription
GET/dashboard/statsDashboard statistics
GET/dashboard/calendarCalendar data
GET/dashboard/patient-flowPatient flow metrics
GET/dashboard/upcoming-surgeriesUpcoming surgeries
GET/dashboard/patient-demographicsDemographics

Global Routes (Auth required, no branch context)

Master Data (all CRUD)

EndpointDescription
/bill-itemsBillable items
/medicinesMedicine reference
/proceduresMedical procedures
/insurancesInsurance plans
/servicesClinical services
/doctorsDoctor profiles
/surgery-schedulesSurgery scheduling

Pharmacy & Inventory (all CRUD)

EndpointDescription
/pharmacy-itemsPharmacy products
/stock-availablesStock levels
/stock-movementsStock tracking
/purchase-ordersPurchase orders
/transactionsPharmacy transactions
/deliveriesDelivery records

Read-Only Lookups

EndpointDescription
/bill-item-categoriesBill categories
/payment-methodsPayment methods
/suppliersSuppliers
/purchase-order-statusesPO statuses
/enumsEnum definitions

Admin Routes (Require admin.access permission)

MethodEndpointDescription
GET/POST/branchesList/create branches
GET/PUT/DELETE/branches/{id}Manage branch
GET/POST/branches/{id}/servicesBranch services
GET/PUT/DELETE/branches/{id}/services/{svc}Manage service
POST/branches/{id}/services/{svc}/staffAssign staff
DELETE/branches/{id}/services/{svc}/staff/{user}Remove staff
GET/POST/PUT/DELETE/rolesRole management

Toggle Status Pattern

Several resources support a status toggle endpoint:

http
PATCH /api/v1/medicines/{id}/toggle-status
PATCH /api/v1/procedures/{id}/toggle-status
PATCH /api/v1/insurances/{id}/toggle-status
PATCH /api/v1/pharmacy-items/{id}/toggle-status
PATCH /api/v1/services/{id}/toggle-status

Auto-Generated API Docs

The project uses Dedoc Scramble to auto-generate OpenAPI documentation from the codebase. Access it at:

http://localhost:8000/docs/api

CPR - Clinical Patient Records