From df122b6dddcbb72bd095cbc5299556980fb6b68c Mon Sep 17 00:00:00 2001 From: Andrew Bruce Date: Mon, 9 Dec 2024 00:11:45 -0800 Subject: [PATCH] * Begin breaking changes --- DESCRIPTION | 15 +- NAMESPACE | 15 +- R/appendices.R | 155 ++++++++++++------ ...lobals-generated.R => generated-globals.R} | 2 + R/helpers.R | 108 ++++++++++++ R/icd_10_cm.R | 47 +++--- R/icd_edits.R | 12 +- R/msdrg.R | 48 ------ R/pathologie-package.R | 1 + R/pins.R | 74 +++++++++ R/utils.R | 101 +++++++++--- _pkgdown.yml | 6 + .../deprecated/icd_chapter_case_regex.R | 47 ------ data-raw/pins_internal.R | 24 +++ man/add_dot.Rd | 24 --- man/appendix_A.Rd | 33 ---- man/appendix_B.Rd | 20 --- man/case_chapter_icd10.Rd | 24 --- man/ex_data.Rd | 2 +- man/get_pin.Rd | 20 +++ man/icd10cm.Rd | 9 +- man/icd_code_to_chapter.Rd | 28 ++++ man/insert_period.Rd | 25 +++ man/list_pins.Rd | 18 ++ man/mount_board.Rd | 7 +- man/msdrg_index.Rd | 34 ++++ man/msdrg_list.Rd | 38 +++++ man/{appendix_C.Rd => msdrg_pdx.Rd} | 14 +- man/pathologie-package.Rd | 6 +- man/remove_dot.Rd | 23 --- man/remove_period.Rd | 23 +++ man/search_edits.Rd | 4 +- man/search_msdrg.Rd | 7 +- 33 files changed, 642 insertions(+), 372 deletions(-) rename R/{roxyglobals-generated.R => generated-globals.R} (91%) create mode 100644 R/helpers.R delete mode 100644 R/msdrg.R create mode 100644 R/pins.R rename R/utils-icd.R => data-raw/deprecated/icd_chapter_case_regex.R (82%) create mode 100644 data-raw/pins_internal.R delete mode 100644 man/add_dot.Rd delete mode 100644 man/appendix_A.Rd delete mode 100644 man/appendix_B.Rd delete mode 100644 man/case_chapter_icd10.Rd create mode 100644 man/get_pin.Rd create mode 100644 man/icd_code_to_chapter.Rd create mode 100644 man/insert_period.Rd create mode 100644 man/list_pins.Rd create mode 100644 man/msdrg_index.Rd create mode 100644 man/msdrg_list.Rd rename man/{appendix_C.Rd => msdrg_pdx.Rd} (85%) delete mode 100644 man/remove_dot.Rd create mode 100644 man/remove_period.Rd diff --git a/DESCRIPTION b/DESCRIPTION index f90b357..c7988fd 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,10 +1,10 @@ Package: pathologie -Title: Tidy ICD-10-CM Tools +Title: Tidy ICD-10-CM Interface Version: 0.0.1 Authors@R: - person("Andrew", "Bruce", , "andrewallenbruce@gmail.com", role = c("aut", "cre", "cph")) + person(c("Andrew", "Allen"), "Bruce", , "andrewallenbruce@gmail.com", role = c("aut", "cre", "cph")) Maintainer: Andrew Bruce -Description: Tools for working with ICD-10-CM codes. +Description: Tidy tools for accessing and working with ICD-10-CM. License: MIT + file LICENSE URL: https://andrewallenbruce.github.io/pathologie/, https://github.com/andrewallenbruce/pathologie @@ -15,6 +15,7 @@ Imports: cli (>= 3.6.2), dplyr (>= 1.1.4), fs (>= 1.6.3), + fuimus (>= 0.0.3), httr2 (>= 1.0.0), pins (>= 1.3.0), purrr (>= 1.0.2), @@ -23,19 +24,21 @@ Imports: tidyr (>= 1.3.1), vctrs (>= 0.6.5) Suggests: + cheapr, fontawesome, - fuimus, + data.table, gt, + kit, knitr, qs, - rmarkdown, roxyglobals, + stringfish, testthat (>= 3.0.0) VignetteBuilder: knitr Remotes: github::andrewallenbruce/fuimus -Config/roxyglobals/filename: roxyglobals-generated.R +Config/roxyglobals/filename: generated-globals.R Config/roxyglobals/unique: TRUE Config/testthat/edition: 3 Config/testthat/parallel: true diff --git a/NAMESPACE b/NAMESPACE index 4909bb6..1b574b0 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -1,20 +1,23 @@ # Generated by roxygen2: do not edit by hand -export(add_dot) -export(appendix_A) -export(appendix_B) -export(appendix_C) export(appendix_D) export(appendix_G) export(appendix_H) export(apply_age_edits) -export(case_chapter_icd10) export(ex_data) +export(get_pin) export(gt_style) export(icd10api) export(icd10cm) +export(icd_code_to_chapter) +export(insert_period) export(is_valid_icd) +export(list_pins) export(mount_board) -export(remove_dot) +export(msdrg_index) +export(msdrg_list) +export(msdrg_pdx) +export(remove_period) export(search_edits) export(search_msdrg) +importFrom(fuimus,search_in) diff --git a/R/appendices.R b/R/appendices.R index 76fa29a..947a45a 100644 --- a/R/appendices.R +++ b/R/appendices.R @@ -1,62 +1,122 @@ -#' Appendix A: List of MS-DRGs Version 41.1 +#' Medicare Severity Diagnosis-Related Groups #' -#' Appendix A contains a list of each MS-DRG with a specification of the MDC and -#' whether the MS-DRG is medical or surgical. Some MS-DRGs which contain patients -#' from multiple MDCs (e.g., 014 Allogeneic Bone Marrow Transplant) do not have -#' an MDC specified. The letter M is used to designate a medical MS-DRG and the -#' letter P is used to designate a surgical MS-DRG. +#' The Medicare Severity Diagnosis-Related Group (MS-DRG) is a classification +#' system used by the Centers for Medicare and Medicaid Services (CMS) to group +#' patients with similar clinical characteristics and resource utilization into +#' a single payment category. #' -#' @template args-drg +#' The system is primarily used for Medicare reimbursement purposes, but it is +#' also adopted by many other payers as a basis for payment determination. #' -#' @template args-mdc +#' MS-DRGs are based on the principal diagnosis, up to 24 additional diagnoses, +#' and up to 25 procedures performed during the stay. In a small number of +#' MS-DRGs, classification is also based on the age, sex, and discharge status +#' of the patient. #' -#' @param type `` DRG type: `M` (Medical) or `P` (Surgical) +#' Hospitals serving more severely ill patients receive increased +#' reimbursements, while hospitals treating less severely ill patients will +#' receive less reimbursement. #' -#' @template args-dots +#' @param drg `` vector of 3-digit DRG codes +#' +#' @param mdc `` vector of 2-digit Major Diagnostic Category codes +#' +#' @param type `` DRG type: `Medical` or `Surgical` #' #' @template returns #' #' @examples -#' appendix_A(drg = "011") +#' search_msdrg(drg = "011") #' -#' appendix_A(mdc = "24") +#' search_msdrg(mdc = "24") #' #' @autoglobal #' #' @export -appendix_A <- function(drg = NULL, - mdc = NULL, - type = NULL, - ...) { +search_msdrg <- function(drg = NULL, mdc = NULL, type = NULL) { - msd <- pins::pin_read(mount_board(), "msdrg_41.1") + x <- get_pin("msdrg") + x <- search_in(x, x[["drg"]], drg) + x <- search_in(x, x[["mdc"]], mdc) + x <- search_in(x, x[["drg_type"]], type) - if (!is.null(type)) { - msd <- vctrs::vec_slice(msd, msd$drg_type == type) - } + return(x) +} - msd <- fuimus::search_in_if(msd, msd$drg, drg) - msd <- fuimus::search_in_if(msd, msd$mdc, mdc) +#' MS-DRG List +#' +#' __Appendix A__: Contains each MS-DRG with a specification of +#' the MDC and whether the MS-DRG is Medical or Surgical. +#' +#' Some MS-DRGs which contain patients from multiple MDCs +#' e.g., `"014"` (Allogeneic Bone Marrow Transplant) do not +#' have an MDC specified. +#' +#' The letter M is used to designate a medical MS-DRG and the +#' letter P is used to designate a surgical MS-DRG. +#' +#' @template args-drg +#' +#' @template args-mdc +#' +#' @param type `` `"M"` (Medical) or `"P"` (Surgical) +#' +#' @template returns +#' +#' @examples +#' msdrg_list(drg = "014") +#' +#' msdrg_list(mdc = "24") +#' +#' msdrg_list(type = "M") +#' +#' @autoglobal +#' +#' @export +msdrg_list <- function(drg = NULL, mdc = NULL, type = NULL) { + + x <- get_pin("msdrg_41.1") + x <- search_in(x, x[["drg_abb"]], type) + x <- search_in(x, x[["drg"]], drg) + x <- search_in(x, x[["mdc"]], mdc) - return(msd) + return(x) } -#' Appendix B: Diagnosis Code/MDC/MS-DRG Index +#' ICD-10-CM|MDC|MS-DRG Index +#' +#' __Appendix B__: ICD-10-CM|MDC|MS-DRG Index +#' +#' The Diagnosis Code/MDC/MS-DRG Index lists each ICD-10-CM code, +#' the MDC and the MS-DRGs to which the diagnosis is used to define +#' the logic of the MS-DRG either as a principal or secondary diagnosis. +#' +#' @param icd `` ICD-10-CM code +#' +#' @template args-drg #' -#' The Diagnosis Code/MDC/MS-DRG Index lists each diagnosis code, as well as -#' the MDC, and the MS-DRGs to which the diagnosis is used to define the logic -#' of the DRG either as a principal or secondary diagnosis. +#' @template args-mdc #' #' @template returns #' #' @examples -#' head(appendix_B()) +#' msdrg_index(icd = "A17.81") +#' +#' msdrg_index(drg = "011") +#' +#' msdrg_index(mdc = "24") #' #' @autoglobal #' #' @export -appendix_B <- function() { - pins::pin_read(mount_board(), "msdrg_index_41.1") +msdrg_index <- function(icd = NULL, drg = NULL, mdc = NULL) { + + x <- get_pin("msdrg_index_41.1") + x <- search_in(x, x[["icd_code"]], icd) + x <- search_in(x, x[["drg"]], drg) + x <- search_in(x, x[["mdc"]], mdc) + + return(x) } #' Appendix C: Complications or Comorbidities Exclusion list @@ -83,32 +143,27 @@ appendix_B <- function() { #' @param pdx `` 4-digit Principal Diagnosis (PDX) Group number, e.g., #' `0011` (~ 2,040 in total) #' -#' @param unnest `` Unnest the `pdx_icd` column -#' -#' @template args-dots +#' @param unnest `` Unnest the `pdx_icd` column; default is `FALSE` #' #' @template returns #' #' @examples -#' appendix_C(icd = "A17.81") +#' msdrg_pdx(icd = "A17.81") #' -#' appendix_C(pdx = "0032") +#' msdrg_pdx(pdx = "0032") #' #' @autoglobal #' #' @export -appendix_C <- function(icd = NULL, - pdx = NULL, - unnest = FALSE, - ...) { - - mcc <- pins::pin_read(mount_board(), "msdrg_ccmcc_41.1") +msdrg_pdx <- function(icd = NULL, pdx = NULL, unnest = FALSE) { - mcc <- fuimus::search_in_if(mcc, mcc$pdx_group, pdx) + x <- get_pin("msdrg_ccmcc_41.1") + x <- search_in(x, x[["pdx_group"]], pdx) + x <- search_in(x, x[["icd_code"]], icd) - mcc <- fuimus::search_in_if(mcc, mcc$icd_code, icd) + if (unnest) x <- tidyr::unnest(x, pdx_icd) - return(mcc) + return(x) } @@ -157,9 +212,7 @@ appendix_C <- function(icd = NULL, #' @autoglobal #' #' @export -appendix_D <- function() { - pins::pin_read(mount_board(), "msdrg_drg_groups_41.1") -} +appendix_D <- \() get_pin("msdrg_drg_groups_41.1") #' Appendix G Diagnoses Defined as Complications or Comorbidities #' @@ -175,9 +228,7 @@ appendix_D <- function() { #' @autoglobal #' #' @export -appendix_G <- function() { - pins::pin_read(mount_board(), "msdrg_icd_ccs_41.1") -} +appendix_G <- \() get_pin("msdrg_icd_ccs_41.1") #' Appendix H Diagnoses Defined as Major Complications or Comorbidities #' @@ -196,6 +247,4 @@ appendix_G <- function() { #' @autoglobal #' #' @export -appendix_H <- function() { - pins::pin_read(mount_board(), "msdrg_icd_mccs_41.1") -} +appendix_H <- \() get_pin("msdrg_icd_mccs_41.1") diff --git a/R/roxyglobals-generated.R b/R/generated-globals.R similarity index 91% rename from R/roxyglobals-generated.R rename to R/generated-globals.R index 502bc46..d3e524a 100644 --- a/R/roxyglobals-generated.R +++ b/R/generated-globals.R @@ -9,6 +9,8 @@ utils::globalVariables(c( "icd_description", # "icd_sec_code", + # + "pdx_icd", # # <.multiple_request> "V1", diff --git a/R/helpers.R b/R/helpers.R new file mode 100644 index 0000000..4fac772 --- /dev/null +++ b/R/helpers.R @@ -0,0 +1,108 @@ +#' Is `x` `NULL`? +#' +#' @param x vector +#' +#' @returns `` `TRUE` if `x` is `NULL`, `FALSE` otherwise +#' +#' @autoglobal +#' +#' @noRd +null <- \(x) is.null(x) + +#' Is `x` not `NULL`? +#' +#' @param x vector +#' +#' @returns `` `FALSE` if `x` is `NULL`, `TRUE` otherwise +#' +#' @autoglobal +#' +#' @noRd +not_null <- \(x) !is.null(x) + +#' Is `x` empty? +#' +#' @param x vector +#' +#' @returns `` +#' +#' @autoglobal +#' +#' @noRd +empty <- \(x) vctrs::vec_is_empty(x) + +#' Is `x` `NA`? +#' +#' @param x vector +#' +#' @returns `` +#' +#' @autoglobal +#' +#' @noRd +na <- \(x) cheapr::is_na(x) + +#' Is `x` not `NA`? +#' +#' @param x vector +#' +#' @returns `` +#' +#' @autoglobal +#' +#' @noRd +not_na <- \(x) !na(x) + +#' Detect by Regex +#' +#' @param s `` vector +#' +#' @param p `` regex pattern +#' +#' @returns `` vector the same length as `s` +#' +#' @autoglobal +#' +#' @noRd +rdetect <- \(s, p) stringfish::sf_grepl(s, p, nthreads = 4L) + +#' Remove by Regex +#' +#' @param s `` vector +#' +#' @param p `` regex pattern +#' +#' @param fix `` fixed pattern matching +#' +#' @returns `` vector the same length as `s` +#' +#' @autoglobal +#' +#' @noRd +rremove <- \(s, p, fix = FALSE) stringfish::sf_gsub(s, p, "", nthreads = 4L, fixed = fix) + +#' Count of characters in character vector +#' +#' @param x `` vector +#' +#' @returns `` vector of character counts +#' +#' @autoglobal +#' +#' @noRd +rnchar <- \(x) stringfish::sf_nchar(x, nthreads = 4L) + +#' Fast ifelse wrapper +#' +#' @param x `` vector +#' +#' @param yes,no Values to return depending on TRUE/FALSE element of `x`. Must +#' be same type and be either length 1 or same length of `x`. +#' +#' @returns vector of same length as `x` and attributes as `yes`. Data values +#' are taken from values of `yes` and `no`. +#' +#' @autoglobal +#' +#' @noRd +iifelse <- \(x, yes, no) kit::iif(test = x, yes = yes, no = no, nThread = 4L) diff --git a/R/icd_10_cm.R b/R/icd_10_cm.R index c0ab2b9..1f69f73 100644 --- a/R/icd_10_cm.R +++ b/R/icd_10_cm.R @@ -6,44 +6,39 @@ #' #' @template args-icd_code #' -#' @template args-dots -#' #' @template returns #' #' @examples -#' icd10cm( c("F50.8", "G40.311", "Q96.8", "Z62.890", "R45.4", "E06.3", -#' "H00.019", "D50.1", "C4A.70") ) +#' icd10cm(c("F50.8", "G40.311", "Q96.8", +#' "Z62.890", "R45.4", "E06.3", +#' "H00.019", "D50.1", "C4A.70")) #' #' @autoglobal #' #' @export -icd10cm <- function(icd = NULL, ...) { +icd10cm <- function(icd = NULL) { - icd10 <- pins::pin_read(mount_board(), "icd10cm") + x <- get_pin("icd10cm") - if (!is.null(icd)) { + if (null(icd)) + return(x) - icd10 <- tidyr::unnest( - icd10, - icd_ch_sec - ) |> - tidyr::unnest(icd_sec_code) + x <- tidyr::unnest(x, icd_ch_sec) |> + tidyr::unnest(icd_sec_code) - icd10 <- fuimus::search_in(icd10, icd10$icd_code, icd) + x <- search_in(x, x[["icd_code"]], icd) - edit <- search_edits(icd = icd) + edit <- search_edits(icd = icd) - if (!vctrs::vec_is_empty(edit)) { + if (empty(edit)) + return(x) - icd10 <- dplyr::left_join( - icd10, - edit, - by = dplyr::join_by( - icd_code, - icd_description - ) - ) - } - } - return(icd10) + dplyr::left_join( + x, + edit, + by = dplyr::join_by( + icd_code, + icd_description + ) + ) } diff --git a/R/icd_edits.R b/R/icd_edits.R index 70bbbd1..7537fb3 100644 --- a/R/icd_edits.R +++ b/R/icd_edits.R @@ -10,8 +10,6 @@ #' #' @template args-icd_code #' -#' @template args-dots -#' #' @template returns #' #' @examples @@ -20,13 +18,11 @@ #' @autoglobal #' #' @export -search_edits <- function(icd = NULL, ...) { - - edt <- pins::pin_read(mount_board(), "code_edits") - - edt <- fuimus::search_in_if(edt, edt$icd_code, icd) +search_edits <- function(icd = NULL) { - return(edt) + x <- get_pin("code_edits") + x <- search_in(x, x[["icd_code"]], icd) + return(x) } #' Apply Age Conflict Edits diff --git a/R/msdrg.R b/R/msdrg.R deleted file mode 100644 index 9291011..0000000 --- a/R/msdrg.R +++ /dev/null @@ -1,48 +0,0 @@ -#' Medicare Severity Diagnosis-Related Groups -#' -#' The Medicare Severity Diagnosis-Related Group (MS-DRG) is a classification -#' system used by the Centers for Medicare and Medicaid Services (CMS) to group -#' patients with similar clinical characteristics and resource utilization into -#' a single payment category. -#' -#' The system is primarily used for Medicare reimbursement purposes, but it is -#' also adopted by many other payers as a basis for payment determination. -#' -#' MS-DRGs are based on the principal diagnosis, up to 24 additional diagnoses, -#' and up to 25 procedures performed during the stay. In a small number of -#' MS-DRGs, classification is also based on the age, sex, and discharge status -#' of the patient. -#' -#' Hospitals serving more severely ill patients receive increased -#' reimbursements, while hospitals treating less severely ill patients will -#' receive less reimbursement. -#' -#' @param drg `` vector of 3-digit DRG codes -#' -#' @param mdc `` vector of 2-digit Major Diagnostic Category codes -#' -#' @param type `` DRG type: `Medical` or `Surgical` -#' -#' @template args-dots -#' -#' @template returns -#' @examples -#' search_msdrg(drg = "011") -#' -#' search_msdrg(mdc = "24") -#' @autoglobal -#' @export -search_msdrg <- function(drg = NULL, - mdc = NULL, - type = NULL, - ...) { - - ms <- pins::pin_read(mount_board(), "msdrg") - ms <- fuimus::search_in_if(ms, ms$drg, drg) - ms <- fuimus::search_in_if(ms, ms$mdc, mdc) - - if (!is.null(type)) { - ms <- vctrs::vec_slice(ms, ms$drg_type == type) - } - return(ms) -} diff --git a/R/pathologie-package.R b/R/pathologie-package.R index a65cf64..a3d533e 100644 --- a/R/pathologie-package.R +++ b/R/pathologie-package.R @@ -2,5 +2,6 @@ "_PACKAGE" ## usethis namespace: start +#' @importFrom fuimus search_in ## usethis namespace: end NULL diff --git a/R/pins.R b/R/pins.R new file mode 100644 index 0000000..e02c741 --- /dev/null +++ b/R/pins.R @@ -0,0 +1,74 @@ +#' Mount [pins][pins::pins-package] board +#' +#' @param source `` `"local"` or `"remote"` +#' +#' @returns `` or `` +#' +#' @autoglobal +#' +#' @keywords internal +#' +#' @export +mount_board <- function(source = c("local", "remote")) { + + gh_raw <- \(x) paste0("https://raw.githubusercontent.com/andrewallenbruce/", x) + + source <- match.arg(source) + + switch(source, + local = pins::board_folder(fs::path_package("extdata/pins", package = "pathologie")), + remote = pins::board_url(gh_raw("pathologie/master/inst/extdata/pins/")), + stop("Invalid source")) +} + +#' Get a pinned dataset from a [pins][pins::pins-package] board +#' +#' @param pin `` string name of pinned dataset +#' +#' @param ... additional arguments passed to `mount_board()` +#' +#' @returns `` or `` +#' +#' @autoglobal +#' +#' @keywords internal +#' +#' @export +get_pin <- function(pin, ...) { + + board <- mount_board(...) + + pin <- match.arg(pin, list_pins()) + + pins::pin_read(board, pin) +} + +#' List pins from a [pins][pins::pins-package] board +#' +#' @param ... arguments to pass to [mount_board()] +#' +#' @returns `` of [pins][pins::pins-package] +#' +#' @autoglobal +#' +#' @keywords internal +#' +#' @export +list_pins <- function(...) { + + board <- mount_board(...) + + pins::pin_list(board) +} + + +#' Example data set +#' +#' @template returns +#' +#' @keywords internal +#' +#' @autoglobal +#' +#' @export +ex_data <- \() get_pin("exdata") diff --git a/R/utils.R b/R/utils.R index 62fc0f6..3930f1c 100644 --- a/R/utils.R +++ b/R/utils.R @@ -1,28 +1,89 @@ -#' Mount [pins][pins::pins-package] board +#' Match ICD-10-CM Codes to Chapter Labels #' -#' @param source `` string; whether source is `"local"` or `"remote"` +#' @param x `` vector of ICD-10-CM codes #' -#' @returns `` if `source = "local"` or `` -#' if `source = "remote"` +#' @returns `` vector of ICD-10-CM chapter labels #' -#' @keywords internal +#' @examples +#' codes <- c("F50.8", "G40.311", "Q96.8", +#' "R45.4", "E06.3", "H00.019", +#' "D50.1", "C4A.70", "Z20.818") +#' +#' icd_code_to_chapter(codes) +#' +#' data.frame(code = codes, +#' chapter = icd_code_to_chapter(codes)) #' #' @autoglobal #' #' @export -mount_board <- function(source = c("local", "remote")) { +icd_code_to_chapter <- function(x) { - source <- match.arg(source) + data.table::fcase( + rdetect(x, "^[AB]"), "Certain infectious and parasitic diseases", + rdetect(x, "^(C|D[0-4])"), "Neoplasms", + rdetect(x, "^D[5-8]"), "Diseases of the blood and blood-forming organs and certain disorders involving the immune mechanism", + rdetect(x, "^E"), "Endocrine, nutritional and metabolic diseases", + rdetect(x, "^F"), "Mental, behavioral and neurodevelopmental disorders", + rdetect(x, "^G"), "Diseases of the nervous system", + rdetect(x, "^H[0-5]"), "Diseases of the eye and adnexa", + rdetect(x, "^H[6-9]"), "Diseases of the ear and mastoid process", + rdetect(x, "^I"), "Diseases of the circulatory system", + rdetect(x, "^J"), "Diseases of the respiratory system", + rdetect(x, "^K"), "Diseases of the digestive system", + rdetect(x, "^L"), "Diseases of the skin and subcutaneous tissue", + rdetect(x, "^M"), "Diseases of the musculoskeletal system and connective tissue", + rdetect(x, "^N"), "Diseases of the genitourinary system", + rdetect(x, "^O"), "Pregnancy, childbirth and the puerperium", + rdetect(x, "^P"), "Certain conditions originating in the perinatal period", + rdetect(x, "^Q"), "Congenital malformations, deformations and chromosomal abnormalities", + rdetect(x, "^R"), "Symptoms, signs and abnormal clinical and laboratory findings, not elsewhere classified", + rdetect(x, "^[ST]"), "Injury, poisoning and certain other consequences of external causes", + rdetect(x, "^[VWXY]"), "External causes of morbidity", + rdetect(x, "^Z"), "Factors influencing health status and contact with health services", + rdetect(x, "^U"), "Codes for special purposes", + default = NA_character_) - switch( - source, - local = pins::board_folder(fs::path_package("extdata/pins", package = "pathologie")), - remote = pins::board_url(fuimus::gh_raw( - "andrewallenbruce/pathologie/master/inst/extdata/pins/" - )) - ) } +#' Insert period into an ICD-10-CM code +#' +#' Inserts period into an ICD-10-CM code in between the 3rd and 4th +#' characters, if not present or if the code is longer than 3 characters +#' +#' @param x vector of ICD-10-CM codes +#' +#' @returns vector of ICD-10-CM codes with period inserted +#' +#' @examples +#' insert_period("F320") +#' +#' # Not inserted if code is only 3 characters +#' insert_period("F32") +#' +#' @autoglobal +#' +#' @export +insert_period <- \(x) iifelse(rnchar(x) > 3, gsub("^(.{3})(.*)$", paste0("\\1.\\2"), x), x) + +#' Remove period from ICD-10-CM code +#' +#' Removes period from the ICD-10 code if it exists +#' +#' @param x A valid ICD-10 code with a dot +#' +#' @returns A valid ICD-10 code without a dot included +#' +#' @examples +#' remove_period("F32.0") +#' +#' remove_period("F32") +#' +#' @autoglobal +#' +#' @export +remove_period <- \(x) rremove(x, ".", fix = TRUE) + #' gt Theme #' #' @param tbl `` object @@ -72,15 +133,3 @@ gt_style <- function(tbl, ) } -#' Example data set -#' -#' @template returns -#' -#' @keywords internal -#' -#' @autoglobal -#' -#' @export -ex_data <- function() { - pins::pin_read(pathologie::mount_board(), "exdata") -} diff --git a/_pkgdown.yml b/_pkgdown.yml index 81466fd..ff1bdc9 100644 --- a/_pkgdown.yml +++ b/_pkgdown.yml @@ -10,3 +10,9 @@ template: includes: in_header: +home: + title: pathologie • Tidy ICD-10-CM Interface + description: > + Tidy tools for accessing and working with ICD-10-CM. + sidebar: + structure: [links, license, community, citation, authors, dev] diff --git a/R/utils-icd.R b/data-raw/deprecated/icd_chapter_case_regex.R similarity index 82% rename from R/utils-icd.R rename to data-raw/deprecated/icd_chapter_case_regex.R index 7130187..f3e3283 100644 --- a/R/utils-icd.R +++ b/data-raw/deprecated/icd_chapter_case_regex.R @@ -107,50 +107,3 @@ icd10_chapter_regex <- function() { ), ) } - -#' Add a dot to an ICD-10 code -#' -#' `add_dot()` adds a dot to the ICD-10 code in the appropriate position -#' where one does not exist -#' -#' @param x A valid ICD-10 code without a dot -#' -#' @returns A valid ICD-10 code with a dot included -#' -#' @export -#' -#' @keywords internal -#' -#' @examples -#' add_dot("F320") -#' -#' add_dot("F32") # no dot added if code is only 3-digits -add_dot <- function(x) { - - # stopifnot(!stringr::str_detect(x, stringr::fixed("."))) - - ifelse(stringr::str_length(x) > 3, - gsub("^(.{3})(.*)$", paste0("\\1.\\2"), x), - x) -} - - -#' Remove dot from an ICD-10 code -#' -#' `remove_dot()` removes a dot from the ICD-10 code if it exists -#' -#' @param x A valid ICD-10 code with a dot -#' -#' @returns A valid ICD-10 code without a dot included -#' -#' @export -#' -#' @keywords internal -#' -#' @examples -#' remove_dot("F32.0") -#' -#' remove_dot("F32") -remove_dot <- function(x) { - stringr::str_remove(x, stringr::fixed(".")) -} diff --git a/data-raw/pins_internal.R b/data-raw/pins_internal.R new file mode 100644 index 0000000..e38e7e5 --- /dev/null +++ b/data-raw/pins_internal.R @@ -0,0 +1,24 @@ +pin_update <- function(x, name, title, description, force = FALSE) { + + board <- pins::board_folder( + here::here("inst/extdata/pins")) + + board |> + pins::pin_write( + x, + name = name, + title = title, + description = description, + type = "qs", + force_identical_write = force) + + board |> pins::write_board_manifest() +} + +delete_pins <- function(pin_names) { + + board <- pins::board_folder( + here::here("inst/extdata/pins")) + + pins::pin_delete(board, names = pin_names) +} diff --git a/man/add_dot.Rd b/man/add_dot.Rd deleted file mode 100644 index f3104c6..0000000 --- a/man/add_dot.Rd +++ /dev/null @@ -1,24 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/utils-icd.R -\name{add_dot} -\alias{add_dot} -\title{Add a dot to an ICD-10 code} -\usage{ -add_dot(x) -} -\arguments{ -\item{x}{A valid ICD-10 code without a dot} -} -\value{ -A valid ICD-10 code with a dot included -} -\description{ -\code{add_dot()} adds a dot to the ICD-10 code in the appropriate position -where one does not exist -} -\examples{ -add_dot("F320") - -add_dot("F32") # no dot added if code is only 3-digits -} -\keyword{internal} diff --git a/man/appendix_A.Rd b/man/appendix_A.Rd deleted file mode 100644 index 3786e25..0000000 --- a/man/appendix_A.Rd +++ /dev/null @@ -1,33 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/appendices.R -\name{appendix_A} -\alias{appendix_A} -\title{Appendix A: List of MS-DRGs Version 41.1} -\usage{ -appendix_A(drg = NULL, mdc = NULL, type = NULL, ...) -} -\arguments{ -\item{drg}{\verb{} vector of 3-digit Diagnosis-Related Group codes} - -\item{mdc}{\verb{} vector of 2-digit Major Diagnostic Category codes} - -\item{type}{\verb{} DRG type: \code{M} (Medical) or \code{P} (Surgical)} - -\item{...}{Empty dots} -} -\value{ -a \link[tibble:tibble-package]{tibble} -} -\description{ -Appendix A contains a list of each MS-DRG with a specification of the MDC and -whether the MS-DRG is medical or surgical. Some MS-DRGs which contain patients -from multiple MDCs (e.g., 014 Allogeneic Bone Marrow Transplant) do not have -an MDC specified. The letter M is used to designate a medical MS-DRG and the -letter P is used to designate a surgical MS-DRG. -} -\examples{ -appendix_A(drg = "011") - -appendix_A(mdc = "24") - -} diff --git a/man/appendix_B.Rd b/man/appendix_B.Rd deleted file mode 100644 index 42436ba..0000000 --- a/man/appendix_B.Rd +++ /dev/null @@ -1,20 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/appendices.R -\name{appendix_B} -\alias{appendix_B} -\title{Appendix B: Diagnosis Code/MDC/MS-DRG Index} -\usage{ -appendix_B() -} -\value{ -a \link[tibble:tibble-package]{tibble} -} -\description{ -The Diagnosis Code/MDC/MS-DRG Index lists each diagnosis code, as well as -the MDC, and the MS-DRGs to which the diagnosis is used to define the logic -of the DRG either as a principal or secondary diagnosis. -} -\examples{ -head(appendix_B()) - -} diff --git a/man/case_chapter_icd10.Rd b/man/case_chapter_icd10.Rd deleted file mode 100644 index 53a5c26..0000000 --- a/man/case_chapter_icd10.Rd +++ /dev/null @@ -1,24 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/utils-icd.R -\name{case_chapter_icd10} -\alias{case_chapter_icd10} -\title{Add ICD-10-CM Chapter Labels} -\usage{ -case_chapter_icd10(df, col) -} -\arguments{ -\item{df}{\verb{}data frame} - -\item{col}{\verb{} unquoted column name of ICD-10-CM codes to match} -} -\value{ -A \link[tibble:tibble-package]{tibble} with a \code{chapter} column -} -\description{ -Add ICD-10-CM Chapter Labels -} -\examples{ -dplyr::tibble(code = c("F50.8", "G40.311", "Q96.8", "Z62.890", "R45.4", -"E06.3", "H00.019", "D50.1", "C4A.70", "Z20.818")) |> -case_chapter_icd10(code) -} diff --git a/man/ex_data.Rd b/man/ex_data.Rd index 781fc74..30d73e8 100644 --- a/man/ex_data.Rd +++ b/man/ex_data.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/utils.R +% Please edit documentation in R/pins.R \name{ex_data} \alias{ex_data} \title{Example data set} diff --git a/man/get_pin.Rd b/man/get_pin.Rd new file mode 100644 index 0000000..b4948bc --- /dev/null +++ b/man/get_pin.Rd @@ -0,0 +1,20 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/pins.R +\name{get_pin} +\alias{get_pin} +\title{Get a pinned dataset from a \link[pins:pins-package]{pins} board} +\usage{ +get_pin(pin, ...) +} +\arguments{ +\item{pin}{\verb{} string name of pinned dataset} + +\item{...}{additional arguments passed to \code{mount_board()}} +} +\value{ +\verb{} or \verb{} +} +\description{ +Get a pinned dataset from a \link[pins:pins-package]{pins} board +} +\keyword{internal} diff --git a/man/icd10cm.Rd b/man/icd10cm.Rd index 9376fc3..e5aa6dc 100644 --- a/man/icd10cm.Rd +++ b/man/icd10cm.Rd @@ -4,12 +4,10 @@ \alias{icd10cm} \title{ICD-10-CM Codes} \usage{ -icd10cm(icd = NULL, ...) +icd10cm(icd = NULL) } \arguments{ \item{icd}{\verb{} vector of ICD-10-CM codes} - -\item{...}{Empty dots} } \value{ a \link[tibble:tibble-package]{tibble} @@ -20,7 +18,8 @@ Clinical Modification) is a medical coding system for classifying diagnoses and reasons for visits in U.S. health care settings. } \examples{ -icd10cm( c("F50.8", "G40.311", "Q96.8", "Z62.890", "R45.4", "E06.3", -"H00.019", "D50.1", "C4A.70") ) +icd10cm(c("F50.8", "G40.311", "Q96.8", + "Z62.890", "R45.4", "E06.3", + "H00.019", "D50.1", "C4A.70")) } diff --git a/man/icd_code_to_chapter.Rd b/man/icd_code_to_chapter.Rd new file mode 100644 index 0000000..640294f --- /dev/null +++ b/man/icd_code_to_chapter.Rd @@ -0,0 +1,28 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/utils.R +\name{icd_code_to_chapter} +\alias{icd_code_to_chapter} +\title{Match ICD-10-CM Codes to Chapter Labels} +\usage{ +icd_code_to_chapter(x) +} +\arguments{ +\item{x}{\verb{} vector of ICD-10-CM codes} +} +\value{ +\verb{} vector of ICD-10-CM chapter labels +} +\description{ +Match ICD-10-CM Codes to Chapter Labels +} +\examples{ +codes <- c("F50.8", "G40.311", "Q96.8", + "R45.4", "E06.3", "H00.019", + "D50.1", "C4A.70", "Z20.818") + +icd_code_to_chapter(codes) + +data.frame(code = codes, + chapter = icd_code_to_chapter(codes)) + +} diff --git a/man/insert_period.Rd b/man/insert_period.Rd new file mode 100644 index 0000000..09ed25b --- /dev/null +++ b/man/insert_period.Rd @@ -0,0 +1,25 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/utils.R +\name{insert_period} +\alias{insert_period} +\title{Insert period into an ICD-10-CM code} +\usage{ +insert_period(x) +} +\arguments{ +\item{x}{vector of ICD-10-CM codes} +} +\value{ +vector of ICD-10-CM codes with period inserted +} +\description{ +Inserts period into an ICD-10-CM code in between the 3rd and 4th +characters, if not present or if the code is longer than 3 characters +} +\examples{ +insert_period("F320") + +# Not inserted if code is only 3 characters +insert_period("F32") + +} diff --git a/man/list_pins.Rd b/man/list_pins.Rd new file mode 100644 index 0000000..b11d7e6 --- /dev/null +++ b/man/list_pins.Rd @@ -0,0 +1,18 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/pins.R +\name{list_pins} +\alias{list_pins} +\title{List pins from a \link[pins:pins-package]{pins} board} +\usage{ +list_pins(...) +} +\arguments{ +\item{...}{arguments to pass to \code{\link[=mount_board]{mount_board()}}} +} +\value{ +\verb{} of \link[pins:pins-package]{pins} +} +\description{ +List pins from a \link[pins:pins-package]{pins} board +} +\keyword{internal} diff --git a/man/mount_board.Rd b/man/mount_board.Rd index 73402e9..afa9151 100644 --- a/man/mount_board.Rd +++ b/man/mount_board.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/utils.R +% Please edit documentation in R/pins.R \name{mount_board} \alias{mount_board} \title{Mount \link[pins:pins-package]{pins} board} @@ -7,11 +7,10 @@ mount_board(source = c("local", "remote")) } \arguments{ -\item{source}{\verb{} string; whether source is \code{"local"} or \code{"remote"}} +\item{source}{\verb{} \code{"local"} or \code{"remote"}} } \value{ -\verb{} if \code{source = "local"} or \verb{} -if \code{source = "remote"} +\verb{} or \verb{} } \description{ Mount \link[pins:pins-package]{pins} board diff --git a/man/msdrg_index.Rd b/man/msdrg_index.Rd new file mode 100644 index 0000000..972f9eb --- /dev/null +++ b/man/msdrg_index.Rd @@ -0,0 +1,34 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/appendices.R +\name{msdrg_index} +\alias{msdrg_index} +\title{ICD-10-CM|MDC|MS-DRG Index} +\usage{ +msdrg_index(icd = NULL, drg = NULL, mdc = NULL) +} +\arguments{ +\item{icd}{\verb{} ICD-10-CM code} + +\item{drg}{\verb{} vector of 3-digit Diagnosis-Related Group codes} + +\item{mdc}{\verb{} vector of 2-digit Major Diagnostic Category codes} +} +\value{ +a \link[tibble:tibble-package]{tibble} +} +\description{ +\strong{Appendix B}: ICD-10-CM|MDC|MS-DRG Index +} +\details{ +The Diagnosis Code/MDC/MS-DRG Index lists each ICD-10-CM code, +the MDC and the MS-DRGs to which the diagnosis is used to define +the logic of the MS-DRG either as a principal or secondary diagnosis. +} +\examples{ +msdrg_index(icd = "A17.81") + +msdrg_index(drg = "011") + +msdrg_index(mdc = "24") + +} diff --git a/man/msdrg_list.Rd b/man/msdrg_list.Rd new file mode 100644 index 0000000..8870cdf --- /dev/null +++ b/man/msdrg_list.Rd @@ -0,0 +1,38 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/appendices.R +\name{msdrg_list} +\alias{msdrg_list} +\title{MS-DRG List} +\usage{ +msdrg_list(drg = NULL, mdc = NULL, type = NULL) +} +\arguments{ +\item{drg}{\verb{} vector of 3-digit Diagnosis-Related Group codes} + +\item{mdc}{\verb{} vector of 2-digit Major Diagnostic Category codes} + +\item{type}{\verb{} \code{"M"} (Medical) or \code{"P"} (Surgical)} +} +\value{ +a \link[tibble:tibble-package]{tibble} +} +\description{ +\strong{Appendix A}: Contains each MS-DRG with a specification of +the MDC and whether the MS-DRG is Medical or Surgical. +} +\details{ +Some MS-DRGs which contain patients from multiple MDCs +e.g., \code{"014"} (Allogeneic Bone Marrow Transplant) do not +have an MDC specified. + +The letter M is used to designate a medical MS-DRG and the +letter P is used to designate a surgical MS-DRG. +} +\examples{ +msdrg_list(drg = "014") + +msdrg_list(mdc = "24") + +msdrg_list(type = "M") + +} diff --git a/man/appendix_C.Rd b/man/msdrg_pdx.Rd similarity index 85% rename from man/appendix_C.Rd rename to man/msdrg_pdx.Rd index bbae14b..8b9de58 100644 --- a/man/appendix_C.Rd +++ b/man/msdrg_pdx.Rd @@ -1,10 +1,10 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/appendices.R -\name{appendix_C} -\alias{appendix_C} +\name{msdrg_pdx} +\alias{msdrg_pdx} \title{Appendix C: Complications or Comorbidities Exclusion list} \usage{ -appendix_C(icd = NULL, pdx = NULL, unnest = FALSE, ...) +msdrg_pdx(icd = NULL, pdx = NULL, unnest = FALSE) } \arguments{ \item{icd}{\verb{} vector of ICD-10-CM codes} @@ -12,9 +12,7 @@ appendix_C(icd = NULL, pdx = NULL, unnest = FALSE, ...) \item{pdx}{\verb{} 4-digit Principal Diagnosis (PDX) Group number, e.g., \code{0011} (~ 2,040 in total)} -\item{unnest}{\verb{} Unnest the \code{pdx_icd} column} - -\item{...}{Empty dots} +\item{unnest}{\verb{} Unnest the \code{pdx_icd} column; default is \code{FALSE}} } \value{ a \link[tibble:tibble-package]{tibble} @@ -39,8 +37,8 @@ diagnosis and grouped to one of the listed DRGs the diagnosis is excluded from acting as a CC/MCC for severity in DRG assignment. } \examples{ -appendix_C(icd = "A17.81") +msdrg_pdx(icd = "A17.81") -appendix_C(pdx = "0032") +msdrg_pdx(pdx = "0032") } diff --git a/man/pathologie-package.Rd b/man/pathologie-package.Rd index 85eafdd..f13c634 100644 --- a/man/pathologie-package.Rd +++ b/man/pathologie-package.Rd @@ -4,9 +4,9 @@ \name{pathologie-package} \alias{pathologie} \alias{pathologie-package} -\title{pathologie: Tidy ICD-10-CM Tools} +\title{pathologie: Tidy ICD-10-CM Interface} \description{ -Tools for working with ICD-10-CM codes. +Tidy tools for accessing and working with ICD-10-CM. } \seealso{ Useful links: @@ -18,7 +18,7 @@ Useful links: } \author{ -\strong{Maintainer}: Andrew Bruce \email{andrewallenbruce@gmail.com} [copyright holder] +\strong{Maintainer}: Andrew Allen Bruce \email{andrewallenbruce@gmail.com} [copyright holder] } \keyword{internal} diff --git a/man/remove_dot.Rd b/man/remove_dot.Rd deleted file mode 100644 index b360ae2..0000000 --- a/man/remove_dot.Rd +++ /dev/null @@ -1,23 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/utils-icd.R -\name{remove_dot} -\alias{remove_dot} -\title{Remove dot from an ICD-10 code} -\usage{ -remove_dot(x) -} -\arguments{ -\item{x}{A valid ICD-10 code with a dot} -} -\value{ -A valid ICD-10 code without a dot included -} -\description{ -\code{remove_dot()} removes a dot from the ICD-10 code if it exists -} -\examples{ -remove_dot("F32.0") - -remove_dot("F32") -} -\keyword{internal} diff --git a/man/remove_period.Rd b/man/remove_period.Rd new file mode 100644 index 0000000..811bcd7 --- /dev/null +++ b/man/remove_period.Rd @@ -0,0 +1,23 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/utils.R +\name{remove_period} +\alias{remove_period} +\title{Remove period from ICD-10-CM code} +\usage{ +remove_period(x) +} +\arguments{ +\item{x}{A valid ICD-10 code with a dot} +} +\value{ +A valid ICD-10 code without a dot included +} +\description{ +Removes period from the ICD-10 code if it exists +} +\examples{ +remove_period("F32.0") + +remove_period("F32") + +} diff --git a/man/search_edits.Rd b/man/search_edits.Rd index e0cf76f..e117b96 100644 --- a/man/search_edits.Rd +++ b/man/search_edits.Rd @@ -4,12 +4,10 @@ \alias{search_edits} \title{ICD-10-CM Code Edits} \usage{ -search_edits(icd = NULL, ...) +search_edits(icd = NULL) } \arguments{ \item{icd}{\verb{} vector of ICD-10-CM codes} - -\item{...}{Empty dots} } \value{ a \link[tibble:tibble-package]{tibble} diff --git a/man/search_msdrg.Rd b/man/search_msdrg.Rd index 466022d..cb87947 100644 --- a/man/search_msdrg.Rd +++ b/man/search_msdrg.Rd @@ -1,10 +1,10 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/msdrg.R +% Please edit documentation in R/appendices.R \name{search_msdrg} \alias{search_msdrg} \title{Medicare Severity Diagnosis-Related Groups} \usage{ -search_msdrg(drg = NULL, mdc = NULL, type = NULL, ...) +search_msdrg(drg = NULL, mdc = NULL, type = NULL) } \arguments{ \item{drg}{\verb{} vector of 3-digit DRG codes} @@ -12,8 +12,6 @@ search_msdrg(drg = NULL, mdc = NULL, type = NULL, ...) \item{mdc}{\verb{} vector of 2-digit Major Diagnostic Category codes} \item{type}{\verb{} DRG type: \code{Medical} or \code{Surgical}} - -\item{...}{Empty dots} } \value{ a \link[tibble:tibble-package]{tibble} @@ -41,4 +39,5 @@ receive less reimbursement. search_msdrg(drg = "011") search_msdrg(mdc = "24") + }