Skip to main content

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.

Project description

FHIRSheets

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.

Table of Contents

Features

  • 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.

Requirements

  • Python 3.x
  • Required Python packages (see requirements.txt)

Installation

  1. Clone this repository:
    git clone https://github.com/CDCgov/synthetic-data.git
    cd fhir-python-cohort-generation
    
  2. Install the required packages:
    pip install -r requirements.txt
    
    Or use poetry
    poetry build
    

Usage

  1. Fill Out the Template:

    • Open the template file src/resources/Fhir_Cohort_Import_Template.xlsx.
    • Fill out each row with the relevant data.
  2. Run the Tool:

    • Use the python -m src.cli.fhirsheets module 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
    
  3. The tool will generate one FHIR bundle JSON file for each row defined in the template.

Example

python -m src.fhir_sheets.cli.main --input_file src/resources/Fhir_Cohort_Import_Template.xlsx --output_folder ./output_bundles

In 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.

Configuration

FHIRSheets supports configuration through JSON files or command-line arguments to customize behavior, including default resource references.

Using a Configuration File

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.json

Configuration Options

  • enable_default_resource_links (boolean, default: true): Enable/disable automatic default resource linking
  • default_resource_references (array): Customize which default resource references to create automatically
  • array_type_references (array): Specify which references should be arrays
  • preview_mode (boolean, default: false): Generate resources in preview mode
  • medications_as_reference (boolean, default: false): Convert medicationCodeableConcept to medication resources
  • build_empty_resources (boolean, default: false): Build resources even when no data exists

Command-Line Arguments

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 false

Or 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-links

Note: For advanced configuration like customizing default_resource_references lists, use a JSON config file.

Example Configuration File

See config_example.json for a complete example with all default values and available options.

Programmatic Usage

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
)

License

This project is licensed under the MIT License. See the LICENSE file for more information.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fhir_sheets-2.5.6.tar.gz (25.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

fhir_sheets-2.5.6-py3-none-any.whl (33.5 kB view details)

Uploaded Python 3

File details

Details for the file fhir_sheets-2.5.6.tar.gz.

File metadata

  • Download URL: fhir_sheets-2.5.6.tar.gz
  • Upload date:
  • Size: 25.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for fhir_sheets-2.5.6.tar.gz
Algorithm Hash digest
SHA256 b07a4815488680258aafd1c325357d1a12a63dbdfad1bdd857780506f15757f2
MD5 cd98e54a751d76915163a8d156686e03
BLAKE2b-256 eed7c731100ea7df02bced990d0ea22cdae5900bce866f5149be5d7b0ea1e0eb

See more details on using hashes here.

File details

Details for the file fhir_sheets-2.5.6-py3-none-any.whl.

File metadata

  • Download URL: fhir_sheets-2.5.6-py3-none-any.whl
  • Upload date:
  • Size: 33.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for fhir_sheets-2.5.6-py3-none-any.whl
Algorithm Hash digest
SHA256 26c5a9979edf4b43f1b8851eaf186ea5dfc84f6727251968af719b6c713a270e
MD5 5e23263203314e8e45d4840b22c33963
BLAKE2b-256 df3a961dae48a66c50fa93ca497222e8d5784cb093e9a894f4525f5fb5027e9f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page