Back to Openemr

OpenEMR REST API Documentation

API_README.md

latest13.8 KB
Original Source

OpenEMR REST API Documentation

๐Ÿ“š Complete documentation has moved to Documentation/api/

This project provides comprehensive REST and FHIR APIs for OpenEMR, supporting:

  • FHIR R4 - Full FHIR Release 4 implementation
  • US Core 8.0 - US healthcare compliance
  • SMART on FHIR v2.2.0 - Advanced app integration
  • OAuth 2.0 / OpenID Connect - Secure authentication
  • Bulk Data Export - Population health analytics

๐Ÿš€ Quick Start

1. Enable the API

Administration โ†’ Config โ†’ Connectors

  • โ˜‘ Enable OpenEMR Standard REST API
  • โ˜‘ Enable OpenEMR Standard FHIR REST API

2. Configure SSL

Set your base URL at: Administration โ†’ Config โ†’ Connectors โ†’ Site Address (required for OAuth2 and FHIR)

3. Register Your Application

bash
curl -X POST https://localhost:9300/oauth2/default/registration \
  -H 'Content-Type: application/json' \
  --data '{
    "client_name": "My App",
    "redirect_uris": ["https://myapp.example.com/callback"],
    "scope": "openid api:fhir patient/Patient.rs patient/Observation.rs"
  }'

4. Make Your First Request

bash
curl -X GET 'https://localhost:9300/apis/default/fhir/Patient' \
  -H 'Authorization: Bearer YOUR_ACCESS_TOKEN'

๐Ÿ“– Documentation

Core Documentation

๐ŸŽฏ Common Tasks

Authenticate Your Application

โ†’ Authorization Code Grant

Understand Scopes

โ†’ Scopes Reference

Access Patient Data

โ†’ FHIR Patient Resource

Integrate a SMART App

โ†’ SMART Registration

Launch Apps from EHR

โ†’ EHR Launch Flow

Export Bulk Data

โ†’ Bulk FHIR Exports

Generate Care Documents (CCD)

โ†’ DocumentReference $docref

โœจ What's New in SMART v2.2.0

Enhanced Security & Permissions

Enhanced Context & Discovery

New FHIR Resources

See complete resource list in FHIR API Documentation

๐Ÿ“š API Endpoints

FHIR API (FHIR R4)

https://localhost:9300/apis/default/fhir

โ†’ Full FHIR Documentation

Key Endpoints:

  • GET /fhir/metadata - Capability statement (no auth required)
  • GET /fhir/Patient - Patient search
  • GET /fhir/Observation?patient=123 - Patient observations
  • POST /fhir/DocumentReference/$docref - Generate CCD
  • GET /fhir/$export - Bulk data export

Standard API (OpenEMR REST)

https://localhost:9300/apis/default/api

โ†’ Full Standard API Documentation

Key Endpoints:

  • GET /api/patient - List patients
  • GET /api/patient/123 - Get patient details
  • GET /api/patient/123/encounter - Patient encounters
  • POST /api/patient - Create patient

Patient Portal API (Experimental)

https://localhost:9300/apis/default/portal

โ†’ Portal API Documentation

๐Ÿ”’ Security & Compliance

Required Security Measures

  • โœ… HTTPS/TLS Required - All API communication must be encrypted
  • โœ… OAuth 2.0 - Industry-standard authorization
  • โœ… Granular Scopes - Principle of least privilege
  • โœ… PKCE for Public Apps - Enhanced security for native/browser apps
  • โœ… Token Validation - Introspection support

Standards Compliance

  • โœ… HIPAA - Protected health information safeguards
  • โœ… ONC Cures Update - Information blocking compliance
  • โœ… FHIR R4 - HL7 FHIR Release 4
  • โœ… US Core 8.0 - US healthcare requirements
  • โœ… SMART v2.2.0 - App launch framework

โ†’ Security Best Practices

๐Ÿงช Testing & Development

Interactive Testing

Test endpoints interactively with Swagger UI:

https://your-openemr-install/swagger/

Online Demos

Try the API on live demo instances:

Configure Swagger OAuth

When testing with Swagger, set your client's redirect URI to:

<OpenEMR base URI>/swagger/oauth2-redirect.html

๐ŸŒ Multisite Support

OpenEMR supports multiple sites with site-specific endpoints:

Default site:

https://localhost:9300/apis/default/fhir
https://localhost:9300/apis/default/api

Alternate site:

https://localhost:9300/apis/alternate/fhir
https://localhost:9300/apis/alternate/api

โ†’ Multisite Documentation

๐Ÿ“‹ Scope Examples

Patient-Facing App (Vital Signs Tracker)

openid
offline_access
patient/Patient.rs
patient/Observation.rs?category=http://terminology.hl7.org/CodeSystem/observation-category|vital-signs

Provider App (Clinical Documentation)

openid
fhirUser
launch
launch/patient
launch/encounter
user/Patient.rs
user/Encounter.cruds
user/Observation.crs
user/DocumentReference.crs

Backend Service (Analytics)

system/Patient.$export
system/*.$bulkdata-status
system/Binary.read

โ†’ Complete Scope Reference

๐Ÿ†˜ Support & Resources

Documentation

Community

Standards & Specifications

๐Ÿ”„ Migration from Previous Versions

V1 to V2 Scope Migration

V1 Scopes (Deprecated but supported):

patient/Patient.read
patient/Observation.read

V2 Scopes (Recommended):

patient/Patient.rs
patient/Observation.rs

Mapping:

  • .read โ†’ .rs (read + search)
  • .write โ†’ .cud (create + update + delete)

โ†’ V1 Compatibility Guide

๐Ÿ“ Example Code

JavaScript/Node.js

javascript
// Fetch patient data
const response = await fetch('https://localhost:9300/apis/default/fhir/Patient/123', {
  headers: {
    'Authorization': `Bearer ${accessToken}`,
    'Accept': 'application/fhir+json'
  }
});

const patient = await response.json();
console.log(`Patient: ${patient.name[0].given[0]} ${patient.name[0].family}`);

Python

python
import requests

# Fetch observations
response = requests.get(
    'https://localhost:9300/apis/default/fhir/Observation',
    headers={
        'Authorization': f'Bearer {access_token}',
        'Accept': 'application/fhir+json'
    },
    params={'patient': '123', 'category': 'vital-signs'}
)

observations = response.json()

cURL

bash
# Get patient medications
curl -X GET 'https://localhost:9300/apis/default/fhir/MedicationRequest?patient=123' \
  -H 'Authorization: Bearer YOUR_TOKEN' \
  -H 'Accept: application/fhir+json'

โ†’ More Examples

๐Ÿ—๏ธ For Developers

Internal API Usage

Extending the API

Architecture

Request โ†’ Authentication โ†’ Authorization โ†’ Controller โ†’ Service โ†’ Database
                                              โ†“
Response โ† JSON Formatting โ† Validation โ† Processing

โ†’ Developer Guide

๐Ÿ“Š API Coverage

FHIR Resources (30+)

โœ… Patient, Practitioner, Organization, Location โœ… Observation, Condition, Procedure, AllergyIntolerance โœ… MedicationRequest, MedicationDispense, Immunization โœ… Encounter, Appointment, CarePlan, CareTeam โœ… DiagnosticReport, ServiceRequest, Specimen โœ… DocumentReference, Binary, Provenance โœ… Goal, Device, Coverage, RelatedPerson

โ†’ Complete Resource List

Operations

โœ… Read, Search, Create, Update, Delete (per resource) โœ… Bulk Export ($export) โœ… CCD Generation ($docref) โœ… Token Introspection โœ… Capability Statement

๐ŸŽ“ Tutorials

Getting Started

  1. Register Your First App
  2. Obtain an Access Token
  3. Make Your First API Call
  4. Handle Token Refresh

Advanced Topics

  1. Implement EHR Launch
  2. Use Granular Scopes
  3. Export Bulk Data
  4. Generate Clinical Documents

๐Ÿ“œ License

OpenEMR is licensed under GPL v3.

API integrations must comply with:

  • HIPAA requirements
  • State/federal healthcare regulations
  • OpenEMR license terms
TopicDocumentation
AuthenticationAUTHENTICATION.md
Scopes & PermissionsAUTHORIZATION.md
FHIR EndpointsFHIR_API.md
SMART AppsSMART_ON_FHIR.md
Standard APISTANDARD_API.md
DevelopmentDEVELOPER_GUIDE.md

Documentation Attribution

Authorship

This documentation represents the collective knowledge and contributions of the OpenEMR open-source community. The content is based on:

  • Original documentation by OpenEMR developers and contributors
  • Technical specifications from the OpenEMR codebase
  • Community feedback and real-world implementation experience

AI Assistance

The organization, structure, and presentation of this documentation was enhanced using Claude AI (Anthropic) to:

  • Reorganize content into a more accessible modular structure
  • Add comprehensive examples and use cases
  • Improve navigation and cross-referencing
  • Enhance clarity and consistency across documents

All technical accuracy is maintained from the original community-authored documentation.

Contributing

OpenEMR is an open-source project. To contribute to this documentation:

Last Updated: November 2025 License: GPL v3