Metadata-Version: 2.4
Name: pycomorb
Version: 1.20261001.2
Summary: Comorbidity and frailty score calculation utilities (Charlson, Elixhauser, Gagne, HFRS) using polars
Author-email: "Finn S. Fassbender" <research@finnfassbender.de>
License-Expression: MIT
Project-URL: Homepage, https://github.com/CUB-CORR/pycomorb
Project-URL: Repository, https://github.com/CUB-CORR/pycomorb
Project-URL: Issues, https://github.com/CUB-CORR/pycomorb/issues
Project-URL: Changelog, https://github.com/CUB-CORR/pycomorb/releases
Keywords: comorbidity,Charlson,Elixhauser,frailty,ICD-10,polars
Classifier: Programming Language :: Python :: 3
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Intended Audience :: Science/Research
Classifier: Topic :: Scientific/Engineering :: Medical Science Apps.
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
License-File: NOTICE
Requires-Dist: pandas
Requires-Dist: pyarrow
Requires-Dist: polars>=1.21.0
Requires-Dist: pyyaml
Provides-Extra: test
Requires-Dist: pytest; extra == "test"
Requires-Dist: pytest-cov; extra == "test"
Provides-Extra: docs
Requires-Dist: zensical; extra == "docs"
Requires-Dist: mkdocstrings[python]; extra == "docs"
Dynamic: license-file

# pycomorb

[![DOI](https://zenodo.org/badge/1031788374.svg)](https://doi.org/10.5281/zenodo.23436346)

Python package to calculate comorbidity and frailty scores using ICD codes and polars DataFrames.

## Overview

`pycomorb` provides fast, flexible, and reproducible calculation of clinical risk scores from ICD-coded data. It supports multiple comorbidity and frailty indices, including several international variants.

It is inspired by the R package [`comorbidity`](https://github.com/ellessenne/comorbidity) by Alessandro Gasparini and the corresponding Python rewrite [`comorbidipy`](https://github.com/vvcb/comorbidipy) by Vishnu V Chandrabalan.

As a special feature, it also implements the history of the German Modification of the ICD-10 (ICD-10-GM) coding system, allowing users to apply the correct mappings and weights based on the year of diagnosis.

## Included Indices / Scores

- **Charlson Comorbidity Index** (multiple mappings and weights)
- **Elixhauser Comorbidity Index** (multiple mappings and weights)
- **Combined Comorbidity Score** (Gagne et al.)
- **Hospital Frailty Risk Score (HFRS)**

## Supported Variants

Details, options and category names are in the [documentation](https://cub-corr.github.io/pycomorb/scores/); references in [common/README.md](https://github.com/CUB-CORR/pycomorb/blob/main/common/README.md).

### Charlson Comorbidity Index

- **Mappings**:
  - Deyo et al. 1992 ([Deyo 1992](https://doi.org/10.1016/0895-4356(92)90133-8)) – ICD-9-CM (`implementation="deyo"`)
  - Romano et al. 1993 ([Romano 1993](https://doi.org/10.1016/0895-4356(93)90103-8)) – ICD-9-CM (`implementation="romano"`)
  - D'Hoore et al. 1996 ([D'Hoore 1996](https://doi.org/10.1016/s0895-4356(96)00271-5)) – ICD-9-CM (`implementation="dhoore"`)
  - Australia, Sundararajan et al. 2004 ([Sundararajan 2004](https://doi.org/10.1016/j.jclinepi.2004.03.012)) – ICD-10-AM (`implementation="australia"`)
  - Quan et al. 2005 ([Quan 2005](https://doi.org/10.1097/01.mlr.0000182534.19832.83)) – ICD-9-CM and ICD-10 (`implementation="quan"`)
  - RCS, Armitage and van der Meulen 2010 ([Armitage & van der Meulen 2010](https://doi.org/10.1002/bjs.6930)) – ICD-10 (always used with RCS weights) (`implementation="rcs"`)
  - Denmark, Thygesen et al. 2011 ([Thygesen 2011](https://doi.org/10.1186/1471-2288-11-83)) – ICD-10 (`implementation="thygesen"`)
  - Sweden, Ludvigsson et al. 2021 ([Ludvigsson 2021](https://doi.org/10.2147/CLEP.S282475)) – ICD-9 and ICD-10 (`implementation="sweden"`)
  - UK SHMI, NHS Digital v1.60 (June 2026) – ICD-10 (always used with SHMI weights) (`implementation="uk_shmi"`)
  - Germany, Sokołowski et al. 2026 ([Sokołowski 2026](https://doi.org/10.2196/93923)) – ICD-10-GM (year-specific; requires `year_col`) (`implementation="sokolowski"`)
- **Weights**:
  - Charlson et al. 1987 ([Charlson 1987](https://doi.org/10.1016/0021-9681(87)90171-8)) (`weights="charlson"`)
  - Schneeweiss et al. 2003 ([Schneeweiss 2003](https://doi.org/10.1111/1475-6773.00165)) (`weights="schneeweiss"`)
  - RCS, Armitage and van der Meulen 2010 ([Armitage & van der Meulen 2010](https://doi.org/10.1002/bjs.6930)) (`weights="rcs"`)
  - Quan et al. 2011 ([Quan 2011](https://doi.org/10.1093/aje/kwq433)) (`weights="quan"`)
  - UK SHMI, NHS Digital v1.60 (June 2026) (negative totals are floored at zero) (`weights="uk_shmi"`)

### Elixhauser Comorbidity Index

- **Mappings**:
  - Elixhauser et al. 1998 ([Elixhauser 1998](https://doi.org/10.1097/00005650-199801000-00004)) – ICD-9-CM (`implementation="elixhauser"`)
  - Quan et al. 2005 ([Quan 2005](https://doi.org/10.1097/01.mlr.0000182534.19832.83)) – ICD-9-CM and ICD-10 (`implementation="quan"`)
  - AHRQ v3.7 ([AHRQ Comorbidity Software](https://hcup-us.ahrq.gov/toolssoftware/comorbidity/comorbidity.jsp)) – ICD-9-CM (`implementation="ahrq_icd9"`)
  - AHRQ Refined v2026.1 ([AHRQ Comorbidity Software](https://hcup-us.ahrq.gov/toolssoftware/comorbidityicd10/comorbidity_icd10.jsp)) – ICD-10-CM (year-specific; requires `year_col`) (`implementation="ahrq_icd10"`)
- **Weights**:
  - van Walraven et al. 2009 ([van Walraven 2009](https://doi.org/10.1097/MLR.0b013e31819432e5)) (`weights="van_walraven"`)
  - Thompson et al. 2015 ([Thompson 2015](https://doi.org/10.1097/MLR.0000000000000326)) (`weights="thompson_30"` or `weights="thompson_29"`)
  - AHRQ v3.7, Moore et al. 2017 ([Moore 2017](https://doi.org/10.1097/MLR.0000000000000735)) – ICD-9-CM (`weights="ahrq"`; always used with `implementation="ahrq_icd9"`)
  - AHRQ Refined v2026.1 ([AHRQ Comorbidity Software](https://hcup-us.ahrq.gov/toolssoftware/comorbidityicd10/comorbidity_icd10.jsp)) – ICD-10-CM (`weights="ahrq"`; always used with `implementation="ahrq_icd10"`)
  - Swiss, Sharma et al. 2021 ([Sharma 2021](https://doi.org/10.1186/s12913-020-05999-5)) (`weights="swiss"`)

### Combined Comorbidity Score

- **Mappings**:
  - Gagne et al. 2011 ([Gagne 2011](https://doi.org/10.1016/j.jclinepi.2010.10.004)) – ICD-9-CM (`score="combined"`, `icd_version="icd9"`; Charlson conditions after Romano 1993, Elixhauser conditions after Quan 2005)
  - Sun et al. 2017 ([Sun 2017](https://doi.org/10.1097/MLR.0000000000000824)) – ICD-10-CM (`score="combined"`, `icd_version="icd10"`)
- **Weights**:
  - Gagne et al. 2011 ([Gagne 2011](https://doi.org/10.1016/j.jclinepi.2010.10.004)) (`score="combined"`)

### Hospital Frailty Risk Score

- **Mappings**:
  - Gilbert et al. 2018 ([Gilbert 2018](https://doi.org/10.1016/S0140-6736(18)30668-8)) – ICD-10 (`score="hfrs"`)
- **Weights**:
  - Gilbert et al. 2018 ([Gilbert 2018](https://doi.org/10.1016/S0140-6736(18)30668-8)) (`score="hfrs"`)

## Documentation

Full documentation, including all supported variants, options, ICD modification handling and reporting, is at **<https://cub-corr.github.io/pycomorb/>**:

- [Scores](https://cub-corr.github.io/pycomorb/scores/): mappings, weights and categories of every variant
- [Input and output](https://cub-corr.github.io/pycomorb/input-output/)
- [ICD modification](https://cub-corr.github.io/pycomorb/icd-modification/): year-specific ICD-10-GM and ICD-10-CM mappings
- [Reporting](https://cub-corr.github.io/pycomorb/reporting/): document the exact definition behind a score
- [References](https://cub-corr.github.io/pycomorb/references/)

## Installation

You can install `pycomorb` via pip:

```bash
pip install pycomorb
```

## Usage

```python
import polars as pl
from pycomorb import comorbidity

# Example: Calculate Charlson score
df = pl.DataFrame({
    "id": [1, 2, 3],
    "code": ["I21", "E119", "C349"],
    "age": [65, 72, 80]
})

charlson = comorbidity(
    score="charlson",
    df=df,
    id_col="id",
    code_col="code",
    age_col="age",
    icd_version="icd10",
    implementation="quan",
    return_categories=True
)
```

See the [documentation](https://cub-corr.github.io/pycomorb/) for all arguments and supported variants.

### Reporting

`comorbidity_reporting` documents the exact definition behind a score: a methods table to paste into a manuscript, plus the weights, code list and hierarchy rules used. `read_reporting` reads such a folder back, so a published definition can be reused as a `"custom"` index. See the [reporting documentation](https://cub-corr.github.io/pycomorb/reporting/).

## License and citation

- Free software: MIT license (see [LICENSE](https://github.com/CUB-CORR/pycomorb/blob/main/LICENSE))
- Citation: see [CITATION.cff](https://github.com/CUB-CORR/pycomorb/blob/main/CITATION.cff) (GitHub "Cite this repository" button)
- Data sources and attributions (incl. BfArM ICD-10-GM): see [NOTICE](https://github.com/CUB-CORR/pycomorb/blob/main/NOTICE); variant references in [common/README.md](https://github.com/CUB-CORR/pycomorb/blob/main/common/README.md)
