Converts FHIR resources to flat formats using SQL on FHIR
Project description
SASFHIR
A Python implementation that converts FHIR resources into tabular formats.
Overview
This library provides functionality to transform FHIR resources into tabular data structures based on SQL on FHIR view definitions. It extends the fhirpathpy library with custom functions and handles the conversion of FHIR resources into structured data that can be used for analytics and reporting.
Features
- FHIRPath Expression Evaluation: Evaluates FHIRPath expressions against FHIR resources
- SQL on FHIR View Processing: Processes view definitions to extract structured data
- Union Operations: Supports
unionAlloperations for combining multiple data sources - Conditional Processing: Handles
whereclauses and conditional logic - Column Mapping: Maps FHIR resource elements to named columns
- Iteration Support: Provides
forEachandforEachOrNulloperations
Installation
pip install sqlonfhir
Dependencies
fhirpathpy: Core FHIRPath evaluation engineantlr4-python3-runtime: ANTLR runtime for parsingpython-dateutil: Date/time utilities
Usage
from sqlonfhir import evaluate
# Define your view definition
view_definition = {
"resource": "Patient",
"column": [
{"name": "id", "path": "id"},
{"name": "name", "path": "name.given.first()"}
]
}
# Your FHIR resources
resources = [
{
"resourceType": "Patient",
"id": "patient1",
"name": [{"given": ["John"], "family": "Doe"}]
}
]
# Evaluate the view
result = evaluate(resources, view_definition)
print(result)
API
eval(resources, view_definition)
Main evaluation function that processes FHIR resources against a view definition.
Parameters:
resources: List of FHIR resources to processview_definition: SQL on FHIR view definition
Returns:
- List of dictionaries representing the extracted tabular data
Testing
Run the test suite:
uv run pytest
Generate test report:
./generate_test_report.sh
Project Structure
sasfhir/
├── sasfhir/
│ ├── __init__.py
│ └── sasfhir.py # Main implementation
├── tests/
│ ├── resources/ # Test FHIR resources and view definitions
│ └── test.py # Test suite
├── test_report/ # Test reporting utilities
├── requirements.txt # Dependencies
└── README.md # This file
Contributing
Maintainers are accepting patches and contributions to this project. Please read CONTRIBUTING.md for details about submitting contributions to this project.
License
This project is licensed under the Apache 2.0 License.
Those implementing FHIR projects should ensure they have the appropriate licenses to cover any required third party data standards.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file sqlonfhir-0.0.2.tar.gz.
File metadata
- Download URL: sqlonfhir-0.0.2.tar.gz
- Upload date:
- Size: 4.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.8.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
eb105bd2741de28c45928eb1f9b6d680407fd1f1423fb49877ee0d0000fac8e5
|
|
| MD5 |
c8ba557a7a60853e2f02fa992eaf4ba6
|
|
| BLAKE2b-256 |
f9e3b46d06f7b6127d1ac453ca1eb50c5aae0d342fbc2f75ae1d093ffdd3fa4c
|
File details
Details for the file sqlonfhir-0.0.2-py3-none-any.whl.
File metadata
- Download URL: sqlonfhir-0.0.2-py3-none-any.whl
- Upload date:
- Size: 5.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.8.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1e1f4104d0f49572a7536fbd14277eb927f7869f4eba75d795833013e52e3dbf
|
|
| MD5 |
6b0821548ec776b23557e09cfdddee82
|
|
| BLAKE2b-256 |
9d37c2b0a2af98c801131a47d97352a3269a80091e3341f2554e08b827b63163
|