FhirSheets is a command-line tool that reads an Excel file in FHIR cohort format and generates FHIR bundle JSON files from it. Each row in the template Excel file is used to create an individual JSON file, outputting them to a specified folder.
- Reads an Excel file following the FHIR cohort import template.
- Converts each row in the Excel file to a FHIR bundle JSON file.
- Exports generated JSON files to a specified output folder.
- Python 3.x
- Required Python packages (see
requirements.txt)
- Clone this repository:
git clone https://github.com/CDCgov/synthetic-data.git cd fhir-python-cohort-generation - Install the required packages:
Or use poetry
pip install -r requirements.txt
poetry build
-
Fill Out the Template:
- Open the template file
src/resources/Fhir_Cohort_Import_Template.xlsx. - Fill out each row with the relevant data.
- Open the template file
-
Run the Tool:
- Use the
python -m src.cli.fhirsheetsmodule script with the required arguments:--input-file: The path to the input Excel file.--output-folder: The path to the output folder where the JSON files will be saved.
python -m src.fhir_sheets.cli.main --input_file src/resources/Fhir_Cohort_Import_Template.xlsx --output_folder /path/to/output/folder
- Use the
-
The tool will generate one FHIR bundle JSON file for each row defined in the template.
python -m src.fhir_sheets.cli.main --input_file src/resources/Fhir_Cohort_Import_Template.xlsx --output_folder ./output_bundlesIn this example, each row in the Fhir_Cohort_Import_Template.xlsx file will be processed, and a corresponding JSON file will be generated in the output_bundles folder.
FHIRSheets supports configuration through JSON files or command-line arguments to customize behavior, including default resource references.
Create a JSON configuration file (e.g., my_config.json):
{
"enable_default_resource_links": true,
"default_resource_references": [
["observation", "patient", "subject"],
["procedure", "patient", "subject"]
]
}Then use it with the CLI:
python -m src.fhir_sheets.cli.main --input_file input.xlsx --output_folder output/ --config_file my_config.jsonenable_default_resource_links(boolean, default:true): Enable/disable automatic default resource linkingdefault_resource_references(array): Customize which default resource references to create automaticallyarray_type_references(array): Specify which references should be arrayspreview_mode(boolean, default:false): Generate resources in preview modemedications_as_reference(boolean, default:false): Convert medicationCodeableConcept to medication resourcesbuild_empty_resources(boolean, default:false): Build resources even when no data exists
You can also pass configuration options directly:
python -m src.fhir_sheets.cli.main \
--input_file input.xlsx \
--output_folder output/ \
--enable_default_resource_links true \
--build_empty_resources falseOr use the convenient flag to disable default resource links:
python -m src.fhir_sheets.cli.main \
--input_file input.xlsx \
--output_folder output/ \
--no-default-linksNote: For advanced configuration like customizing default_resource_references lists, use a JSON config file.
See config_example.json for a complete example with all default values and available options.
When using FHIRSheets as a Python library:
from fhir_sheets.core.config.FhirSheetsConfiguration import FhirSheetsConfiguration
from fhir_sheets.core import conversion, read_input
import json
# Load configuration from JSON file
with open('my_config.json', 'r') as f:
config_dict = json.load(f)
config = FhirSheetsConfiguration(config_dict)
# Use the configuration
resource_defs, resource_links, cohort_data = read_input.read_xlsx_and_process("input.xlsx")
bundle = conversion.create_transaction_bundle(
resource_defs,
resource_links,
cohort_data,
index=0,
config=config
)This project is licensed under the MIT License. See the LICENSE file for more information.