Metadata-Version: 2.3
Name: sqlonfhir
Version: 0.0.2
Summary: Converts FHIR resources to flat formats using SQL on FHIR
Keywords: sqlonfhir,fhir
Author: Stuart Mackle, SAS Healthcare Solutions
Author-email: Stuart Mackle <stuart.mackle@sas.com>, SAS Healthcare Solutions <support@sas.com>
License: Copyright 2025 SAS Institute LLC
         
         Licensed under the Apache License, Version 2.0 (the "License");
         you may not use this file except in compliance with the License.
         You may obtain a copy of the License at
         
             http://www.apache.org/licenses/LICENSE-2.0
         
         Unless required by applicable law or agreed to in writing, software
         distributed under the License is distributed on an "AS IS" BASIS,
         WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
         See the License for the specific language governing permissions and
         limitations under the License.
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Operating System :: OS Independent
Requires-Dist: fhirpathpy~=2.1.0
Requires-Dist: pytest==8.4.1 ; extra == 'test'
Requires-Python: >=3.9
Provides-Extra: test
Description-Content-Type: text/markdown

# 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 `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

```bash
pip install sqlonfhir
```

## Dependencies

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

## Usage

```python
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 process
- `view_definition`: SQL on FHIR view definition

**Returns:**
- List of dictionaries representing the extracted tabular data

## Testing

Run the test suite:
```bash
uv run pytest
```

Generate test report:
```bash
./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.
