Metadata-Version: 2.4
Name: comorbidipy
Version: 0.7.0
Summary: Python package to calculate comorbidity scores and other clinical risk scores.
Project-URL: Homepage, https://github.com/vvcb/comorbidipy
Project-URL: Repsoitory, https://github.com/vvcb/comorbidipy
Project-URL: Issues, https://github.com/vvcb/comorbidipy/issues
Project-URL: Documentation, https://vvcb.github.io/comorbidipy
Author: vvcb
License: MIT License
        
        Copyright (c) 2021-2025, vvcb
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
License-File: AUTHORS.md
License-File: LICENSE
Keywords: clinical risk scores,comorbidity,data analysis,healthcare
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Healthcare Industry
Classifier: Intended Audience :: Science/Research
Classifier: License :: OSI Approved :: MIT License
Classifier: Natural Language :: English
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Requires-Python: >=3.13
Requires-Dist: polars>=1.27.1
Requires-Dist: rich>=13.0.0
Requires-Dist: typer>=0.15.2
Description-Content-Type: text/markdown

# comorbidipy

[![PyPI](https://img.shields.io/pypi/v/comorbidipy)](https://pypi.python.org/pypi/comorbidipy)
[![Tests](https://github.com/vvcb/comorbidipy/actions/workflows/tests.yml/badge.svg)](https://github.com/vvcb/comorbidipy/actions/workflows/tests.yml)
[![Docs](https://github.com/vvcb/comorbidipy/actions/workflows/docs.yml/badge.svg)](https://vvcb.github.io/comorbidipy)
[![Python](https://img.shields.io/badge/python-3.13+-blue.svg)](https://www.python.org/downloads/)
[![License](https://img.shields.io/badge/license-MIT-green.svg)](LICENSE)

A high-performance Python package for calculating comorbidity scores and clinical risk scores from ICD codes.

Built with [Polars](https://pola.rs/) for blazing-fast processing of large datasets.

## Features

- **Charlson Comorbidity Index** – Multiple mapping variants (Quan, Swedish, Australian, SHMI) and weighting schemes
- **Elixhauser Comorbidity Index** – Quan mapping with van Walraven or Swiss weights
- **Hospital Frailty Risk Score (HFRS)** – For patients ≥75 years
- **Disability & Sensory Impairments** – Learning disabilities, visual and hearing impairments

## Installation

```bash
pip install comorbidipy
```

Requires Python 3.13+.

## Quick Start

### Python API

```python
import polars as pl
from comorbidipy import comorbidity, hfrs, disability

# Sample data
df = pl.DataFrame({
    "id": ["P001", "P001", "P002", "P002"],
    "code": ["I21", "E112", "I50", "J44"],
    "age": [65, 65, 72, 72],
})

# Calculate Charlson Comorbidity Index
result = comorbidity(df, id="id", code="code", age="age")

# Calculate Hospital Frailty Risk Score
frailty = hfrs(df, id="id", code="code")

# Identify disabilities
disabilities = disability(df, id="id", code="code")
```

### Command Line Interface

```bash
# Charlson score
comorbidipy charlson input.csv output.csv --age-col age

# Elixhauser score
comorbidipy elixhauser input.parquet output.parquet --weights vanwalraven

# Hospital Frailty Risk Score
comorbidipy hfrs input.csv output.csv

# Disability identification
comorbidipy disability input.csv output.csv

# Show available options
comorbidipy info
```

Supported file formats: CSV, Parquet, JSON, NDJSON, Avro.

## Charlson Variants

| Mapping | ICD-9 | ICD-10 | Description |
|---------|-------|--------|-------------|
| `quan` | ✅ | ✅ | Quan et al. (2005) |
| `swedish` | ❌ | ✅ | Swedish National Patient Register |
| `australian` | ❌ | ✅ | Australian IHW adaptation |
| `shmi` | ❌ | ✅ | UK SHMI specification |

| Weighting | Description |
|-----------|-------------|
| `charlson` | Original 1987 weights |
| `quan` | Quan et al. updated weights |
| `shmi` | UK SHMI weights |
| `shmi_modified` | Modified SHMI weights |

## Documentation

Full documentation: [https://vvcb.github.io/comorbidipy](https://vvcb.github.io/comorbidipy)

## License

MIT License – see [LICENSE](LICENSE) for details.

## Credits

- Inspired by the R library [`comorbidity`](https://github.com/ellessenne/comorbidity/) by Alessandro Gasparini
- Built with [Polars](https://pola.rs/) and [Typer](https://typer.tiangolo.com/)
