You access FHIR server using REST API requests which are just standard HTTP calls (https://www.hl7.org/fhir/http.html).
Typically, this is done via:
- A tool like Postman (https://www.postman.com/) to do the calls manually for testing
- A command line tool like curl (https://curl.se/)
curl --location --request GET 'https://fhir.icanbwell.com/4_0_0/Patient' \ --header 'Authorization: Bearer {token here}' --header 'Content-Type: application/fhir+json'
- Code in Javascript or Python or other programming language
Javascript Example:
var xhr = new XMLHttpRequest();
xhr.withCredentials = true;
xhr.addEventListener('readystatechange', function () {
if (this.readyState === 4) {
console.log(this.responseText);
}
});
xhr.open('GET', 'https://fhir.icanbwell.com/4_0_0/Patient');
xhr.setRequestHeader('Authorization', 'Bearer {token here}');
xhr.setRequestHeader('Content-Type', 'application/fhir+json');
xhr.send();
Python Example:
import requests
url = "https://fhir.icanbwell.com/4_0_0/Patient"
payload={}
headers = {
'Authorization': 'Bearer {token here}',
'Content-Type': 'application/fhir+json'
}
response = requests.request("GET", url, headers=headers, data=payload)
print(response.text)
Note: Make sure you set Content-Type: application/fhir+json
header in your HTTP call to the FHIR server.
You can search for resources by going to the /4_0_0/{resource} url e.g., https://fhir.icanbwell.com/4_0_0/Patient
Note: The server will return only 10 records unless the _count query parameter is specified per below.
Use the _count
query parameter e.g.,
https://fhir.icanbwell.com/4_0_0/Practitioner?_count=10
The default is 100
Note: Passing 0 in this query parameter is equivalent to no limit.
FHIR Specification: https://www.hl7.org/fhir/search.html#count
Specify a comma separated list in _elements
query parameter e.g.,
https://fhir.icanbwell.com/4_0_0/QuestionnaireResponse?_elements=id,meta
FHIR Specification: https://www.hl7.org/fhir/search.html#elements
Specify a comma separated list in _sort
query parameter e.g.,
https://fhir.icanbwell.com/4_0_0/QuestionnaireResponse?_count=10&_sort=meta.lastUpdated (ascending)
To specify sorted a field descending, prepend the field name with -
https://fhir.icanbwell.com/4_0_0/QuestionnaireResponse?_count=10&_sort=-meta.lastUpdated
Multiple sort fields can be specified: https://fhir.icanbwell.com/4_0_0/QuestionnaireResponse?_count=10&_sort=-meta.lastUpdated,id
FHIR Specification: https://www.hl7.org/fhir/search.html#_sort
To page through the data specify the _count
and the _getpageoffset
query parameters e.g., https://fhir.icanbwell.com/4_0_0/ExplanationOfBenefit?_count=2&_getpagesoffset=2
When you get no resources back then this means you've reached the end.
Note: Do not use _getpagesoffset based paging if a recource have millions of records. If FHIR Server is not able read 1st record from MongoDB within 1 minute then it will return as error with 500 status code.
Each REST Search to FHIR Server returns _next
url in bundle that can be used to fetch next set of data for search and _count
can specify the no. of records that can be returned in each API call. When you get no resources back then this means you've reached the end.
We do not have any maximum number for _count
. It can be anything but _count=0
in this query parameter is equivalent to no limit and return all the records that can be transfered in 1 hours.
Note: FHIR Server can keep REST resouce fetch connection open till 1 hour and if request is not able to complete in 1 hour then last record may be in-complete json.
Helix FHIR Server supports all the standard FHIR search parameters: https://www.hl7.org/fhir/searchparameter-registry.html. Below are some examples:
FHIR Specification: https://www.hl7.org/fhir/search.html.
By default, the FHIR server just returns the page of data was requested. However, you can request to get the total count of records that meet your query by passing the _total=accurate
query parameter e.g.,
https://fhir.icanbwell.com/4_0_0/Practitioner?source=http://somehealth.org/insurance&_count=10&_total=accurate
The total count will be returned in the total
field of the Bundle
that is returned.
Note: This is an expensive operation when the count of records that match your query is high. It is recommended to only request total
when it is actually needed.
FHIR Specification: https://www.hl7.org/fhir/search.html#total
By default, the FHIR server does not validate if a search parameter passed in a request is valid or not. Pass the header handling=strict
to enable strict parameter validation. Default value of the header is lenient
that does not perform the unsupported or unknown parameter validation. Ref: https://www.hl7.org/fhir/search.html#errors
Parameter Type | Modifier | Example | Description |
---|---|---|---|
All | |||
missing | [base]/ExplanationOfBenefit?patient:missing=true | will match on all elements where either the underlying element is omitted or where the element is present with no value | |
not | [base]/4_0_0/Patient?_security:not=https://www.icanbwell.com/owner%7Cbwell | can be used to negate any search filter | |
ID | |||
above | [base]/Observation?id:above=07ee0c18-a6c6-5b8e-b7ba-adb395447f52 | allows to fetch result for resources after specified id. Mainly used for pagination to get next page along with default or specified sorting order | |
below | [base]/Observation?id:below=07ee0c18-a6c6-5b8e-b7ba-adb395447f52 | allows to fetch result for resources before specified id. Mainly used for pagination to get previous page along with default or specified sorting order | |
String | |||
exact | [base]/Patient?family:exact=Son | allows to indicate that a supplied string input is the complete and exact value that should be matched | |
contains | [base]/Patient?family:contains=son | allows to indicate that a supplied string input should be matched as a case-insensitive match anywhere in the target string | |
Token | |||
text | [base]/Condition?code:text=headache | allows to indicate that a supplied string should be used to perform a string-search against the text associated with a code or value | |
of-type | [base]/Patient?identifier:of-type=http://terminology.hl7.org/CodeSystem/v2-0203|MR|446053 | can only be used with identifier field and allows to filter based on the Identifier.type.coding.system, Identifier.type.coding.code and Identifier.value. The format when using 'of-type' is [system]|[code]|[value] and all three values are must. |
|
Reference | |||
[type] | [base]/Observation?subject:Patient=23 | allows to restrict the resource type of a reference. Provided example is similar to using [base]/Observation?subject=Patient/23 |
FHIR specification: https://www.hl7.org/fhir/search.html#modifiers
For parameter types of number, date, and quantity
Prefix | Example | Description |
---|---|---|
ne | [base]/RiskAssessment?probability=ne0.8 | not equals: the value for the parameter in the resource is not equal to the provided value |
gt | [base]/RiskAssessment?probability=gt1e2 | greater than: the value for the parameter in the resource is greater than the provided value |
ge | [base]/RiskAssessment?probability=ge8 | greater than or equal to: the value for the parameter in the resource is greater or equal to the provided value |
lt | [base]/RiskAssessment?probability=lt100.00 | less than: the value for the parameter in the resource is less than the provided value |
le | [base]/RiskAssessment?probability=le5.40e-3 | less than or equal to: the value for the parameter in the resource is less or equal to the provided value |
FHIR specification: https://www.hl7.org/fhir/search.html#prefix
Add the id of the resource in the url e.g., https://fhir.icanbwell.com/4_0_0/HealthcareService/1952669236-MGB-MGTB
FHIR Specification: https://www.hl7.org/fhir/http.html#read
Add /_history
to a resource url to get the history of changes to that resource e.g.,
https://fhir.icanbwell.com/4_0_0/HealthcareService/1952669236-MGB-MGTB/_history
There are two ways to do this:
- (Recommended) Use the $merge endpoint which handles both creating a new resource and updating an existing resource. This is the recommended path to avoid the timing issue where someone else may add that resource between the time you checked the resource exists and sent the call to add it.
- Use the POST method. You can POST the resource as the body to /4_0_0/{resource} e.g., /4_0_0/Patient.
FHIR Specification: https://www.hl7.org/fhir/http.html#create
There are two ways to do this:
- (Recommended) Use the $merge endpoint which handles both creating a new resource and updating an existing resource. This is the recommended path to avoid the timing issue where someone else may update that resource between the time you checked the resource exists and sent the call to add it.
- Use the PUT method. You can PUT the resource as the body to /4_0_0/{resource}/{id} e.g., /4_0_0/Patient/123
- Note: This will completely replace the existing resource
- Use the PATCH method. http://hl7.org/fhir/http.html#patch
- Note: You must pass the Content-Type as
application/json-patch+json
and the patch must be in JSONPatch format: https://jsonpatch.com/
- Note: You must pass the Content-Type as
FHIR Specification: https://www.hl7.org/fhir/http.html#update
The $merge method supports sending a list of resources (which can be of different resource types).
The DELETE method allows you to logically delete a resource. You can send a DELETE call to /4_0_0/{resource}/{id} e.g., /4_0_0/Patient/123
FHIR Specification: https://www.hl7.org/fhir/http.html#delete
Requesting resources and then requesting the related resources can result in many calls which can be slow. The Helix FHIR server provides the $graph endpoint to do this in one call.
Use the $graph endpoint to get a resource and the specified related resources. The requested graph is passed in as GraphDefinition in the body and all the resources are returned in a Bundle
.
Note: You can pass in a list of resource ids in the id
parameter to get the graphs for multiple resources.
For example: https://fhir.dev.bwell.zone/4_0_0/Organization/$graph?id=733797173,1234&contained=true
FHIR Server uses OAuth Authentication. You can authenticate either:
- Service to Service via a
client id
andclient secret
- As a User via a
user id
andpassword
See Security for details.
FHIR Server uses the SMART on FHIR scopes:
- user/{resource}.{read or write} e.g.,
user/Patient.read
- This determines what resource types you can access and whether you can read or write (or both)
- access/{access tag}._ e.g.,
access/my_client._
- This determines which resources you can access within a resource type.
See Security for details.
This is a python package that can make it easier to talk to FHIR servers. Note this is optional; You can talk to our FHIR server using standard HTTP REST API.
https://github.com/icanbwell/helix.fhir.client.sdk
This SDK encapsulates all the aspects of calling the FHIR API so you can just call Python functions.
The SDK handles:
- Authentication to FHIR server
- Renewing access token when it expires
- Retry when there are transient errors
- Un-bundling the resources received from FHIR server
- Paging