FHIR Operation Framework
In addition to the standard API endpoints for creating, reading, and updating resources, FHIR offers a variety of
RPC-like Operation APIs to expose arbitrary functionality as a FHIR API.
Each API endpoint is defined by an OperationDefinition resource,
which provides information about how to call the API and what to expect in response.
Operation Definition
For example, consider the ValueSet/$validate-code operation,
which is summarized below:
OperationDefinition JSON
{
"resourceType": "OperationDefinition",
"url": "http://hl7.org/fhir/OperationDefinition/ValueSet-validate-code",
"status": "active",
"kind": "operation",
// Endpoint configuration
"code": "validate-code",
"resource": ["ValueSet"],
"system": false,
"type": true,
"instance": true,
"parameter": [
// Input Parameters
{
"use": "in",
"name": "url",
"documentation": "Value set canonical URL",
"min": 0,
"max": "1",
"type": "uri"
},
{
"use": "in",
"name": "valueSet",
"documentation": "The value set is provided directly as part of the request",
"min": 0,
"max": "1",
"type": "ValueSet"
},
{
"use": "in",
"name": "code",
"documentation": "The code that is to be validated",
"min": 0,
"max": "1",
"type": "code"
},
{
"use": "in",
"name": "system",
"documentation": "The system for the code that is to be validated",
"min": 0,
"max": "1",
"type": "uri"
},
{
"use": "in",
"name": "display",
"documentation": "The display associated with the code, if provided",
"min": 0,
"max": "1",
"type": "string"
},
{
"use": "in",
"name": "coding",
"documentation": "A coding to validate",
"min": 0,
"max": "1",
"type": "Coding"
},
{
"use": "in",
"name": "codeableConcept",
"documentation": "A full codeableConcept to validate",
"min": 0,
"max": "1",
"type": "CodeableConcept"
},
// Output Parameters
{
"use": "out",
"name": "result",
"documentation": "True if the concept details supplied are valid",
"min": 1,
"max": "1",
"type": "boolean"
},
{
"use": "out",
"name": "message",
"documentation": "Error details, if result = false; otherwise may contain hints and warnings",
"min": 0,
"max": "1",
"type": "string"
},
{
"use": "out",
"name": "display",
"documentation": "A valid display for the concept if the system wishes to display this to a user",
"min": 0,
"max": "1",
"type": "string"
}
]
}
This definition supplies the information needed to correctly call the operation API endpoint:
- All operation requests can be made using the
POSTHTTP method - The
validate-codeoperation is available as type- and instance-level endpoints forValueSetresources, i.e.[baseUrl]/ValueSet/$validate-code[baseUrl]/ValueSet/[id]/$validate-code
- Input parameters are passed via a
Parametersresource in the request body
Invoking an Operation
Given the information from the OperationDefinition, we can construct a request to the operation API endpoint. For
each in parameter, corresponding entries may appear in the request Parameters.parameter array. Value types must
match the OperationDefinition.
Request:
- TypeScript
- cURL
const result = await medplum.post(medplum.fhirUrl('ValueSet', '$validate-code').toString(), {
resourceType: 'Parameters',
parameter: [
{ name: 'url', valueUri: 'http://hl7.org/fhir/ValueSet/condition-severity' },
{ name: 'coding', valueCoding: { system: 'http://snomed.info/sct', code: '255604002' } },
],
});
curl 'https://api.medplum.com/fhir/R4/ValueSet/$validate-code' \
-X POST \
-H "Content-Type: application/fhir+json" \
-H "Authorization: Bearer $MY_ACCESS_TOKEN" \
-d '{"resourceType":"Parameters","parameter":[{"name":"url","valueUri":"http://hl7.org/fhir/ValueSet/condition-severity"},{"name":"coding","valueCoding":{"system":"http://snomed.info/sct","code":"255604002"}}]}'
Response: (200 OK)
{
"resourceType": "Parameters",
"parameter": [
{ "name": "result", "valueBoolean": true },
{ "name": "display", "valueString": "Mild (qualifier value)" }
]
}
Via GET Request
In some cases, it may be simpler to invoke an operation with a GET request and encode the input parameters in the query string of the request URL. For example, the following operation requests are equivalent:
curl 'https://api.medplum.com/fhir/R4/ValueSet/$validate-code' \
-X POST \
-H "Content-Type: application/fhir+json" \
-H "Authorization: Bearer $MY_ACCESS_TOKEN" \
-d '{"resourceType":"Parameters","parameter":[{"name":"url","valueUri":"http://hl7.org/fhir/ValueSet/condition-severity"},{"name":"system","valueUri":"http://snomed.info/sct"},{"name":"code","valueCode":"255604002"}]}'
curl 'https://api.medplum.com/fhir/R4/ValueSet/$validate-code' \
--get \
-H "Authorization: Bearer $MY_ACCESS_TOKEN" \
-d 'url=http://hl7.org/fhir/ValueSet/condition-severity' \
-d 'system=http://snomed.info/sct' \
-d 'code=255604002'
This is possible when the request is idempotent and contains only simple input parameter types, i.e.
- The
OperationDefinitionmust not contain"affectsState": true - The request may only contain
inparameters with a simpletype(one starting with a lower-case letter, likestringorpositiveInt- but notCoding)
Reading the Response
For each out parameter in the response, the typed value(s) are recorded in the Parameters.parameter array. Multiple
values for a given output parameter will appear as multiple entries in the array, not a nested array in the value[x]
field.
Many operations return a specific resource type, instead of the usual Parameters resource. These cases are marked by
a single, required return output parameter with type specifying the returned resource type.
Error Responses
In case of an error, the server will return an HTTP status code in the 4xx-5xx range. The response body will contain
an OperationOutcome resource with details about the error.
For example, if the specified ValueSet could not be found by URL:
{
"resourceType": "OperationOutcome",
"issue": [
{
"severity": "error"
"code": "invalid",
"details": {
"text": "ValueSet http://example.com/ValueSet/missing not found"
},
}
]
}
Operation Documentation
Details about the FHIR Operations supported by Medplum server are organized below by category. For information about other available operations, see the complete list from the FHIR specification.
Terminology Operations
Operations for managing CodeSystem, ConceptMap, and ValueSet resources.
CodeSystem:
- CodeSystem/$import - Import codes into a CodeSystem
- CodeSystem/$lookup - Look up code details
- CodeSystem/$subsumes - Test subsumption relationship
- CodeSystem/$validate-code - Validate a code in a CodeSystem
ConceptMap:
- ConceptMap/$import - Import mappings into a ConceptMap
- ConceptMap/$translate - Translate a code using a ConceptMap
ValueSet:
- ValueSet/$expand - Expand a ValueSet
- ValueSet/$validate-code - Validate a code against a ValueSet
Patient Operations
Operations specific to Patient resources.
- Patient/$everything - Retrieve all patient data
- Patient/$summary - Generate International Patient Summary (IPS)
Bot Operations
Deploy, execute, and extend Medplum Bots.
- Bot/$deploy - Deploy bot code
- Bot/$execute - Execute a bot
- Custom Bot Operations - Create custom FHIR operations with Bots
Resource Validation & Transformation
Validate resources and transform data structures.
- $graph - Fetch related resources via GraphDefinition
- GraphQL - Query resources using GraphQL
- Questionnaire/$extract - Extract data from QuestionnaireResponse
- Resource/$validate - Validate a resource against profiles
- StructureDefinition/$expand-profile - Expand a StructureDefinition with nested profiles
Data Export & Import
Bulk data operations and format conversions.
- $csv - Export resources as CSV
- Bulk Data Export - FHIR Bulk Data Access
- CCDA Export - Export data as C-CDA documents
- Claim/$export - Export claims as CMS-1500 PDFs
Clinical Decision Support
Operations for measures, clinical plans, charges, and AI assistance.
- AI Assistant - AI-powered clinical assistance
- ChargeItemDefinition/$apply - Apply pricing rules to ChargeItem
- Measure/$evaluate-measure - Evaluate a clinical quality measure
- PlanDefinition/$apply - Apply a PlanDefinition to generate resources
Project & System Administration
Project management and system operations.
- AsyncJob/$cancel - Cancel an asynchronous job
- Project/$clone - Clone a Medplum project
- Project/$init - Initialize a new project
- $expunge - Permanently delete resources
- $resend - Resend a subscription notification
- $set-accounts - Set resource account references
Authentication & Security
Client application, credential, and user management operations.
- ClientApplication/$rotate-secret - Rotate client secrets
- ClientApplication/$smart-launch - SMART on FHIR app launch
- User/$update-email - Update user email address