Skip to content

Commit

Permalink
added hospice arg to order_refer to reflect api update
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewallenbruce committed Apr 19, 2024
1 parent f4a5b0a commit 4d69993
Show file tree
Hide file tree
Showing 8 changed files with 115 additions and 47 deletions.
104 changes: 74 additions & 30 deletions R/order_refer.R
Original file line number Diff line number Diff line change
Expand Up @@ -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 `<chr>` Individual provider's first/last name
#'
#' @param partb,dme,hha,pmd,hos `<lgl>` 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,
Expand All @@ -67,6 +79,7 @@ order_refer <- function(npi = NULL,
dme = NULL,
hha = NULL,
pmd = NULL,
hos = NULL,
tidy = TRUE,
pivot = TRUE,
...) {
Expand All @@ -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,
Expand All @@ -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()
Expand All @@ -100,34 +116,53 @@ 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)
return(invisible(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 `<data.frame>`
#'
#' @template returns
#'
#' @autoglobal
#'
#' @noRd
cols_ord <- function(df) {

Expand All @@ -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 `<chr>` 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"
)
)
}
4 changes: 3 additions & 1 deletion R/quality_payment.R
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -313,6 +314,7 @@ cols_qcomb <- function(df) {
}

#' @autoglobal
#'
#' @noRd
cols_qpp <- function(df, step = c("tidy", "nest")) {

Expand Down
1 change: 1 addition & 0 deletions man-roxygen/args-pivot.R
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#' @param pivot `<lgl>` Pivot output; __default__ is `TRUE`
27 changes: 17 additions & 10 deletions man/order_refer.Rd

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

6 changes: 4 additions & 2 deletions tests/testthat/test-cols.R
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)
})
Expand Down
10 changes: 10 additions & 0 deletions tests/testthat/test-fct.R
Original file line number Diff line number Diff line change
Expand Up @@ -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))
})
8 changes: 5 additions & 3 deletions vignettes/articles/linking-providers.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ library(gt)

## Individual Provider

```{r}
```{r echo=FALSE, eval=FALSE}
library(chainr)
mark <- chain(
Expand All @@ -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
Expand All @@ -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()
```
Expand Down
2 changes: 1 addition & 1 deletion vignettes/articles/partb-stats.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ performance
```


```{r}
```{r echo=FALSE, eval=FALSE}
performance |>
pivot_longer(!year,
names_to = "measure",
Expand Down

0 comments on commit 4d69993

Please sign in to comment.