Skip to main content

🔥 fhiry — FHIR to Pandas DataFrame for Data Analytics, AI, and ML

Release Build status codecov Commit activity License Downloads Documentation

Generated by github-dependents-info

FHIRy is a Python package that simplifies health data analytics and machine learning by converting FHIR bundles or NDJSON files from bulk data export into pandas DataFrames. These DataFrames can be used directly with ML libraries such as TensorFlow and PyTorch. FHIRy also supports FHIR server search and FHIR tables on BigQuery.


✨ Features

  • Flatten FHIR Bundles/NDJSON to DataFrames for analytics and ML
  • Import from FHIR Server via FHIR Search API
  • Query FHIR Data on Google BigQuery
  • LLM-based Natural Language Queries (see examples/llm_example.py)
  • Flexible Filtering and Column Selection

🔧 Quick Start

Installation

Stable release:

pip install fhiry

Latest development version:

pip install git+https://github.com/dermatologist/fhiry.git

LLM support:

pip install fhiry[llm]

Usage

1. Import FHIR Bundles (JSON) from Folder

import fhiry.parallel as fp
df = fp.process('/path/to/fhir/resources')
print(df.info())

Example dataset: Synthea Notebook: notebooks/synthea.ipynb


2. Import NDJSON from Folder

import fhiry.parallel as fp
df = fp.ndjson('/path/to/fhir/ndjson/files')
print(df.info())

Example dataset: SMART Bulk Data Server Notebook: notebooks/ndjson.ipynb


3. Import FHIR Search Results

Fetch resources from a FHIR server using the FHIR Search API:

from fhiry.fhirsearch import Fhirsearch

fs = Fhirsearch(fhir_base_url="http://fhir-server:8080/fhir")
params = {"code": "http://snomed.info/sct|39065001"}
df = fs.search(resource_type="Condition", search_parameters=params)
print(df.info())

See fhir-search.md for details.


4. Import from Google BigQuery FHIR Dataset

from fhiry.bqsearch import BQsearch
bqs = BQsearch()
df = bqs.search("SELECT * FROM `bigquery-public-data.fhir_synthea.patient` LIMIT 20")

🚀 5. LLM-based Natural Language Queries

FHIRy supports natural language queries over FHIR bundles/NDJSON using llama-index:

pip install fhiry[llm]

See usage: examples/llm_example.py


🚀 6. Convert FHIR Bundles/Resources to Text for LLMs

Convert a FHIR Bundle or resource to a textual representation for LLMs:

from fhiry import FlattenFhir
import json

bundle = json.load(open('bundle.json'))
flatten_fhir = FlattenFhir(bundle)
print(flatten_fhir.flattened)

Filters and Column Selection

You can pass a config JSON to any constructor to remove or rename columns:

df = fp.process('/path/to/fhir/resources', config_json='{ "REMOVE": ["resource.text.div"], "RENAME": { "resource.id": "id" } }')
fs = Fhirsearch(fhir_base_url="http://fhir-server:8080/fhir", config_json='{ "REMOVE": ["resource.text.div"], "RENAME": { "resource.id": "id" } }')
bqs = BQsearch('{ "REMOVE": ["resource.text.div"], "RENAME": { "resource.id": "id" } }')

See df.columns for available columns. Example columns:

patientId
fullUrl
resource.resourceType
resource.id
resource.name
resource.telecom
resource.gender
...

Command Line Interface (CLI)

See CLI examples:

fhiry --help

Documentation

Full documentation: https://dermatologist.github.io/fhiry/


Contributing

We welcome contributions! See CONTRIBUTING.md.


Give Us a Star ⭐️

If you find this project useful, please give us a star to help others discover it.


Contributors

Release files for fhiry 5.2.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for fhiry 5.2.2
File Size Uploaded
fhiry-5.2.2.tar.gz 715.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for fhiry 5.2.2
File Interpreter ABI Platform
fhiry-5.2.2-py3-none-any.whl Python 3 none any Details

Total release size: 734.8 kB

Release files / fhiry-5.2.2.tar.gz

Download URL fhiry-5.2.2.tar.gz
Size 715.3 kB
Tags Source
SHA-256 checksum
How to use checksums
f583412afeeb26714a2d2fc3e1bba80e5438804c3d12f257fb08c96538c6e047
BLAKE2b-256 checksum
How to use checksums
792d4106076de73b886aac071e7b41238628915454c126f1a2bb0b4dcc3267f9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Release files / fhiry-5.2.2-py3-none-any.whl

Download URL fhiry-5.2.2-py3-none-any.whl
Size 19.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6324df48673314d617dc86686b633ce677ced3cecd65bc4cf1b14fda828ad998
BLAKE2b-256 checksum
How to use checksums
ff720bdb7a1f6e77df183ba631f63ee9e2765590bd26ac8196f606b21f44512c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Release history Release notifications | RSS feed

This release

5.2.2 This release

2 release files

5.2.1

2 release files

5.2.0

2 release files

5.1.1

2 release files

5.1.0

2 release files

5.0.0

1 release file

4.2.1

1 release file

4.1.3

1 release file

4.0.0

1 release file

3.2.2

1 release file

3.2.1

1 release file

3.2.0

1 release file

3.1.0

1 release file

3.0.0

1 release file

2.1.0

1 release file

2.0.0

1 release file

1.0.0

1 release file

0.5.0

2 release files

0.3.0

2 release files

0.2.1

2 release files

0.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page