diff --git a/NAMESPACE b/NAMESPACE index 63f2897..15fd030 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -4,6 +4,7 @@ export(add_dot) export(appendix_A) export(appendix_B) export(appendix_C) +export(appendix_D) export(apply_age_edits) export(case_chapter_icd10) export(ex_data) diff --git a/R/appendices.R b/R/appendices.R index 01d9513..4f21d02 100644 --- a/R/appendices.R +++ b/R/appendices.R @@ -65,8 +65,8 @@ appendix_B <- function() { #' complication or comorbidity (CC) or a major complication or comorbidity (MCC) #' when used as a secondary diagnosis. #' -#' Part 1 lists these codes. Each code is indicated as CC or MCC. A link is given -#' to a collection of diagnosis codes which, when used as the principal +#' Part 1 lists these codes. Each code is indicated as CC or MCC. A link is +#' given to a collection of diagnosis codes which, when used as the principal #' diagnosis, will cause the CC or MCC to be considered as only a non-CC. #' #' Part 2 lists codes which are assigned as a Major CC only for patients @@ -75,12 +75,15 @@ appendix_B <- function() { #' Part 3 lists diagnosis codes that are designated as a complication or #' comorbidity (CC) or major complication or comorbidity (MCC) and included in #' the definition of the logic for the listed DRGs. When reported as a secondary -#' diagnosis and grouped to one of the listed DRGs the diagnosis is excluded from -#' acting as a CC/MCC for severity in DRG assignment. +#' diagnosis and grouped to one of the listed DRGs the diagnosis is excluded +#' from acting as a CC/MCC for severity in DRG assignment. #' #' @template args-icd_code #' -#' @param pdx `` 4-digit Principal Diagnosis (PDX) Group number +#' @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 #' @@ -96,6 +99,7 @@ appendix_B <- function() { #' @export appendix_C <- function(icd = NULL, pdx = NULL, + unnest = FALSE, ...) { mcc <- pins::pin_read(mount_board(), "msdrg_ccmcc_41.1") @@ -106,3 +110,53 @@ appendix_C <- function(icd = NULL, return(mcc) } + + +#' Appendix D MS-DRG Surgical Hierarchy by MDC and MS-DRG + +#' Since patients can have multiple procedures related to their principal +#' diagnosis during a particular hospital stay, and a patient can be assigned to +#' only one surgical class, the surgical classes in each MDC are defined in a +#' hierarchical order. +#' +#' Patients with multiple procedures are assigned to the highest surgical class +#' in the hierarchy to which one of the procedures is assigned. Thus, if a +#' patient receives both a D&C and a hysterectomy, the patient is assigned to the +#' hysterectomy surgical class because a hysterectomy is higher in the hierarchy +#' than a D&C. Because of the surgical hierarchy, ordering of the surgical +#' procedures on the patient abstract or claim has no influence on the assignment +#' of the surgical class and the MS-DRG. The surgical hierarchy for each MDC +#' reflects the relative resource requirements of various surgical procedures. +#' +#' In some cases a surgical class in the hierarchy is actually an MS-DRG. For +#' example, Arthroscopy is both a surgical class in the hierarchy and MS-DRG 509 +#' in MDC 8, Diseases and Disorders of the Musculoskeletal System and Connective +#' Tissue. +#' +#' In other cases the surgical class in the hierarchy is further partitioned +#' based on other variables such as complications and comorbidities, or principal +#' diagnosis to form multiple MS-DRGs. As an example, in MDC 5, Diseases and +#' Disorders of the Circulatory System, the surgical class for permanent +#' pacemaker implantation is divided into three MS-DRGs (242-244) based on +#' whether or not the patient had no CCs, a CC or an MCC. +#' +#' Appendix D presents the surgical hierarchy for each MDC. Appendix D is +#' organized by MDC with a list of the surgical classes associated with that MDC +#' listed in hierarchical order as well as the MS-DRGs that are included in each +#' surgical class. +#' +#' The names given to the surgical classes in the hierarchy correspond to the +#' names used in the MS-DRG logic tables and in the body of the Definitions +#' Manual. +#' +#' @template returns +#' +#' @examples +#' head(appendix_D()) +#' +#' @autoglobal +#' +#' @export +appendix_D <- function() { + pins::pin_read(mount_board(), "msdrg_drg_groups_41.1") +} diff --git a/data-raw/appendixD.R b/data-raw/appendixD.R index 69b0dbd..4b5e925 100644 --- a/data-raw/appendixD.R +++ b/data-raw/appendixD.R @@ -35,15 +35,97 @@ # names used in the MS-DRG logic tables and in the body of the Definitions # Manual. +library(tidyverse) + path_d <- "C:/Users/Andrew/Desktop/payer_guidelines/data/MSDRG/MSDRGv41.1ICD10_R0_DefinitionsManual_TEXT_0/appendix_D.txt" +dfile <- readr::read_table( + path_d, + skip = 27, + col_names = FALSE) |> + dplyr::mutate(row = dplyr::row_number(), .before = 1) |> + dplyr::slice(2:dplyr::n()) |> + tidyr::unite("drg_group_description", X2:X12, na.rm = TRUE, sep = " ") |> + dplyr::rename(drg_groups = X1) + + +drows <- dfile |> + dplyr::filter(drg_groups == "MDC") |> + dplyr::mutate(end = lead(row) - 1, + drg_groups = NULL) |> + dplyr::mutate(mdc_group = substr(drg_group_description, 1, 2), + mdc_group_description = substr(drg_group_description, 4, 100), + drg_group_description = NULL) + + + +dfinal <- dfile |> + dplyr::left_join(drows) |> + dplyr::mutate(end = NULL) |> + tidyr::fill(mdc_group, mdc_group_description) |> + tidyr::separate_longer_delim(cols = drg_groups, delim = "-") |> + dplyr::select( + mdc = mdc_group, + mdc_description = mdc_group_description, + drg_group = drg_groups, + drg_group_description = drg_group_description + ) |> + dplyr::filter(drg_group != "MDC") + + +# Update Pin +board <- pins::board_folder(here::here("inst/extdata/pins")) + +board |> pins::pin_write( + dfinal, + name = "msdrg_drg_groups_41.1", + title = "Appendix D MS-DRG Surgical Hierarchy by MDC and MS-DRG 41.1", + description = c( + "Appendix D presents the surgical hierarchy for each MDC. Appendix D is organized by MDC with a list of the surgical classes associated with that MDC listed in hierarchical order as well as the MS-DRGs that are included in each surgical class." + ), + type = "qs" +) + +board |> pins::write_board_manifest() + + +mdcs <- dplyr::tribble( + ~mdc, ~mdc_description, + "00", "Pre-MDC", + "01", "Diseases and disorders of the nervous system", + "02", "Diseases and disorders of the eye", + "03", "Diseases and disorders of the ear, nose, mouth, and throat", + "04", "Diseases and disorders of the respiratory system", + "05", "Diseases and disorders of the circulatory system", + "06", "Diseases and disorders of the digestive system", + "07", "Diseases and disorders of the hepatobiliary system and pancreas", + "08", "Diseases and disorders of the musculoskeletal system and connective tissue", + "09", "Diseases and disorders of the skin, subcutaneous tissue, and breast", + "10", "Endocrine, nutritional and metabolic diseases and disorders", + "11", "Diseases and disorders of the kidney and urinary tract", + "12", "Diseases and disorders of the male reproductive system", + "13", "Diseases and disorders of the female reproductive system", + "14", "Pregnancy, childbirth and the puerperium", + "15", "Newborns and other neonates with conditions originating in the perinatal period", + "16", "Diseases and disorders of blood, blood forming organs and immunological disorders", + "17", "Myeloproliferative diseases and disorders, poor blood cell formation", + "18", "Infectious and parasitic diseases", + "19", "Mental diseases and disorders", + "20", "Alcohol/drug use and alcohol/drug induced organic mental disorders", + "21", "Injuries, poisonings and toxic effects of drugs", + "22", "Burns", + "23", "Factors influencing health status and other contacts with health services", + "24", "Multiple significant trauma", + "25", "Human immunodeficiency virus infections", +) + readr::read_fwf( path_d, readr::fwf_cols( icd_code = c(1, 7), cc_mcc = c(9, 12), pdx_group = c(14, sum(14 + 5)), - icd_description = c(31, 500) + icd_description = c(31, 500), ) ) |> tidyr::separate_wider_delim( diff --git a/inst/extdata/pins/_pins.yaml b/inst/extdata/pins/_pins.yaml index dea9845..940050b 100644 --- a/inst/extdata/pins/_pins.yaml +++ b/inst/extdata/pins/_pins.yaml @@ -10,5 +10,7 @@ msdrg_41.1: - msdrg_41.1/20240405T103411Z-1ed8e/ msdrg_ccmcc_41.1: - msdrg_ccmcc_41.1/20240415T024824Z-61fa0/ +msdrg_drg_groups_41.1: +- msdrg_drg_groups_41.1/20240417T055023Z-5ae76/ msdrg_index_41.1: - msdrg_index_41.1/20240405T103150Z-3ca9d/ diff --git a/inst/extdata/pins/msdrg_drg_groups_41.1/20240417T055023Z-5ae76/data.txt b/inst/extdata/pins/msdrg_drg_groups_41.1/20240417T055023Z-5ae76/data.txt new file mode 100644 index 0000000..9bba55a --- /dev/null +++ b/inst/extdata/pins/msdrg_drg_groups_41.1/20240417T055023Z-5ae76/data.txt @@ -0,0 +1,13 @@ +file: msdrg_drg_groups_41.qs +file_size: 4153 +pin_hash: 5ae76dedd2b23d07 +type: qs +title: Appendix D MS-DRG Surgical Hierarchy by MDC and MS-DRG 41.1 +description: Appendix D presents the surgical hierarchy for each MDC. Appendix D is + organized by MDC with a list of the surgical classes associated with that MDC listed + in hierarchical order as well as the MS-DRGs that are included in each surgical + class. +tags: ~ +urls: ~ +created: 20240417T055023Z +api_version: 1 diff --git a/inst/extdata/pins/msdrg_drg_groups_41.1/20240417T055023Z-5ae76/msdrg_drg_groups_41.qs b/inst/extdata/pins/msdrg_drg_groups_41.1/20240417T055023Z-5ae76/msdrg_drg_groups_41.qs new file mode 100644 index 0000000..b8eb296 Binary files /dev/null and b/inst/extdata/pins/msdrg_drg_groups_41.1/20240417T055023Z-5ae76/msdrg_drg_groups_41.qs differ diff --git a/man/appendix_C.Rd b/man/appendix_C.Rd index b24a50b..bbae14b 100644 --- a/man/appendix_C.Rd +++ b/man/appendix_C.Rd @@ -4,12 +4,15 @@ \alias{appendix_C} \title{Appendix C: Complications or Comorbidities Exclusion list} \usage{ -appendix_C(icd = NULL, pdx = NULL, ...) +appendix_C(icd = NULL, pdx = NULL, unnest = FALSE, ...) } \arguments{ \item{icd}{\verb{} vector of ICD-10-CM codes} -\item{pdx}{\verb{} 4-digit Principal Diagnosis (PDX) Group number} +\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} } @@ -22,8 +25,8 @@ complication or comorbidity (CC) or a major complication or comorbidity (MCC) when used as a secondary diagnosis. } \details{ -Part 1 lists these codes. Each code is indicated as CC or MCC. A link is given -to a collection of diagnosis codes which, when used as the principal +Part 1 lists these codes. Each code is indicated as CC or MCC. A link is +given to a collection of diagnosis codes which, when used as the principal diagnosis, will cause the CC or MCC to be considered as only a non-CC. Part 2 lists codes which are assigned as a Major CC only for patients @@ -32,8 +35,8 @@ discharged alive. Otherwise they are assigned as a non-CC. Part 3 lists diagnosis codes that are designated as a complication or comorbidity (CC) or major complication or comorbidity (MCC) and included in the definition of the logic for the listed DRGs. When reported as a secondary -diagnosis and grouped to one of the listed DRGs the diagnosis is excluded from -acting as a CC/MCC for severity in DRG assignment. +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") diff --git a/man/appendix_D.Rd b/man/appendix_D.Rd new file mode 100644 index 0000000..702b545 --- /dev/null +++ b/man/appendix_D.Rd @@ -0,0 +1,51 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/appendices.R +\name{appendix_D} +\alias{appendix_D} +\title{Appendix D MS-DRG Surgical Hierarchy by MDC and MS-DRG +Since patients can have multiple procedures related to their principal +diagnosis during a particular hospital stay, and a patient can be assigned to +only one surgical class, the surgical classes in each MDC are defined in a +hierarchical order.} +\usage{ +appendix_D() +} +\value{ +a \link[tibble:tibble-package]{tibble} +} +\description{ +Patients with multiple procedures are assigned to the highest surgical class +in the hierarchy to which one of the procedures is assigned. Thus, if a +patient receives both a D&C and a hysterectomy, the patient is assigned to the +hysterectomy surgical class because a hysterectomy is higher in the hierarchy +than a D&C. Because of the surgical hierarchy, ordering of the surgical +procedures on the patient abstract or claim has no influence on the assignment +of the surgical class and the MS-DRG. The surgical hierarchy for each MDC +reflects the relative resource requirements of various surgical procedures. +} +\details{ +In some cases a surgical class in the hierarchy is actually an MS-DRG. For +example, Arthroscopy is both a surgical class in the hierarchy and MS-DRG 509 +in MDC 8, Diseases and Disorders of the Musculoskeletal System and Connective +Tissue. + +In other cases the surgical class in the hierarchy is further partitioned +based on other variables such as complications and comorbidities, or principal +diagnosis to form multiple MS-DRGs. As an example, in MDC 5, Diseases and +Disorders of the Circulatory System, the surgical class for permanent +pacemaker implantation is divided into three MS-DRGs (242-244) based on +whether or not the patient had no CCs, a CC or an MCC. + +Appendix D presents the surgical hierarchy for each MDC. Appendix D is +organized by MDC with a list of the surgical classes associated with that MDC +listed in hierarchical order as well as the MS-DRGs that are included in each +surgical class. + +The names given to the surgical classes in the hierarchy correspond to the +names used in the MS-DRG logic tables and in the body of the Definitions +Manual. +} +\examples{ +head(appendix_D()) + +}