Skip to content

Commit

Permalink
maintenance
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewallenbruce committed Mar 21, 2024
1 parent e9d7954 commit 26a4a92
Show file tree
Hide file tree
Showing 11 changed files with 171 additions and 143 deletions.
83 changes: 83 additions & 0 deletions R/adjustment.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
#' Adjustment Codes
#'
#' Claim Adjustment Reason Codes (CARCs) and
#' Remittance Advice Remark Codes (RARCs)
#'
#' @section Claim Adjustment Reason Codes:
#'
#' _X12 External Code Source 139_
#'
#' These codes describe why a claim or service line was paid differently
#' than it was billed and generally assign responsibility for the
#' adjustment amounts. The format is always two alpha characters.
#'
#' The Claim Adjustment Group Codes (e.g., PR, OA) are internal to the X12 standard.
#'
#' @section Remittance Advice Remark Codes:
#'
#' _X12 External Code Source 411_
#'
#' These codes provide additional explanation for an adjustment already
#' described by a Claim Adjustment Reason Code (CARC) or convey information
#' about remittance processing.
#'
#' Remittance Advice Remark Codes (RARCs) are used to provide additional
#' explanation for an adjustment already described by a Claim Adjustment Reason
#' Code (CARC) or to convey information about remittance processing.
#'
#' There are two types of RARCs, supplemental and informational. The majority
#' of the RARCs are supplemental; these are generally referred to as RARCs
#' without further distinction.
#'
#' Supplemental RARCs provide additional explanation for an adjustment already
#' described by a CARC.
#'
#' The second type of RARC is informational; these RARCs are all prefaced
#' with `Alert:` and are often referred to as Alerts.
#'
#' Alerts are used to convey information about remittance processing and are
#' never related to a specific adjustment or CARC.
#' @param df data.frame
#' @param col column of Adjustment codes to match on
#' @param type type of Adjustment code; `all` (default), `carc`, `rarc`
#' @param ... description
#' @return a [dplyr::tibble()]
#' @examples
#' adjustment_codes()$group
#'
#' dplyr::tibble(code = c("CO-253", "OA-23", "PI-185")) |>
#' adjustment_codes(type = "carc", col = "code")
#' @export
#' @autoglobal
adjustment_codes <- function(df = NULL,
col = NULL,
type = c("all", "carc", "rarc"),
...) {

type <- match.arg(type)

adj <- pins::pin_read(mount_board(), "rarc_carc")

if (type == "all") {return(adj)}

if (type == "carc") {

adj$carc <- dplyr::select(adj$carc, -c(usage:end_date))

adj <- df |>
tidyr::separate_wider_delim({{ col }},
delim = "-",
names = c("group", "code"),
too_few = "align_start") |>
dplyr::left_join(adj$group, by = dplyr::join_by(group == code)) |>
dplyr::left_join(adj$carc, by = dplyr::join_by(code == code)) |>
tidyr::unite("adj_code", group, code, sep = "-", na.rm = TRUE) |>
dplyr::rename(group = description.x, description = description.y)
}

if (type == "rarc") {

adj$rarc <- dplyr::select(adj$rarc, -c(notes:last_modified))
}
return(adj)
}
124 changes: 2 additions & 122 deletions R/databases.R
Original file line number Diff line number Diff line change
Expand Up @@ -360,42 +360,6 @@ opps <- function(hcpcs = NULL,
return(op)
}

#' NCD Download Database
#'
#' Last Updated 2022-12-08
#'
#' @param coverage Coverage level; `"Full"`, `"Restricted"`, `"None"`, `"Unknown"`
#' @return a [tibble][tibble::tibble-package]
#' @examples
#' ncd(coverage = "Unknown")
#' @export
#' @autoglobal
ncd <- function(coverage = NULL) {

ncd <- pins::pin_read(mount_board(), "ncd")

if (!is.null(coverage)) {

coverage <- rlang::arg_match(coverage, c("Full", "Restricted", "None", "Unknown"))

ncd <- vctrs::vec_slice(ncd, ncd$coverage == coverage)
}
return(ncd)
}

#' LCD Download Database
#'
#' Last Updated 2023-04-27
#'
#' @return a [tibble][tibble::tibble-package]
#' @examplesIf interactive()
#' lcd()
#' @export
#' @autoglobal
lcd <- function() {
pins::pin_read(mount_board(), "lcd")
}

#' Medicare Severity Diagnosis-Related Groups (MS-DRG)
#'
#' The Medicare Severity Diagnosis-Related Group (MS-DRG) is a classification
Expand All @@ -420,7 +384,7 @@ lcd <- function() {
#' @param type description
#' @param ... description
#' @return A [tibble][tibble::tibble-package]
#' @examplesIf interactive()
#' @examples
#' msdrg()
#' @autoglobal
#' @export
Expand Down Expand Up @@ -455,7 +419,7 @@ msdrg <- function(drg = NULL,
#' @param ... description
#' @return a [dplyr::tibble()]
#' @examples
#' modifiers()
#' modifiers(mod = c("25", "59"))
#' @export
#' @autoglobal
modifiers <- function(mod = NULL, ...) {
Expand All @@ -469,87 +433,3 @@ modifiers <- function(mod = NULL, ...) {
}
return(md)
}

#' Adjustment Codes
#'
#' Claim Adjustment Reason Codes (CARCs) and
#' Remittance Advice Remark Codes (RARCs)
#'
#' @section Claim Adjustment Reason Codes:
#'
#' _X12 External Code Source 139_
#'
#' These codes describe why a claim or service line was paid differently
#' than it was billed and generally assign responsibility for the
#' adjustment amounts. The format is always two alpha characters.
#'
#' The Claim Adjustment Group Codes (e.g., PR, OA) are internal to the X12 standard.
#'
#' @section Remittance Advice Remark Codes:
#'
#' _X12 External Code Source 411_
#'
#' These codes provide additional explanation for an adjustment already
#' described by a Claim Adjustment Reason Code (CARC) or convey information
#' about remittance processing.
#'
#' Remittance Advice Remark Codes (RARCs) are used to provide additional
#' explanation for an adjustment already described by a Claim Adjustment Reason
#' Code (CARC) or to convey information about remittance processing.
#'
#' There are two types of RARCs, supplemental and informational. The majority
#' of the RARCs are supplemental; these are generally referred to as RARCs
#' without further distinction.
#'
#' Supplemental RARCs provide additional explanation for an adjustment already
#' described by a CARC.
#'
#' The second type of RARC is informational; these RARCs are all prefaced
#' with `Alert:` and are often referred to as Alerts.
#'
#' Alerts are used to convey information about remittance processing and are
#' never related to a specific adjustment or CARC.
#' @param df data.frame
#' @param col column of Adjustment codes
#' @param type type of Adjustment code; `"none"` (default), `"carc"`, `"rarc"`
#' @param ... description
#' @return a [dplyr::tibble()]
#' @examples
#' adjustment_codes()$group
#'
#' dplyr::tibble(code = c("CO-253", "OA-23", "PI-185")) |>
#' adjustment_codes(type = "carc", col = "code")
#' @export
#' @autoglobal
adjustment_codes <- function(df = NULL,
col = NULL,
type = c("none", "carc", "rarc"),
...) {

type <- match.arg(type)

adj <- pins::pin_read(mount_board(), "rarc_carc")

if (type == "none") {return(adj)}

if (type == "carc") {

adj$carc <- dplyr::select(adj$carc, -c(usage:end_date))

adj <- df |>
tidyr::separate_wider_delim({{ col }},
delim = "-",
names = c("group", "code"),
too_few = "align_start") |>
dplyr::left_join(adj$group, by = dplyr::join_by(group == code)) |>
dplyr::left_join(adj$carc, by = dplyr::join_by(code == code)) |>
tidyr::unite("adj_code", group, code, sep = "-", na.rm = TRUE) |>
dplyr::rename(group = description.x, description = description.y)
}

if (type == "rarc") {

adj$rarc <- dplyr::select(adj$rarc, -c(notes:last_modified))
}
return(adj)
}
4 changes: 2 additions & 2 deletions R/generated-globals.R
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ utils::globalVariables(c(
"fprvu",
# <adjustment_codes>
"group",
# <taxonomy>
"hierarchy",
# <level2>
"labcert",
# <col_lb>
Expand Down Expand Up @@ -76,8 +78,6 @@ utils::globalVariables(c(
"price",
# <opps>
"procstat",
# <taxonomy>
"results",
# <case_section>
"section",
# <level2>
Expand Down
46 changes: 46 additions & 0 deletions R/lcd_ncd.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#' NCD Download Database
#'
#' Last Updated 2022-12-08
#'
#' @param coverage Coverage level; `"Full"`, `"Restricted"`, `"None"`, `"Unknown"`
#' @return a [tibble][tibble::tibble-package]
#' @examples
#' ncd(coverage = "Unknown")
#' @export
#' @autoglobal
ncd <- function(coverage = NULL) {

ncd <- pins::pin_read(mount_board(), "ncd")

if (!is.null(coverage)) {

coverage <- rlang::arg_match(coverage, c("Full", "Restricted", "None", "Unknown"))

ncd <- vctrs::vec_slice(ncd, ncd$coverage == coverage)
}
return(ncd)
}

#' LCD Download Database
#'
#' Last Updated 2023-04-27
#'
#' @param hcpcs vector of HCPCS codes
#' @param ... Empty
#' @return a [tibble][tibble::tibble-package]
#' @examplesIf interactive()
#' lcd(hcpcs = "A4555", "E0766")
#' @export
#' @autoglobal
lcd <- function(hcpcs = NULL,
...) {

lcd <- pins::pin_read(mount_board(), "lcd")

if (!is.null(hcpcs)) {
lcd <- vctrs::vec_slice(lcd,
vctrs::vec_in(lcd$hcpc_code_id,
collapse::funique(hcpcs)))
}
return(lcd)
}
18 changes: 14 additions & 4 deletions R/taxonomy.R
Original file line number Diff line number Diff line change
Expand Up @@ -110,16 +110,23 @@
#'
#' @param shape shape of the data frame returned, 'wide' or 'long'
#' @param code vector of taxonomy codes to filter
#' @param unnest unnest the hierarchy column, default is `FALSE`
#' @param ... Empty
#'
#' @return A [tibble][tibble::tibble-package] with the columns:
#'
#' @examplesIf interactive()
#' taxonomy("wide")
#' taxonomy("wide", code = c("207K00000X", "193200000X"))
#'
#' taxonomy("long")
#' taxonomy("long", code = "207K00000X")
#'
#' taxonomy("long", code = "207K00000X", unnest = TRUE)
#' @autoglobal
#' @export
taxonomy <- function(shape = c('wide', 'long'), code = NULL) {
taxonomy <- function(shape = c('wide', 'long'),
code = NULL,
unnest = FALSE,
...) {

shape <- match.arg(shape)

Expand All @@ -137,5 +144,8 @@ taxonomy <- function(shape = c('wide', 'long'), code = NULL) {
collapse::funique(code)))
}

return(results)
if (shape == 'long' && unnest == TRUE) {
txn <- tidyr::unnest(txn, cols = c(hierarchy))
}
return(txn)
}
10 changes: 5 additions & 5 deletions man/adjustment_codes.Rd

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

11 changes: 8 additions & 3 deletions man/lcd.Rd

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

2 changes: 1 addition & 1 deletion man/modifiers.Rd

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

Loading

0 comments on commit 26a4a92

Please sign in to comment.