Skip to content

Commit

Permalink
added appendix D pin (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewallenbruce committed Apr 17, 2024
1 parent c616fc5 commit 90b8bec
Show file tree
Hide file tree
Showing 8 changed files with 218 additions and 12 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
64 changes: 59 additions & 5 deletions R/appendices.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 `<chr>` 4-digit Principal Diagnosis (PDX) Group number
#' @param pdx `<chr>` 4-digit Principal Diagnosis (PDX) Group number, e.g.,
#' `0011` (~ 2,040 in total)
#'
#' @param unnest `<lgl>` Unnest the `pdx_icd` column
#'
#' @template args-dots
#'
Expand All @@ -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")
Expand All @@ -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")
}
84 changes: 83 additions & 1 deletion data-raw/appendixD.R
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 2 additions & 0 deletions inst/extdata/pins/_pins.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Original file line number Diff line number Diff line change
@@ -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
Binary file not shown.
15 changes: 9 additions & 6 deletions man/appendix_C.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

51 changes: 51 additions & 0 deletions man/appendix_D.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 90b8bec

Please sign in to comment.