Skip to content

Commit

Permalink
commit
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewallenbruce committed Sep 27, 2023
1 parent c23d12d commit bb8d71a
Show file tree
Hide file tree
Showing 15 changed files with 202 additions and 198 deletions.
25 changes: 15 additions & 10 deletions R/affiliations.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#' *Update Frequency:* **Monthly**
#'
#' @param npi < *integer* > 10-digit national provider identifier
#' @param pac_id_ind < *integer* > 10-digit individual provider associate level variable
#' @param pac_ind < *integer* > 10-digit individual provider associate level variable
#' Links all entity-level information and may be associated with multiple
#' enrollment IDs if the individual or organization enrolled multiple times
#' @param first,middle,last < *character* > Individual provider's first, middle,
Expand All @@ -32,14 +32,15 @@
#' @param parent_ccn < *integer* > 6-digit CMS Certification Number of a
#' sub-unit's primary hospital, should the provider provide services in said unit
#' @param offset < *integer* > offset; API pagination
#' @param tidy < *boolean* > Tidy output; default is `TRUE`.
#' @param tidy < *boolean* > Tidy output; default is `TRUE`
#' @param na.rm < *boolean* > Remove empty rows and columns; default is `TRUE`
#'
#' @return A [tibble][tibble::tibble-package] with the columns:
#'
#' |**Field** |**Description** |
#' |:---------------|:---------------------------------|
#' |`npi` |10-digit NPI |
#' |`pac_id_ind` |10-digit individual PAC ID |
#' |`pac_ind` |10-digit individual PAC ID |
#' |`first` |Individual provider's first name |
#' |`middle` |Individual provider's middle name |
#' |`last` |Individual provider's last name |
Expand All @@ -55,18 +56,19 @@
#' @autoglobal
#' @export
affiliations <- function(npi = NULL,
pac_id_ind = NULL,
pac_ind = NULL,
first = NULL,
middle = NULL,
last = NULL,
facility_type = NULL,
facility_ccn = NULL,
parent_ccn = NULL,
offset = 0L,
tidy = TRUE) {
tidy = TRUE,
na.rm = TRUE) {

if (!is.null(npi)) {npi <- npi_check(npi)}
if (!is.null(pac_id_ind)) {pac_id_ind <- pac_check(pac_id_ind)}
if (!is.null(pac_ind)) {pac_ind <- pac_check(pac_ind)}
if (!is.null(facility_ccn)) {facility_ccn <- as.character(facility_ccn)}
if (!is.null(parent_ccn)) {parent_ccn <- as.character(parent_ccn)}

Expand Down Expand Up @@ -94,7 +96,7 @@ affiliations <- function(npi = NULL,
args <- dplyr::tribble(
~param, ~arg,
"npi", npi,
"ind_pac_id", pac_id_ind,
"ind_pac_id", pac_ind,
"frst_nm", first,
"mid_nm", middle,
"lst_nm", last,
Expand All @@ -115,7 +117,7 @@ affiliations <- function(npi = NULL,
cli_args <- dplyr::tribble(
~x, ~y,
"npi", npi,
"pac_id_ind", pac_id_ind,
"pac_ind", pac_ind,
"first", first,
"middle", middle,
"last", last,
Expand All @@ -130,7 +132,10 @@ affiliations <- function(npi = NULL,

}

if (tidy) {results <- tidyup(results) |> aff_cols()}
if (tidy) {results <- tidyup(results) |> aff_cols()
if (na.rm) {
results <- janitor::remove_empty(results, which = c("rows", "cols"))}
}

return(results)
}
Expand All @@ -141,7 +146,7 @@ affiliations <- function(npi = NULL,
aff_cols <- function(df) {

cols <- c("npi",
"pac_id_ind" = "ind_pac_id",
"pac_ind" = "ind_pac_id",
"first" = "frst_nm",
"middle" = "mid_nm",
"last" = "lst_nm",
Expand Down
45 changes: 22 additions & 23 deletions R/clinicians.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#' *Update Frequency:* **Monthly**
#'
#' @param npi < *integer* > 10-digit national provider identifier
#' @param pac_id_ind < *integer* > 10-digit individual provider associate-level
#' @param pac_ind < *integer* > 10-digit individual provider associate-level
#' control identifier
#' @param enroll_id_ind < *character* > 15-digit individual provider Medicare
#' enrollment identifier; begins with capital "I"
Expand All @@ -26,20 +26,21 @@
#' specialty reported in the selected enrollment
#' @param facility_name < *character* > Name of facility associated with the
#' individual provider
#' @param pac_id_org < *integer* > 10-digit organizational/group provider
#' @param pac_org < *integer* > 10-digit organizational/group provider
#' associate-level control identifier
#' @param city < *character* > Provider's city
#' @param state < *character* > Provider's state
#' @param zip < *character* > Provider's ZIP code
#' @param offset < *integer* > offset; API pagination
#' @param tidy < *boolean* > Tidy output; default is `TRUE`.
#' @param tidy < *boolean* > Tidy output; default is `TRUE`
#' @param na.rm < *boolean* > Remove empty rows and columns; default is `TRUE`
#'
#' @return A [tibble][tibble::tibble-package] with the columns:
#'
#' |**Field** |**Description** |
#' |:---------------|:-----------------------------------------------------|
#' |`npi` |10-digit individual NPI |
#' |`pac_id_ind` |10-digit individual PAC ID |
#' |`pac_ind` |10-digit individual PAC ID |
#' |`enroll_id_ind` |15-digit individual enrollment ID |
#' |`first` |Provider's first name |
#' |`middle` |Provider's middle name |
Expand All @@ -52,7 +53,7 @@
#' |`specialty` |Provider's primary specialty |
#' |`specialty_sec` |Provider's secondary specialty |
#' |`facility_name` |Facility associated with provider |
#' |`pac_id_org` |Facility's 10-digit PAC ID |
#' |`pac_org` |Facility's 10-digit PAC ID |
#' |`members` |Number of providers associated with facility's PAC ID |
#' |`address` |Provider's street address |
#' |`city` |Provider's city |
Expand All @@ -61,17 +62,17 @@
#' |`phone` |Provider's phone number |
#' |`telehealth` |Indicates if provider offers telehealth services |
#' |`assign_ind` |Indicates if provider accepts Medicare assignment |
#' |`assign_group` |Indicates if facility accepts Medicare assignment |
#' |`assign_org` |Indicates if facility accepts Medicare assignment |
#'
#' @seealso [hospitals()], [providers()], [affiliations()]
#'
#' @examplesIf interactive()
#' clinicians(enroll_id = "I20081002000549")
#' clinicians(enroll_id_ind = "I20081002000549")
#' clinicians(school = "NEW YORK UNIVERSITY SCHOOL OF MEDICINE")
#' @autoglobal
#' @export
clinicians <- function(npi = NULL,
pac_id_ind = NULL,
pac_ind = NULL,
enroll_id_ind = NULL,
first = NULL,
middle = NULL,
Expand All @@ -81,16 +82,17 @@ clinicians <- function(npi = NULL,
grad_year = NULL,
specialty = NULL,
facility_name = NULL,
pac_id_org = NULL,
pac_org = NULL,
city = NULL,
state = NULL,
zip = NULL,
offset = 0L,
tidy = TRUE) {
tidy = TRUE,
na.rm = TRUE) {

if (!is.null(npi)) {npi <- npi_check(npi)}
if (!is.null(pac_id_ind)) {pac_id_ind <- pac_check(pac_id_ind)}
if (!is.null(pac_id_org)) {pac_id_org <- pac_check(pac_id_org)}
if (!is.null(pac_ind)) {pac_id_ind <- pac_check(pac_ind)}
if (!is.null(pac_org)) {pac_id_org <- pac_check(pac_org)}
if (!is.null(enroll_id_ind)) {enroll_check(enroll_id_ind)}
if (!is.null(enroll_id_ind)) {enroll_ind_check(enroll_id_ind)}
if (!is.null(grad_year)) {grad_year <- as.character(grad_year)}
Expand All @@ -100,7 +102,7 @@ clinicians <- function(npi = NULL,
args <- dplyr::tribble(
~param, ~arg,
"NPI", npi,
"Ind_PAC_ID", pac_id_ind,
"Ind_PAC_ID", pac_ind,
"Ind_enrl_ID", enroll_id_ind,
"frst_nm", first,
"mid_nm", middle,
Expand All @@ -110,16 +112,11 @@ clinicians <- function(npi = NULL,
"grd_yr", grad_year,
"pri_spec", specialty,
"facility_name", facility_name,
"org_pac_id", pac_id_org,
"org_pac_id", pac_org,
"citytown", city,
"state", state,
"zip_code", zip)

# url <- paste0("https://data.cms.gov/provider-data/api/1/datastore/sql?query=",
# "[SELECT * FROM ", file_id("c"), "]",
# encode_param(args, type = "sql"),
# "[LIMIT 10000 OFFSET ", offset, "]")

error_body <- function(response) {httr2::resp_body_json(response)$message}

response <- httr2::request(file_url("c", args, offset)) |>
Expand All @@ -133,7 +130,7 @@ clinicians <- function(npi = NULL,
cli_args <- dplyr::tribble(
~x, ~y,
"npi", npi,
"pac_id_ind", pac_id_ind,
"pac_ind", pac_ind,
"enroll_id_ind", enroll_id_ind,
"first", first,
"middle", middle,
Expand All @@ -143,7 +140,7 @@ clinicians <- function(npi = NULL,
"grad_year", grad_year,
"specialty", specialty,
"facility_name", facility_name,
"pac_id_org", pac_id_org,
"pac_org", pac_org,
"city", city,
"state", state,
"zip", zip) |>
Expand All @@ -163,6 +160,8 @@ clinicians <- function(npi = NULL,
grd_yr = as.integer(grd_yr),
telehlth = yn_logical(telehlth)) |>
clin_cols()
if (na.rm) {
results <- janitor::remove_empty(results, which = c("rows", "cols"))}
}
return(results)
}
Expand All @@ -173,7 +172,7 @@ clinicians <- function(npi = NULL,
clin_cols <- function(df) {

cols <- c('npi',
'pac_id_ind' = 'ind_pac_id',
'pac_ind' = 'ind_pac_id',
'enroll_id_ind' = 'ind_enrl_id',
'first' = 'frst_nm',
'middle' = 'mid_nm',
Expand All @@ -186,7 +185,7 @@ clin_cols <- function(df) {
'specialty' = 'pri_spec',
'specialty_sec' = 'sec_spec_all',
'facility_name',
'pac_id_org' = 'org_pac_id',
'pac_org' = 'org_pac_id',
'members' = 'num_org_mem',
'address',
# 'address_id' = 'adrs_id',
Expand Down
2 changes: 1 addition & 1 deletion R/hospitals.R
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ hosp_cols <- function(df) {
cols <- c('npi',
'organization' = 'organization_name',
'doing_business_as' = 'doing_business_as_name',
'pac_id_org' = 'associate_id',
'pac_org' = 'associate_id',
'enroll_id_org' = 'enrollment_id',
'facility_ccn' = 'ccn',
'specialty_code' = 'provider_type_code',
Expand Down
10 changes: 5 additions & 5 deletions R/laboratories.R
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@
#' @param city City
#' @param state State
#' @param zip Zip code
#' @param tidy Tidy output; default is `TRUE`.
#' @param na.rm Remove empty rows and columns; default is `TRUE`.
#' @param pivot Pivot output; default is `TRUE`.
#' @param tidy Tidy output; default is `TRUE`
#' @param na.rm Remove empty rows and columns; default is `TRUE`
#' @param pivot Pivot output; default is `TRUE`
#'
#' @return A [tibble][tibble::tibble-package] containing the search results.
#'
Expand Down Expand Up @@ -129,8 +129,8 @@ laboratories <- function(name = NULL,

if (tidy) {
results <- tidyup(results) |>
dplyr::mutate(dplyr::across(dplyr::contains("_dt"), ~anytime::anydate(.)),
dplyr::across(dplyr::contains("_sw"), ~yn_logical(.)),
dplyr::mutate(dplyr::across(dplyr::contains("_dt"), anytime::anydate),
dplyr::across(dplyr::contains("_sw"), yn_logical),
pgm_trmntn_cd = termcd(pgm_trmntn_cd),
crtfctn_actn_type_cd = toa(crtfctn_actn_type_cd),
cmplnc_stus_cd = status(cmplnc_stus_cd),
Expand Down
26 changes: 15 additions & 11 deletions R/order_refer.R
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,14 @@
#'
#' @param npi < *integer* > 10-digit national provider identifier
#' @param first,last < *character* > Individual provider's first/last name
#' @param partb,dme,hha,pmd < *boolean* > `TRUE` or `FALSE`. Whether a provider
#' is eligible to order and refer to:
#' @param partb,dme,hha,pmd < *boolean* > 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* > Tidy output; default is `TRUE`.
#' @param tidy < *boolean* > Tidy output; default is `TRUE`
#' @param pivot Pivot output; default is `TRUE`
#'
#'
#' @return A [tibble][tibble::tibble-package] with the columns:
Expand All @@ -55,7 +56,6 @@
#' |`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 |
#' |`eligible` |Indicates Provider's Eligibility |
#'
#' @seealso [providers()], [opt_out()], [pending()]
#'
Expand All @@ -74,7 +74,8 @@ order_refer <- function(npi = NULL,
dme = NULL,
hha = NULL,
pmd = NULL,
tidy = TRUE) {
tidy = TRUE,
pivot = TRUE) {

if (!is.null(npi)) {npi <- npi_check(npi)}
if (!is.null(partb)) {partb <- tf_2_yn(partb)}
Expand Down Expand Up @@ -119,10 +120,13 @@ order_refer <- function(npi = NULL,
results <- tidyup(results) |>
dplyr::mutate(dplyr::across(
dplyr::contains(c("partb", "hha", "dme", "pmd")), yn_logical)) |>
ord_cols() |>
tidyr::pivot_longer(cols = !c(npi, first, last),
ord_cols()
if (pivot) {
results <- tidyr::pivot_longer(results, cols = !c(npi, first, last),
names_to = "service",
values_to = "eligible")
values_to = "status")
results$status <- NULL
}
}
return(results)
}
Expand All @@ -136,9 +140,9 @@ ord_cols <- function(df) {
'first' = 'first_name',
'last' = 'last_name',
"Medicare Part B" = 'partb',
"Home Health Agency (HHA)" = 'hha',
"Durable Medical Equipment (DME)" = 'dme',
"Power Mobility Device (PMD)" = 'pmd')
"Home Health Agency" = 'hha',
"Durable Medical Equipment" = 'dme',
"Power Mobility Devices" = 'pmd')

df |> dplyr::select(dplyr::all_of(cols))

Expand Down
12 changes: 6 additions & 6 deletions R/revalidation_date.R
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
#' * `2`: DME
#' * `3`: Non-DME Part B
#' @param specialty_description < *character* > Enrollment specialty
#' @param tidy Tidy output; default is `TRUE`.
#' @param na.rm < *boolean* > Remove empty rows and columns; default is `TRUE`.
#' @param tidy Tidy output; default is `TRUE`
#' @param na.rm < *boolean* > Remove empty rows and columns; default is `TRUE`
#'
#' @return A [tibble][tibble::tibble-package] containing the search results.
#'
Expand Down Expand Up @@ -120,11 +120,11 @@ rdate_cols <- function(df) {
'organization' = 'organization_name',
'state' = 'enrollment_state_code',
'enrollment_type' = 'provider_type_text',
'specialty_description' = 'enrollment_specialty',
# 'specialty_description' = 'enrollment_specialty',
# 'due_date' = 'revalidation_due_date',
# 'due_date_adj' = 'adjusted_due_date',
'reassignments_org' = 'individual_total_reassign_to',
'reassignments_ind' = 'receiving_benefits_reassignment',
'due_date' = 'revalidation_due_date',
'due_date_adj' = 'adjusted_due_date')
'reassignments_ind' = 'receiving_benefits_reassignment')

df |> dplyr::select(dplyr::all_of(cols))

Expand Down
Loading

0 comments on commit bb8d71a

Please sign in to comment.