This repository contains tools for building a prepopulated FHIR R4 server,
intended for the construction of sandbox environments for Electronic Health
Records (EHR). fhir-sandbox
creates a FHIR server inside a
docker container. The FHIR server contains Patients
and Observations from a user defined data source. Currently,
a handful of observation types are supported such as heart rate and some mechanical ventilation parameters.
The full list of supported observation types can be found in observation_types.json.
- Ensure that Docker and Git are installed.
- Clone this project.
git clone git@github.com:KitwareMedical/fhir-sandbox.git
- Install the required pacakages (python verion >= 3.9 required):
pip install -r requirements.txt
- Download the empty hapi r4 container by the SMART on FHIR team.
docker pull smartonfhir/hapi-5:r4-empty
- Run the docker container.
The port "3000" may be replaced by your choice of port; just replace appearances of "3000" by your choice in the rest of the instructions.
docker run -dp 3000:8080 smartonfhir/hapi-5:r4-empty
- Verify that the server is working by visiting http://localhost:3000/hapi-fhir-jpaserver/fhir/Patient. This should display some json.
With the initial setup finished, there are two ways to use
fhir-sandbox
:
- Use one of the existing data sources, such as the random data generator used for testing, or the data source that takes NICU data from a downloaded MIMIC-III dataset.
- Create your own
PatientDataSource
to populate custom patient and observation data into a FHIR server.
This approach can be used to test basic functionality by populating a FHIR server with random data:
python populate_fhir_server.py --json_file ./data_sources/random.json
--fhir_server http://localhost:3000/hapi-fhir-jpaserver/fhir/
The amount of data to generate can be configured in data_sources/random.json.
This approach uses a downloaded MIMIC-III dataset to populate a FHIR server with NICU patients and ventilator observations. Note that the MIMIC-III dataset requires credentialed access on PhysioNet.
- Get access to and download MIMIC-III.
- Configure data_sources/mimic3.json to point to the location of your downloaded data and the MIMIC-III schema files:
The schema files are provided in this repository here.
"args": { "mimic3_data_dir": "path/to/mimic3/data/dir", "mimic3_schemas_dir": "path/to/mimic3/schema/dir" }
- Run
populate_fhir_server.py
:python populate_fhir_server.py --json_file ./data_sources/mimic3.json --fhir_server http://localhost:3000/hapi-fhir-jpaserver/fhir/
To populate the FHIR server with custom data, a bit of Python is needed.
The procedure is to subclass the PatientDataSource
, Patient
, and Observation
classes in data_sources/patient_data_source.py, specifying how the patient and observation data should be created.
A more in-depth explanation with examples can be found here.
In cases where the custom data source has additional observation types not supported in observation_types.json, it is possible to add new observation types by simply adding an entry to observation_types.json:
"ObservationTypeName":
{
"display_string": "...",
"unit_code": "...",
"loinc_code": "..."
}
- The
display_string
is a a human readable description of the observation type, e.g. "heart rate". - The
unit_code
describes the observation's unit of measure in the format of the UCUM system - The
loinc_code
is a LOINC code identifying the observation type. You can search for LOINC codes here.
This tool only works with only two out of the many types of FHIR resources: Patients and Observations. Extending this tool to work with other types of FHIR resources requires a more involved development effort, as well as getting friendly with the FHIR documentation.
Johnson, A., Pollard, T., & Mark, R. (2016). MIMIC-III Clinical Database (version 1.4). PhysioNet. https://doi.org/10.13026/C2XW26.
This work was supported by the National Institutes of Health under Award Number R42HL145669. The content is solely the responsibility of the authors and does not necessarily represent the official views of the National Institutes of Health.