Overview
The Patient API provides endpoints for searching patient records in the OpenEyes system. This API is used for patient lookup, integration with external systems, and patient data retrieval. Source:protected/modules/Api/controllers/PatientController.php
Authentication
All Patient API endpoints require:- HTTP Basic Authentication
- User must have the
OprnApirole - Authenticated user access (
users => ['@'])
Endpoints
Search Patients
Search for patients by term and optional identifier type.Query Parameters
Search term for patient lookup. Can be a name, identifier, or partial match.The term is validated using
PatientSearch::getValidSearchTerm() before processing.Filter by specific patient identifier type ID.When provided, searches only within that identifier type. When omitted, searches across all identifier types and uses the primary identifier for display.
Response
Returns an array of patient objects matching the search criteria.Patient database ID
Patient’s first name
Patient’s last name
Patient age or “Deceased” if patient has died
Patient gender code (e.g., “M”, “F”)
Date of birth in YYYY-MM-DD format
Whether the patient is deceased
Array of all patient identifiers
Primary patient identifier based on institution settings
Response Example
Empty Results
When no patients match the search criteria, an empty array is returned:200 OK
Implementation Details
Search Logic
The search functionality (lines 42-91 inPatientController.php):
- Retrieves search parameters from the request
- Creates a
PatientSearchinstance - Validates the search term using
getValidSearchTerm() - Executes the search with
PatientSearch::search() - Iterates through results to build response array
- Collects all patient identifiers
- Determines primary identifier based on institution settings
- Returns JSON response with status 200
Primary Identifier Logic
Whenpatient_identifier_type is NOT specified:
PatientController.php:64-69
When patient_identifier_type IS specified:
PatientController.php:61-63
Access Control
The controller enforces strict access control:PatientController.php:20-33
Behaviors
PatientController.php:35-40
Patient Model Reference
The Patient model (protected/models/Patient.php) includes:
Core Attributes
id- Primary keytitle- Patient title (Mr, Mrs, Dr, etc.)first_name- First namelast_name- Last namedob- Date of birthdate_of_death- Date of death (if applicable)gender- Genderhos_num- Hospital number (legacy)nhs_num- NHS number (legacy)primary_phone- Primary phone numberdeleted- Soft delete flagethnic_group_id- Ethnic grouppatient_source- Source of patient recordprimary_institution_id- Primary institution
Related Models
episodes[]- Patient episodesaddresses[]- Patient addressescontact- Contact informationidentifiers[]- Patient identifiers (modern approach)allergies[]- Patient allergiestrials[]- Clinical trials
protected/models/Patient.php:1-100
Usage Examples
Search by Name
Search by Hospital Number
Search by NHS Number
Search with Specific Identifier Type
Integration Example (Python)
Error Handling
Invalid Search Term
If the search term fails validation, an empty result set is returned:Authentication Failure
Status:401 Unauthorized
Insufficient Permissions
Status:403 Forbidden
Best Practices
Search Term Validation
Search Term Validation
Always provide meaningful search terms. Empty or very short terms may not return results depending on the
PatientSearch validation rules.Handle Empty Results
Handle Empty Results
Always check for empty arrays in responses. Not finding a patient is a valid outcome, not an error.
Use Primary Identifiers
Use Primary Identifiers
The
primary_patient_identifiers field provides the institution-configured primary identifier, which should be used for display purposes.Respect Deceased Status
Respect Deceased Status
Always check the
is_deceased field and age value before displaying patient information or scheduling appointments.Next Steps
Events API
Access clinical events and attachments
Authentication
Learn about API security