fhir-query
Leveraging FHIR GraphDefinition for Data Traversals and Local Analysis
Overview
This project leverages FHIR GraphDefinition objects to define and execute graph-based traversals across multiple interconnected FHIR resource graphs. The data retrieved is written to a local SQLite database for persistence and later transformed into analyst-friendly dataframes for analysis using tools like Python’s pandas library.
Motivation
FHIR Search provides a robust querying framework but comes with significant limitations:
-
Deep Chaining Limits:
Chaining searches (e.g.,Patient -> Observation -> Encounter -> Procedure) often hits server depth limitations. -
Inefficient Query Execution:
Searching deeply related resources requires multiple chained requests, leading to performance issues and unnecessary round trips. -
Lack of Explicit Traversals:
Relationships in FHIR are implicit in references (e.g.,Observation.subjectpointing toPatient). This implicit structure requires manual composition of queries, which is prone to errors.
By using FHIR GraphDefinition, we declaratively define resource relationships and efficiently retrieve data. Once retrieved, the data is stored locally and can be transformed into dataframes for advanced analysis.
Key Features
- GraphDefinition-Driven Traversals: Use GraphDefinition objects to define explicit relationships between resources and automate traversal logic.
- Local SQLite Storage: Persist the retrieved FHIR data in a local SQLite database for querying and offline analysis.
- Analyst-Friendly Dataframes: Convert stored FHIR resources into pandas dataframes for ease of use in analytical workflows.
- Reusable Graph Definitions: Maintain a library of GraphDefinition YAML files that can be reused across different workflows and projects.
Architecture
Components
-
GraphDefinition Library
- A collection of reusable GraphDefinition objects in JSON/YAML format. A GraphDefinition defines a traversal path between resources.
- See Example GraphDefinition, FHIR Devdays 2021
-
Traversal Engine
- Reads a GraphDefinition and iteratively queries the FHIR server using RESTful
_includeand_revincludeoperations for efficiency. - Stores the retrieved resources in a SQLite database in JSON format for flexibility.
- Reads a GraphDefinition and iteratively queries the FHIR server using RESTful
-
SQLite Data Storage
- Table Schema: see fhir_query.ResourceDB
-
Analyst-Friendly DataFrames TODO
- Transforms FHIR data from SQLite into pandas dataframes for easier analysis.
- Data can be filtered, aggregated, or visualized to meet analytical use cases.
Workflow
-
Load a GraphDefinition
- Define a GraphDefinition object (e.g.,
study-to-documents) to specify the traversal path.
- Define a GraphDefinition object (e.g.,
-
Execute Traversal
- Use the
Traversal Engineto query the FHIR server based on the GraphDefinition. - Follow each link and include related resources efficiently using
_includeor_revinclude.
- Use the
-
Store Data Locally
- Write the retrieved resources to the SQLite database with their resource types and full JSON representation.
-
Transform to DataFrames TODO
- Retrieve specific resource types or relationships from the SQLite database.
- Convert the JSON data into structured pandas dataframes for analysis.
Usage
To use the fq command, you need to provide the necessary options. Below is an example of how to use the command:
fq --help
Usage: fq [OPTIONS] COMMAND [ARGS]...
FHIR-Aggregator utilities.
Commands:
ls List all the installed GraphDefinitions.
run Run GraphDefinition queries.
results Work with the results of a GraphDefinition query.
vocabulary FHIR-Aggregator's key Resources and CodeSystems.
Examples:
- See Vocabulary
- See Patient SurvivalCurves
- See GraphDefinitions
Metadata
Release files for fhir-aggregator-client 0.3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| fhir_aggregator_client-0.3.0.tar.gz | 78.9 kB | With provenance | Details for fhir_aggregator_client-0.3.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| fhir_aggregator_client-0.3.0-py3-none-any.whl | Python 3 | none | any | Details for fhir_aggregator_client-0.3.0-py3-none-any.whl |
Total release size: 110.2 kB
Release files / fhir_aggregator_client-0.3.0.tar.gz
| Download URL | fhir_aggregator_client-0.3.0.tar.gz |
|---|---|
| Size | 78.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b6348b345f48813c386769f23b275f6a4bb40de8edfb7c2df02705748be92e33
|
|
BLAKE2b-256 checksum How to use checksums |
80404aefb8156dcffeda022dfa1fbb5f4326a76145de3d9c9915d958455e6144
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jun 24, 2026.
Transparency logRelease files / fhir_aggregator_client-0.3.0-py3-none-any.whl
| Download URL | fhir_aggregator_client-0.3.0-py3-none-any.whl |
|---|---|
| Size | 31.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
fdc17589b5a1d0ac6e49d9b0b3f7c7e826f455fb88479ac7ba52a91f1a39623d
|
|
BLAKE2b-256 checksum How to use checksums |
c16b809413cdae9dd761f22adf217444d26dee1546a3316a4efb71b474e2adec
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jun 24, 2026.
Transparency logSecurity for fhir-aggregator-client 0.3.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
All 2 files in this release have been uploaded with provenance metadata.
Attestation for fhir_aggregator_client-0.3.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jun 24, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.