Skip to content

Commit

Permalink
added ms-drg pin, function
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewallenbruce committed Mar 31, 2024
1 parent 3508ae9 commit 9cce1ef
Show file tree
Hide file tree
Showing 7 changed files with 143 additions and 0 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ export(gt_style)
export(icd10api)
export(icd10cm)
export(is_valid_icd)
export(search_msdrg)
54 changes: 54 additions & 0 deletions R/msdrg.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#' 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 `<chr>` vector of 3-digit DRG codes
#' @param mdc `<chr>` vector of 2-digit Major Diagnostic Category codes
#' @param type `<chr>` DRG type: `Medical` or `Surgical`
#' @param ... Empty
#' @return A [tibble][tibble::tibble-package]
#' @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")

if (!is.null(type)) {
ms <- vctrs::vec_slice(ms, ms$drg_type == type)
}

if (!is.null(drg)) {
ms <- vctrs::vec_slice(ms,
vctrs::vec_in(ms$drg,
collapse::funique(drg)))
}

if (!is.null(mdc)) {
ms <- vctrs::vec_slice(ms,
vctrs::vec_in(ms$mdc,
collapse::funique(mdc)))
}
return(ms)
}
32 changes: 32 additions & 0 deletions data-raw/msdrg.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
library(rvest)

ms_drg_v36 <- read_html("https://www.hipaaspace.com/medical.coding.library/drgs/") |>
html_element(xpath = '//*[contains(concat( " ", @class, " " ), concat( " ", "table-striped", " " ))]') |>
html_table(na.strings = c("N/A", "N/S"), convert = FALSE)

ms_drg_v36 <- ms_drg_v36 |>
janitor::clean_names() |>
dplyr::select(-number) |>
dplyr::mutate(
mdc = dplyr::na_if(mdc, "N/A"),
mdc_description = dplyr::na_if(mdc_description, "N/S")) |>
tidyr::separate_wider_delim(drg_type, " ", names = c("drg_type", "drg_abbrev")) |>
dplyr::mutate(
drg_abbrev = stringr::str_remove(drg_abbrev, "\\("),
drg_abbrev = stringr::str_remove(drg_abbrev, "\\)"),
drg_abbrev = dplyr::na_if(drg_abbrev, "")
)

ms_drg_v36
ms_drg_v36 <- northstar::search_msdrg()
# Update Pin
board <- pins::board_folder(here::here("inst/extdata/pins"))

board |>
pins::pin_write(ms_drg_v36,
name = "msdrg",
title = "MS-DRG Version 36.0",
description = "Medicare Severity Diagnosis-Related Groups (MS-DRGs) Version 36.0",
type = "qs")

board |> pins::write_board_manifest()
2 changes: 2 additions & 0 deletions inst/extdata/pins/_pins.yaml
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
icd10cm:
- icd10cm/20240331T055428Z-905e8/
msdrg:
- msdrg/20240331T114524Z-c6366/
10 changes: 10 additions & 0 deletions inst/extdata/pins/msdrg/20240331T114524Z-c6366/data.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
file: msdrg.qs
file_size: 10851
pin_hash: c6366a293c28ff8a
type: qs
title: MS-DRG Version 36.0
description: Medicare Severity Diagnosis-Related Groups (MS-DRGs) Version 36.0
tags: ~
urls: ~
created: 20240331T114524Z
api_version: 1
Binary file not shown.
44 changes: 44 additions & 0 deletions man/search_msdrg.Rd

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

0 comments on commit 9cce1ef

Please sign in to comment.