1 # OpenEMR FHIR API Documentation
5 Easy-to-use JSON-based REST API for OpenEMR FHIR. All code is done in classes and separate from the view to help with codebase modernization efforts. See standard OpenEMR API docs [here](API_README.md)
9 FHIR endpoints are defined in the [primary routes file](_rest_routes.inc.php). The routes file maps an external, addressable
10 endpoint to the OpenEMR FHIR controller which handles the request, and also handles the JSON data conversions.
13 "POST /fhir/Patient" => function () {
14 RestConfig::authorization_check("patients", "demo");
15 $data = (array)(json_decode(file_get_contents("php://input"), true));
16 return (new FhirPatientRestController())->post($data);
20 At a high level, the request processing flow consists of the following steps:
23 JSON Request -> FHIR Controller Component -> FHIR Validation -> Parsing FHIR Resource -> Standard Service Component -> Validation -> Database
26 The logical response flow begins with the database result:
29 Database Result -> Service Component -> FHIR Service Component -> Parse OpenEMR Record -> FHIR Controller Component -> RequestControllerHelper -> JSON Response
34 - [FHIR API Endpoints](FHIR_README.md#fhir-endpoints)
35 - [Capability Statement](FHIR_README.md#capability-statement)
36 - [Patient](FHIR_README.md#patient-resource)
37 - [Encounter](FHIR_README.md#encounter-resource)
38 - [Practitioner](FHIR_README.md#practitioner-resource)
39 - [PractitionerRole](FHIR_README.md#practitionerrole-resource)
40 - [Immunization](FHIR_README.md#immunization-resource)
41 - [AllergyIntolerance](FHIR_README.md#allergyintolerance-resource)
42 - [Organization](FHIR_README.md#organization-resource)
43 - [Observation](FHIR_README.md#observation-resource)
44 - [QuestionnaireResponse](FHIR_README.md#questionnaireresponse-resource)
45 - [Condition](FHIR_README.md#condition-resource)
46 - [Procedure](FHIR_README.md#procedure-resource)
47 - [MedicationRequest](FHIR_README.md#medicationrequest-resource)
48 - [Medication](FHIR_README.md#medication-resource)
49 - [Location](FHIR_README.md#location-resource)
50 - [CareTeam](FHIR_README.md#careTeam-resource)
51 - [Provenance](FHIR_README.md#Provenance-resources)
52 - [Patient Portal FHIR API Endpoints](FHIR_README.md#patient-portal-fhir-endpoints)
53 - [Patient](FHIR_README.md#patient-portal-patient-resource)
57 Enable the Standard FHIR service (/fhir/ endpoints) in OpenEMR menu: Administration->Globals->Connectors->"Enable OpenEMR Standard FHIR REST API"
59 Enable the Patient Portal FHIR service (/portalfhir/ endpoints) in OpenEMR menu: Administration->Globals->Connectors->"Enable OpenEMR Patient Portal FHIR REST API"
61 ### Using FHIR API Internally
63 There are several ways to make API calls from an authorized session and maintain security:
65 - See the script at tests/api/InternalApiTest.php for examples of internal API use cases.
69 Multisite is supported by including the site in the endpoint. When not using multisite or using the `default` multisite site, then a typical path would look like `apis/default/fhir/patient`. If you were using multisite and using a site called `alternate`, then the path would look like `apis/alternate/fhir/patient`.
73 OpenEMR uses OIDC compliant authorization for API. SSL is required and setting baseurl at Administration->Globals->Connectors->'Site Address (required for OAuth2 and FHIR)' is required.
75 See [Authorization](API_README.md#authorization) for more details.
79 Standard FHIR endpoints Use `http://localhost:8300/apis/default/fhir as base URI.`
81 Note that the `default` component can be changed to the name of the site when using OpenEMR's multisite feature.
83 _Example:_ `http://localhost:8300/apis/default/fhir/Patient` returns a Patient's bundle resource, etc
85 The Bearer token is required for each OpenEMR FHIR request (except for the Capability Statement), and is conveyed using an Authorization header. Note that the Bearer token is the access_token that is obtained in the [Authorization](API_README.md#authorization) section.
90 curl -X GET 'http://localhost:8300/apis/fhir/Patient' \
91 -H 'Authorization: Bearer eyJ0b2tlbiI6IjAwNnZ3eGJZYmFrOXlxUjF4U290Y1g4QVVDd3JOcG5yYXZEaFlqaHFjWXJXRGNDQUtFZmJONkh2cElTVkJiaWFobHBqOTBYZmlNRXpiY2FtU01pSHk1UzFlMmgxNmVqZEhcL1ZENlNtaVpTRFRLMmtsWDIyOFRKZzNhQmxMdUloZmNJM3FpMGFKZ003OXdtOGhYT3dpVkx5b3BFRXQ1TlNYNTE3UW5TZ0dsUVdQbG56WjVxOVYwc21tdDlSQ3RvcDV3TEkiLCJzaXRlX2lkIjoiZGVmYXVsdCIsImFwaSI6ImZoaXIifQ=='
96 ### Capability Statement
98 #### GET fhir/metadata
100 This will return the Capability Statement.
103 curl -X GET 'http://localhost:8300/apis/default/fhir/metadata'
110 #### GET fhir/Patient
115 curl -X GET 'http://localhost:8300/apis/default/fhir/Patient'
118 #### GET fhir/Patient[id]
123 curl -X GET 'http://localhost:8300/apis/default/fhir/Patient/90a8923c-0b1c-4d0a-9981-994b143381a7'
126 - Supported Search Parameters
140 #### POST fhir/Patient
145 curl -X POST -H 'Content-Type: application/fhir+json' 'http://localhost:8300/apis/default/fhir/Patient' -d \
147 "resourceType": "Patient",
148 "identifier": [ { "system": "urn:oid:1.2.36.146.595.217.0.1", "value": "12345" } ],
150 "family": "Chalmers",
151 "given": [ "Peter", "James" ]
154 "birthDate": "1974-12-25"
158 #### PUT fhir/Patient/[id]
163 curl -X PUT -H 'Content-Type: application/fhir+json' 'http://localhost:8300/apis/default/fhir/Patient/90a8923c-0b1c-4d0a-9981-994b143381a7' -d \
165 "resourceType": "Patient",
167 "identifier": [ { "system": "urn:oid:1.2.36.146.595.217.0.1", "value": "12345" } ],
169 "family": "Chalmers",
170 "given": [ "Peter", "James" ]
173 "birthDate": "1974-01-13",
175 "line": [ "534 Erewhon St" ],
176 "city": "PleasantVille",
183 #### PATCH fhir/Patient/[id]
188 curl -X PATCH -H 'Content-Type: application/fhir+json' 'http://localhost:8300/apis/default/fhir/Patient/90a8923c-0b1c-4d0a-9981-994b143381a7' -d \
192 "path": "/address/0/postalCode",
197 "path": "/birthDate",
198 "value": "1974-02-13"
205 ### Encounter Resource
207 #### GET fhir/Encounter
212 curl -X GET 'http://localhost:8300/apis/default/fhir/Encounter'
215 #### GET fhir/Encounter[id]
220 curl -X GET 'http://localhost:8300/apis/default/fhir/Encounter/90c196f2-51cc-4655-8858-3a80aebff3ef'
223 - Supported Search Parameters
230 ### Practitioner Resource
232 #### GET fhir/Practitioner
237 curl -X GET 'http://localhost:8300/apis/default/fhir/Practitioner'
240 #### GET fhir/Practitioner[id]
245 curl -X GET 'http://localhost:8300/apis/default/fhir/Practitioner/90a8923c-0b1c-4d0a-9981-994b143381a7'
248 - Supported Search Parameters
261 #### POST fhir/Practitioner
266 curl -X POST -H 'Content-Type: application/fhir+json' 'http://localhost:8300/apis/default/fhir/Practitioner' -d \
268 "resourceType": "Practitioner",
269 "identifier": [ { "system": "http://hl7.org/fhir/sid/us-npi", "value": "1122334499" } ],
272 "family": "Chalmers",
273 "given": [ "Peter", "James" ]
278 #### PATCH fhir/Practitioner/[id]
283 curl -X PATCH -H 'Content-Type: application/fhir+json' 'http://localhost:8300/apis/default/fhir/Practitioner/90a8923c-0b1c-4d0a-9981-994b143381a7' -d \
285 "resourceType": "Practitioner",
286 "identifier": [ { "system": "http://hl7.org/fhir/sid/us-npi", "value": "1155667799" } ],
290 "given": [ "Katy", "Wilson" ]
293 "line": [ "534 Erewhon St" ],
294 "city": "PleasantVille",
303 ### PractitionerRole Resource
305 #### GET fhir/PractitionerRole
310 curl -X GET 'http://localhost:8300/apis/default/fhir/PractitionerRole'
313 #### GET fhir/PractitionerRole/[id]
318 curl -X GET 'http://localhost:8300/apis/default/fhir/PractitionerRole/90de091a-91e9-4bbe-9a81-75ed623f65bf'
321 - Supported Search Parameters
327 ### Immunization Resource
329 #### GET fhir/Immunization
334 curl -X GET 'http://localhost:8300/apis/default/fhir/Immunization'
337 #### GET fhir/Immunization/[id]
342 curl -X GET 'http://localhost:8300/apis/default/fhir/Immunization/90feaaa2-4097-4437-966e-c425d1958dd6'
345 - Supported Search Parameters
350 ### AllergyIntolerance Resource
352 #### GET fhir/AllergyIntolerance
357 curl -X GET 'http://localhost:8300/apis/default/fhir/AllergyIntolerance'
360 #### GET fhir/AllergyIntolerance/[id]
365 curl -X GET 'http://localhost:8300/apis/default/fhir/AllergyIntolerance/90feaaa2-4097-4437-966e-c425d1958dd6'
370 ### Organization Resource
372 #### GET /fhir/Organization
377 curl -X GET 'http://localhost:8300/apis/default/fhir/Organization'
380 #### GET /fhir/Organization/:id
385 curl -X GET 'http://localhost:8300/apis/default/fhir/Organization/1'
390 ### Observation Resource
392 #### GET /fhir/Observation
397 curl -X GET 'http://localhost:8300/apis/default/fhir/Observation'
400 #### GET /fhir/Observation/:uuid
405 curl -X GET 'http://localhost:8300/apis/default/fhir/Observation/9150635b-0705-4a27-8820-df8b56cf07eb'
410 ### QuestionnaireResponse Resource
412 #### POST /fhir/QuestionnaireResponse
417 curl -X POST -H 'Content-Type: application/fhir+json' 'http://localhost:8300/apis/default/fhir/QuestionnaireResponse' -d \
419 "resourceType": "QuestionnaireResponse",
423 "lastUpdated": "2020-03-22T09:11:45.181+00:00",
424 "source": "#L0otRLyoImuOVD2S"
426 "status": "completed",
429 "text": "Do you have allergies?"
432 "text": "General questions",
435 "text": "What is your gender?"
438 "text": "What is your date of birth?"
447 ### Condition Resource
449 #### GET fhir/Condition
454 curl -X GET 'http://localhost:8300/apis/default/fhir/Condition'
457 #### GET fhir/Condition/[id]
462 curl -X GET 'http://localhost:8300/apis/default/fhir/Condition/9109890a-6756-44c1-a82d-bdfac91c7424'
467 ### Procedure Resource
469 #### GET /fhir/Procedure
474 curl -X GET 'http://localhost:8300/apis/default/fhir/Procedure'
477 #### GET /fhir/Procedure/:uuid
482 curl -X GET 'http://localhost:8300/apis/default/fhir/Procedure/9109890a-6756-44c1-a82d-bdfac91c7424'
487 ### MedicationRequest Resource
489 #### GET /fhir/MedicationRequest
494 curl -X GET 'http://localhost:8300/apis/default/fhir/MedicationRequest'
497 #### GET /fhir/MedicationRequest/:uuid
502 curl -X GET 'http://localhost:8300/apis/default/fhir/MedicationRequest/9128a1ec-95be-4649-8a66-d3686b7ab0ca'
507 ### Medication Resource
509 #### GET /fhir/Medication
514 curl -X GET 'http://localhost:8300/apis/default/fhir/Medication'
517 #### GET /fhir/Medication/:uuid
522 curl -X GET 'http://localhost:8300/apis/default/fhir/Medication/9109890a-6756-44c1-a82d-bdfac91c7424'
527 ### Location Resource
529 #### GET /fhir/Location
534 curl -X GET 'http://localhost:8300/apis/default/fhir/Location'
537 #### GET /fhir/Location/:uuid
542 curl -X GET 'http://localhost:8300/apis/default/fhir/Location/90f3d0e9-2a19-453b-84bd-1fa2b533f96c'
547 ### CareTeam Resource
549 #### GET /fhir/CareTeam
554 curl -X GET 'http://localhost:8300/apis/default/fhir/CareTeam'
557 #### GET /fhir/CareTeam/:uuid
562 curl -X GET 'http://localhost:8300/apis/default/fhir/CareTeam/915e8fb4-86b2-4365-a420-d46fc07d5aed'
567 ### Provenance Resources
569 Provenance resources are requested by including `_revinclude=Provenance:target` in the search of a resource. Is currently supported for the following resources:
572 curl -X GET 'http://localhost:8300/apis/default/fhir/AllergyIntolerance?_revinclude=Provenance:target'
575 ## Patient Portal FHIR Endpoints
577 OpenEMR patient portal fhir endpoints Use `http://localhost:8300/apis/default/portalfhir as base URI.`
579 Note that the `default` component can be changed to the name of the site when using OpenEMR's multisite feature.
581 _Example:_ `http://localhost:8300/apis/default/portalfhir/Patient` returns a resource of the patient.
583 The Bearer token is required for each OpenEMR FHIR request (except for the Capability Statement), and is conveyed using an Authorization header. Note that the Bearer token is the access_token that is obtained in the [Authorization](API_README.md#authorization) section.
588 curl -X GET 'http://localhost:8300/apis/default/portalfhir/Patient' \
589 -H 'Authorization: Bearer eyJ0b2tlbiI6IjAwNmZ4TWpsNWhsZmNPelZicXBEdEZVUlNPQUY5KzdzR1Jjejc4WGZyeGFjUjY2QlhaaEs4eThkU3cxbTd5VXFBeTVyeEZpck9mVzBQNWc5dUlidERLZ0trUElCME5wRDVtTVk5bE9WaE5DTHF5RnRnT0Q0OHVuaHRvbXZ6OTEyNmZGUmVPUllSYVJORGoyZTkzTDA5OWZSb0ZRVGViTUtWUFd4ZW5cL1piSzhIWFpJZUxsV3VNcUdjQXR5dmlLQXRXNDAiLCJzaXRlX2lkIjoiZGVmYXVsdCIsImFwaSI6Im9lbXIifQ=='
594 ### Patient Portal Patient Resource
596 #### GET /portalfhir/Patient
601 curl -X GET 'http://localhost:8300/apis/default/portalfhir/Patient'