Skip to content

Commit

Permalink
commit
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewallenbruce committed Oct 10, 2023
1 parent 1ebb476 commit 19354c4
Show file tree
Hide file tree
Showing 27 changed files with 507 additions and 565 deletions.
6 changes: 3 additions & 3 deletions R/affiliations.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
#'
#' *Update Frequency:* **Monthly**
#'
#' @param npi < *integer | character* > 10-digit Individual National Provider Identifier
#' @param pac < *integer | character* > 10-digit Individual PECOS Associate Control ID
#' @param npi < *integer* > 10-digit Individual National Provider Identifier
#' @param pac < *integer* > 10-digit Individual PECOS Associate Control ID
#' @param first,middle,last < *character* > Individual Provider's name
#' @param facility_type < *character* >
#' + `"Hospital"` or `"hp"`
Expand All @@ -25,7 +25,7 @@
#' + `"Skilled nursing facility"` or `"snf"`
#' + `"Hospice"` or `"hs"`
#' + `"Dialysis facility"` or `"df"`
#' @param facility_ccn < *integer | character* > 6-digit CMS Certification Number of
#' @param facility_ccn < *character* > 6-digit CMS Certification Number of
#' facility or unit within hospital where an individual provider provides service
#' @param parent_ccn < *integer* > 6-digit CMS Certification Number of a sub-unit's
#' primary hospital, should the provider provide services in said unit
Expand Down
19 changes: 8 additions & 11 deletions R/beneficiaries.R
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@
#' beneficiaries(level = "State", fips = "10")
#' @autoglobal
#' @export
beneficiaries <- function(year = NULL,
period = NULL,
level = NULL,
state = NULL,
county = NULL,
fips = NULL,
tidy = TRUE) {
beneficiaries <- function(year = NULL,
period = NULL,
level = NULL,
state = NULL,
county = NULL,
fips = NULL,
tidy = TRUE) {

if (!is.null(year)) {
year <- as.character(year)
Expand Down Expand Up @@ -115,7 +115,6 @@ beneficiaries <- function(year = NULL,
tidyr::unnest(cols = c(y))

format_cli(cli_args)

return(invisible(NULL))

}
Expand All @@ -125,8 +124,6 @@ beneficiaries <- function(year = NULL,
if (tidy) {
results <- tidyup(results) |>
dplyr::mutate(year = as.integer(year),
bene_fips_cd = stringr::str_squish(bene_fips_cd),
dplyr::across(dplyr::where(is.character), na_star),
dplyr::across(dplyr::contains("_benes"), as.integer)) |>
bene_cols()

Expand Down Expand Up @@ -169,6 +166,6 @@ bene_cols <- function(df) {
"bene_rx_lis_part" = "prscrptn_drug_partial_lis_benes",
"bene_rx_lis_no" = "prscrptn_drug_no_lis_benes")

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

}
38 changes: 19 additions & 19 deletions R/betos.R
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
#' Restructured BETOS Classification System
#' Restructured BETOS Classification for HCPCS
#'
#' @description
#' `r lifecycle::badge("experimental")`
#'
#' `betos_classification()` allows the user to group HCPCS codes into clinically
#' meaningful categories based on the original Berenson-Eggers Type of Service
#' (BETOS) classification. Users may use the RBCS to analyze trends and perform
#' other types of health services analytic work.
#' [betos()] allows the user to group HCPCS codes into clinically
#' meaningful categories based on the original _Berenson-Eggers Type of Service_
#' (BETOS) classification.
#'
#' @section From BETOS to RBCS:
#'
#' ## BETOS
#' The Restructured BETOS Classification System (RBCS) is a taxonomy that allows
#' researchers to group healthcare service codes for Medicare Part B services
#' into clinically meaningful categories and subcategories. It is based on the
#' original Berenson-Eggers Type of Service (BETOS) classification created in
#' the 1980s, and includes notable updates such as Part B non-physician services.
#' The RBCS will undergo annual updates by a technical expert panel of
#' researchers to group Medicare Part B healthcare service codes into clinically
#' meaningful categories and subcategories.
#'
#' Based on the original Berenson-Eggers Type of Service (BETOS) classification
#' created in the 1980s, it includes notable updates such as Part B non-physician
#' services and undergoes annual updates by a technical expert panel of
#' researchers and clinicians.
#'
#' The general framework for grouping service codes into the new RBCS taxonomy
Expand All @@ -26,8 +28,8 @@
#'
#' Links:
#'
#' - [Restructured BETOS Classification System](https://data.cms.gov/provider-summary-by-type-of-service/provider-service-classifications/restructured-betos-classification-system)
#' - [Restructured BETOS Classification System Data Dictionary](https://data.cms.gov/resources/restructured-betos-classification-system-data-dictionary)
#' + [Restructured BETOS Classification System](https://data.cms.gov/provider-summary-by-type-of-service/provider-service-classifications/restructured-betos-classification-system)
#' + [RBCS Data Dictionary](https://data.cms.gov/resources/restructured-betos-classification-system-data-dictionary)
#'
#' *Update Frequency:* **Annually**
#'
Expand All @@ -37,7 +39,7 @@
#' @param family < *character* > RBCS Family Description
#' @param procedure < *character* > Whether the HCPCS code is a Major (`"M"`),
#' Other (`"O"`), or Non-Procedure code (`"N"`).
#' @param tidy < *boolean* > Tidy output; default is `TRUE`
#' @param tidy < *boolean* > // __default:__ `TRUE` Tidy output
#'
#' @return A [tibble][tibble::tibble-package] with the columns:
#'
Expand Down Expand Up @@ -99,10 +101,8 @@ betos <- function(hcpcs_code = NULL,
results <- httr2::resp_body_json(response, simplifyVector = TRUE)

if (tidy) {
results <- tidyup(results) |>
dplyr::mutate(dplyr::across(dplyr::everything(), stringr::str_squish),
dplyr::across(dplyr::contains("dt"), anytime::anydate),
rbcs_major_ind = dplyr::case_match(rbcs_major_ind,
results <- tidyup(results, dt = c("dt")) |>
dplyr::mutate(rbcs_major_ind = dplyr::case_match(rbcs_major_ind,
"N" ~ "Non-procedure",
"M" ~ "Major",
"O" ~ "Other")) |>
Expand Down Expand Up @@ -130,6 +130,6 @@ betos_cols <- function(df) {
'rbcs_start_date' = 'rbcs_assignment_eff_dt',
'rbcs_end_date' = 'rbcs_assignment_end_dt')

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

}
21 changes: 9 additions & 12 deletions R/clinicians.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
#'
#' *Update Frequency:* **Monthly**
#'
#' @param npi < *integer|character* > 10-digit Individual National Provider Identifier
#' @param pac < *integer|character* > 10-digit Individual PECOS Associate Control ID
#' @param npi < *integer* > 10-digit Individual National Provider Identifier
#' @param pac < *integer* > 10-digit Individual PECOS Associate Control ID
#' @param enid < *character* > 15-digit Individual Medicare Enrollment ID
#' @param first,middle,last < *character* > Individual provider's name
#' @param gender < *character* > Individual provider's gender; `"F"` (Female)
Expand All @@ -23,7 +23,7 @@
#' specialty reported in the selected enrollment
#' @param facility_name < *character* > Name of facility associated with the
#' individual provider
#' @param pac_org < *integer|character* > 10-digit Organizational PECOS
#' @param pac_org < *integer* > 10-digit Organizational PECOS
#' Associate Control ID
#' @param city < *character* > Provider's city
#' @param state < *character* > Provider's state
Expand Down Expand Up @@ -64,7 +64,7 @@
#' @seealso [hospitals()], [providers()], [affiliations()]
#'
#' @examplesIf interactive()
#' clinicians(enroll_id_ind = "I20081002000549")
#' clinicians(enid = "I20081002000549")
#' clinicians(school = "NEW YORK UNIVERSITY SCHOOL OF MEDICINE")
#' @autoglobal
#' @export
Expand Down Expand Up @@ -152,13 +152,10 @@ clinicians <- function(npi = NULL,
}

if (tidy) {
results <- tidyup(results) |>
tidyr::unite("address_org", adr_ln_1:adr_ln_2,
remove = TRUE, na.rm = TRUE, sep = " ") |>
dplyr::mutate(address_org = stringr::str_squish(address_org),
num_org_mem = as.integer(num_org_mem),
grd_yr = as.integer(grd_yr),
telehlth = yn_logical(telehlth)) |>
results <- tidyup(results, yn = c("telehlth")) |>
address(c("adr_ln_1", "adr_ln_2")) |>
dplyr::mutate(num_org_mem = as.integer(num_org_mem),
grd_yr = as.integer(grd_yr)) |>
clin_cols()
if (na.rm) {
results <- janitor::remove_empty(results, which = c("rows", "cols"))}
Expand Down Expand Up @@ -187,7 +184,7 @@ clin_cols <- function(df) {
'organization' = 'facility_name',
'pac_org' = 'org_pac_id',
'members_org' = 'num_org_mem',
'address_org',
'address_org' = 'address',
# 'address_id' = 'adrs_id',
'city_org' = 'city_town',
'state_org' = 'state',
Expand Down
21 changes: 8 additions & 13 deletions R/hospitals.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#' @description
#' `r lifecycle::badge("experimental")`
#'
#'
#' [hospitals()] allows the user to search for information on all hospitals
#' currently enrolled in Medicare. Data returned includes the hospital's
#' sub-group types, legal business name, doing-business-as name, organization
Expand All @@ -13,11 +12,11 @@
#'
#' *Update Frequency:* **Monthly**
#'
#' @param npi < *integer | character* > 10-digit Organizational National Provider Identifier
#' @param pac_org < *integer | character* > 10-digit Organizational PECOS Associate Control ID
#' @param npi < *integer* > 10-digit Organizational National Provider Identifier
#' @param pac_org < *integer* > 10-digit Organizational PECOS Associate Control ID
#' @param enid_org < *character* > 15-digit Organizational Medicare Enrollment ID
#' @param enid_state < *character* > Hospital’s enrollment state
#' @param facility_ccn < *integer | character* > 6-digit CMS Certification Number
#' @param facility_ccn < *integer* > 6-digit CMS Certification Number
#' @param specialty_code < *character* > Medicare Part A Provider specialty code:
#' + `"00-00"`: Religious Non-Medical Healthcare Institution (RNHCI)
#' + `"00-01"`: Community Mental Health Center
Expand All @@ -40,7 +39,7 @@
#' @param dba < *character* > Hospital’s doing-business-as name
#' @param city < *character* > City of the hospital’s practice location
#' @param state < *character* > State of the hospital’s practice location
#' @param zip < *integer | character* > Zip code of the hospital’s practice location
#' @param zip < *integer* > Zip code of the hospital’s practice location
#' @param registration < *character* > Hospital's IRS designation:
#' + `"P"`: Registered as __Proprietor__
#' + `"N"`: Registered as __Non-Profit__
Expand Down Expand Up @@ -101,6 +100,7 @@
#' hospitals(pac_org = 6103733050)
#'
#' hospitals(state = "GA", reh = TRUE)
#'
#' @autoglobal
#' @export
hospitals <- function(npi = NULL,
Expand Down Expand Up @@ -235,16 +235,11 @@ hospitals <- function(npi = NULL,
results <- httr2::resp_body_json(response, simplifyVector = TRUE)

if (tidy) {
results <- tidyup(results) |>
dplyr::mutate(dplyr::across(dplyr::contains(c("flag", "subgroup")), yn_logical),
dplyr::across(dplyr::contains("date"), anytime::anydate),
dplyr::across(dplyr::contains("location"), stringr::str_squish),
proprietary_nonprofit = dplyr::case_match(proprietary_nonprofit,
results <- tidyup(results, yn = c("flag", "subgroup")) |>
dplyr::mutate(roprietary_nonprofit = dplyr::case_match(proprietary_nonprofit,
"P" ~ "Proprietary", "N" ~ "Non-Profit", .default = NA),
zip_code = as.character(zip_code)) |>
tidyr::unite("address",
address_line_1:address_line_2,
remove = TRUE, na.rm = TRUE) |>
address(c("address_line_1", "address_line_2")) |>
tidyr::unite("structure",
organization_type_structure:organization_other_type_text,
remove = TRUE, na.rm = TRUE, sep = ": ") |>
Expand Down
Loading

0 comments on commit 19354c4

Please sign in to comment.