|
| 1 | +library(medicalcoder) |
| 2 | + |
| 3 | +################################################################################ |
| 4 | +# Regression test: selected ICD-10 codes should map to specific Elixhauser |
| 5 | +# comorbidities under the Quan (2005) implementation. The codes were drawn from |
| 6 | +# the internal lookup table (get_elixhauser_codes()). |
| 7 | +################################################################################ |
| 8 | + |
| 9 | +example_codes <- |
| 10 | + data.frame( |
| 11 | + patid = c("P1", "P1", "P1", "P2", "P2", "P2", "P3"), |
| 12 | + icdv = 10L, |
| 13 | + dx = 1L, |
| 14 | + code = c("I099", # CHF |
| 15 | + "I110", # Hypertensive heart disease with heart failure (supports CHF) |
| 16 | + "I132", # Hypertensive heart and kidney disease with heart failure |
| 17 | + "E109", # Diabetes mellitus without complications |
| 18 | + "E1021", # Diabetes with renal complications |
| 19 | + "E6609", # Other obesity |
| 20 | + "N185" # Chronic kidney disease, stage 5 (renal failure) |
| 21 | + ), |
| 22 | + stringsAsFactors = FALSE |
| 23 | + ) |
| 24 | + |
| 25 | +res <- comorbidities( |
| 26 | + data = example_codes, |
| 27 | + icd.codes = "code", |
| 28 | + id.vars = "patid", |
| 29 | + icdv.var = "icdv", |
| 30 | + dx.var = "dx", |
| 31 | + method = "elixhauser_quan2005", |
| 32 | + poa = 1, |
| 33 | + primarydx = 0, |
| 34 | + flag.method = "current" |
| 35 | +) |
| 36 | + |
| 37 | +res_df <- as.data.frame(res[, c("patid", "CHF", "DM", "DMCX", "OBESE", "RENLFAIL", "num_cmrb")]) |
| 38 | + |
| 39 | +# P1: congestive heart failure only |
| 40 | +stopifnot(res_df[["CHF"]][res_df[["patid"]] == "P1"] == 1L) |
| 41 | +stopifnot(all(res_df[["CHF"]][res_df[["patid"]] != "P1"] == 0L)) |
| 42 | + |
| 43 | +# P2: diabetes (with and without complications) + obesity |
| 44 | +stopifnot(res_df[["DM"]][res_df[["patid"]] == "P2"] == 1L) |
| 45 | +stopifnot(res_df[["DMCX"]][res_df[["patid"]] == "P2"] == 1L) |
| 46 | +stopifnot(res_df[["OBESE"]][res_df[["patid"]] == "P2"] == 1L) |
| 47 | + |
| 48 | +# P3: renal failure only |
| 49 | +stopifnot(res_df[["RENLFAIL"]][res_df[["patid"]] == "P3"] == 1L) |
| 50 | + |
| 51 | +# Overall comorbidity counts match the manual expectation |
| 52 | +stopifnot(res_df[["num_cmrb"]][res_df[["patid"]] == "P1"] == 1L) |
| 53 | +stopifnot(res_df[["num_cmrb"]][res_df[["patid"]] == "P2"] == 3L) |
| 54 | +stopifnot(res_df[["num_cmrb"]][res_df[["patid"]] == "P3"] == 1L) |
| 55 | + |
| 56 | +################################################################################ |
| 57 | +# End of File # |
| 58 | +################################################################################ |
0 commit comments