From 90b8bec8f75915732db62bf54c4284bd418177cc Mon Sep 17 00:00:00 2001 From: Andrew Bruce Date: Tue, 16 Apr 2024 22:55:28 -0700 Subject: [PATCH] added appendix D pin (#2) --- NAMESPACE | 1 + R/appendices.R | 64 +++++++++++-- data-raw/appendixD.R | 84 +++++++++++++++++- inst/extdata/pins/_pins.yaml | 2 + .../20240417T055023Z-5ae76/data.txt | 13 +++ .../msdrg_drg_groups_41.qs | Bin 0 -> 4153 bytes man/appendix_C.Rd | 15 ++-- man/appendix_D.Rd | 51 +++++++++++ 8 files changed, 218 insertions(+), 12 deletions(-) create mode 100644 inst/extdata/pins/msdrg_drg_groups_41.1/20240417T055023Z-5ae76/data.txt create mode 100644 inst/extdata/pins/msdrg_drg_groups_41.1/20240417T055023Z-5ae76/msdrg_drg_groups_41.qs create mode 100644 man/appendix_D.Rd 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 0000000000000000000000000000000000000000..b8eb296b067cdfde357707a6bf7d7458d49b5d56 GIT binary patch literal 4153 zcmV-95XSEd4hjqa000030S^EH000000000T5C8xuwJ-f(1aqB$0IIc6AVENBlRU<; z6~?M4ilV4(?kEcAZVWZL36yLTY+Gy776G?nlvaA34;_tB^!Bem8aj%QA|$~drnBJJ zNqnt>`MR;|0k8oC0?OG_E}8PkltZTcG3Bl)XH9u(%Ar#Jlyaw(H>I2@<*Ox6ExBaL zAxr*P^2U-gmRzyqi6xIKIb6xzO5RrTwUVcmoT=nWB~L1OOv$B64ps7(lDm|=rQ|Fn zUn#jt$)ifX2oQk2Pp%xOLhn~vCC}X1JQoaDX7lVjX_eGFsT#d?>b4Jtgr}7wKV{b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bVozGDXO0TuSiSbPuPoF6Eo z35L*RRfSjzsi43XyR0Nr?A3eVwD+hyboDJKB2xM< z+>{)Y3R!W|uT(7car4truq^m^^odZP2ra-z9!N)cM#5j6NC|(t?SbC0X>UCE={CKt zi2$RF#F2Vw)nln){X+ak&^sZ_m;a0whRI^U`SAjR1^E^7wpc=IK~TS_bsfKX|@s9!mN9^zaZK;p3! z_0-J5g?J@s^@gJu9io7`L=6o}+TK&AnIJ$ISsmbCL5gkbdGZMGg1ENY#j2XWDk&SU z;o9k3_{msYErb*8V%TPYX)rEhn>#I45rI)8obfYJuO7{$qGrzu1Y!aZ5rdcWMZ^+K zmup{c5E_sHjW>iD5?9e!(8ryak%K~h&~QakzS_a=A?vW_KB~^uWP?pk$KZMxxBXq!xQeg9&7C+`Tw_2><6=m2Gu?a&LyZV zpJ-fRP0|ShHJgIip?Y^)gJl7gB|6#--pID071xDv-#JU?HgYcZ}*a2Fv*ulHC_&5|g zaHzs&S%Vg__G|PYFR(PiI7H)!%fTxh=ChF39n5F} 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()) + +}