Introduction
The OmniEHR API provides a FHIR R4-compatible REST interface for managing electronic health records. All API endpoints are available under the/api base path and return JSON responses.
Base URL
API Routes Structure
The API is organized into four main route groups:Authentication Routes
- Base Path:
/api/auth - Purpose: User authentication and token management
- Rate Limit: 100 requests per 15 minutes
- Authentication: Not required for login, required for profile endpoints
FHIR Routes
- Base Path:
/api/fhir - Purpose: FHIR R4-compliant resource management
- Rate Limit: None (protected by authentication and audit trail)
- Authentication: Required (JWT Bearer token)
- Supported Resources:
- Patient
- Observation
- Condition
- AllergyIntolerance
- MedicationRequest
- Encounter
- Appointment
- Task
Admin Routes
- Base Path:
/api/admin - Purpose: User management, practitioner directory, audit logs
- Rate Limit: None (protected by authentication and role-based authorization)
- Authentication: Required (admin or auditor roles)
Public Routes
- Base Path:
/api/public - Purpose: Patient self-registration
- Rate Limit: 50 requests per 15 minutes
- Authentication: Not required
FHIR Compliance
FHIR Version
OmniEHR implements FHIR R4 (4.0.1) specification.Capability Statement
Query the server’s capabilities:Always “CapabilityStatement”
FHIR version (4.0.1)
Array of REST capabilities including supported resources and interactions
Supported Interactions
All FHIR resources support the following interactions:- read: Read a single resource by ID
- search-type: Search for resources with query parameters
- create: Create a new resource
- update: Update an existing resource
Search Results Format
Search operations return FHIR Bundle resources with type “searchset”:Rate Limiting
Authentication Endpoints
Rate limiting is configured in/server/src/app.js:27-36:
Time window: 15 minutes (900,000 ms)
Maximum requests: 100 per window
Returns
RateLimit-* headersPublic Endpoints
Rate limiting is configured in/server/src/app.js:38-47:
Time window: 15 minutes (900,000 ms)
Maximum requests: 50 per window
Rate Limit Headers
When rate limiting is active, responses include:Rate Limit Exceeded
When the rate limit is exceeded, the API returns:Security Features
Helmet.js
Security headers are enforced via Helmet middleware (/server/src/app.js:16):
- Content Security Policy
- DNS Prefetch Control
- Frame Options
- HSTS (HTTP Strict Transport Security)
- IE No Open
- X-Powered-By header removal
CORS Configuration
CORS is configured in/server/src/app.js:17-23:
CORS_ORIGIN environment variable.
Request Body Size Limit
JSON request bodies are limited to 1MB (/server/src/app.js:24).
Audit Trail
All authenticated FHIR and admin requests are logged via therequestAuditTrail middleware (/server/src/app.js:49):
- Actor information (user ID, email, role)
- Resource type and action
- Request timestamp
- Outcome (success/failure)
- IP address and user agent
/api/admin/audit-logs for admin and auditor roles.
Health Check
Verify API availability:Server health status (“ok” if running)
Current server time in ISO 8601 format
Error Handling
All errors follow a consistent format:Common HTTP Status Codes
| Status Code | Meaning |
|---|---|
200 | Success |
201 | Resource created |
400 | Bad request (validation error) |
401 | Unauthorized (missing or invalid token) |
403 | Forbidden (insufficient permissions) |
404 | Resource not found |
409 | Conflict (e.g., duplicate resource) |
429 | Too many requests (rate limit exceeded) |
500 | Internal server error |
Environment Configuration
Required environment variables (from/server/src/config/env.js):
Environment (development, production)
Server port (e.g., 3000)
MongoDB connection string
Secret key for JWT signing
Token expiration (e.g., “24h”, “7d”)
Encryption key for Protected Health Information (PHI)
Allowed CORS origin (defaults to http://localhost:5173)
Request Logging
All requests are logged using Morgan with the “combined” format (/server/src/app.js:25):
Next Steps
Authentication
Learn how to authenticate and manage JWT tokens
FHIR Resources
Explore FHIR resource endpoints
Admin API
User management and audit logs
Public API
Patient registration endpoints