### Load Libraries and Get Package Info Source: http://www.peteredewitt.com/medicalcoder/articles/medicalcoder-vs-multimorbidity.html Loads necessary R packages and retrieves version and description information for the multimorbidity package. This is a setup step for comparing the packages. ```r library(data.table) library(medicalcoder) library(multimorbidity) packageVersion("multimorbidity") packageDescription("multimorbidity")$Title cat(packageDescription("multimorbidity")$Description) ``` -------------------------------- ### Install medicalcoder from Source (Command Line) Source: http://www.peteredewitt.com/medicalcoder/index.html Install the medicalcoder package from a local source file (.tar.gz) using the R CMD INSTALL command in your terminal. ```bash R CMD INSTALL medicalcoder_X.Y.Z.tar.gz ``` -------------------------------- ### Install medicalcoder from Source (.tar.gz) Source: http://www.peteredewitt.com/medicalcoder/index.html Install the medicalcoder package from a local source file (.tar.gz). This method is useful if you have downloaded the package source or are installing a specific version. ```R install.packages(pkgs = "medicalcoder_X.Y.Z.tar.gz", repos = NULL, type = "source") ``` -------------------------------- ### Get PCCC Conditions Source: http://www.peteredewitt.com/medicalcoder/reference/get_pccc_conditions.html This example shows how to call the get_pccc_conditions() function and displays the resulting data frame, which maps conditions to subconditions and provides condition labels. ```R get_pccc_conditions() #> condition subcondition #> 1 malignancy neoplasms #> 2 cvd device_and_technology_use #> 3 misc transplantation #> 4 neuromusc other_neurologic_disorders #> 5 neuromusc device_and_technology_use #> 6 metabolic endocrine_disorders #> 7 gi other #> 8 respiratory other #> 9 respiratory device_and_technology_use #> 10 respiratory transplantation #> 11 cvd heart_and_great_vessel_malformations #> 12 cvd transplantation #> 13 renal device_and_technology_use #> 14 hemato_immu transplantation #> 15 hemato_immu other #> 16 gi device_and_technology_use #> 17 gi transplantation #> 18 renal other #> 19 renal transplantation #> 20 misc device_and_technology_use #> 21 metabolic device_and_technology_use #> 22 hemato_immu acquired_immunodeficiency #> 23 hemato_immu sarcoidosis #> 24 congeni_genetic bone_and_joint_anomalies #> 25 metabolic amino_acid_metabolism #> 26 metabolic carbohydrate_metabolism #> 27 metabolic lipid_metabolism #> 28 metabolic other_metabolic_disorders #> 29 respiratory cystic_fibrosis #> 30 metabolic storage_disorders #> 31 hemato_immu hereditary_immunodeficiency #> 32 hemato_immu hereditary_anemias #> 33 hemato_immu aplastic_anemias #> 34 hemato_immu coagulation_hemorrhagic #> 35 hemato_immu leukopenia #> 36 hemato_immu hemophagocytic_syndromes #> 37 neuromusc intellectual_disabilities #> 38 respiratory chronic_respiratory_diseases #> 39 neuromusc cns_degeneration_and_diseases #> 40 neuromusc movement_diseases #> 41 neuromusc infantile_cerebral_palsy #> 42 renal chronic_bladder_diseases #> 43 neuromusc epilepsy #> 44 neuromusc muscular_dystrophies_and_myopathies #> 45 cvd other #> 46 cvd endocardium_diseases #> 47 cvd cardiomyopathies #> 48 cvd conduction_disorder #> 49 cvd dysrhythmias #> 50 neuromusc occlusion_of_cerebral_arteries #> 51 hemato_immu polyarteritis_nodosa_and_related_conditions #> 52 congeni_genetic diaphragm_and_abdominal_wall_anomalies #> 53 gi inflammatory_bowel_disease #> 54 gi chronic_liver_disease_and_cirrhosis #> 55 renal chronic_renal_failure #> 56 hemato_immu diffuse_diseases_of_connective_tissue #> 57 neuromusc brain_and_spinal_cord_malformations #> 58 respiratory respiratory_malformations #> 59 gi congenital_anomalies #> 60 renal congenital_anomalies #> 61 congeni_genetic chromosomal_anomalies #> 62 congeni_genetic other_congenital_anomalies #> 63 neonatal fetal_malnutrition #> 64 neonatal extreme_immaturity #> 65 neonatal cerebral_hemorrhage_at_birth #> 66 neonatal spinal_cord_injury_at_birth #> 67 neonatal birth_asphyxia #> 68 neonatal hypoxic_ischemic_encephalopathy #> 69 neonatal respiratory_diseases #> 70 neonatal other #> 71 malignancy transplantation #> condition_label #> 1 Malignancy #> 2 Cardiovascular #> 3 Miscellaneous, Not Elsewhere Classified ``` -------------------------------- ### Install medicalcoder from GitHub Source: http://www.peteredewitt.com/medicalcoder/index.html Install the development version of the medicalcoder package directly from its GitHub repository using the remotes package. ```R remotes::install_github("dewittpe/medicalcoder") ``` -------------------------------- ### Load and Inspect icdcomorbid Package Source: http://www.peteredewitt.com/medicalcoder/articles/medicalcoder-vs-icdcomorbid.html Loads the icdcomorbid package and displays its version, title, and description. Ensure the package is installed before running. ```R library(medicalcoder) library(icdcomorbid) packageVersion("icdcomorbid") ## [1] '1.0.0' packageDescription("icdcomorbid")$Title ## [1] "Mapping ICD Codes to Comorbidity" cat(packageDescription("icdcomorbid")$Description) ## ## Provides tools for mapping International Classification of Diseases codes to comorbidity, ## enabling the identification and analysis of various medical conditions within healthcare data. ``` -------------------------------- ### Load and Inspect R Packages Source: http://www.peteredewitt.com/medicalcoder/articles/medicalcoder-vs-comorbidity.html Loads the 'medicalcoder' and 'comorbidity' R packages and displays their versions and descriptions. Ensure these packages are installed before running. ```R library(medicalcoder) library(comorbidity) packageVersion("comorbidity") ## [1] '1.1.0' packageDescription("comorbidity")$Title ## [1] "Computing Comorbidity Scores" cat(packageDescription("comorbidity")$Description) ## Computing comorbidity indices and scores such as the weighted Charlson ## score (Charlson, 1987 ) and the Elixhauser ## comorbidity score (Elixhauser, 1998 ) ## using ICD-9-CM or ICD-10 codes (Quan, 2005 ). ## Australian and Swedish modifications of the Charlson Comorbidity Index are available ## as well (Sundararajan, 2004 and Ludvigsson, 2021 ## ), together with different weighting algorithms for both ## the Charlson and Elixhauser comorbidity scores. ``` -------------------------------- ### Prepare Data for Benchmarking with data.table Source: http://www.peteredewitt.com/medicalcoder/articles/medicalcoder-vs-comorbidity.html Copies and converts input data frames to data.tables for performance testing. Ensure the data.table package is installed and loaded. ```R mdcrDT <- data.table::copy(mdcr) data.table::setDT(mdcrDT) mdcr_icd9dxDT <- data.table::copy(mdcr_icd9dx) mdcr_icd10dxDT <- data.table::copy(mdcr_icd10dx) data.table::setDT(mdcr_icd9dxDT) data.table::setDT(mdcr_icd10dxDT) ``` -------------------------------- ### Load medicalcoder and check version Source: http://www.peteredewitt.com/medicalcoder/articles/charlson.html Load the medicalcoder package and display its version. Ensure you have the correct version installed. ```r library(medicalcoder) packageVersion("medicalcoder") ``` -------------------------------- ### Open Elixhauser Vignette Source: http://www.peteredewitt.com/medicalcoder/index.html Access the vignette for detailed examples and information on Elixhauser comorbidity calculations. ```R vignette(topic = "elixhauser", package = "medicalcoder") ``` -------------------------------- ### Load Example Datasets in medicalcoder Source: http://www.peteredewitt.com/medicalcoder/index.html Loads the `mdcr` and `mdcr_longitudinal` datasets into the R environment. These datasets are used for demonstrating the package's functionality. ```r data(mdcr, mdcr_longitudinal, package = "medicalcoder") ``` -------------------------------- ### Loading and Checking Package Versions Source: http://www.peteredewitt.com/medicalcoder/articles/transition-pccc-to-medicalcoder.html Loads the pccc and medicalcoder R packages and displays their current versions. This is a common setup step before using the functions from these packages. ```R library(pccc) packageVersion("pccc") ## [1] '1.0.7' library(medicalcoder) ``` -------------------------------- ### Install medicalcoder from CRAN Source: http://www.peteredewitt.com/medicalcoder/index.html Use this command to install the latest stable version of the medicalcoder package from the Comprehensive R Archive Network (CRAN). ```R install.packages("medicalcoder") ``` -------------------------------- ### Example of Identical Comorbidity Comparisons Source: http://www.peteredewitt.com/medicalcoder/articles/medicalcoder-vs-comorbidity.html Illustrates the output of the comparison loop, showing `identical()` calls and their `TRUE` results for various comorbidity pairs between the 'comorbidity' and 'medicalcoder' packages. ```r ## identical(elixhauser_delta[["aids"]], elixhauser_delta[["AIDS"]]) ## [1] TRUE ## identical(elixhauser_delta[["alcohol"]], elixhauser_delta[["ALCOHOL"]]) ## [1] TRUE ## identical(elixhauser_delta[["blane"]], elixhauser_delta[["BLDLOSS"]]) ## [1] TRUE ## identical(elixhauser_delta[["dane"]], elixhauser_delta[["ANEMDEF"]]) ## [1] TRUE ## identical(elixhauser_delta[["carit"]], elixhauser_delta[["CARDIAC_ARRHYTHMIAS"]]) ## [1] TRUE ## identical(elixhauser_delta[["solidtum"]], elixhauser_delta[["TUMOR"]]) ## [1] TRUE ## identical(elixhauser_delta[["metacanc"]], elixhauser_delta[["METS"]]) ## [1] TRUE ## identical(elixhauser_delta[["cpd"]], elixhauser_delta[["CHRNLUNG"]]) ## [1] TRUE ## identical(elixhauser_delta[["coag"]], elixhauser_delta[["COAG"]]) ## [1] TRUE ## identical(elixhauser_delta[["chf"]], elixhauser_delta[["CHF"]]) ## [1] TRUE ## identical(elixhauser_delta[["depre"]], elixhauser_delta[["DEPRESS"]]) ## [1] TRUE ## identical(elixhauser_delta[["diabc"]], elixhauser_delta[["DMCX"]]) ## [1] TRUE ## identical(elixhauser_delta[["diabunc"]], elixhauser_delta[["DM"]]) ## [1] TRUE ## identical(elixhauser_delta[["drug"]], elixhauser_delta[["DRUG"]]) ## [1] TRUE ## identical(elixhauser_delta[["fed"]], elixhauser_delta[["LYTES"]]) ## [1] TRUE ## identical(elixhauser_delta[["hypc"]], elixhauser_delta[["HTN_CX"]]) ## [1] TRUE ## identical(elixhauser_delta[["hypunc"]], elixhauser_delta[["HTN_UNCX"]]) ## [1] TRUE ## identical(elixhauser_delta[["hypothy"]], elixhauser_delta[["HYPOTHY"]]) ## [1] TRUE ## identical(elixhauser_delta[["ld"]], elixhauser_delta[["LIVER"]]) ## [1] TRUE ## identical(elixhauser_delta[["lymph"]], elixhauser_delta[["LYMPH"]]) ## [1] TRUE ## identical(elixhauser_delta[["obes"]], elixhauser_delta[["OBESE"]]) ## [1] TRUE ## identical(elixhauser_delta[["ond"]], elixhauser_delta[["NEURO"]]) ## [1] TRUE ## identical(elixhauser_delta[["para"]], elixhauser_delta[["PARA"]]) ## [1] TRUE ## identical(elixhauser_delta[["pud"]], elixhauser_delta[["ULCER"]]) ## [1] TRUE ## identical(elixhauser_delta[["pvd"]], elixhauser_delta[["PERIVASC"]]) ## [1] TRUE ## identical(elixhauser_delta[["psycho"]], elixhauser_delta[["PSYCH"]]) ## [1] TRUE ## identical(elixhauser_delta[["pcd"]], elixhauser_delta[["PULMCIRC"]]) ## [1] TRUE ## identical(elixhauser_delta[["rf"]], elixhauser_delta[["RENLFAIL"]]) ## [1] TRUE ## identical(elixhauser_delta[["rheumd"]], elixhauser_delta[["ARTH"]]) ## [1] TRUE ## identical(elixhauser_delta[["valv"]], elixhauser_delta[["VALVE"]]) ## [1] TRUE ## identical(elixhauser_delta[["wloss"]], elixhauser_delta[["WGHTLOSS"]]) ## [1] TRUE ``` -------------------------------- ### Comorbidity Flagging with DX Variable Source: http://www.peteredewitt.com/medicalcoder/articles/pccc.html This example includes the `dx.var` argument, useful when your data distinguishes between diagnostic and procedure codes. It helps refine comorbidity flagging. ```R comorbidities( data = DF, id.vars = "id", icd.codes = "code", dx.var = "dx", poa = 1, full.code = FALSE, compact.codes = TRUE, method = "pccc_v3.1" )[, c("id", "cmrb_flag", "renal_dxpr_or_tech")] ``` -------------------------------- ### pccc Package Data Format Example Source: http://www.peteredewitt.com/medicalcoder/articles/transition-pccc-to-medicalcoder.html Illustrates the data structure expected by the pccc::ccc() function, where each row represents a patient/encounter and columns denote diagnostic and procedure codes. ```R patid dx1 dx2 dx3 dx4 dx5 dx6 pr1 pr2 pr3 pr4 pr5 patXX T8619 E8809 E876 Z7982 NA NA 02PAX3Z 5A1D70Z 04Q90ZZ 0TS60ZZ NA ``` -------------------------------- ### Open Charlson Vignette Source: http://www.peteredewitt.com/medicalcoder/index.html Access the vignette for detailed examples and information on Charlson comorbidity calculations. ```R vignette(topic = "charlson", package = "medicalcoder") ``` -------------------------------- ### Comorbidity Flagging with Full Codes Only Source: http://www.peteredewitt.com/medicalcoder/articles/pccc.html This example demonstrates flagging comorbidities when `full.code` is TRUE and `compact.codes` is FALSE, useful for ensuring only full ICD codes are considered. ```R comorbidities( data = DF, id.vars = "id", icd.codes = "code", poa = 1, full.code = TRUE, compact.codes = FALSE, method = "pccc_v3.1" )[, c("id", "cmrb_flag", "renal_dxpr_or_tech")] ``` -------------------------------- ### Open Comorbidities Vignette Source: http://www.peteredewitt.com/medicalcoder/index.html Opens the main vignette for the `comorbidities` function, providing general examples and explanations for how conditions are flagged. ```r vignette(topic = "comorbidities", package = "medicalcoder") ``` -------------------------------- ### View First Few Rows of PCCC Codes Source: http://www.peteredewitt.com/medicalcoder/reference/get_pccc_codes.html Display the first few rows of the PCCC codes data frame to get a quick overview of the data structure and content. ```R head(get_pccc_codes()) ``` -------------------------------- ### Get ICD Codes with Descriptions Source: http://www.peteredewitt.com/medicalcoder/articles/icd.html Retrieves the ICD code lookup table including descriptions for each code by setting the 'with.descriptions' argument to TRUE. This provides more detailed information about each ICD code. ```R str(get_icd_codes(with.descriptions = TRUE)) ``` -------------------------------- ### Lookup ICD Codes (Compact Codes Only) Source: http://www.peteredewitt.com/medicalcoder/articles/icd.html This example shows how to restrict the lookup_icd_codes function to only consider compact ICD codes by setting `full.codes = FALSE`. The output is formatted using knitr::kable. ```r knitr::kable( lookup_icd_codes(codes, full.codes = FALSE), row.names = FALSE ) ``` -------------------------------- ### Comorbidity Flagging with ICD Version Variable Source: http://www.peteredewitt.com/medicalcoder/articles/pccc.html This example uses `icdv.var = "icdv"` to dynamically determine the ICD version from a column in the data. It's a flexible approach for handling mixed ICD versions. ```R comorbidities( data = subset(mdcr, patid == "95471"), icd.codes = "code", id.vars = 'patid', dx.var = "dx", icdv.var = "icdv", poa = 1, method = "pccc_v3.0" )[, c('patid', 'cmrb_flag')] ``` -------------------------------- ### Get ICD Codes Function Signature Source: http://www.peteredewitt.com/medicalcoder/reference/get_icd_codes.html This is the basic function signature for retrieving ICD codes. Use `with.descriptions = TRUE` to include code descriptions or `with.hierarchy = TRUE` to include the ICD hierarchy. ```R get_icd_codes(with.descriptions = FALSE, with.hierarchy = FALSE) ``` -------------------------------- ### Apply PCCC Methods to MDCR Data Source: http://www.peteredewitt.com/medicalcoder/articles/pccc.html Use the `comorbidities` function to flag conditions in the `mdcr` dataset. This example applies both `pccc_v2.1` and `pccc_v3.1` methods, specifying 'code' for ICD codes and 'patid' as the patient identifier. The `poa` argument is set to 1, and `flag.method` is set to 'current'. ```r mdcr_results_v2.1_01 <- comorbidities( data = mdcr, icd.codes = "code", id.vars = "patid", poa = 1, flag.method = 'current', method = "pccc_v2.1" ) mdcr_results_v3.1_01 <- comorbidities( data = mdcr, icd.codes = "code", id.vars = "patid", poa = 1, flag.method = 'current', method = "pccc_v3.1" ) ``` -------------------------------- ### medicalcoder Package Data Format Example Source: http://www.peteredewitt.com/medicalcoder/articles/transition-pccc-to-medicalcoder.html Shows the data structure required by the medicalcoder::comorbidities() function, where each row represents a single ICD code for a patient/encounter, with a column indicating if it's a diagnostic (dx=1) or procedure (dx=0) code. ```R patid code dx patXX T8619 1 patXX E8809 1 patXX E876 1 patXX Z7982 1 patXX 02PAX3Z 0 patXX 5A1D70Z 0 patXX 04Q90ZZ 0 patXX 0TS60ZZ 0 ``` -------------------------------- ### Run MIMIC-IV Charlson Query Locally Source: http://www.peteredewitt.com/medicalcoder/articles/medicalcoder-vs-mimic.html Connects to an in-memory SQLite database, writes prepared data, executes the modified MIMIC-IV Charlson SQL query, and retrieves the results. ```r library(odbc) library(DBI) library(RSQLite) con <- dbConnect(drv = RSQLite::SQLite(), dbname = ":memory:") # add data to the data base dbWriteTable(conn = con, name = "diagnoses", value = mdcr_for_mimic[dx == 1L]) dbWriteTable(conn = con, name = "admissions", value = mdcr_for_mimic[, unique(.SD), .SDcols = c("subject_id", "hadm_id")]) dbWriteTable(conn = con, name = "ages", value = mdcr_for_mimic[, unique(.SD), .SDcols = c("hadm_id", "age")]) # get the charlson results via MIMIC-IV mimic_charlson_results <- dbGetQuery(con, mimic_charson_query) # close DB connection dbDisconnect(conn = con) setDT(mimic_charlson_results) ``` -------------------------------- ### Prepare Data for MIMIC Comparison Source: http://www.peteredewitt.com/medicalcoder/articles/medicalcoder-vs-mimic.html Prepares the `mdcr` dataset for comparison with MIMIC-IV by renaming columns and creating new identifiers and sequence numbers. ```r library(medicalcoder) library(data.table) mdcr_for_mimic <- data.table::copy(mdcr) setDT(mdcr_for_mimic) # create a hospital admission id (one admission per patient id in mdcr) setnames( mdcr_for_mimic, old = c("patid", "code", "icdv"), new = c("subject_id", "icd_code", "icd_version") ) mdcr_for_mimic[, hadm_id := paste0(subject_id, "e1")] mdcr_for_mimic[, seq_num := 1L:.N, by = .(subject_id, hadm_id)] mdcr_for_mimic[, age := as.integer(substr(as.character(subject_id), 1L, 2L))] ``` -------------------------------- ### Allow Header Codes and Specify Year Source: http://www.peteredewitt.com/medicalcoder/reference/is_icd.html Shows how to allow header codes and specify a particular year for validation. This is useful for checking codes that might not be directly assignable but are valid headers. ```R is_icd(x, icdv = 9, dx = 1, headerok = TRUE) #> [1] TRUE TRUE TRUE is_icd(x, icdv = 9, dx = 1, year = 2006) #> [1] TRUE TRUE TRUE ``` -------------------------------- ### Get and Inspect ICD Codes Source: http://www.peteredewitt.com/medicalcoder/reference/get_icd_codes.html Retrieve all available ICD codes and inspect their structure. This is useful for understanding the dataset. ```r icd_codes <- get_icd_codes() str(icd_codes) #> 'data.frame': 249819 obs. of 9 variables: #> $ icdv : int 9 9 9 9 9 9 9 9 9 9 ... #> $ dx : int 0 0 0 0 0 0 0 0 0 0 ... #> $ full_code : chr "00" "00" "00.0" "00.0" ... #> $ code : chr "00" "00" "000" "000" ... #> $ src : chr "cms" "cdc" "cms" "cdc" ... #> $ known_start : int 2006 2003 2006 2003 2006 2003 2006 2003 2006 2003 ... #> $ known_end : int 2015 2012 2015 2012 2015 2012 2015 2012 2015 2012 ... #> $ assignable_start: int NA NA NA NA 2006 2003 2006 2003 2006 2003 ... #> $ assignable_end : int NA NA NA NA 2015 2012 2015 2012 2015 2012 2015 2012 ... ``` -------------------------------- ### Open ICD Vignette Source: http://www.peteredewitt.com/medicalcoder/index.html Opens the vignette for the 'icd' topic in the medicalcoder package, providing more details and examples on working with ICD codes. ```r vignette(topic = "icd", package = "medicalcoder") ``` -------------------------------- ### Download and Modify MIMIC-IV Charlson SQL Query Source: http://www.peteredewitt.com/medicalcoder/articles/medicalcoder-vs-mimic.html Downloads the Charlson SQL query from GitHub and modifies it to be compatible with RSQLite. ```r mimic_charson_query <- scan( file = "https://raw.githubusercontent.com/MIT-LCP/mimic-code/278df75ec30991ff3a6f5ceb6d2221635a085e9f/mimic-iv/concepts/comorbidity/charlson.sql", what = character(), sep = "\n" ) # modify the query to work in SQLite mimic_charson_query <- gsub(pattern = "physionet-data.mimiciv_hosp.admissions", replacement = "admissions", x = mimic_charson_query, fixed = TRUE) mimic_charson_query <- gsub(pattern = "physionet-data.mimiciv_hosp.diagnoses_icd", replacement = "diagnoses", x = mimic_charson_query, fixed = TRUE) mimic_charson_query <- gsub(pattern = "physionet-data.mimiciv_derived.age", replacement = "ages", x = mimic_charson_query, fixed = TRUE) mimic_charson_query <- gsub(pattern = "GREATEST", replacement = "MAX", x = mimic_charson_query, fixed = TRUE) mimic_charson_query <- paste(mimic_charson_query, collapse = "\n") ``` -------------------------------- ### Open PCCC Vignette Source: http://www.peteredewitt.com/medicalcoder/index.html Opens the vignette specific to the Pediatric Complex Chronic Conditions (PCCC) algorithm, offering further details and examples. ```r vignette(topic = "pccc", package = "medicalcoder") ``` -------------------------------- ### Get Elixhauser Codes Function Source: http://www.peteredewitt.com/medicalcoder/reference/get_elixhauser_codes.html Retrieves the internal lookup tables for Elixhauser comorbidity ICD codes. This function does not require any arguments. ```R get_elixhauser_codes() ``` -------------------------------- ### Format Condition Summaries with kableExtra Source: http://www.peteredewitt.com/medicalcoder/articles/transition-pccc-to-medicalcoder.html Use this code to subset and format summary data for specific conditions using kableExtra. Ensure the 'with_subconditions' data is available and properly structured. ```r cvd_and_metabolic <- subset(summary(with_subconditions), condition %in% c("cvd", "metabolic")) cvd_and_metabolic$subcondition[is.na(cvd_and_metabolic$subcondition)] <- "Any subcondition" kableExtra::kbl( x = cvd_and_metabolic[, c("subcondition", "count", "percent_of_cohort", "percent_of_those_with_condition")], caption = "Patients with cardiovascular and/or metabolic conditions and the associated with_subconditions.", row.names = FALSE, digits = 2, col.names = c("Subcondition", "Patients", "% of chort", "% of those with the primary condition") ) |> kableExtra::kable_styling(bootstrap_options = "striped") |> kableExtra::pack_rows(index = table(cvd_and_metabolic$condition)) ``` -------------------------------- ### Get Elixhauser POA Requirements Source: http://www.peteredewitt.com/medicalcoder/reference/get_elixhauser_poa.html Retrieves the internal lookup table for Elixhauser comorbidities and their present-on-admission requirements. This function requires no arguments. ```R get_elixhauser_poa() ``` -------------------------------- ### View First Few Elixhauser Index Scores Source: http://www.peteredewitt.com/medicalcoder/reference/get_elixhauser_index_scores.html Use `head()` with `get_elixhauser_index_scores()` to display the initial rows of the Elixhauser index scores data frame, showing condition, index type, and scores for different variants. ```R head(get_elixhauser_index_scores()) ``` -------------------------------- ### Get PCCC Conditions Source: http://www.peteredewitt.com/medicalcoder/reference/get_pccc_conditions.html Retrieves a data frame containing syntax-valid and human-readable labels for Pediatric Complex Chronic Conditions (PCCC) and their subconditions. ```APIDOC ## get_pccc_conditions() ### Description Retrieve a copy of internal lookup tables for the syntax valid and human readable labels of the Pediatric Complex Chronic Conditions (PCCC) conditions and subconditions. ### Usage ```R get_pccc_conditions() ``` ### Value a `data.frame` with the following columns * `condition`: (character) syntax valid name for the condition * `subcondition`: (character) syntax valid name for the subcondition * `condition_label`: (character) human readable label for the condition * `subcondition_label`: (character) human readable label for the subcondition ### See also * `get_pccc_codes()` for the lookup table of ICD codes used for the PCCC. * `comorbidities()` for applying comorbidity algorithms to a data set. ``` -------------------------------- ### Display First Few Rows of Elixhauser Codes Source: http://www.peteredewitt.com/medicalcoder/reference/get_elixhauser_codes.html Shows the first few rows of the Elixhauser codes lookup table to give an idea of the data structure and content. Useful for a quick inspection. ```R head(get_elixhauser_codes()) ``` -------------------------------- ### Get ICD Codes Table Source: http://www.peteredewitt.com/medicalcoder/index.html Retrieves a comprehensive table of ICD codes. Use this to inspect the structure and content of the available ICD data. ```r str(medicalcoder::get_icd_codes()) ``` -------------------------------- ### List Available Comorbidity Methods Source: http://www.peteredewitt.com/medicalcoder/articles/comorbidities.html Retrieve a list of all supported comorbidity calculation methods within the package. This helps in selecting the appropriate algorithm and version for your analysis. ```r medicalcoder:::comorbidities_methods() ## [1] "pccc_v2.0" "pccc_v2.1" ## [3] "pccc_v3.0" "pccc_v3.1" ## [5] "charlson_deyo1992" "charlson_quan2011" ## [7] "charlson_quan2005" "charlson_cdmf2019" ## [9] "elixhauser_elixhauser1988" "elixhauser_ahrq_web" ## [11] "elixhauser_quan2005" "elixhauser_ahrq2022" ## [13] "elixhauser_ahrq2023" "elixhauser_ahrq2024" ## [15] "elixhauser_ahrq2025" "elixhauser_ahrq2026" ## [17] "elixhauser_ahrq_icd10" ``` -------------------------------- ### Compare Dimensions and Column Names Source: http://www.peteredewitt.com/medicalcoder/articles/medicalcoder-vs-comorbidity.html Examine the dimensions and column names of the results from both packages to identify differences in the output structure. ```R dim(medicalcoder_elixhauser_results) ## [1] 38262 37 names(medicalcoder_elixhauser_results) ## [1] "patid" "AIDS" "LIVER" ## [4] "PERIVASC" "VALVE" "TUMOR" ## [7] "METS" "LYMPH" "HYPOTHY" ## [10] "DM" "DMCX" "LYTES" ## [13] "WGHTLOSS" "ALCOHOL" "OBESE" ## [16] "BLDLOSS" "ANEMDEF" "COAG" ## [19] "DRUG" "PSYCH" "DEPRESS" ## [22] "NEURO" "PARA" "CHF" ## [25] "HTN_UNCX" "HTN_CX" "RENLFAIL" ## [28] "PULMCIRC" "CHRNLUNG" "CARDIAC_ARRHYTHMIAS" ## [31] "ARTH" "ULCER" "HTN_C" ## [34] "num_cmrb" "cmrb_flag" "mortality_index" ## [37] "readmission_index" dim(comorbidity_elixhauser_results) ## [1] 38262 32 names(comorbidity_elixhauser_results) ## [1] "patid" "chf" "carit" "valv" "pcd" "pvd" ## [7] "hypunc" "hypc" "para" "ond" "cpd" "diabunc" ## [13] "diabc" "hypothy" "rf" "ld" "pud" "aids" ## [19] "lymph" "metacanc" "solidtum" "rheumd" "coag" "obes" ## [25] "wloss" "fed" "blane" "dane" "alcohol" "drug" ## [31] "psycho" "depre" ``` -------------------------------- ### Create Patient Data Frame Source: http://www.peteredewitt.com/medicalcoder/articles/pccc.html Prepare a data frame with ICD codes for a patient. Ensure `dx` is 1 for diagnostic and 0 for procedure codes, and `icdv` specifies the ICD version. ```r pat1 <- data.frame( dx = c(1, 1, 1, 1, 0, 0), icdv = 9L, code = c("34590", "78065", "3432", "78065", "9929", "8606") ) ``` -------------------------------- ### Access Comorbidities Function Documentation Source: http://www.peteredewitt.com/medicalcoder/articles/comorbidities.html Display the help manual for the `comorbidities` function. This provides detailed information on its arguments, usage, and return values. ```r help(topic = "comorbidities", package = "medicalcoder") ``` -------------------------------- ### Get Elixhauser POA Requirements Source: http://www.peteredewitt.com/medicalcoder/reference/get_elixhauser_poa.html Retrieves a data frame containing information about Elixhauser comorbidities, including whether a diagnosis needs to be present-on-admission (POA) to be flagged. ```APIDOC ## get_elixhauser_poa() ### Description Retrieves a copy of internal lookup table with details on which Elixhauser comorbidities do and do not require the associated ICD codes to be present-on-admission to be flagged. ### Usage ```R get_elixhauser_poa() ``` ### Value A `data.frame` with the following columns: * `condition`: Character vector of the conditions * `desc`: Character vector with a verbose description of the condition * `poa_required`: Integer indicators if the code needs to present on admission to be considered a comorbidity * `elixhauser_`: indicators for the Elixhauser `` ### See also * `get_elixhauser_index_scores()` for the lookup table of the condition by condition scores for mortality and readmission indices. * `get_elixhauser_codes()` for the lookup table of ICD codes mapping to the Elixhauser comorbidities. * `comorbidities()` for applying comorbidity algorithms to a data set. ### Examples ```R head(get_elixhauser_poa()) str(get_elixhauser_poa()) ``` ``` -------------------------------- ### Apply Elixhauser Method with Warning Source: http://www.peteredewitt.com/medicalcoder/articles/elixhauser.html This code applies the Elixhauser method without specifying primary diagnosis information, which will generate a warning. Pass `primarydx = 0` or `primarydx.var` to suppress this warning. ```r # will warn because primarydx and primarydx.var are both NULL mdcr_results0 <- comorbidities( data = mdcr, id.vars = "patid", icdv.var = "icdv", icd.codes = "code", dx.var = "dx", flag.method = "current", poa = 1, method = "elixhauser_ahrq2025" ) ## Warning: Assuming all codes provided are secondary diagnostic codes. Define ## `primarydx.var` or `primarydx` if this assumption is incorrect. ``` -------------------------------- ### Get PCCC Codes by ICD-10 Source: http://www.peteredewitt.com/medicalcoder/articles/pccc.html Retrieves PCCC codes matching specific ICD-10 diagnostic codes. Useful for understanding code details and technology dependency flags. ```r codes <- c("H49.811", "J84.111", "Z96.41") subset(get_pccc_codes(), full_code %in% codes) ## icdv dx full_code code condition subcondition ## 6438 10 1 H49.811 H49811 metabolic other_metabolic_disorders ## 6705 10 1 J84.111 J84111 respiratory chronic_respiratory_diseases ## 7898 10 1 Z96.41 Z9641 metabolic device_and_technology_use ## transplant_flag tech_dep_flag pccc_v3.1 pccc_v3.0 pccc_v2.1 pccc_v2.0 ## 6438 0 0 1 1 1 1 ## 6705 0 0 1 1 0 0 ## 7898 0 1 1 1 1 1 ``` -------------------------------- ### Inspect First Few Rows of Charlson Codes Source: http://www.peteredewitt.com/medicalcoder/reference/get_charlson_codes.html Use `head()` to display the first few rows of the data frame returned by `get_charlson_codes()`. This is useful for a quick overview of the data structure and content. ```r head(get_charlson_codes()) ``` -------------------------------- ### Get Charlson Index Scores Source: http://www.peteredewitt.com/medicalcoder/articles/charlson.html Retrieve the lookup table for Charlson index scores associated with specific conditions. This data.frame includes scores for different algorithm variants. ```r str(get_charlson_index_scores()) ``` -------------------------------- ### Calculate Elixhauser Comorbidities Source: http://www.peteredewitt.com/medicalcoder/reference/summary.medicalcoder_comorbidities.html Calculates Elixhauser comorbidity scores using the 'elixhauser_ahrq2025' method. This example specifies the primary diagnosis variable. The `poa` argument indicates presence of absence. ```r elixhauser_results <- comorbidities(data = mdcr, icd.codes = "code", id.vars = "patid", dx.var = "dx", method = "elixhauser_ahrq2025", primarydx = 1, flag.method = 'current', poa = 1) summary(elixhauser_results) ``` -------------------------------- ### Get PCCC Codes Data Frame Source: http://www.peteredewitt.com/medicalcoder/reference/get_pccc_codes.html Use this function to retrieve the complete lookup table for PCCC ICD codes. The output is a data frame suitable for further analysis or mapping. ```R get_pccc_codes() ``` -------------------------------- ### Get Charlson Index Scores Function Source: http://www.peteredewitt.com/medicalcoder/reference/get_charlson_index_scores.html This function retrieves a data frame containing Charlson comorbidity index scores for various conditions across different scoring variants. ```APIDOC ## get_charlson_index_scores() ### Description Retrieve a copy of internal lookup tables of index scores used in assessing Charlson comorbidities. ### Usage ```R get_charlson_index_scores() ``` ### Value A `data.frame` with the following columns: * `condition`: Character vector of the conditions * `index`: Character vector indicating if the score is for the mortality or the readmission index score * `charlson_`: the index scores for the variant ### See also * `get_charlson_codes()` for a lookup table of the ICD codes mapping to the Charlson comorbidities. * `comorbidities()` for applying comorbidity algorithms to a data set. ### Examples ```R head(get_charlson_index_scores()) str(get_charlson_index_scores()) ``` ``` -------------------------------- ### Comorbidity Flagging with ICD-9 Specified Source: http://www.peteredewitt.com/medicalcoder/articles/pccc.html This example explicitly sets `icdv = 9L` to ensure that all input codes are treated as ICD-9, which can prevent unexpected flags when dealing with mixed ICD versions. ```R comorbidities( data = subset(mdcr, patid == "95471"), icd.codes = "code", id.vars = 'patid', dx.var = "dx", icdv = 9L, poa = 1, method = "pccc_v3.1" )[, c('patid', 'cmrb_flag')] ``` -------------------------------- ### Apply Elixhauser Method Suppressing Warning Source: http://www.peteredewitt.com/medicalcoder/articles/elixhauser.html This code applies the Elixhauser method and suppresses the warning by setting `primarydx = 0`. The output is identical to the version that generated a warning. ```r # no warning mdcr_results <- comorbidities( data = mdcr, id.vars = "patid", icdv.var = "icdv", icd.codes = "code", dx.var = "dx", flag.method = "current", poa = 1, method = "elixhauser_ahrq2025", primarydx = 0 ) identical(mdcr_results, mdcr_results0) ## [1] TRUE ``` -------------------------------- ### Define Column Mapping for Comparison Source: http://www.peteredewitt.com/medicalcoder/articles/medicalcoder-vs-mimic.html Creates a data frame to map column names between the `medicalcoder` output and the MIMIC-IV SQL results for easier comparison. ```r dcolumns <- fread(text = " medicalcoder | mimic aidshiv | aids cebvd | cerebrovascular_disease copd | chronic_pulmonary_disease chf | congestive_heart_failure dem | dementia hp | paraplegia mi | myocardial_infarct pud | peptic_ulcer_disease pvd | peripheral_vascular_disease rnd | renal_disease rhd | rheumatic_disease age_score.x | age_score.y cci | charlson_comorbidity_index ") ```