couple more minor documentation updates
[openemr.git] / FHIR_README.md
bloba1c1e0d486de685169958c806151453bbabe448b
1 # OpenEMR FHIR API Documentation
3 ## Overview
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)
7 ## Implementation
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.
12 ```php
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);
18 ```
20 At a high level, the request processing flow consists of the following steps:
22 ```
23 JSON Request -> FHIR Controller Component -> FHIR Validation -> Parsing FHIR Resource -> Standard Service Component -> Validation -> Database
24 ```
26 The logical response flow begins with the database result:
28 ```
29 Database Result -> Service Component -> FHIR Service Component -> Parse OpenEMR Record -> FHIR Controller Component -> RequestControllerHelper -> JSON Response
30 ```
32 ### Sections
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)
55 ### Prerequisite
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.
67 ### Multisite Support
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`.
71 ### Authorization
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.
77 ### FHIR Endpoints
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.
87 Request:
89 ```sh
90 curl -X GET 'http://localhost:8300/apis/fhir/Patient' \
91   -H 'Authorization: Bearer eyJ0b2tlbiI6IjAwNnZ3eGJZYmFrOXlxUjF4U290Y1g4QVVDd3JOcG5yYXZEaFlqaHFjWXJXRGNDQUtFZmJONkh2cElTVkJiaWFobHBqOTBYZmlNRXpiY2FtU01pSHk1UzFlMmgxNmVqZEhcL1ZENlNtaVpTRFRLMmtsWDIyOFRKZzNhQmxMdUloZmNJM3FpMGFKZ003OXdtOGhYT3dpVkx5b3BFRXQ1TlNYNTE3UW5TZ0dsUVdQbG56WjVxOVYwc21tdDlSQ3RvcDV3TEkiLCJzaXRlX2lkIjoiZGVmYXVsdCIsImFwaSI6ImZoaXIifQ=='
92 ```
94 ---
96 ### Capability Statement
98 #### GET fhir/metadata
100 This will return the Capability Statement.
102 ```sh
103 curl -X GET 'http://localhost:8300/apis/default/fhir/metadata'
108 ### Patient Resource
110 #### GET fhir/Patient
112 Request:
114 ```sh
115 curl -X GET 'http://localhost:8300/apis/default/fhir/Patient'
118 #### GET fhir/Patient[id]
120 Request:
122 ```sh
123 curl -X GET 'http://localhost:8300/apis/default/fhir/Patient/90a8923c-0b1c-4d0a-9981-994b143381a7'
126 -   Supported Search Parameters
127     -   address
128     -   address-city
129     -   address-postalcode
130     -   address-state
131     -   birthdate
132     -   email
133     -   family
134     -   gender
135     -   given
136     -   name
137     -   phone
138     -   telecom
140 #### POST fhir/Patient
142 Request:
144 ```sh
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" } ],
149   "name": [ {
150       "family": "Chalmers",
151       "given": [ "Peter", "James" ]
152   } ],
153   "gender": "male",
154   "birthDate": "1974-12-25"
158 #### PUT fhir/Patient/[id]
160 Request:
162 ```sh
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",
166   "id": "1",
167   "identifier": [ { "system": "urn:oid:1.2.36.146.595.217.0.1", "value": "12345" } ],
168   "name": [ {
169       "family": "Chalmers",
170       "given": [ "Peter", "James" ]
171   } ],
172   "gender": "male",
173   "birthDate": "1974-01-13",
174   "address": [ {
175       "line": [ "534 Erewhon St" ],
176       "city": "PleasantVille",
177       "state": "Vic",
178       "postalCode": "3999"
179   } ]
183 #### PATCH fhir/Patient/[id]
185 Request:
187 ```sh
188 curl -X PATCH -H 'Content-Type: application/fhir+json' 'http://localhost:8300/apis/default/fhir/Patient/90a8923c-0b1c-4d0a-9981-994b143381a7' -d \
191    "op": "replace",
192    "path": "/address/0/postalCode",
193    "value": "M5C 2X8"
194  },
196    "op": "replace",
197    "path": "/birthDate",
198    "value": "1974-02-13"
205 ### Encounter Resource
207 #### GET fhir/Encounter
209 Request:
211 ```sh
212 curl -X GET 'http://localhost:8300/apis/default/fhir/Encounter'
215 #### GET fhir/Encounter[id]
217 Request:
219 ```sh
220 curl -X GET 'http://localhost:8300/apis/default/fhir/Encounter/90c196f2-51cc-4655-8858-3a80aebff3ef'
223 -   Supported Search Parameters
224     -   \_id
225     -   patient
226     -   date {gt|lt|ge|le}
230 ### Practitioner Resource
232 #### GET fhir/Practitioner
234 Request:
236 ```sh
237 curl -X GET 'http://localhost:8300/apis/default/fhir/Practitioner'
240 #### GET fhir/Practitioner[id]
242 Request:
244 ```sh
245 curl -X GET 'http://localhost:8300/apis/default/fhir/Practitioner/90a8923c-0b1c-4d0a-9981-994b143381a7'
248 -   Supported Search Parameters
249     -   address
250     -   address-city
251     -   address-postalcode
252     -   address-state
253     -   email
254     -   active
255     -   family
256     -   given
257     -   name
258     -   phone
259     -   telecom
261 #### POST fhir/Practitioner
263 Request:
265 ```sh
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" } ],
270   "name": [ {
271       "use": "official",
272       "family": "Chalmers",
273       "given": [ "Peter", "James" ]
274   } ]
278 #### PATCH fhir/Practitioner/[id]
280 Request:
282 ```sh
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" } ],
287   "name": [ {
288       "use": "official",
289       "family": "Theil",
290       "given": [ "Katy", "Wilson" ]
291   } ],
292   "address": [ {
293       "line": [ "534 Erewhon St" ],
294       "city": "PleasantVille",
295       "state": "Vic",
296       "postalCode": "3999"
297   } ]
303 ### PractitionerRole Resource
305 #### GET fhir/PractitionerRole
307 Request:
309 ```sh
310 curl -X GET 'http://localhost:8300/apis/default/fhir/PractitionerRole'
313 #### GET fhir/PractitionerRole/[id]
315 Request:
317 ```sh
318 curl -X GET 'http://localhost:8300/apis/default/fhir/PractitionerRole/90de091a-91e9-4bbe-9a81-75ed623f65bf'
321 -   Supported Search Parameters
322     -   speciality
323     -   practitioner
327 ### Immunization Resource
329 #### GET fhir/Immunization
331 Request:
333 ```sh
334 curl -X GET 'http://localhost:8300/apis/default/fhir/Immunization'
337 #### GET fhir/Immunization/[id]
339 Request:
341 ```sh
342 curl -X GET 'http://localhost:8300/apis/default/fhir/Immunization/90feaaa2-4097-4437-966e-c425d1958dd6'
345 -   Supported Search Parameters
346     -   patient
350 ### AllergyIntolerance Resource
352 #### GET fhir/AllergyIntolerance
354 Request:
356 ```sh
357 curl -X GET 'http://localhost:8300/apis/default/fhir/AllergyIntolerance'
360 #### GET fhir/AllergyIntolerance/[id]
362 Request:
364 ```sh
365 curl -X GET 'http://localhost:8300/apis/default/fhir/AllergyIntolerance/90feaaa2-4097-4437-966e-c425d1958dd6'
370 ### Organization Resource
372 #### GET /fhir/Organization
374 Request:
376 ```sh
377 curl -X GET 'http://localhost:8300/apis/default/fhir/Organization'
380 #### GET /fhir/Organization/:id
382 Request:
384 ```sh
385 curl -X GET 'http://localhost:8300/apis/default/fhir/Organization/1'
390 ### Observation Resource
392 #### GET /fhir/Observation
394 Request:
396 ```sh
397 curl -X GET 'http://localhost:8300/apis/default/fhir/Observation'
400 #### GET /fhir/Observation/:uuid
402 Request:
404 ```sh
405 curl -X GET 'http://localhost:8300/apis/default/fhir/Observation/9150635b-0705-4a27-8820-df8b56cf07eb'
410 ### QuestionnaireResponse Resource
412 #### POST /fhir/QuestionnaireResponse
414 Request:
416 ```sh
417 curl -X POST -H 'Content-Type: application/fhir+json' 'http://localhost:8300/apis/default/fhir/QuestionnaireResponse' -d \
419   "resourceType": "QuestionnaireResponse",
420   "id": "697485",
421   "meta": {
422     "versionId": "1",
423     "lastUpdated": "2020-03-22T09:11:45.181+00:00",
424     "source": "#L0otRLyoImuOVD2S"
425   },
426   "status": "completed",
427   "item": [ {
428     "linkId": "1",
429     "text": "Do you have allergies?"
430   }, {
431     "linkId": "2",
432     "text": "General questions",
433     "item": [ {
434       "linkId": "2.1",
435       "text": "What is your gender?"
436     }, {
437       "linkId": "2.2",
438       "text": "What is your date of birth?"
439     }]
440   }]
441   } ]
447 ### Condition Resource
449 #### GET fhir/Condition
451 Request:
453 ```sh
454 curl -X GET 'http://localhost:8300/apis/default/fhir/Condition'
457 #### GET fhir/Condition/[id]
459 Request:
461 ```sh
462 curl -X GET 'http://localhost:8300/apis/default/fhir/Condition/9109890a-6756-44c1-a82d-bdfac91c7424'
467 ### Procedure Resource
469 #### GET /fhir/Procedure
471 Request:
473 ```sh
474 curl -X GET 'http://localhost:8300/apis/default/fhir/Procedure'
477 #### GET /fhir/Procedure/:uuid
479 Request:
481 ```sh
482 curl -X GET 'http://localhost:8300/apis/default/fhir/Procedure/9109890a-6756-44c1-a82d-bdfac91c7424'
487 ### MedicationRequest Resource
489 #### GET /fhir/MedicationRequest
491 Request:
493 ```sh
494 curl -X GET 'http://localhost:8300/apis/default/fhir/MedicationRequest'
497 #### GET /fhir/MedicationRequest/:uuid
499 Request:
501 ```sh
502 curl -X GET 'http://localhost:8300/apis/default/fhir/MedicationRequest/9128a1ec-95be-4649-8a66-d3686b7ab0ca'
507 ### Medication Resource
509 #### GET /fhir/Medication
511 Request:
513 ```sh
514 curl -X GET 'http://localhost:8300/apis/default/fhir/Medication'
517 #### GET /fhir/Medication/:uuid
519 Request:
521 ```sh
522 curl -X GET 'http://localhost:8300/apis/default/fhir/Medication/9109890a-6756-44c1-a82d-bdfac91c7424'
527 ### Location Resource
529 #### GET /fhir/Location
531 Request:
533 ```sh
534 curl -X GET 'http://localhost:8300/apis/default/fhir/Location'
537 #### GET /fhir/Location/:uuid
539 Request:
541 ```sh
542 curl -X GET 'http://localhost:8300/apis/default/fhir/Location/90f3d0e9-2a19-453b-84bd-1fa2b533f96c'
547 ### CareTeam Resource
549 #### GET /fhir/CareTeam
551 Request:
553 ```sh
554 curl -X GET 'http://localhost:8300/apis/default/fhir/CareTeam'
557 #### GET /fhir/CareTeam/:uuid
559 Request:
561 ```sh
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:
570   - AllergyIntolerance
571       ```sh
572       curl -X GET 'http://localhost:8300/apis/default/fhir/AllergyIntolerance?_revinclude=Provenance:target'
573       ```
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.
585 Request:
587 ```sh
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
598 Request:
600 ```sh
601 curl -X GET 'http://localhost:8300/apis/default/portalfhir/Patient'