Python package to calculate comorbidity and frailty scores using ICD codes and polars DataFrames.
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 by Alessandro Gasparini and the corresponding Python rewrite 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.
- 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)
See common/README.md for more details and references.
Categories are: Myocardial infarction, Congestive heart failure, Peripheral vascular disease, Cerebrovascular disease, Dementia, Chronic pulmonary disease, Rheumatic disease, Peptic ulcer disease, Mild liver disease, Diabetes without chronic complication, Diabetes with chronic complication, Hemiplegia or paraplegia, Renal disease, Any malignancy, including lymphoma and leukemia, except malignant neoplasm of skin, Moderate or severe liver disease, Metastatic solid tumor, AIDS/HIV.
- Mappings:
- Quan et al. 2005 (Quan 2005)
- Deyo et al. 1992 (Deyo 1992)
- Romano et al. 1993 (Romano 1993)
- Australia (Sundararajan et al. 2004, ICD-10-AM) (Sundararajan 2004)
- Sweden (Ludvigsson et al. 2021, ICD-10) (Ludvigsson 2021)
- UK SHMI (NHS Digital, v1.55)
- Weights:
- Charlson et al. 1987 (Charlson 1987)
- Quan et al. 2011 (Quan 2011)
- SHMI (NHS Digital, v1.55)
- Modified SHMI (NHS Digital, v1.55)
Categories are: Congestive heart failure, Cardiac arrhythmias, Valvular disease, Pulmonary circulation disorders, Peripheral vascular disorders, Hypertension uncomplicated, Hypertension complicated, Paralysis, Other neurological disorders, Chronic pulmonary disease, Diabetes uncomplicated, Diabetes complicated, Hypothyroidism, Renal failure, Liver disease, Peptic ulcer disease excluding bleeding, AIDS/HIV, Lymphoma, Metastatic cancer, Solid tumor without metastasis, Rheumatoid arthritis/collagen vascular diseases, Coagulopathy, Obesity, Weight loss, Fluid and electrolyte disorders, Blood loss anemia, Deficiency anemia, Alcohol abuse, Drug abuse, Psychoses, Depression.
- Mappings:
- Quan et al. 2005 (Quan 2005)
- Original Elixhauser et al. 1998 (ICD-9) (Elixhauser 1998)
- Weights:
- van Walraven et al. 2009 (van Walraven 2009)
- Thompson et al. 2015 (Thompson 2015)
- AHRQ (Moore et al. 2017, AHRQ Comorbidity Software)
- Swiss (Sharma et al. 2021, Sharma 2021)
Categories are: Alcohol abuse, Any tumor, Cardiac arrhythmias, Chronic pulmonary disease, Coagulopathy, Complicated diabetes, Congestive heart failure, Deficiency anemia, Dementia, Fluid and electrolyte disorders, Hemiplegia, HIV/AIDS, Hypertension, Liver disease, Metastatic cancer, Peripheral vascular disease, Psychosis, Pulmonary circulation disorders, Renal failure, Weight loss.
- Gagne et al. 2011 (Gagne 2011), with ICD-9 and ICD-10 support (Sun 2017)
- Gilbert et al. 2018, ICD-10 (Gilbert 2018)
You can install pycomorb via pip:
pip install pycomorbimport 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 docstrings in each module for details on arguments and supported variants.
- Free software: MIT license
- Documentation: (TODO)
- Die Erstellung erfolgt unter Verwendung der maschinenlesbaren Fassung des Bundesinstituts für Arzneimittel und Medizinprodukte (BfArM).