diff --git a/R/order_refer.R b/R/order_refer.R index edd5b107..08a450c8 100644 --- a/R/order_refer.R +++ b/R/order_refer.R @@ -31,34 +31,46 @@ #' #' *Update Frequency:* **Twice Weekly** #' -#' @param npi < *integer* > 10-digit national provider identifier -#' @param first,last < *character* > Individual provider's first/last name -#' @param partb,dme,hha,pmd < *boolean* > Whether a provider is eligible to +#' @template args-npi +#' +#' @param first,last `` Individual provider's first/last name +#' +#' @param partb,dme,hha,pmd,hos `` Whether a provider is eligible to #' order and refer to: #' + `partb`: Medicare Part B #' + `dme`: Durable Medical Equipment #' + `hha`: Home Health Agency #' + `pmd`: Power Mobility Devices -#' @param tidy < *boolean* > // __default:__ `TRUE` Tidy output -#' @param pivot < *boolean* > // __default:__ `TRUE` Pivot output -#' @param ... Empty +#' + `hos`: Hospice +#' +#' @template args-tidy #' -#' @return A [tibble][tibble::tibble-package] with the columns: +#' @template args-pivot #' -#' |**Field** |**Description** | -#' |:----------|:-------------------------------------------------| -#' |`npi` |National Provider Identifier | -#' |`first` |Order and Referring Provider's First Name | -#' |`last` |Order and Referring Provider's Last Name | -#' |`service` |Services An Eligible Provider Can Order/Refer To | +#' @template args-dots #' -#' @examplesIf interactive() +#' @returns A [tibble][tibble::tibble-package] with the columns: +#' +#' |**Field** |**Description** | +#' |:-----------|:-------------------------------------------------| +#' |`npi` |National Provider Identifier | +#' |`first` |Order and Referring Provider's First Name | +#' |`last` |Order and Referring Provider's Last Name | +#' |`eligible` |Services An Eligible Provider Can Order/Refer To | +#' +#' @examples #' order_refer(npi = 1003026055) #' #' # Filter for certain privileges -#' order_refer(last = "Smith", partb = FALSE, hha = TRUE) +#' order_refer(first = "Jennifer", +#' last = "Smith", +#' partb = TRUE, +#' hos = FALSE, +#' hha = FALSE, +#' pmd = FALSE) #' #' @autoglobal +#' #' @export order_refer <- function(npi = NULL, first = NULL, @@ -67,6 +79,7 @@ order_refer <- function(npi = NULL, dme = NULL, hha = NULL, pmd = NULL, + hos = NULL, tidy = TRUE, pivot = TRUE, ...) { @@ -76,6 +89,7 @@ order_refer <- function(npi = NULL, dme <- dme %nn% tf_2_yn(dme) hha <- hha %nn% tf_2_yn(hha) pmd <- pmd %nn% tf_2_yn(pmd) + hos <- hos %nn% tf_2_yn(hos) args <- dplyr::tribble( ~param, ~arg, @@ -85,7 +99,9 @@ order_refer <- function(npi = NULL, "PARTB", partb, "DME", dme, "HHA", hha, - "PMD", pmd) + "PMD", pmd, + "HOSPICE", hos + ) response <- httr2::request(build_url("ord", args)) |> httr2::req_perform() @@ -100,7 +116,8 @@ order_refer <- function(npi = NULL, "partb", partb, "dme", dme, "hha", hha, - "pmd", pmd) |> + "pmd", pmd, + "hos", hos) |> tidyr::unnest(cols = c(y)) format_cli(cli_args) @@ -108,26 +125,44 @@ order_refer <- function(npi = NULL, } - results <- httr2::resp_body_json(response, simplifyVector = TRUE) + results <- httr2::resp_body_json( + response, + simplifyVector = TRUE + ) if (tidy) { - results <- tidyup(results, yn = c("partb", "hha", "dme", "pmd")) + results <- tidyup( + results, + yn = c( + "partb", + "hha", + "dme", + "pmd", + "hos" + ) + ) if (pivot) { results <- cols_ord(results) |> - tidyr::pivot_longer(cols = !c(npi, first, last), - names_to = "eligible", - values_to = "status") |> + tidyr::pivot_longer( + cols = !c(npi, first, last), + names_to = "eligible", + values_to = "status" + ) |> dplyr::filter(status == TRUE) |> - dplyr::mutate(status = NULL, + dplyr::mutate(status = NULL, eligible = fct_ord(eligible)) } } return(results) } -#' @param df data frame +#' @param df `` +#' +#' @template returns +#' #' @autoglobal +#' #' @noRd cols_ord <- function(df) { @@ -137,17 +172,26 @@ cols_ord <- function(df) { "Medicare Part B" = 'partb', "Home Health Agency" = 'hha', "Durable Medical Equipment" = 'dme', - "Power Mobility Devices" = 'pmd') + "Power Mobility Devices" = 'pmd', + "Hospice" = 'hospice') df |> dplyr::select(dplyr::any_of(cols)) } +#' @param x `` vector +#' #' @autoglobal +#' #' @noRd fct_ord <- function(x) { - factor(x, - levels = c("Medicare Part B", - "Home Health Agency", - "Durable Medical Equipment", - "Power Mobility Devices")) + factor( + x, + levels = c( + "Medicare Part B", + "Home Health Agency", + "Durable Medical Equipment", + "Power Mobility Devices", + "Hospice" + ) + ) } diff --git a/R/quality_payment.R b/R/quality_payment.R index 9b7aea1c..e322c8f5 100644 --- a/R/quality_payment.R +++ b/R/quality_payment.R @@ -238,8 +238,9 @@ quality_payment_ <- function(year = qpp_years(), ...) { .options = furrr::furrr_options(seed = NULL)) } -#' @noRd #' @autoglobal +#' +#' @noRd cols_qcomb <- function(df) { cols <- c('year', @@ -313,6 +314,7 @@ cols_qcomb <- function(df) { } #' @autoglobal +#' #' @noRd cols_qpp <- function(df, step = c("tidy", "nest")) { diff --git a/man-roxygen/args-pivot.R b/man-roxygen/args-pivot.R new file mode 100644 index 00000000..233a7739 --- /dev/null +++ b/man-roxygen/args-pivot.R @@ -0,0 +1 @@ +#' @param pivot `` Pivot output; __default__ is `TRUE` diff --git a/man/order_refer.Rd b/man/order_refer.Rd index 56140df6..d57ba2aa 100644 --- a/man/order_refer.Rd +++ b/man/order_refer.Rd @@ -12,30 +12,33 @@ order_refer( dme = NULL, hha = NULL, pmd = NULL, + hos = NULL, tidy = TRUE, pivot = TRUE, ... ) } \arguments{ -\item{npi}{< \emph{integer} > 10-digit national provider identifier} +\item{npi}{\verb{} Unique 10-digit National Provider Identifier number issued +by CMS to US healthcare providers through NPPES.} -\item{first, last}{< \emph{character} > Individual provider's first/last name} +\item{first, last}{\verb{} Individual provider's first/last name} -\item{partb, dme, hha, pmd}{< \emph{boolean} > Whether a provider is eligible to +\item{partb, dme, hha, pmd, hos}{\verb{} Whether a provider is eligible to order and refer to: \itemize{ \item \code{partb}: Medicare Part B \item \code{dme}: Durable Medical Equipment \item \code{hha}: Home Health Agency \item \code{pmd}: Power Mobility Devices +\item \code{hos}: Hospice }} -\item{tidy}{< \emph{boolean} > // \strong{default:} \code{TRUE} Tidy output} +\item{tidy}{\verb{} Tidy output; \strong{default} is \code{TRUE}} -\item{pivot}{< \emph{boolean} > // \strong{default:} \code{TRUE} Pivot output} +\item{pivot}{\verb{} Pivot output; \strong{default} is \code{TRUE}} -\item{...}{Empty} +\item{...}{Empty dots} } \value{ A \link[tibble:tibble-package]{tibble} with the columns:\tabular{ll}{ @@ -43,7 +46,7 @@ A \link[tibble:tibble-package]{tibble} with the columns:\tabular{ll}{ \code{npi} \tab National Provider Identifier \cr \code{first} \tab Order and Referring Provider's First Name \cr \code{last} \tab Order and Referring Provider's Last Name \cr - \code{service} \tab Services An Eligible Provider Can Order/Refer To \cr + \code{eligible} \tab Services An Eligible Provider Can Order/Refer To \cr } } \description{ @@ -73,12 +76,16 @@ Medicare may reimburse on behalf of its beneficiaries. order and refer. They can also enroll solely to order and refer. } \examples{ -\dontshow{if (interactive()) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} order_refer(npi = 1003026055) # Filter for certain privileges -order_refer(last = "Smith", partb = FALSE, hha = TRUE) -\dontshow{\}) # examplesIf} +order_refer(first = "Jennifer", + last = "Smith", + partb = TRUE, + hos = FALSE, + hha = FALSE, + pmd = FALSE) + } \references{ links: diff --git a/tests/testthat/test-cols.R b/tests/testthat/test-cols.R index 45e79ca0..3575c527 100644 --- a/tests/testthat/test-cols.R +++ b/tests/testthat/test-cols.R @@ -244,7 +244,8 @@ test_that("cols_ord() works", { partb = 1, hha = 1, dme = 1, - pmd = 1) + pmd = 1, + hospice = 1) y <- dplyr::tibble( npi = 1, @@ -253,7 +254,8 @@ test_that("cols_ord() works", { `Medicare Part B` = 1, `Home Health Agency` = 1, `Durable Medical Equipment` = 1, - `Power Mobility Devices` = 1) + `Power Mobility Devices` = 1, + `Hospice` = 1) expect_equal(cols_ord(x), y) }) diff --git a/tests/testthat/test-fct.R b/tests/testthat/test-fct.R index 31fb4365..f950e24e 100644 --- a/tests/testthat/test-fct.R +++ b/tests/testthat/test-fct.R @@ -276,3 +276,13 @@ test_that("fct_record() works", { expect_equal(fct_record(x), factor(c("Employment", "Reassignment"))) }) +test_that("fct_ord() works", { + x <- c( + "Medicare Part B", + "Home Health Agency", + "Durable Medical Equipment", + "Power Mobility Devices", + "Hospice" + ) + expect_equal(fct_ord(x), factor(x, levels = x)) +}) diff --git a/vignettes/articles/linking-providers.Rmd b/vignettes/articles/linking-providers.Rmd index 807ed2ba..9ef1c6fb 100644 --- a/vignettes/articles/linking-providers.Rmd +++ b/vignettes/articles/linking-providers.Rmd @@ -35,7 +35,7 @@ library(gt) ## Individual Provider -```{r} +```{r echo=FALSE, eval=FALSE} library(chainr) mark <- chain( @@ -45,7 +45,9 @@ mark <- chain( nppes = nppes(npi = 1043245657), referrals = order_refer(npi = 1043245657), affiliations = affiliations(pac = 7810891009), - hospitals = affiliations(pac = 7810891009) |> pull(facility_ccn) |> map_dfr(~hospitals(facility_ccn = .x)), + hospitals = affiliations(pac = 7810891009) |> + pull(facility_ccn) |> + map_dfr(~hospitals(facility_ccn = .x)), utilization = utilization_(npi = 1043245657, type = "Provider")) mark @@ -68,7 +70,7 @@ vctrs::vec_rbind( heading.background.color = "black", heading.align = "left", stub_row_group.font.weight = "bold") |> - tab_header(title = md("**PROVIDER**: Mark, K. Fung, M.D.")) |> + tab_header(title = md("**PROVIDER**: Mark K. Fung, M.D.")) |> opt_horizontal_padding(scale = 2) |> opt_all_caps() ``` diff --git a/vignettes/articles/partb-stats.Rmd b/vignettes/articles/partb-stats.Rmd index 39438aa4..c4c23047 100644 --- a/vignettes/articles/partb-stats.Rmd +++ b/vignettes/articles/partb-stats.Rmd @@ -65,7 +65,7 @@ performance ``` -```{r} +```{r echo=FALSE, eval=FALSE} performance |> pivot_longer(!year, names_to = "measure",