From bb8d71ac9bea412a75d16d351d041a0d518c933c Mon Sep 17 00:00:00 2001 From: Andrew Bruce Date: Wed, 27 Sep 2023 01:45:21 -0400 Subject: [PATCH] commit --- R/affiliations.R | 25 +++--- R/clinicians.R | 45 +++++----- R/hospitals.R | 2 +- R/laboratories.R | 10 +-- R/order_refer.R | 26 +++--- R/revalidation_date.R | 12 +-- R/revalidation_reassign.R | 14 ++-- man/affiliations.Rd | 13 +-- man/clinicians.Rd | 23 +++--- man/laboratories.Rd | 6 +- man/order_refer.Rd | 12 +-- man/revalidation_date.Rd | 4 +- vignettes/articles/partb-stats.Rmd | 64 ++++++++++++++- vignettes/linking_providers.Rmd | 127 ++++++----------------------- vignettes/provider.Rmd | 17 ++-- 15 files changed, 202 insertions(+), 198 deletions(-) diff --git a/R/affiliations.R b/R/affiliations.R index 218e36ff..ac5386a9 100644 --- a/R/affiliations.R +++ b/R/affiliations.R @@ -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, @@ -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 | @@ -55,7 +56,7 @@ #' @autoglobal #' @export affiliations <- function(npi = NULL, - pac_id_ind = NULL, + pac_ind = NULL, first = NULL, middle = NULL, last = NULL, @@ -63,10 +64,11 @@ affiliations <- function(npi = 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)} @@ -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, @@ -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, @@ -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) } @@ -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", diff --git a/R/clinicians.R b/R/clinicians.R index 4518c0e1..9dbfbb8e 100644 --- a/R/clinicians.R +++ b/R/clinicians.R @@ -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" @@ -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 | @@ -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 | @@ -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, @@ -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)} @@ -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, @@ -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)) |> @@ -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, @@ -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) |> @@ -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) } @@ -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', @@ -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', diff --git a/R/hospitals.R b/R/hospitals.R index 721b707a..779a4820 100644 --- a/R/hospitals.R +++ b/R/hospitals.R @@ -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', diff --git a/R/laboratories.R b/R/laboratories.R index f8dffef1..48cea73a 100644 --- a/R/laboratories.R +++ b/R/laboratories.R @@ -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. #' @@ -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), diff --git a/R/order_refer.R b/R/order_refer.R index 39aab8fd..34c0ceb4 100644 --- a/R/order_refer.R +++ b/R/order_refer.R @@ -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: @@ -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()] #' @@ -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)} @@ -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) } @@ -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)) diff --git a/R/revalidation_date.R b/R/revalidation_date.R index 27d18bba..ed3b891f 100644 --- a/R/revalidation_date.R +++ b/R/revalidation_date.R @@ -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. #' @@ -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)) diff --git a/R/revalidation_reassign.R b/R/revalidation_reassign.R index 868ed0a1..a167d12b 100644 --- a/R/revalidation_reassign.R +++ b/R/revalidation_reassign.R @@ -127,21 +127,21 @@ revalidation_reassign <- function(npi = NULL, rass_cols <- function(df) { cols <- c('npi' = 'individual_npi', - 'pac_ind' = 'individual_pac_id', - 'enroll_id_ind' = 'individual_enrollment_id', + 'pac' = 'individual_pac_id', + 'enroll_id' = 'individual_enrollment_id', 'first' = 'individual_first_name', 'last' = 'individual_last_name', - 'state_ind' = 'individual_state_code', - 'specialty_description' = 'individual_specialty_description', + # 'state_ind' = 'individual_state_code', + # 'specialty_description' = 'individual_specialty_description', 'reassignments_ind' = 'individual_total_employer_associations', 'organization' = 'group_legal_business_name', 'pac_org' = 'group_pac_id', 'enroll_id_org' = 'group_enrollment_id', 'state_org' = 'group_state_code', 'reassignments_org' = 'group_reassignments_and_physician_assistants', - 'record_type', - 'due_date_ind' = 'individual_due_date', - 'due_date_org' = 'group_due_date') + # 'due_date_ind' = 'individual_due_date', + # 'due_date_org' = 'group_due_date', + 'record_type') df |> dplyr::select(dplyr::all_of(cols)) diff --git a/man/affiliations.Rd b/man/affiliations.Rd index 0ea3b99f..e7e66de6 100644 --- a/man/affiliations.Rd +++ b/man/affiliations.Rd @@ -6,7 +6,7 @@ \usage{ affiliations( npi = NULL, - pac_id_ind = NULL, + pac_ind = NULL, first = NULL, middle = NULL, last = NULL, @@ -14,13 +14,14 @@ affiliations( facility_ccn = NULL, parent_ccn = NULL, offset = 0L, - tidy = TRUE + tidy = TRUE, + na.rm = TRUE ) } \arguments{ \item{npi}{< \emph{integer} > 10-digit national provider identifier} -\item{pac_id_ind}{< \emph{integer} > 10-digit individual provider associate level variable +\item{pac_ind}{< \emph{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} @@ -47,13 +48,15 @@ sub-unit's primary hospital, should the provider provide services in said unit} \item{offset}{< \emph{integer} > offset; API pagination} -\item{tidy}{< \emph{boolean} > Tidy output; default is \code{TRUE}.} +\item{tidy}{< \emph{boolean} > Tidy output; default is \code{TRUE}} + +\item{na.rm}{< \emph{boolean} > Remove empty rows and columns; default is \code{TRUE}} } \value{ A \link[tibble:tibble-package]{tibble} with the columns:\tabular{ll}{ \strong{Field} \tab \strong{Description} \cr \code{npi} \tab 10-digit NPI \cr - \code{pac_id_ind} \tab 10-digit individual PAC ID \cr + \code{pac_ind} \tab 10-digit individual PAC ID \cr \code{first} \tab Individual provider's first name \cr \code{middle} \tab Individual provider's middle name \cr \code{last} \tab Individual provider's last name \cr diff --git a/man/clinicians.Rd b/man/clinicians.Rd index fa3c37a2..6a590f86 100644 --- a/man/clinicians.Rd +++ b/man/clinicians.Rd @@ -6,7 +6,7 @@ \usage{ clinicians( npi = NULL, - pac_id_ind = NULL, + pac_ind = NULL, enroll_id_ind = NULL, first = NULL, middle = NULL, @@ -16,18 +16,19 @@ clinicians( 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 ) } \arguments{ \item{npi}{< \emph{integer} > 10-digit national provider identifier} -\item{pac_id_ind}{< \emph{integer} > 10-digit individual provider associate-level +\item{pac_ind}{< \emph{integer} > 10-digit individual provider associate-level control identifier} \item{enroll_id_ind}{< \emph{character} > 15-digit individual provider Medicare @@ -49,7 +50,7 @@ specialty reported in the selected enrollment} \item{facility_name}{< \emph{character} > Name of facility associated with the individual provider} -\item{pac_id_org}{< \emph{integer} > 10-digit organizational/group provider +\item{pac_org}{< \emph{integer} > 10-digit organizational/group provider associate-level control identifier} \item{city}{< \emph{character} > Provider's city} @@ -60,13 +61,15 @@ associate-level control identifier} \item{offset}{< \emph{integer} > offset; API pagination} -\item{tidy}{< \emph{boolean} > Tidy output; default is \code{TRUE}.} +\item{tidy}{< \emph{boolean} > Tidy output; default is \code{TRUE}} + +\item{na.rm}{< \emph{boolean} > Remove empty rows and columns; default is \code{TRUE}} } \value{ A \link[tibble:tibble-package]{tibble} with the columns:\tabular{ll}{ \strong{Field} \tab \strong{Description} \cr \code{npi} \tab 10-digit individual NPI \cr - \code{pac_id_ind} \tab 10-digit individual PAC ID \cr + \code{pac_ind} \tab 10-digit individual PAC ID \cr \code{enroll_id_ind} \tab 15-digit individual enrollment ID \cr \code{first} \tab Provider's first name \cr \code{middle} \tab Provider's middle name \cr @@ -79,7 +82,7 @@ A \link[tibble:tibble-package]{tibble} with the columns:\tabular{ll}{ \code{specialty} \tab Provider's primary specialty \cr \code{specialty_sec} \tab Provider's secondary specialty \cr \code{facility_name} \tab Facility associated with provider \cr - \code{pac_id_org} \tab Facility's 10-digit PAC ID \cr + \code{pac_org} \tab Facility's 10-digit PAC ID \cr \code{members} \tab Number of providers associated with facility's PAC ID \cr \code{address} \tab Provider's street address \cr \code{city} \tab Provider's city \cr @@ -88,7 +91,7 @@ A \link[tibble:tibble-package]{tibble} with the columns:\tabular{ll}{ \code{phone} \tab Provider's phone number \cr \code{telehealth} \tab Indicates if provider offers telehealth services \cr \code{assign_ind} \tab Indicates if provider accepts Medicare assignment \cr - \code{assign_group} \tab Indicates if facility accepts Medicare assignment \cr + \code{assign_org} \tab Indicates if facility accepts Medicare assignment \cr } } \description{ @@ -105,7 +108,7 @@ Links: } \examples{ \dontshow{if (interactive()) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} -clinicians(enroll_id = "I20081002000549") +clinicians(enroll_id_ind = "I20081002000549") clinicians(school = "NEW YORK UNIVERSITY SCHOOL OF MEDICINE") \dontshow{\}) # examplesIf} } diff --git a/man/laboratories.Rd b/man/laboratories.Rd index e95a8300..0dff8871 100644 --- a/man/laboratories.Rd +++ b/man/laboratories.Rd @@ -36,11 +36,11 @@ laboratories( \item{zip}{Zip code} -\item{tidy}{Tidy output; default is \code{TRUE}.} +\item{tidy}{Tidy output; default is \code{TRUE}} -\item{na.rm}{Remove empty rows and columns; default is \code{TRUE}.} +\item{na.rm}{Remove empty rows and columns; default is \code{TRUE}} -\item{pivot}{Pivot output; default is \code{TRUE}.} +\item{pivot}{Pivot output; default is \code{TRUE}} } \value{ A \link[tibble:tibble-package]{tibble} containing the search results. diff --git a/man/order_refer.Rd b/man/order_refer.Rd index 20842eac..4aa4bfd1 100644 --- a/man/order_refer.Rd +++ b/man/order_refer.Rd @@ -12,7 +12,8 @@ order_refer( dme = NULL, hha = NULL, pmd = NULL, - tidy = TRUE + tidy = TRUE, + pivot = TRUE ) } \arguments{ @@ -20,8 +21,8 @@ order_refer( \item{first, last}{< \emph{character} > Individual provider's first/last name} -\item{partb, dme, hha, pmd}{< \emph{boolean} > \code{TRUE} or \code{FALSE}. Whether a provider -is eligible to order and refer to: +\item{partb, dme, hha, pmd}{< \emph{boolean} > Whether a provider is eligible to +order and refer to: \itemize{ \item \code{partb}: Medicare Part B \item \code{dme}: Durable Medical Equipment @@ -29,7 +30,9 @@ is eligible to order and refer to: \item \code{pmd}: Power Mobility Devices }} -\item{tidy}{< \emph{boolean} > Tidy output; default is \code{TRUE}.} +\item{tidy}{< \emph{boolean} > Tidy output; default is \code{TRUE}} + +\item{pivot}{Pivot output; default is \code{TRUE}} } \value{ A \link[tibble:tibble-package]{tibble} with the columns:\tabular{ll}{ @@ -38,7 +41,6 @@ A \link[tibble:tibble-package]{tibble} with the columns:\tabular{ll}{ \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 Indicates Provider's Eligibility \cr } } \description{ diff --git a/man/revalidation_date.Rd b/man/revalidation_date.Rd index 00caf62b..dc8db780 100644 --- a/man/revalidation_date.Rd +++ b/man/revalidation_date.Rd @@ -37,9 +37,9 @@ revalidation_date( \item{specialty_description}{< \emph{character} > Enrollment specialty} -\item{tidy}{Tidy output; default is \code{TRUE}.} +\item{tidy}{Tidy output; default is \code{TRUE}} -\item{na.rm}{< \emph{boolean} > Remove empty rows and columns; default is \code{TRUE}.} +\item{na.rm}{< \emph{boolean} > Remove empty rows and columns; default is \code{TRUE}} } \value{ A \link[tibble:tibble-package]{tibble} containing the search results. diff --git a/vignettes/articles/partb-stats.Rmd b/vignettes/articles/partb-stats.Rmd index 9b62365f..de0a88db 100644 --- a/vignettes/articles/partb-stats.Rmd +++ b/vignettes/articles/partb-stats.Rmd @@ -15,7 +15,6 @@ knitr::opts_chunk$set( out.width = "100%", fig.path = "man/figures/README-" ) -library(printr) ``` ```{r message=FALSE, warning=FALSE} @@ -28,15 +27,72 @@ library(gt) ## Provider Utilization Summary ```{r} -df <- prac_years() |> - map(\(x) by_provider(year = x, npi = 1023076643)) |> - list_rbind() +df <- map_dfr(prac_years(), ~by_provider(year = .x, npi = 1023076643)) ``` ### Counts & Amounts +```{r} +select(df, + year, + Charges = tot_charges, + Allowed = tot_allowed, + Payment = tot_payment) |> + ggplot() + + geom_line(aes(year, Charges), color = "gray70", linewidth = 1) + + geom_line(aes(year, Allowed), color = "gray50", linewidth = 1) + + geom_line(aes(year, Payment), color = "gray10", linewidth = 1) + + geom_hline(yintercept = mean(df$tot_charges), color = "gray70", linetype = "dashed") + + geom_hline(yintercept = mean(df$tot_allowed), color = "gray50", linetype = "dashed") + + geom_hline(yintercept = mean(df$tot_payment), color = "gray10", linetype = "dashed") + + labs(x = NULL, y = NULL) + + scale_x_continuous(breaks = c(2013:2019)) + + scale_y_continuous(labels = scales::label_dollar(scale = 1)) + + ggthemes::theme_fivethirtyeight() +``` + +
+ +```{r} +select(df, + year, + Beneficiaries = tot_benes, + Services = tot_srvcs) |> + ggplot() + + geom_line(aes(year, Beneficiaries), color = "gray50", linewidth = 1) + + geom_line(aes(year, Services), color = "gray", linewidth = 1) + + geom_hline(yintercept = mean(df$tot_benes), color = "gray50", linetype = "dashed") + + geom_hline(yintercept = mean(df$tot_srvcs), color = "gray", linetype = "dashed") + + labs(x = NULL, y = NULL) + + scale_x_continuous(breaks = c(2013:2019)) + + scale_y_continuous(labels = scales::label_comma()) + + ggthemes::theme_fivethirtyeight() +``` +
+ +```{r} +select(df, + year, + Beneficiaries = tot_benes, + Services = tot_srvcs, + Payment = tot_payment) |> + change(c(Beneficiaries, Services, Payment)) |> + ggplot() + + geom_line(aes(year, Beneficiaries_chg_cum), color = "gray50", linewidth = 1) + + geom_line(aes(year, Services_chg_cum), color = "gray30", linewidth = 1) + + #geom_line(aes(year, Payment_chg_cum), color = "gray10", linewidth = 1) + + #geom_hline(yintercept = mean(df$tot_benes), color = "gray50", linetype = "dashed") + + #geom_hline(yintercept = mean(df$tot_srvcs), color = "gray", linetype = "dashed") + + labs(x = NULL, y = NULL) + + scale_x_continuous(breaks = c(2013:2019)) + + #scale_y_continuous(labels = scales::label_percent()) + + ggthemes::theme_fivethirtyeight() +``` + +
+ ```{r} select(df, year, diff --git a/vignettes/linking_providers.Rmd b/vignettes/linking_providers.Rmd index b8805d18..9f68c088 100644 --- a/vignettes/linking_providers.Rmd +++ b/vignettes/linking_providers.Rmd @@ -19,8 +19,6 @@ knitr::opts_chunk$set( out.width = "100%", fig.path = "man/figures/README-" ) - -library(printr) ``` ```{r message=FALSE, warning=FALSE} @@ -29,6 +27,30 @@ library(dplyr) ``` +## Individual Provider + +```{r} +full_join( + providers(pac = 7810891009), + revalidation_date(enroll_id = "I20031120000251")) |> +full_join(revalidation_reassign(pac_ind = 7810891009)) |> + glimpse() +``` + +
+ +```{r} +affiliations(pac_ind = 7810891009) |> + pull(facility_ccn) |> + map_dfr(~hospitals(facility_ccn = .x)) +``` +
+ +```{r} +clinicians(pac_ind = 7810891009) +``` +
+ Exploring links between providers can lead to many interesting insights. For example, there is a hospital in New York named **Elizabethtown Community Hospital**.
@@ -55,9 +77,7 @@ The **Hospital Enrollment** API includes only Medicare Part A (hospital) provide
```{r} -affiliations(facility_ccn = 331302) |> - select(-c(middle, suffix, parent_ccn)) |> - head(10) +affiliations(facility_ccn = 331302) ``` @@ -67,8 +87,7 @@ That returns individual providers affiliated with the hospital. Now to search th ```{r} -affiliations(facility_ccn = "33Z302") |> - select(-c(middle, suffix)) +affiliations(facility_ccn = "33Z302") ```
@@ -77,97 +96,5 @@ That returns more affiliated individual providers that practice in the Hospital'
-> An *alphanumeric* CCN represents a sub-unit of the hospital, here a nursing home. We would get the same result if we'd set the `parent_ccn` argument to the numeric CCN, i.e. `facility_affiliations(parent_ccn = 331302)` - -
- -```{r echo=FALSE, eval=FALSE} -unique(elizabethtown$npi) |> - map(\(x) nppes_npi(npi = x)) |> - list_rbind() |> - filter(purpose != "MAILING") - -elizabeth.prov <- providers(organization = "Elizabethtown Community Hospital") |> - select(organization, - pac_organization = pac_id, - npi_organization = npi, - enroll_organization = enroll_id, - specialty) - -elizabeth.hosp <- hospitals(organization = "Elizabethtown Community Hospital") |> - select(organization, - pac_organization = pac_id_org, - npi_organization = npi, - enroll_organization = enroll_id, - facility_ccn) - -elizabeth.affil <- elizabeth.hosp$facility_ccn |> - map(\(x) affiliations(facility_ccn = x)) |> - list_rbind() |> - select(pac_individual = pac_id_ind, - npi_individual = npi, - facility_ccn) - -left_join(elizabeth.prov, - elizabeth.hosp, by = join_by(organization, - pac_organization, - npi_organization, - enroll_organization)) |> - left_join(elizabeth.affil, by = join_by(facility_ccn)) - -####################################### - -elizabeth.prov.pac <- unique(elizabeth.affil$pac_individual) |> - map(\(x) providers(pac_id = x)) |> - list_rbind() |> - select(pac_individual = pac_id, - npi_individual = npi, - enroll_individual = enroll_id) - -elizabeth.group <- unique(elizabeth.prov.pac$npi_individual) |> - map(\(x) revalidation_group(npi = x)) |> - list_rbind() |> - select(npi_individual = npi, - enroll_individual = enroll_id, - pac_organization = group_pac_id, - enroll_organization = group_enroll_id, - organization = group_legal_business_name, - organization_reassignments = group_reassignments) - -left_join(elizabeth.prov.pac, - elizabeth.group, - by = join_by(npi_individual, enroll_individual)) |> - arrange(desc(organization_reassignments)) -``` - -
- -### CLIA Laboratories - -```{r} -laboratories(city = "Valdosta", - certificate = "accreditation") |> - dplyr::filter(confirmed == TRUE) |> - dplyr::select(name, - clia_number, - expiration_date, - termination_reason, - facility_type, - organization, - confirmed_date) |> - dplyr::distinct() |> - gt::gt(rowname_col = "name") |> - gt::cols_label(termination_reason = "status", - clia_number = "clia", - expiration_date = "expires", - confirmed_date = "confirmed", - facility_type = "type") |> - gt::cols_label_with(fn = toupper) |> - gt::tab_spanner(label = "ACCREDITATION", - columns = c(organization, confirmed_date)) |> - gt::fmt_date(columns = gt::contains("date"), - date_style = "m_day_year") |> - gt::opt_table_font(font = gt::google_font(name = "JetBrains Mono")) |> - gt::opt_stylize(color = "red") -``` +> An *alphanumeric* CCN represents a sub-unit of the hospital, here a nursing home. We would get the same result if we'd set the `parent_ccn` argument to the numeric CCN, i.e. `affiliations(parent_ccn = 331302)` diff --git a/vignettes/provider.Rmd b/vignettes/provider.Rmd index 9af1852a..109b5281 100644 --- a/vignettes/provider.Rmd +++ b/vignettes/provider.Rmd @@ -19,7 +19,6 @@ knitr::opts_chunk$set( out.width = "100%", fig.path = "man/figures/README-" ) -library(printr) ``` ```{r} @@ -67,6 +66,14 @@ order_refer(npi = 1043477615, tidy = FALSE)
+Setting it to `FALSE` will return the un-processed output: + +```{r} +order_refer(npi = 1043477615, pivot = FALSE) +``` + +
+ The `tidy` transformations applied to the output of each function include: - Favoring a long format over wide. @@ -126,9 +133,7 @@ quality_years() These can also be used in a pipeline, for searching all available years: ```{r} -quality_years() |> - map(\(x) quality_payment(year = x, npi = 1043477615)) |> - list_rbind() |> +map_dfr(quality_years(), ~quality_payment(year = .x, npi = 1043477615)) |> select(year:final_score) ``` @@ -160,10 +165,10 @@ pending(npi = 001234569123, type = "physician") ```{r} # Must be 10 digits long -affiliations(pac_id_ind = 0123456789) +affiliations(pac_ind = 0123456789) # Must be numeric -hospitals(pac_id_org = "O12345678912") +hospitals(pac_org = "O12345678912") ```