### Quick start: run all comorbidipy commands Source: https://vvcb.github.io/comorbidipy/cli Quick start examples for the four main CLI commands: charlson, elixhauser, hfrs, and disability. Each command takes an input file and an output file. ```bash # Calculate Charlson score comorbidipy charlson input.csv output.csv # Calculate Elixhauser score comorbidipy elixhauser input.parquet output.parquet # Calculate HFRS comorbidipy hfrs input.csv output.csv # Identify disabilities comorbidipy disability input.csv output.csv ``` -------------------------------- ### Install from source Source: https://vvcb.github.io/comorbidipy/getting-started Clone the repository and install in editable mode. ```bash git clone https://github.com/vvcb/comorbidipy.git cd comorbidipy pip install -e . ``` -------------------------------- ### Install via PyPI Source: https://vvcb.github.io/comorbidipy/getting-started Install the package using pip. ```bash pip install comorbidipy ``` -------------------------------- ### Clone and set up comorbidipy with uv Source: https://vvcb.github.io/comorbidipy/contributing Clone the repository, create a virtual environment and install dependencies with uv sync, then verify the installation by running pytest. ```bash git clone https://github.com/yourusername/comorbidipy.git cd comorbidipy ``` ```bash uv sync ``` ```bash uv run pytest ``` -------------------------------- ### disability command examples Source: https://vvcb.github.io/comorbidipy/cli Examples for the disability command: basic usage and processing Parquet files. ```bash # Basic disability identification comorbidipy disability data.csv results.csv # From Parquet to Parquet comorbidipy disability data.parquet results.parquet ``` -------------------------------- ### elixhauser command examples Source: https://vvcb.github.io/comorbidipy/cli Examples for the elixhauser command: basic usage and using Swiss weights with the --weights swiss option. ```bash # Basic Elixhauser comorbidipy elixhauser data.csv results.csv # With Swiss weights comorbidipy elixhauser data.parquet results.parquet --weights swiss ``` -------------------------------- ### Verbose logging example Source: https://vvcb.github.io/comorbidipy/cli Example of verbose logging output when running charlson with --verbose. Shows the log messages that appear. ```bash comorbidipy charlson input.csv output.csv --verbose # Output: # INFO: Reading input file: input.csv # INFO: Found 1000 rows, 50 unique patients # INFO: Calculating Charlson score with quan mapping # INFO: Writing results to: output.csv # INFO: Done! ``` -------------------------------- ### Install comorbidipy with pip Source: https://vvcb.github.io/comorbidipy Install the comorbidipy package from PyPI using pip. ```bash pip install comorbidipy ``` -------------------------------- ### CLI: Basic and weighted Elixhauser calculation Source: https://vvcb.github.io/comorbidipy/calculators/elixhauser Shows how to run the Elixhauser index from the command line. Includes basic usage and examples with van Walraven and Swiss weights. Input and output files can be CSV or Parquet. ```bash # Basic Elixhauser calculation comorbidipy elixhauser input.csv output.csv # With van Walraven weights comorbidipy elixhauser input.parquet output.parquet --weights van_walraven # With Swiss weights comorbidipy elixhauser input.csv output.csv --weights swiss ``` -------------------------------- ### hfrs command examples Source: https://vvcb.github.io/comorbidipy/cli Examples for the hfrs command: basic usage and custom column names using --id-col and --code-col. ```bash # Basic HFRS comorbidipy hfrs admissions.csv frailty.csv # Custom column names comorbidipy hfrs data.parquet results.parquet --id-col patient_id --code-col diagnosis ``` -------------------------------- ### Example of disability identification with output Source: https://vvcb.github.io/comorbidipy/calculators/disability A complete example showing input DataFrame creation, processing with the disability function, and the resulting binary impairment flags. ```python import polars as pl from comorbidipy import disability df = pl.DataFrame({ "id": [ "P001", "P001", # LD + vision "P002", # Hearing only "P003", # No impairments ], "code": [ "F70", "H541", # Mild LD + low vision "H900", # Conductive hearing loss "J18", # Pneumonia (not an impairment) ], }) result = disability(df, id_col="id", code_col="code") print(result) # Output: # ┌──────┬────────┬─────────────────┬──────────────────┐ # │ id ┆ ld_asd ┆ impaired_vision ┆ impaired_hearing │ # ╞══════╪════════╪═════════════════╪══════════════════╡ # │ P001 ┆ 1 ┆ 1 ┆ 0 │ # │ P002 ┆ 0 ┆ 0 ┆ 1 │ # │ P003 ┆ 0 ┆ 0 ┆ 0 │ # └──────┴────────┴─────────────────┴──────────────────┘ ``` -------------------------------- ### Python API: Example with multiple frailty indicators and output Source: https://vvcb.github.io/comorbidipy/calculators/hfrs Shows a complete example of calculating HFRS for a patient with multiple frailty indicators, including the printed output table. The output displays patient id, hfrs_score, and hfrs_category. ```python import polars as pl from comorbidipy import hfrs # Patient with multiple frailty indicators df = pl.DataFrame({ "id": ["P001", "P001", "P001", "P002"], "code": [ "F00", # Dementia "W19", # Fall "R26", # Gait abnormality "J18", # Pneumonia only ], }) result = hfrs(df, id_col="id", code_col="code") print(result) # Output: # ┌──────┬────────────┬───────────────┐ # │ id ┆ hfrs_score ┆ hfrs_category │ # ╞══════╪════════════╪═══════════════╡ # │ P001 ┆ 8.5 ┆ Intermediate │ # │ P002 ┆ 1.2 ┆ Low │ # └──────┴────────────┴───────────────┘ ``` -------------------------------- ### charlson command examples Source: https://vvcb.github.io/comorbidipy/cli Examples for the charlson command: basic usage, Swedish mapping with age adjustment, and ICD-9 codes with Quan weights. The --age-col option enables age adjustment. ```bash # Basic Charlson with defaults comorbidipy charlson data.csv results.csv # Swedish mapping with age adjustment comorbidipy charlson data.csv results.parquet \ --mapping swedish \ --age-col patient_age # ICD-9 codes with Quan weights comorbidipy charlson data.csv results.csv \ --icd-version 9 \ --weights quan ``` -------------------------------- ### Large file processing with Parquet Source: https://vvcb.github.io/comorbidipy/cli Example for processing large files using Parquet format, which supports lazy evaluation. ```bash # Process large Parquet file efficiently comorbidipy charlson large_data.parquet results.parquet ``` -------------------------------- ### Example calculate_score function with Polars Source: https://vvcb.github.io/comorbidipy/contributing Example function following the project's Python guidelines: uses type annotations, docstring with Args/Returns/Raises sections, and Polars DataFrame operations. ```python def calculate_score( df: pl.DataFrame, id_col: str = "id", value_col: str = "value", ) -> pl.DataFrame: """ Calculate a score from input data. Args: df: Input DataFrame with patient data. id_col: Name of the column containing patient identifiers. value_col: Name of the column containing values. Returns: DataFrame with patient IDs and calculated scores. Raises: KeyError: If required columns are missing. """ if id_col not in df.columns: raise KeyError(f"Column '{id_col}' not found in DataFrame") return df.group_by(id_col).agg( pl.col(value_col).sum().alias("score") ) ``` -------------------------------- ### Python API: Basic and weighted Elixhauser calculation Source: https://vvcb.github.io/comorbidipy/calculators/elixhauser Shows how to compute the Elixhauser index using the comorbidipy Python API. Includes basic calculation and examples with van Walraven and Swiss weights. Requires a Polars DataFrame with patient ID and ICD code columns. ```python import polars as pl from comorbidipy import comorbidity, ScoreType, WeightingVariant df = pl.DataFrame({ "patient_id": ["P001", "P001", "P002", "P002"], "icd_code": ["I50", "E11", "F32", "J44"], }) # Basic Elixhauser calculation result = comorbidity( df, id_col="patient_id", code_col="icd_code", score=ScoreType.ELIXHAUSER, ) # With van Walraven weights result = comorbidity( df, id_col="patient_id", code_col="icd_code", score=ScoreType.ELIXHAUSER, weighting=WeightingVariant.VAN_WALRAVEN, ) # With Swiss weights result = comorbidity( df, id_col="patient_id", code_col="icd_code", score=ScoreType.ELIXHAUSER, weighting=WeightingVariant.SWISS, ) ``` -------------------------------- ### Test with synthetic data fixture Source: https://vvcb.github.io/comorbidipy/contributing Example test using the synthetic data fixture from tests/conftest.py to generate Charlson data and verify the comorbidity function returns the expected number of rows. ```python def test_with_synthetic_data(generate_charlson_data): df = generate_charlson_data(n_patients=100, codes_per_patient=5) result = comorbidity(df, age=None) assert len(result) == 100 ``` -------------------------------- ### Catch KeyError from comorbidity() when columns are missing Source: https://vvcb.github.io/comorbidipy/api Shows how to catch a KeyError when the required columns are missing from the DataFrame. The example creates a Polars DataFrame with incorrect column names and attempts to call comorbidity with id_col="patient_id" and code_col="code", printing the missing column name in the exception message. ```python from comorbidipy import comorbidity import polars as pl df = pl.DataFrame({"wrong_col": ["P001"], "also_wrong": ["I21"]}) try: result = comorbidity(df, id_col="patient_id", code_col="code") except KeyError as e: print(f"Missing column: {e}") ``` -------------------------------- ### disability: Identify learning disabilities and sensory impairments Source: https://vvcb.github.io/comorbidipy/api The disability function identifies learning disabilities and sensory impairments from ICD-10 codes. The example shows usage with a Polars DataFrame containing patient IDs and ICD codes. The function returns a DataFrame with binary flags for learning disability/ASD, visual impairment, and hearing impairment, and raises KeyError if required columns are missing. ```python def disability( df: pl.DataFrame | pl.LazyFrame, id_col: str = "id", code_col: str = "code", ) -> pl.DataFrame: """ Identify learning disabilities and sensory impairments from ICD-10 codes. Detects: - Learning disability / Autism Spectrum Disorder (F70-F79, F84) - Visual impairment (H54) - Hearing impairment (H90-H91) Args: df: DataFrame with patient IDs and ICD-10 codes. id_col: Name of the column containing patient identifiers. code_col: Name of the column containing ICD codes. Returns: DataFrame with columns: - Patient ID (original column name) - ld_asd: 1 if learning disability/ASD present, 0 otherwise - impaired_vision: 1 if visual impairment present, 0 otherwise - impaired_hearing: 1 if hearing impairment present, 0 otherwise Raises: KeyError: If required columns are missing from the input DataFrame. """ ``` ```python import polars as pl from comorbidipy import disability df = pl.DataFrame({ "id": ["P001", "P002"], "code": ["F70", "H90"], }) result = disability(df, id_col="id", code_col="code") ``` -------------------------------- ### Serve and build documentation with mkdocs Source: https://vvcb.github.io/comorbidipy/contributing Serve documentation locally with mkdocs serve and build the documentation with mkdocs build. ```bash # Serve documentation locally uv run mkdocs serve # Build documentation uv run mkdocs build ``` -------------------------------- ### info command Source: https://vvcb.github.io/comorbidipy/cli Displays version number and available calculators. ```bash comorbidipy info ``` -------------------------------- ### Add a new calculator: module, export, CLI, and tests Source: https://vvcb.github.io/comorbidipy/contributing Steps to add a new calculator: create the module, export it from the package, add a CLI command, and write tests. The module uses Polars and the CLI uses Typer's @app.command(). ```python # src/comorbidipy/calculators/new_calculator.py import polars as pl import logging logger = logging.getLogger(__name__) def new_calculator( df: pl.DataFrame | pl.LazyFrame, id: str = "id", code: str = "code", ) -> pl.DataFrame: """Calculate new score.""" logger.info("Calculating new score") # Implementation here return result ``` ```python from comorbidipy.calculators.new_calculator import new_calculator __all__ = [ # ... existing exports "new_calculator", ] ``` ```python @app.command() def new_cmd( input_file: Path, output_file: Path, id: str = "id", code: str = "code", verbose: bool = False, ) -> None: """Calculate new score.""" # Implementation ``` ```python import pytest import polars as pl from comorbidipy import new_calculator def test_new_calculator_basic(): df = pl.DataFrame({ "id": ["P001", "P002"], "code": ["A00", "B00"], }) result = new_calculator(df) assert "score" in result.columns ``` -------------------------------- ### Use Command Line Interface Source: https://vvcb.github.io/comorbidipy/getting-started Process files directly using the CLI for various scores and options. ```bash # View help comorbidipy --help # Calculate Charlson score comorbidipy charlson input.csv output.parquet # With options comorbidipy charlson input.csv output.csv \ --id-col patient_id \ --code-col diagnosis_code \ --age-col patient_age \ --mapping quan \ --weights charlson # Calculate HFRS comorbidipy hfrs-cmd input.parquet output.parquet # Show available options comorbidipy info ``` -------------------------------- ### Run checks before commit Source: https://vvcb.github.io/comorbidipy/contributing Run the required checks before committing: format with ruff, lint with ruff, and run the test suite. ```bash uv run ruff format uv run ruff check uv run pytest ``` -------------------------------- ### Calculate Charlson score with comorbidipy Python API Source: https://vvcb.github.io/comorbidipy Use the Python API to calculate the Charlson Comorbidity Index from a Polars DataFrame. The example creates a sample DataFrame with id, code, and age columns, then calls comorbidity() and prints the result. ```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") print(result) ``` -------------------------------- ### Complete workflow: charlson with age adjustment Source: https://vvcb.github.io/comorbidipy/cli Complete workflow: inspect input, run charlson with age adjustment and verbose logging, then check results. The input file is shown with sample rows. ```bash # 1. Check input file head -5 input.csv # id,code,age # P001,I21,65 # P001,E112,65 # P002,I50,72 # 2. Calculate Charlson with age adjustment comorbidipy charlson input.csv output.csv \ --age-col age \ --verbose # 3. Check results head -5 output.csv ``` -------------------------------- ### Use Parquet format for performance Source: https://vvcb.github.io/comorbidipy/getting-started Parquet files offer faster read/write performance compared to CSV. ```python # Read Parquet df = pl.read_parquet("data.parquet") # Or use CLI comorbidipy charlson input.parquet output.parquet ``` -------------------------------- ### comorbidity: Calculate Charlson or Elixhauser scores Source: https://vvcb.github.io/comorbidipy/api The comorbidity function calculates Charlson or Elixhauser scores from ICD codes. The example shows usage with a Polars DataFrame, specifying patient ID, diagnosis code, and age columns. The function returns a DataFrame with binary flags and scores, and raises KeyError or ValueError for missing columns or invalid combinations. ```python def comorbidity( df: pl.DataFrame | pl.LazyFrame, id_col: str = "id", code_col: str = "code", age_col: str | None = None, score: ScoreType = ScoreType.CHARLSON, icd: ICDVersion = ICDVersion.ICD10, variant: MappingVariant = MappingVariant.QUAN, weighting: WeightingVariant = WeightingVariant.QUAN, assign0: bool = True, ) -> pl.DataFrame: """ Calculate comorbidity scores from ICD diagnosis codes. Args: df: DataFrame with patient IDs and ICD codes. id_col: Name of the column containing patient identifiers. code_col: Name of the column containing ICD codes. age_col: Name of the column containing patient age (optional). When provided with Charlson score and Charlson weights, enables age adjustment and survival calculation. score: Type of comorbidity score (CHARLSON or ELIXHAUSER). icd: Version of ICD codes (ICD9 or ICD10). variant: Mapping variant for ICD code classification. weighting: Weighting scheme for calculating the score. assign0: Whether to zero out less severe conditions when more severe forms are present. Returns: DataFrame with patient IDs, binary comorbidity flags, and calculated scores. Raises: KeyError: If required columns are missing from the input DataFrame. ValueError: If invalid combination of score/mapping/weighting is used. """ ``` ```python import polars as pl from comorbidipy import comorbidity, ScoreType, MappingVariant df = pl.DataFrame({ "patient_id": ["P001", "P001", "P002"], "diagnosis": ["I21", "E112", "I50"], "patient_age": [65, 65, 72], }) result = comorbidity( df, id_col="patient_id", code_col="diagnosis", age_col="patient_age", score=ScoreType.CHARLSON, ) ``` -------------------------------- ### hfrs: Calculate Hospital Frailty Risk Score Source: https://vvcb.github.io/comorbidipy/api The hfrs function calculates the Hospital Frailty Risk Score from ICD-10 codes. The example shows usage with a Polars DataFrame containing patient IDs and ICD codes. The function returns a DataFrame with hfrs_score and hfrs_category columns, and raises KeyError if required columns are missing. The HFRS is validated for patients aged 75 and older. ```python def hfrs( df: pl.DataFrame | pl.LazyFrame, id_col: str = "id", code_col: str = "code", ) -> pl.DataFrame: """ Calculate Hospital Frailty Risk Score from ICD-10 codes. The HFRS identifies frailty in hospital patients using 109 ICD-10 codes associated with frailty conditions. Args: df: DataFrame with patient IDs and ICD-10 codes. id_col: Name of the column containing patient identifiers. code_col: Name of the column containing ICD codes. Returns: DataFrame with columns: - Patient ID (original column name) - hfrs_score: Continuous frailty score - hfrs_category: "Low" (<5), "Intermediate" (5-15), or "High" (>15) Raises: KeyError: If required columns are missing from the input DataFrame. Note: The HFRS is validated for patients aged 75 years and older. """ ``` ```python import polars as pl from comorbidipy import hfrs df = pl.DataFrame({ "id": ["P001", "P001", "P002"], "code": ["F00", "R26", "J18"], }) result = hfrs(df, id_col="id", code_col="code") ``` -------------------------------- ### Format and lint with ruff Source: https://vvcb.github.io/comorbidipy/contributing Format code with ruff, check for linting issues, and fix auto-fixable issues. ```bash # Format code uv run ruff format # Check for linting issues uv run ruff check # Fix auto-fixable issues uv run ruff check --fix ``` -------------------------------- ### Run comorbidipy CLI commands for Charlson, Elixhauser, HFRS, and info Source: https://vvcb.github.io/comorbidipy Use the comorbidipy command-line interface to calculate Charlson, Elixhauser, and HFRS scores, and to show available options. The commands specify input/output files and mapping/weight options. ```bash # Calculate Charlson score comorbidipy charlson input.csv output.parquet --mapping quan --weights charlson # Calculate Elixhauser score comorbidipy elixhauser input.csv output.csv --weights van_walraven # Calculate HFRS comorbidipy hfrs-cmd patients.parquet results.parquet # Show available options comorbidipy info ``` -------------------------------- ### CLI: Basic HFRS calculation and options Source: https://vvcb.github.io/comorbidipy/calculators/hfrs Run the comorbidipy CLI to calculate HFRS from a CSV or Parquet file. The basic command uses default column names, while custom columns can be specified with --id-col and --code-col. Output can be written as Parquet by using a .parquet extension. ```bash # Basic HFRS calculation comorbidipy hfrs input.csv output.csv # With custom columns comorbidipy hfrs input.parquet output.parquet --id-col pat_id --code-col diagnosis # Output as Parquet comorbidipy hfrs input.csv output.parquet ``` -------------------------------- ### Run tests with uv run pytest Source: https://vvcb.github.io/comorbidipy/contributing Commands to run the test suite, with coverage, for a specific file, or matching a pattern. ```bash # Run all tests uv run pytest # Run with coverage uv run pytest --cov=comorbidipy # Run specific test file uv run pytest tests/test_comorbidity.py # Run tests matching a pattern uv run pytest -k "charlson" ``` -------------------------------- ### CLI: comorbidipy charlson with --mapping, --weights, --age-col Source: https://vvcb.github.io/comorbidipy/calculators/charlson Shows the CLI usage for the charlson command. The first command runs a basic calculation, the second specifies mapping, weights, and an age column, and the third uses the Swedish mapping. Output files can be CSV or Parquet. ```bash # Basic Charlson calculation comorbidipy charlson input.csv output.csv # With specific mapping and weights comorbidipy charlson input.csv output.parquet \ --mapping quan \ --weights charlson \ --age-col age # Using Swedish mapping comorbidipy charlson input.csv output.csv --mapping swedish ``` -------------------------------- ### Process large files with streaming Source: https://vvcb.github.io/comorbidipy/getting-started Use the --streaming flag for files that do not fit in memory. ```bash comorbidipy charlson large_input.parquet output.parquet --streaming ``` -------------------------------- ### Type check with mypy Source: https://vvcb.github.io/comorbidipy/contributing Run type checking with mypy on the source directory. ```bash uv run mypy src/comorbidipy ``` -------------------------------- ### Run disability identification via CLI Source: https://vvcb.github.io/comorbidipy/calculators/disability Execute disability identification from the command line. Supports input/output file paths and custom column naming for IDs and diagnosis codes. ```bash # Basic disability identification comorbidipy disability input.csv output.csv # With custom columns comorbidipy disability input.parquet output.parquet --id-col pat_id --code-col diagnosis # Output as Parquet comorbidipy disability input.csv output.parquet ``` -------------------------------- ### Prepare data for analysis Source: https://vvcb.github.io/comorbidipy/getting-started Create a Polars DataFrame with patient identifiers and ICD codes. ```python import polars as pl # Example data format df = pl.DataFrame({ "id": ["P001", "P001", "P001", "P002", "P002"], "code": ["I21", "E112", "I50", "J44", "K703"], "age": [65, 65, 65, 72, 72], # Optional for age-adjusted scores }) ``` -------------------------------- ### Import All Public API from comorbidipy Source: https://vvcb.github.io/comorbidipy/api Imports all public functions and enums from comorbidipy for type hints and usage. Provides IDE support with full type annotations. ```python from comorbidipy import ( comorbidity, hfrs, disability, ScoreType, ICDVersion, MappingVariant, WeightingVariant, ) ``` -------------------------------- ### Batch processing multiple files Source: https://vvcb.github.io/comorbidipy/cli Batch processing: loop over CSV files and run charlson on each, saving results to a results directory. ```bash # Process multiple files for f in data/*.csv; do comorbidipy charlson "$f" "results/$(basename "$f")" done ``` -------------------------------- ### disability command usage Source: https://vvcb.github.io/comorbidipy/cli Usage syntax for the disability command. Options include --id-col, --code-col, --verbose, and others. ```bash comorbidipy disability [OPTIONS] INPUT OUTPUT ``` -------------------------------- ### Python API: Disable assign zero logic Source: https://vvcb.github.io/comorbidipy/calculators/elixhauser Shows how to keep both uncomplicated and complicated forms of conditions by setting assign0=False. By default (assign0=True), the uncomplicated form is set to 0 when the complicated form is present. ```python result = comorbidity(df, assign0=False) ``` -------------------------------- ### elixhauser command usage Source: https://vvcb.github.io/comorbidipy/cli Usage syntax for the elixhauser command. Options include --weights, --icd-version, and --no-assign0. ```bash comorbidipy elixhauser [OPTIONS] INPUT OUTPUT ``` -------------------------------- ### charlson command usage Source: https://vvcb.github.io/comorbidipy/cli Usage syntax for the charlson command. Options include --mapping, --weights, --age-col, --icd-version, and --no-assign0. ```bash comorbidipy charlson [OPTIONS] INPUT OUTPUT ``` -------------------------------- ### Use LazyFrame for deferred computation Source: https://vvcb.github.io/comorbidipy/getting-started Utilize Polars LazyFrame for memory-efficient processing. ```python # Use LazyFrame for memory efficiency lazy_df = pl.scan_parquet("large_file.parquet") result = comorbidity(lazy_df, id="id", code="code", age=None) ``` -------------------------------- ### Python: comorbidity() with assign0=False Source: https://vvcb.github.io/comorbidipy/calculators/charlson Shows how to keep both the less severe and more severe forms of a condition by setting assign0=False. By default assign0=True sets the less severe form to 0 when the more severe form is present. ```python result = comorbidity(df, assign0=False) ``` -------------------------------- ### hfrs command usage Source: https://vvcb.github.io/comorbidipy/cli Usage syntax for the hfrs command. Options include --id-col, --code-col, --verbose, and others. ```bash comorbidipy hfrs [OPTIONS] INPUT OUTPUT ``` -------------------------------- ### Use LazyFrame with comorbidity Function Source: https://vvcb.github.io/comorbidipy/api Shows how to use comorbidipy with a Polars LazyFrame for memory-efficient processing. The function collects data lazily and returns an eager DataFrame with results. ```python import polars as pl from comorbidipy import comorbidity # LazyFrame for memory-efficient processing lf = pl.scan_parquet("large_file.parquet") result = comorbidity(lf, id_col="id", code_col="code") ``` -------------------------------- ### Calculate Elixhauser Comorbidity Index Source: https://vvcb.github.io/comorbidipy/getting-started Compute the Elixhauser score using the Van Walraven weighting. ```python result = comorbidity( df, id_col="id", code_col="code", score=ScoreType.ELIXHAUSER, weighting=WeightingVariant.VAN_WALRAVEN, ) ``` -------------------------------- ### Calculate Hospital Frailty Risk Score Source: https://vvcb.github.io/comorbidipy/getting-started Compute the HFRS using patient identifiers and ICD codes. ```python from comorbidipy import hfrs # HFRS only requires id and code result = hfrs(df, id_col="id", code_col="code") ``` -------------------------------- ### Pipeline usage: pipe charlson output Source: https://vvcb.github.io/comorbidipy/cli Pipeline usage: pipe the output of charlson to another tool (csvstat) for further analysis. ```bash # Chain with other tools comorbidipy charlson input.csv /dev/stdout | \ csvstat --mean comorbidity_score ``` -------------------------------- ### WeightingVariant Enum for Score Weighting Source: https://vvcb.github.io/comorbidipy/api Defines the weighting scheme for score calculation. CHARLSON, QUAN, SHMI, and SHMI_MODIFIED are for Charlson scores; VAN_WALRAVEN and SWISS are for Elixhauser scores. ```python class WeightingVariant(StrEnum): CHARLSON = "charlson" QUAN = "quan" SHMI = "shmi" SHMI_MODIFIED = "shmi_modified" VAN_WALRAVEN = "van_walraven" SWISS = "swiss" ``` -------------------------------- ### disability Source: https://vvcb.github.io/comorbidipy/api Identifies learning disabilities and sensory impairments from ICD-10 codes. Detects learning disability/ASD, visual impairment, and hearing impairment. ```APIDOC ## disability ### Description Identify learning disabilities and sensory impairments from ICD-10 codes. Detects: - Learning disability / Autism Spectrum Disorder (F70-F79, F84) - Visual impairment (H54) - Hearing impairment (H90-H91) ### Function Signature ```python def disability( df: pl.DataFrame | pl.LazyFrame, id_col: str = "id", code_col: str = "code", ) -> pl.DataFrame: ``` ### Parameters - **df** (pl.DataFrame | pl.LazyFrame) - Required - DataFrame with patient IDs and ICD-10 codes. - **id_col** (str) - Optional - Name of the column containing patient identifiers. Default: "id". - **code_col** (str) - Optional - Name of the column containing ICD codes. Default: "code". ### Returns - **pl.DataFrame** - DataFrame with columns: - Patient ID (original column name) - ld_asd: 1 if learning disability/ASD present, 0 otherwise - impaired_vision: 1 if visual impairment present, 0 otherwise - impaired_hearing: 1 if hearing impairment present, 0 otherwise ### Raises - **KeyError** - If required columns are missing from the input DataFrame. ### Example ```python import polars as pl from comorbidipy import disability df = pl.DataFrame({ "id": ["P001", "P002"], "code": ["F70", "H90"], }) result = disability(df, id_col="id", code_col="code") ``` ```