Skip to content

Commit

Permalink
* Begin breaking changes
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewallenbruce committed Dec 9, 2024
1 parent 05e39de commit df122b6
Show file tree
Hide file tree
Showing 33 changed files with 642 additions and 372 deletions.
15 changes: 9 additions & 6 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -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", , "[email protected]", role = c("aut", "cre", "cph"))
person(c("Andrew", "Allen"), "Bruce", , "[email protected]", role = c("aut", "cre", "cph"))
Maintainer: Andrew Bruce <[email protected]>
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
Expand All @@ -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),
Expand All @@ -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
Expand Down
15 changes: 9 additions & 6 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -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)
155 changes: 102 additions & 53 deletions R/appendices.R
Original file line number Diff line number Diff line change
@@ -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 `<chr>` 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 `<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`
#'
#' @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 `<chr>` `"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 `<chr>` 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
Expand All @@ -83,32 +143,27 @@ appendix_B <- function() {
#' @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
#' @param unnest `<lgl>` 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)
}


Expand Down Expand Up @@ -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
#'
Expand All @@ -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
#'
Expand All @@ -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")
2 changes: 2 additions & 0 deletions R/roxyglobals-generated.R → R/generated-globals.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ utils::globalVariables(c(
"icd_description",
# <icd10cm>
"icd_sec_code",
# <msdrg_pdx>
"pdx_icd",
# <icd10api>
# <.multiple_request>
"V1",
Expand Down
Loading

0 comments on commit df122b6

Please sign in to comment.