Package 'icdcomorbid'

Title: Mapping ICD Codes to Comorbidity
Description: Provides tools for mapping International Classification of Diseases codes to comorbidity, enabling the identification and analysis of various medical conditions within healthcare data.
Authors: April Nguyen [aut, cre], Seungwon Lee [aut], Centre for Health Informatics, CHI [fnd]
Maintainer: April Nguyen <[email protected]>
License: MIT + file LICENSE
Version: 1.0.0
Built: 2024-11-20 05:05:32 UTC
Source: https://github.com/cran/icdcomorbid

Help Index


Insert decimals to the ICD codes

Description

This is a preprocessing step to standardize the icd codes to have decimals.

Usage

add_decimal(df, icd_cols, places = 3)

Arguments

df

The dataframe to be converted.

icd_cols

A character vector specifying the names of the columns containing ICD codes.

places

An numeric value specifying the number of decimal places. Default is 3 decimal places.

Value

A dataframe in wide format where each row represents a unique identifier (ID), and each column contains a variable associated with that ID.

Examples

df <- data.frame(
  id = c(1, 2, 3),
  icd_1 = c("C509", "D633", "I210"),
  icd_2 = c("D509", "E788", "N183")
)
add_decimal(df, icd_cols = c("icd_1", "icd_2"), places = 3)

Identify Episodes of Care

Description

This function identifies episodes of care for patients based on their visit and discharge dates from two different data sources (DAD and NACRS).

Usage

episode_of_care(
  dad_df,
  nacrs_df,
  patient_id_col,
  dad_visit_date_col,
  dad_exit_date_col,
  nacrs_visit_date_col,
  nacrs_exit_date_col
)

Arguments

dad_df

DataFrame containing DAD data.

nacrs_df

DataFrame containing NACRS data.

patient_id_col

String representing the column name for patient ID.

dad_visit_date_col

String representing the column name for visit date in DAD data.

dad_exit_date_col

String representing the column name for exit date in DAD data.

nacrs_visit_date_col

String representing the column name for visit date in NACRS data.

nacrs_exit_date_col

String representing the column name for exit date in NACRS data.

Value

A DataFrame with episodes of care identified and a unique record ID for each row.

Examples

# Sample DAD data
dad_df <- data.frame(
  patient_id = c("A001", "A001", "A002", "A002", "A003"),
  admit_dt = c("01Dec2023:10:00:00", "03Jan2024:12:00:00",
  "05Jan2024:09:00:00", "07Jan2024:14:00:00", "12Jan2024:12:00:00"),
  discharge_dt = c("02Dec2023:10:00:00", "04Jan2024:10:00:00",
  "06Jan2024:10:00:00", "08Jan2024:10:00:00", "15Jan2024:08:00:00")
)

# Sample NACRS data
nacrs_df <- data.frame(
  patient_id = c("A001", "A002", "A003", "A003", "A004"),
  visit_dt = c("03Jan2024:09:00:00", "07Feb2024:15:00:00",
  "10Jan2024:09:00:00", "11Jan2024:10:00:00", "12Jan2024:11:00:00"),
  disp_dt = c("03Jan2024:11:00:00", "07Feb2024:17:00:00",
  "10Jan2024:10:00:00", "12Jan2024:12:00:00", "13Jan2024:13:00:00")
)

episode_of_care(dad_df, nacrs_df, "patient_id", "admit_dt", "discharge_dt", "visit_dt", "disp_dt")

Find Comorbidities from ICD_10 Codes

Description

This function maps ICD_10 codes to comorbidities based on a provided mapping in order to indicate whether each comorbidity is present for each ID.

Usage

icd10_to_comorbid(df, idx, icd_cols, mapping, batch_size = 1000)

Arguments

df

The dataframe containing the data.

idx

The name of the column representing the patient identifiers.

icd_cols

A character vector of the columns containing ICD codes.

mapping

The mapping of comorbidities to ICD codes (e.g., quan_elixhauser10, charlson10, custom list).

batch_size

An optional integer specifying the number of rows to process per batch. Default is 1000.

Details

This function assumes that the input dataframe is in wide format, where each row represents a unique identifier (ID), and each column contains a variable associated with that ID. The function maps the ICD_10 codes in the specified columns to comorbidities based on the provided mapping.

The mapping can be one of the following:

- Pre-defined mappings such as "quan_elixhauser10" or "charlson10", which are based on established comorbidity indices.

- Custom mappings (list), where each key represents a comorbidity and its value is a vector of ICD-9 codes associated with that comorbidity. The custom mapping codes may include up to 2 decimal places.

Value

A dataframe with comorbidities as columns and IDs as rows, with True or False values indicating whether each comorbidity is present for each ID.

References

1. Quan, H., Sundararajan, V., Halfon, P., Fong, A., Burnand, B., Luthi, J. C., ... & Ghali, W. A. (2005). Coding algorithms for defining comorbidities in ICD-9-CM and ICD-10 administrative data. Medical care, 43(11), 1130-1139. 2. ICD: Python library for working with International Classification of Diseases (ICD) codes. Available online: https://github.com/mark-hoffmann/icd

Examples

df <- data.frame(ID = c(1, 2, 3),
                 icd_1 = c("I21.0", "I50.3", "J45.1"),
                 icd_2 = c("I63.38", "I10.2", "I25.2"))
# Using pre-existing mapping (e.g., charlson10 or quan_elixhauser10)
mapping <- "charlson10"
icd10_to_comorbid(df, "ID", c("icd_1", "icd_2"), mapping)

# Using custom mapping
custom_mapping <- list("Myocardial Infarction" = c("I21.x", "I22.x", "I25.2"),
                       "Congestive Heart Failure" = c("I43.x", "I50.x", "I09.9"))
icd10_to_comorbid(df, "ID", c("icd_1", "icd_2"), custom_mapping, batch_size = 2)

Find Comorbidities from ICD_9 Codes

Description

This function maps ICD_9 codes to comorbidities based on a provided mapping in order to indicate whether each comorbidity is present for each ID.

Usage

icd9_to_comorbid(df, idx, icd_cols, mapping, batch_size = 1000)

Arguments

df

The dataframe containing the data.

idx

The name of the column representing the patient identifiers.

icd_cols

A character vector of the columns containing ICD codes.

mapping

The mapping of comorbidities to ICD codes (e.g., quan_elixhauser9, charlson9, custom list).

batch_size

An optional integer specifying the number of rows to process per batch. Default is 1000.

Details

This function assumes that the input dataframe is in wide format, where each row represents a unique identifier (ID), and each column contains a variable associated with that ID. The function maps the ICD_9 codes in the specified columns to comorbidities based on the provided mapping.

The mapping can be one of the following:

- Pre-defined mappings such as "quan_elixhauser9" or "charlson9", which are based on established comorbidity indices.

- Custom mappings (list), where each key represents a comorbidity and its value is a vector of ICD-9 codes associated with that comorbidity. The custom mapping codes may include up to 2 decimal places.

Value

A dataframe with comorbidities as columns and IDs as rows, with True or False values indicating whether each comorbidity is present for each ID.

References

1. Quan, H., Sundararajan, V., Halfon, P., Fong, A., Burnand, B., Luthi, J. C., ... & Ghali, W. A. (2005). Coding algorithms for defining comorbidities in ICD-9-CM and ICD-10 administrative data. Medical care, 43(11), 1130-1139. 2. ICD: Python library for working with International Classification of Diseases (ICD) codes. Available online: https://github.com/mark-hoffmann/icd

Examples

df <- data.frame(ID = c(1, 2, 3),
                 icd_1 = c("410.x", "428.0", "496"),
                 icd_2 = c("428.33", "401.9", "493.90"))
# Using pre-existing mapping (e.g., charlson9 or quan_elixhauser9)
mapping <- "charlson9"
icd9_to_comorbid(df, "ID", c("icd_1", "icd_2"), mapping)

# Using custom mapping
custom_mapping <- list("Myocardial Infarction" = c("410.x", "412.x"),
                       "Congestive Heart Failure" = c("398.91", "402.01",
                       "402.11", "402.91", "404.01", "404.03",
                       "404.11", "404.13", "404.91", "404.93", "425.4",
                       "425.5", "425.6", "425.7", "425.8", "425.9", "428.x"))
icd9_to_comorbid(df, "ID", c("icd_1", "icd_2"), custom_mapping, batch_size = 2)

Reshape Long Format Data to Wide Format

Description

This is a preprocessing step to transform a dataframe from long to wide format to use with icd_to_comorbid function.

Usage

long_to_wide(df, idx, icd_cols, batch_size = 1000)

Arguments

df

The dataframe to be converted.

idx

The name of the column containing the unique identifier (ID).

icd_cols

A character vector specifying the names of the columns containing ICD codes.

batch_size

An optional integer specifying the number of rows to process per batch. Default is 1000.

Value

A dataframe in wide format where each row represents a unique identifier (ID), and each column contains a variable associated with that ID.

References

ICD: Python library for working with International Classification of Diseases (ICD) codes. Available online: https://github.com/mark-hoffmann/icd

Examples

df <- data.frame( ID = c(1, 1, 2, 2, 3, 3, 3),
                 icd_1 = c("I10.2", "E03.9", "E11.9", "N18.9", "A04.7", NA, NA),
                 icd_2 = c("I11.9", "E78.5", "E78.2", "E14.9","A04.7", "E11.9", NA))
long_to_wide(df, "ID", c("icd_1", "icd_2"), batch_size = 1000)