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
Enable this FHIR service in OpenEMR menu: Administration->Globals->Connectors->"Enable OpenEMR REST API"
There are several ways to make API calls from an authorized session and maintain security:
- See the script at tests/api/InternalApiTest.php for examples of internal API use cases.
FHIR endpoints Use http:https://localhost:8300/apis/fhir as base URI.
Example: http:https://localhost:8300/apis/fhir/Patient
returns a Patient's bundle resource, etc
The OpenEMR FHIR API utilizes the OAuth2 password credential flow for authentication. To obtain an API token, submit your login credentials and requested scope. The scope must match a site that has been setup in OpenEMR, in the /sites/ directory. If additional sites have not been created, set the scope to 'default'.
curl -X POST -H 'Content-Type: application/json' 'http:https://localhost:8300/apis/fhir/auth' \
-d '{
"grant_type":"password",
"username": "ServiceUser",
"password": "password",
"scope":"site id"
}'
Response:
{
"token_type": "Bearer",
"access_token": "eyJ0b2tlbiI6IjAwNmZ4TWpsNWhsZmNPelZicXBEdEZVUlNPQUY5KzdzR1Jjejc4WGZyeGFjUjY2QlhaaEs4eThkU3cxbTd5VXFBeTVyeEZpck9mVzBQNWc5dUlidERLZ0trUElCME5wRDVtTVk5bE9WaE5DTHF5RnRnT0Q0OHVuaHRvbXZ6OTEyNmZGUmVPUllSYVJORGoyZTkzTDA5OWZSb0ZRVGViTUtWUFd4ZW5cL1piSzhIWFpJZUxsV3VNcUdjQXR5dmlLQXRXNDAiLCJzaXRlX2lkIjoiZGVmYXVsdCIsImFwaSI6Im9lbXIifQ==",
"expires_in": "3600",
"user_data": {
"user_id": "1"
}
}
The Bearer token is required for each OpenEMR API request, and is conveyed using an Authorization header.
curl -X GET 'http:https://localhost:8300/apis/fhir/Patient' \
-H 'Authorization: Bearer eyJ0b2tlbiI6IjAwNnZ3eGJZYmFrOXlxUjF4U290Y1g4QVVDd3JOcG5yYXZEaFlqaHFjWXJXRGNDQUtFZmJONkh2cElTVkJiaWFobHBqOTBYZmlNRXpiY2FtU01pSHk1UzFlMmgxNmVqZEhcL1ZENlNtaVpTRFRLMmtsWDIyOFRKZzNhQmxMdUloZmNJM3FpMGFKZ003OXdtOGhYT3dpVkx5b3BFRXQ1TlNYNTE3UW5TZ0dsUVdQbG56WjVxOVYwc21tdDlSQ3RvcDV3TEkiLCJzaXRlX2lkIjoiZGVmYXVsdCIsImFwaSI6ImZoaXIifQ=='
curl -X GET 'http:https://localhost:8300/apis/fhir/Patient'
curl -X GET 'http:https://localhost:8300/apis/fhir/Patient/1'
curl -X POST -H 'Content-Type: application/fhir+json' 'http:https://localhost:8300/apis/fhir/Patient' -d \
'{
"resourceType": "Patient",
"identifier": [ { "system": "urn:oid:1.2.36.146.595.217.0.1", "value": "12345" } ],
"name": [ {
"family": "Chalmers",
"given": [ "Peter", "James" ]
} ],
"gender": "male",
"birthDate": "1974-12-25"
}'
curl -X PUT -H 'Content-Type: application/fhir+json' 'http:https://localhost:8300/apis/fhir/Patient/1' -d \
'{
"resourceType": "Patient",
"id": "1",
"identifier": [ { "system": "urn:oid:1.2.36.146.595.217.0.1", "value": "12345" } ],
"name": [ {
"family": "Chalmers",
"given": [ "Peter", "James" ]
} ],
"gender": "male",
"birthDate": "1974-01-13",
"address": [ {
"line": [ "534 Erewhon St" ],
"city": "PleasantVille",
"state": "Vic",
"postalCode": "3999"
} ]
}'
curl -X PATCH -H 'Content-Type: application/fhir+json' 'http:https://localhost:8300/apis/fhir/Patient/1' -d \
'[
{
"op": "replace",
"path": "/address/0/postalCode",
"value": "M5C 2X8"
},
{
"op": "replace",
"path": "/birthDate",
"value": "1974-02-13"
}
]'
curl -X GET 'http:https://localhost:8300/apis/fhir/Encounter'
curl -X GET 'http:https://localhost:8300/apis/fhir/Encounter/1'
curl -X GET 'http:https://localhost:8300/apis/fhir/Organization'
curl -X GET 'http:https://localhost:8300/apis/fhir/Organization/1'
curl -X GET 'http:https://localhost:8300/apis/fhir/AllergyIntolerance'
curl -X GET 'http:https://localhost:8300/apis/fhir/AllergyIntolerance/1'
curl -X POST -H 'Content-Type: application/fhir+json' 'http:https://localhost:8300/apis/fhir/QuestionnaireResponse' -d \
'{
"resourceType": "QuestionnaireResponse",
"id": "697485",
"meta": {
"versionId": "1",
"lastUpdated": "2020-03-22T09:11:45.181+00:00",
"source": "#L0otRLyoImuOVD2S"
},
"status": "completed",
"item": [ {
"linkId": "1",
"text": "Do you have allergies?"
}, {
"linkId": "2",
"text": "General questions",
"item": [ {
"linkId": "2.1",
"text": "What is your gender?"
}, {
"linkId": "2.2",
"text": "What is your date of birth?"
}]
}]
} ]
}'
curl -X GET 'http:https://localhost:8300/apis/fhir/Immunization'
curl -X GET 'http:https://localhost:8300/apis/fhir/Immunization/1'
curl -X GET 'http:https://localhost:8300/apis/fhir/Condition'
curl -X GET 'http:https://localhost:8300/apis/fhir/Condition/1'
curl -X GET 'http:https://localhost:8300/apis/fhir/Procedure'
curl -X GET 'http:https://localhost:8300/apis/fhir/Procedure/1'
- For business logic, make or use the services here
- For controller logic, make or use the classes here
- For routing declarations, use the class here.
- TODO(?): ?