### FHIR REST API Operations (cURL Examples)
Source: https://context7.com/context7/hl7_fhir/llms.txt
Provides examples of common FHIR REST API operations using cURL, including creating, reading, searching, and updating patient resources. These examples demonstrate how to interact with a FHIR server via HTTP.
```bash
# Create a new patient resource
curl -X POST https://fhir.example.org/Patient \
-H "Content-Type: application/fhir+json" \
-H "Authorization: Bearer TOKEN" \
-d '{
"resourceType": "Patient",
"name": [{"family": "Doe", "given": ["Jane"]}],
"gender": "female",
"birthDate": "1990-05-15"
}'
```
```bash
# Read a specific patient
curl -X GET https://fhir.example.org/Patient/12345 \
-H "Accept: application/fhir+json" \
-H "Authorization: Bearer TOKEN"
```
```bash
# Search for patients by name
curl -X GET "https://fhir.example.org/Patient?name=Smith&_count=10" \
-H "Accept: application/fhir+json"
```
```bash
# Advanced search with multiple parameters
curl -X GET "https://fhir.example.org/Patient?gender=male&birthdate=gt1970-01-01&_sort=-birthdate&_include=Patient:organization" \
-H "Accept: application/fhir+json"
```
```bash
# Update a patient (full resource replacement)
curl -X PUT https://fhir.example.org/Patient/12345 \
-H "Content-Type: application/fhir+json" \
-H "If-Match: W/\"1\"" \
-d '{
"resourceType": "Patient",
"id": "12345",
"meta": {"versionId": "1"},
"name": [{"family": "Doe-Smith", "given": ["Jane"]}],
"gender": "female",
"birthDate": "1990-05-15"
}'
```
--------------------------------
### Foundation Level Resources - Patient Example
Source: https://context7.com/context7/hl7_fhir/llms.txt
Demonstrates the structure of a FHIR Patient resource in both JSON and XML formats.
```APIDOC
## Foundation Level Resources - Patient Example
This section illustrates the core data structure of a FHIR Patient resource.
### JSON Format
```json
{
"resourceType": "Patient",
"id": "example-patient-001",
"meta": {
"versionId": "1",
"lastUpdated": "2023-03-26T15:26:00Z"
},
"identifier": [
{
"system": "http://hospital.example.org/patients",
"value": "MRN123456"
}
],
"name": [
{
"use": "official",
"family": "Smith",
"given": ["John", "Robert"]
}
],
"gender": "male",
"birthDate": "1974-12-25",
"address": [
{
"use": "home",
"line": ["123 Main Street"],
"city": "Springfield",
"state": "IL",
"postalCode": "62701",
"country": "USA"
}
],
"telecom": [
{
"system": "phone",
"value": "+1-555-123-4567",
"use": "mobile"
},
{
"system": "email",
"value": "john.smith@example.com"
}
]
}
```
### XML Format
```xml
```
```
--------------------------------
### FHIR Resource Examples (JSON and XML)
Source: https://context7.com/context7/hl7_fhir/llms.txt
Demonstrates the structure of a FHIR Patient resource in both JSON and XML formats. These examples illustrate the core components and attributes used in FHIR data representation.
```json
{
"resourceType": "Patient",
"id": "example-patient-001",
"meta": {
"versionId": "1",
"lastUpdated": "2023-03-26T15:26:00Z"
},
"identifier": [
{
"system": "http://hospital.example.org/patients",
"value": "MRN123456"
}
],
"name": [
{
"use": "official",
"family": "Smith",
"given": ["John", "Robert"]
}
],
"gender": "male",
"birthDate": "1974-12-25",
"address": [
{
"use": "home",
"line": ["123 Main Street"],
"city": "Springfield",
"state": "IL",
"postalCode": "62701",
"country": "USA"
}
],
"telecom": [
{
"system": "phone",
"value": "+1-555-123-4567",
"use": "mobile"
},
{
"system": "email",
"value": "john.smith@example.com"
}
]
}
```
```xml
```
--------------------------------
### FHIR CapabilityStatement Example
Source: https://context7.com/context7/hl7_fhir/llms.txt
This JSON snippet defines a CapabilityStatement resource, detailing the capabilities and features supported by a FHIR server. It includes information on supported resource types, interactions, search parameters, and security services like SMART-on-FHIR.
```json
{
"resourceType": "CapabilityStatement",
"id": "hospital-fhir-server",
"status": "active",
"date": "2023-03-26",
"kind": "instance",
"implementation": {
"description": "Hospital FHIR Server",
"url": "https://fhir.hospital.example.org"
},
"fhirVersion": "5.0.0",
"format": ["json", "xml"],
"rest": [{
"mode": "server",
"security": {
"cors": true,
"service": [{
"coding": [{
"system": "http://terminology.hl7.org/CodeSystem/restful-security-service",
"code": "SMART-on-FHIR"
}]
}]
},
"resource": [{
"type": "Patient",
"profile": "http://hl7.org/fhir/StructureDefinition/Patient",
"interaction": [
{"code": "read"},
{"code": "search-type"},
{"code": "create"},
{"code": "update"}
],
"searchParam": [
{"name": "name", "type": "string"},
{"name": "birthdate", "type": "date"},
{"name": "identifier", "type": "token"}
]
}, {
"type": "Observation",
"profile": "http://hl7.org/fhir/StructureDefinition/Observation",
"interaction": [
{"code": "read"},
{"code": "search-type"},
{"code": "create"}
],
"searchParam": [
{"name": "patient", "type": "reference"},
{"name": "code", "type": "token"},
{"name": "date", "type": "date"}
]
}]
}]
}
```
--------------------------------
### FHIR ImplementationGuide Resource Structure (JSON)
Source: https://context7.com/context7/hl7_fhir/llms.txt
Defines the structure of an FHIR ImplementationGuide resource, including metadata, referenced resources (profiles, examples), and navigation pages. This JSON structure is essential for organizing and publishing FHIR artifacts for a specific use case or jurisdiction.
```json
{
"resourceType": "ImplementationGuide",
"id": "hospital-ig",
"url": "http://hospital.example.org/fhir/ImplementationGuide/hospital-ig",
"version": "1.0.0",
"name": "HospitalImplementationGuide",
"title": "Hospital FHIR Implementation Guide",
"status": "active",
"publisher": "Example Hospital",
"description": "Implementation guide for hospital EHR FHIR integration",
"fhirVersion": ["5.0.0"],
"definition": {
"resource": [
{
"reference": {
"reference": "StructureDefinition/hospital-patient-profile"
},
"name": "Hospital Patient Profile",
"description": "Patient profile with required identifiers and contact",
"exampleBoolean": false
},
{
"reference": {
"reference": "Patient/example-001"
},
"name": "Example Patient",
"exampleCanonical": "http://hospital.example.org/fhir/StructureDefinition/hospital-patient-profile"
}
],
"page": {
"nameUrl": "index.html",
"title": "Hospital FHIR IG Home",
"generation": "markdown",
"page": [
{
"nameUrl": "profiles.html",
"title": "Profiles",
"generation": "markdown"
},
{
"nameUrl": "examples.html",
"title": "Examples",
"generation": "markdown"
}
]
}
}
}
```
--------------------------------
### FHIR MedicationRequest Resource Example (Prescription)
Source: https://context7.com/context7/hl7_fhir/llms.txt
This JSON object represents a FHIR MedicationRequest, detailing a prescription for a medication. It includes the medication, dosage instructions, dispensing information, and requester. This resource is crucial for managing the medication workflow from prescription to administration.
```json
{
"resourceType": "MedicationRequest",
"id": "med-request-001",
"status": "active",
"intent": "order",
"medicationCodeableConcept": {
"coding": [{
"system": "http://www.nlm.nih.gov/research/umls/rxnorm",
"code": "860975",
"display": "Metformin 500 MG Oral Tablet"
}],
"text": "Metformin 500mg"
},
"subject": {
"reference": "Patient/12345"
},
"authoredOn": "2023-03-26T09:00:00Z",
"requester": {
"reference": "Practitioner/67890"
},
"dosageInstruction": [{
"sequence": 1,
"text": "Take 1 tablet twice daily with meals",
"timing": {
"repeat": {
"frequency": 2,
"period": 1,
"periodUnit": "d"
}
},
"route": {
"coding": [{
"system": "http://snomed.info/sct",
"code": "26643006",
"display": "Oral route"
}]
},
"doseAndRate": [{
"type": {
"coding": [{
"system": "http://terminology.hl7.org/CodeSystem/dose-rate-type",
"code": "ordered",
"display": "Ordered"
}]
},
"doseQuantity": {
"value": 1,
"unit": "tablet",
"system": "http://unitsofmeasure.org",
"code": "{tablet}"
}
}]
}],
"dispenseRequest": {
"numberOfRepeatsAllowed": 3,
"quantity": {
"value": 60,
"unit": "tablet",
"system": "http://unitsofmeasure.org",
"code": "{tablet}"
},
"expectedSupplyDuration": {
"value": 30,
"unit": "days",
"system": "http://unitsofmeasure.org",
"code": "d"
}
}
}
```
--------------------------------
### FHIR MedicationAdministration Resource Example (Administration)
Source: https://context7.com/context7/hl7_fhir/llms.txt
This JSON object represents a FHIR MedicationAdministration resource, used to record the actual administration of a medication to a patient. It includes the medication administered, subject, occurrence time, performer, and dosage details. This is essential for tracking medication adherence and patient safety.
```json
{
"resourceType": "MedicationAdministration",
"id": "med-admin-001",
"status": "completed",
"medicationReference": {
"reference": "Medication/med-metformin-500"
},
"subject": {
"reference": "Patient/12345"
},
"occurenceDateTime": "2023-03-26T08:00:00Z",
"performer": [{
"actor": {
"reference": "Practitioner/nurse-001"
}
}],
"request": {
"reference": "MedicationRequest/med-request-001"
},
"dosage": {
"dose": {
"value": 1,
"unit": "tablet"
},
"route": {
"coding": [{
"system": "http://snomed.info/sct",
"code": "26643006",
"display": "Oral"
}]
}
}
}
```
--------------------------------
### FHIR Bundles and Transactions
Source: https://context7.com/context7/hl7_fhir/llms.txt
FHIR Bundles allow for grouping multiple resources for batch operations or document exchange. This section provides examples of transaction bundles (for atomic operations) and document bundles (for clinical documents).
```APIDOC
## FHIR Bundles and Transactions
### Description
FHIR Bundles are used to group multiple resources together for various purposes, including batch operations, transactions, and document exchange.
### Types of Bundles
**1. Transaction Bundle**
Used for atomic operations where all entries must succeed or fail together. Each entry includes a `request` object specifying the HTTP method and URL for the operation.
```json
{
"resourceType": "Bundle",
"type": "transaction",
"entry": [
{
"fullUrl": "urn:uuid:patient-temp-001",
"resource": {
"resourceType": "Patient",
"name": [{
"family": "Johnson",
"given": ["Emily"]
}],
"gender": "female",
"birthDate": "1985-07-20"
},
"request": {
"method": "POST",
"url": "Patient"
}
},
{
"resource": {
"resourceType": "Observation",
"status": "final",
"code": {
"coding": [{
"system": "http://loinc.org",
"code": "29463-7",
"display": "Body Weight"
}]
},
"subject": {
"reference": "urn:uuid:patient-temp-001"
},
"valueQuantity": {
"value": 68.5,
"unit": "kg",
"system": "http://unitsofmeasure.org",
"code": "kg"
}
},
"request": {
"method": "POST",
"url": "Observation"
}
}
]
}
```
**2. Document Bundle**
Used to package clinical documents, such as discharge summaries. It typically includes a Composition resource and related resources.
```json
{
"resourceType": "Bundle",
"type": "document",
"timestamp": "2023-03-26T10:00:00Z",
"entry": [
{
"fullUrl": "https://fhir.example.org/Composition/discharge-summary-001",
"resource": {
"resourceType": "Composition",
"id": "discharge-summary-001",
"status": "final",
"type": {
"coding": [{
"system": "http://loinc.org",
"code": "18842-5",
"display": "Discharge Summary"
}]
},
"subject": {"reference": "Patient/12345"},
"date": "2023-03-26T10:00:00Z",
"author": [{"reference": "Practitioner/67890"}],
"title": "Hospital Discharge Summary",
"section": [{
"title": "Chief Complaint",
"code": {
"coding": [{
"system": "http://loinc.org",
"code": "10154-3"
}]
},
"text": {
"status": "generated",
"div": "
Chest pain
"
}
}]
}
},
{
"fullUrl": "https://fhir.example.org/Patient/12345",
"resource": {
"resourceType": "Patient",
"id": "12345"
}
}
]
}
```
### Submitting Transaction Bundles
To submit a transaction bundle, send a POST request to the FHIR server's base URL with the `Content-Type` header set to `application/fhir+json` and the bundle JSON in the request body.
**Method:** POST
**Endpoint:** `https://fhir.example.org/`
**Headers:**
- `Content-Type: application/fhir+json`
**Request Body:**
[Transaction Bundle JSON Example above]
```
--------------------------------
### FHIR Subscription Resource and Notification Handling
Source: https://context7.com/context7/hl7_fhir/llms.txt
Defines a FHIR Subscription resource to monitor changes and provides an example of a Node.js/Express webhook handler for receiving and processing notification payloads. This enables real-time event-driven updates.
```json
// Subscription resource - monitor new observations
{
"resourceType": "Subscription",
"id": "obs-subscription-001",
"status": "active",
"end": "2024-03-26T00:00:00Z",
"reason": "Monitor patient vital signs",
"criteria": "Observation?patient=12345&category=vital-signs",
"channel": {
"type": "rest-hook",
"endpoint": "https://app.example.com/fhir/notifications",
"payload": "application/fhir+json",
"header": ["Authorization: Bearer notification_token_xyz"]
}
}
// Notification payload received at webhook endpoint
{
"resourceType": "Bundle",
"type": "history",
"entry": [{
"fullUrl": "https://fhir.example.org/Observation/obs-002",
"resource": {
"resourceType": "Observation",
"id": "obs-002",
"status": "final",
"category": [{
"coding": [{
"system": "http://terminology.hl7.org/CodeSystem/observation-category",
"code": "vital-signs"
}]
}],
"code": {
"coding": [{
"system": "http://loinc.org",
"code": "8867-4",
"display": "Heart rate"
}]
},
"subject": {"reference": "Patient/12345"},
"valueQuantity": {
"value": 72,
"unit": "beats/minute",
"system": "http://unitsofmeasure.org",
"code": "/min"
}
},
"request": {
"method": "POST",
"url": "Observation"
}
}]
}
```
```javascript
// Webhook endpoint handler (Node.js/Express example)
app.post('/fhir/notifications', express.json({type: 'application/fhir+json'}), (req, res) => {
const bundle = req.body;
if (bundle.resourceType === 'Bundle' && bundle.type === 'history') {
bundle.entry.forEach(entry => {
const resource = entry.resource;
console.log(`Received ${resource.resourceType}/${resource.id}`);
// Process the notification
if (resource.resourceType === 'Observation') {
processVitalSign(resource);
}
});
res.status(200).send();
} else {
res.status(400).send('Invalid notification format');
}
});
```
--------------------------------
### FHIR AuditEvent Resource (JSON)
Source: https://context7.com/context7/hl7_fhir/llms.txt
An example of the FHIR AuditEvent resource, which tracks security-relevant events such as RESTful operations. It includes details about the event type, action, outcome, agent, and entities involved.
```json
{
"resourceType": "AuditEvent",
"type": {
"system": "http://terminology.hl7.org/CodeSystem/audit-event-type",
"code": "rest",
"display": "RESTful Operation"
},
"subtype": [{
"system": "http://hl7.org/fhir/restful-interaction",
"code": "read",
"display": "read"
}],
"action": "R",
"recorded": "2023-03-26T10:15:00Z",
"outcome": "0",
"agent": [{
"type": {
"coding": [{
"system": "http://terminology.hl7.org/CodeSystem/extra-security-role-type",
"code": "humanuser"
}]
},
"who": {
"identifier": {
"value": "user@example.com"
}
},
"requestor": true
}],
"source": {
"observer": {
"display": "FHIR Server"
}
},
"entity": [{
"what": {
"reference": "Patient/12345"
},
"type": {
"system": "http://hl7.org/fhir/resource-types",
"code": "Patient"
}
}]
}
```
--------------------------------
### Lookup Concept
Source: https://context7.com/context7/hl7_fhir/llms.txt
Retrieves details for a specific code within a code system. This is used to get the display text and other metadata for a given code.
```APIDOC
## GET /CodeSystem/$lookup
### Description
Retrieves details for a specific code within a code system. This is used to get the display text and other metadata for a given code.
### Method
GET
### Endpoint
https://fhir.example.org/CodeSystem/$lookup
### Query Parameters
- **system** (uri) - Required - The URI of the code system.
- **code** (code) - Required - The code to look up.
### Request Example
```
GET https://fhir.example.org/CodeSystem/$lookup?system=http://snomed.info/sct&code=44054006
Accept: application/fhir+json
```
### Response
#### Success Response (200)
(Details of success response depend on FHIR server implementation, typically a Parameters resource with lookup results.)
#### Response Example
(Example response structure would typically be a Parameters resource with display and other code-related information.)
```json
{
"resourceType": "Parameters",
"parameter": [
{
"name": "display",
"valueString": "Type 2 diabetes mellitus without complications"
},
{
"name": "system",
"valueUri": "http://snomed.info/sct"
},
{
"name": "code",
"valueCode": "44054006"
}
]
}
```
```
--------------------------------
### Lookup Concept Details using cURL
Source: https://context7.com/context7/hl7_fhir/llms.txt
This operation retrieves detailed information about a specific code within a given code system. It uses a GET request specifying the CodeSystem URL and the code, with an 'Accept' header for a JSON response.
```shell
curl -X GET "https://fhir.example.org/CodeSystem/$lookup?system=http://snomed.info/sct&code=44054006" \
-H "Accept: application/fhir+json"
```
--------------------------------
### FHIR Observation Resource Example (Vital Signs)
Source: https://context7.com/context7/hl7_fhir/llms.txt
This JSON object represents a FHIR Observation resource, specifically for recording vital signs such as blood pressure. It includes details about the observation status, category, code (LOINC), subject, effective time, performer, and components (systolic and diastolic pressure).
```json
{
"resourceType": "Observation",
"id": "blood-pressure-001",
"status": "final",
"category": [{
"coding": [{
"system": "http://terminology.hl7.org/CodeSystem/observation-category",
"code": "vital-signs",
"display": "Vital Signs"
}]
}],
"code": {
"coding": [{
"system": "http://loinc.org",
"code": "85354-9",
"display": "Blood pressure panel"
}]
},
"subject": {
"reference": "Patient/12345"
},
"effectiveDateTime": "2023-03-26T10:30:00Z",
"performer": [{
"reference": "Practitioner/67890"
}],
"component": [{
"code": {
"coding": [{
"system": "http://loinc.org",
"code": "8480-6",
"display": "Systolic blood pressure"
}]
},
"valueQuantity": {
"value": 120,
"unit": "mmHg",
"system": "http://unitsofmeasure.org",
"code": "mm[Hg]"
}
}, {
"code": {
"coding": [{
"system": "http://loinc.org",
"code": "8462-4",
"display": "Diastolic blood pressure"
}]
},
"valueQuantity": {
"value": 80,
"unit": "mmHg",
"system": "http://unitsofmeasure.org",
"code": "mm[Hg]"
}
}]
}
```
--------------------------------
### FHIR Condition Resource Example (Problem List)
Source: https://context7.com/context7/hl7_fhir/llms.txt
This JSON object defines a FHIR Condition resource, used for recording a patient's problem or diagnosis. It includes the condition's status, verification status, category, code (SNOMED CT), subject, onset date, and recorded date. This is useful for managing a patient's medical history.
```json
{
"resourceType": "Condition",
"id": "condition-diabetes",
"clinicalStatus": {
"coding": [{
"system": "http://terminology.hl7.org/CodeSystem/condition-clinical",
"code": "active"
}]
},
"verificationStatus": {
"coding": [{
"system": "http://terminology.hl7.org/CodeSystem/condition-ver-status",
"code": "confirmed"
}]
},
"category": [{
"coding": [{
"system": "http://terminology.hl7.org/CodeSystem/condition-category",
"code": "problem-list-item"
}]
}],
"code": {
"coding": [{
"system": "http://snomed.info/sct",
"code": "44054006",
"display": "Type 2 diabetes mellitus"
}]
},
"subject": {
"reference": "Patient/12345"
},
"onsetDateTime": "2020-08-15",
"recordedDate": "2020-08-20T14:30:00Z"
}
```
--------------------------------
### FHIR Specification Overview
Source: https://context7.com/context7/hl7_fhir/llms.txt
Guidance on navigating the FHIR R5 standard documentation for different user roles and key specification sections.
```APIDOC
## FHIR Specification Overview
This section provides guidance on accessing and understanding the FHIR R5 standard documentation.
### Audience-Specific Guidance
* **For developers starting with FHIR:**
Read: `Developer's Introduction → FHIR Overview → REST API + Search`
* **For healthcare providers and clinicians:**
Read: `Clinical Introduction → Patient/Practitioner resources → Clinical resources`
* **For solution architects:**
Read: `Architect's Introduction → Exchange patterns → Conformance framework`
### Key Specification Sections
* **Foundation:** Base documentation, XML/JSON formats, datatypes, extensions
* **Security:** Security framework, consent, provenance, audit events
* **Terminology:** CodeSystem, ValueSet, ConceptMap, terminology services
* **Exchange:** REST API, documents, messaging, services, subscriptions
```
--------------------------------
### FHIR Batch and Bulk Data Export Operations using cURL
Source: https://context7.com/context7/hl7_fhir/llms.txt
Demonstrates how to perform batch operations with FHIR using cURL, including sending multiple requests in a single bundle. It also shows how to initiate, poll, and download data from FHIR Bulk Data Export operations.
```bash
# Batch bundle (non-atomic operations)
curl -X POST https://fhir.example.org/ \
-H "Content-Type: application/fhir+json" \
-d '{
"resourceType": "Bundle",
"type": "batch",
"entry": [{
"request": {
"method": "GET",
"url": "Patient/12345"
}
}, {
"request": {
"method": "GET",
"url": "Observation?patient=12345&_count=10"
}
}, {
"request": {
"method": "POST",
"url": "Condition"
},
"resource": {
"resourceType": "Condition",
"subject": {"reference": "Patient/12345"},
"code": {
"coding": [{
"system": "http://snomed.info/sct",
"code": "38341003",
"display": "Hypertension"
}]
}
}
}]
}'
# Bulk data export (FHIR Bulk Data Access)
# Initiate export
curl -X GET "https://fhir.example.org/Patient/$export?_type=Patient,Observation,Condition" \
-H "Accept: application/fhir+json" \
-H "Prefer: respond-async" \
-H "Authorization: Bearer TOKEN"
# Response: 202 Accepted
# Content-Location: https://fhir.example.org/bulkdata/status/job123
# Poll export status
curl -X GET https://fhir.example.org/bulkdata/status/job123 \
-H "Authorization: Bearer TOKEN"
# When complete, response includes download URLs:
# {
# "transactionTime": "2023-03-26T10:00:00Z",
# "request": "https://fhir.example.org/Patient/$export",
# "requiresAccessToken": true,
# "output": [{
# "type": "Patient",
# "url": "https://fhir.example.org/bulkdata/download/patients.ndjson"
# }, {
# "type": "Observation",
# "url": "https://fhir.example.org/bulkdata/download/observations.ndjson"
# }]
# }
# Download exported data (NDJSON format)
curl https://fhir.example.org/bulkdata/download/patients.ndjson \
-H "Authorization: Bearer TOKEN" \
-o patients.ndjson
# Each line in NDJSON file is a complete JSON resource
# {"resourceType":"Patient","id":"12345",...}
# {"resourceType":"Patient","id":"12346",...}
```
--------------------------------
### Conformance and Profiling - CapabilityStatement
Source: https://context7.com/context7/hl7_fhir/llms.txt
The CapabilityStatement resource describes the features and capabilities of a FHIR server, including supported resource types, operations, and security.
```APIDOC
## CapabilityStatement
### Description
The CapabilityStatement resource describes the features and capabilities of a FHIR server, including supported resource types, operations, and security.
### Resource Type
CapabilityStatement
### Example
```json
{
"resourceType": "CapabilityStatement",
"id": "hospital-fhir-server",
"status": "active",
"date": "2023-03-26",
"kind": "instance",
"implementation": {
"description": "Hospital FHIR Server",
"url": "https://fhir.hospital.example.org"
},
"fhirVersion": "5.0.0",
"format": ["json", "xml"],
"rest": [{
"mode": "server",
"security": {
"cors": true,
"service": [{
"coding": [{
"system": "http://terminology.hl7.org/CodeSystem/restful-security-service",
"code": "SMART-on-FHIR"
}]
}]
},
"resource": [{
"type": "Patient",
"profile": "http://hl7.org/fhir/StructureDefinition/Patient",
"interaction": [
{"code": "read"},
{"code": "search-type"},
{"code": "create"},
{"code": "update"}
],
"searchParam": [
{"name": "name", "type": "string"},
{"name": "birthdate", "type": "date"},
{"name": "identifier", "type": "token"}
]
}, {
"type": "Observation",
"profile": "http://hl7.org/fhir/StructureDefinition/Observation",
"interaction": [
{"code": "read"},
{"code": "search-type"},
{"code": "create"}
],
"searchParam": [
{"name": "patient", "type": "reference"},
{"name": "code", "type": "token"},
{"name": "date", "type": "date"}
]
}]
}]
}
```
```
--------------------------------
### Subscription Framework API
Source: https://context7.com/context7/hl7_fhir/llms.txt
This section details how to create and manage FHIR subscriptions for receiving real-time notifications about resource changes. It includes the structure of a Subscription resource and how to handle incoming notification payloads at a webhook endpoint.
```APIDOC
## POST /Subscription
### Description
Creates a new FHIR subscription to receive real-time notifications for specific resource changes based on defined criteria.
### Method
POST
### Endpoint
`/Subscription`
### Parameters
#### Request Body
- **Subscription resource** (object) - Required - The FHIR Subscription resource defining the criteria for notifications, channel type, endpoint, and payload format.
### Request Example
```json
{
"resourceType": "Subscription",
"id": "obs-subscription-001",
"status": "active",
"end": "2024-03-26T00:00:00Z",
"reason": "Monitor patient vital signs",
"criteria": "Observation?patient=Patient/12345&category=vital-signs",
"channel": {
"type": "rest-hook",
"endpoint": "https://app.example.com/fhir/notifications",
"payload": "application/fhir+json",
"header": ["Authorization: Bearer notification_token_xyz"]
}
}
```
### Response
#### Success Response (201 Created)
- **Subscription resource** (object) - The created FHIR Subscription resource, often including an ID assigned by the server.
#### Response Example
```json
{
"resourceType": "Subscription",
"id": "obs-subscription-001",
"status": "active",
"end": "2024-03-26T00:00:00Z",
"reason": "Monitor patient vital signs",
"criteria": "Observation?patient=Patient/12345&category=vital-signs",
"channel": {
"type": "rest-hook",
"endpoint": "https://app.example.com/fhir/notifications",
"payload": "application/fhir+json",
"header": ["Authorization: Bearer notification_token_xyz"]
}
}
```
## Webhook Endpoint Handler
### Description
This describes the expected format and handling of notification payloads received at the webhook endpoint specified in the Subscription resource.
### Method
POST
### Endpoint
`[Endpoint specified in Subscription channel.endpoint]`
### Parameters
#### Request Body
- **Bundle resource** (object) - Required - A FHIR Bundle resource of type 'history', containing resources that have changed.
### Request Example
```json
{
"resourceType": "Bundle",
"type": "history",
"entry": [{
"fullUrl": "https://fhir.example.org/Observation/obs-002",
"resource": {
"resourceType": "Observation",
"id": "obs-002",
"status": "final",
"category": [{
"coding": [{
"system": "http://terminology.hl7.org/CodeSystem/observation-category",
"code": "vital-signs"
}]
}],
"code": {
"coding": [{
"system": "http://loinc.org",
"code": "8867-4",
"display": "Heart rate"
}]
},
"subject": {"reference": "Patient/12345"},
"valueQuantity": {
"value": 72,
"unit": "beats/minute",
"system": "http://unitsofmeasure.org",
"code": "/min"
}
},
"request": {
"method": "POST",
"url": "Observation"
}
}]
}
```
### Response
#### Success Response (200 OK)
- Acknowledges receipt of the notification. The body can be empty.
#### Response Example
(Empty body)
#### Error Response (400 Bad Request)
- Indicates an invalid notification format.
```
```
--------------------------------
### SMART on FHIR Authorization Flow (Bash)
Source: https://context7.com/context7/hl7_fhir/llms.txt
Illustrates the SMART on FHIR OAuth 2.0 authorization code grant flow using curl commands. It covers discovering endpoints, redirecting users, exchanging codes for tokens, and accessing FHIR resources.
```bash
# SMART on FHIR authorization flow
# Step 1: Discover authorization endpoints
curl https://fhir.example.org/.well-known/smart-configuration
# Response:
# {
# "authorization_endpoint": "https://auth.example.org/authorize",
# "token_endpoint": "https://auth.example.org/token",
# "capabilities": ["launch-standalone", "client-public", "sso-openid-connect"],
# "scopes_supported": ["patient/*.read", "user/*.write", "openid", "fhirUser"]
# }
# Step 2: Redirect user to authorization endpoint
# https://auth.example.org/authorize?
# response_type=code&
# client_id=app_client_id&
# redirect_uri=https://app.example.com/callback&
# scope=patient/Patient.read patient/Observation.read launch&
# state=abc123&
# aud=https://fhir.example.org
# Step 3: Exchange authorization code for access token
curl -X POST https://auth.example.org/token \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "grant_type=authorization_code" \
-d "code=AUTH_CODE_FROM_STEP_2" \
-d "redirect_uri=https://app.example.com/callback" \
-d "client_id=app_client_id"
# Response:
# {
# "access_token": "eyJhbGciOiJSUzI1NiIs...",
# "token_type": "Bearer",
# "expires_in": 3600,
# "scope": "patient/Patient.read patient/Observation.read",
# "patient": "12345"
# }
# Step 4: Use access token to access FHIR resources
curl https://fhir.example.org/Patient/12345 \
-H "Authorization: Bearer eyJhbGciOiJSUzI1NiIs..." \
-H "Accept: application/fhir+json"
```