Skip to main content

Converts FHIR resources to flat formats using SQL on FHIR

Project description

SASFHIR

A Python implementation for evaluating SQL on FHIR view definitions against FHIR resources using FHIRPath expressions.

Overview

SASFHIR 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 unionAll operations for combining multiple data sources
  • Conditional Processing: Handles where clauses and conditional logic
  • Column Mapping: Maps FHIR resource elements to named columns
  • Iteration Support: Provides forEach and forEachOrNull operations

Installation

pip install sqlonfhir

Dependencies

  • fhirpathpy: Core FHIRPath evaluation engine
  • antlr4-python3-runtime: ANTLR runtime for parsing
  • python-dateutil: Date/time utilities

Usage

from sqlonfhir import eval

# 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 = eval(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 process
  • view_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](CONTRIBUTING.md) for details about submitting contributions to this project.

## License

This project is licensed under the [Apache 2.0 License](LICENSE).

Those implementing FHIR projects should ensure they have the appropriate licenses to cover any required third party data standards.

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

sqlonfhir-0.0.1.tar.gz (4.5 kB view details)

Uploaded Source

Built Distribution

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

sqlonfhir-0.0.1-py3-none-any.whl (5.3 kB view details)

Uploaded Python 3

File details

Details for the file sqlonfhir-0.0.1.tar.gz.

File metadata

  • Download URL: sqlonfhir-0.0.1.tar.gz
  • Upload date:
  • Size: 4.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.13

File hashes

Hashes for sqlonfhir-0.0.1.tar.gz
Algorithm Hash digest
SHA256 add60f1624166af2c14c5e8ecf9877a1932057bb87567dab64a1e3f544c3b5a4
MD5 ea7b1b6d51609017aa419fc43397148a
BLAKE2b-256 2d36e1188dbeca1a647ca68a29687952ce2e3f57c2c2b6a61a6348519e14522a

See more details on using hashes here.

File details

Details for the file sqlonfhir-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: sqlonfhir-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 5.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.13

File hashes

Hashes for sqlonfhir-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 5f06ca8a3b5bbc463e6d1e63823d7e549066ea3de80ea3ec762cf7e89c6a43b6
MD5 dccdd6a62e1d5d7ff5ed471e51bf127d
BLAKE2b-256 def4f44c9d13d25336d6c4de3a007a841629db218865452ac38ee7ea070b04b2

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