Skip to content

Commit

Permalink
quality_payment_ bug
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewallenbruce committed Dec 3, 2023
1 parent a175f1c commit cba09b8
Show file tree
Hide file tree
Showing 8 changed files with 140 additions and 79 deletions.
3 changes: 2 additions & 1 deletion R/add_counties.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
#' @param add_geo add county geometry column, default is `FALSE`
#' @param as_sf convert tibble to an `{sf}` object, default is `FALSE`
#'
#' @examples
#' @examplesIf interactive()
#'
#' # Example data frame containing state abbreviation and zip code
#' ex <- dplyr::tibble(state = "GA",
#' zip = "31605")
Expand Down
14 changes: 0 additions & 14 deletions R/globals.R
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,6 @@ utils::globalVariables(c(
"distro", # <quality_payment>
"y", # <quality_payment>
"participation_type", # <quality_payment>
"org_state", # <quality_payment>
"val", # <quality_payment>
"set", # <quality_payment>
"score", # <quality_payment>
Expand All @@ -243,19 +242,6 @@ utils::globalVariables(c(
"qualified", # <quality_payment>
"org_size", # <quality_payment>
"org_id", # <quality_payment>
"npi_type", # <quality_payment>
"first", # <quality_payment>
"middle", # <quality_payment>
"last", # <quality_payment>
"first_approved_date", # <quality_payment>
"years_in_medicare", # <quality_payment>
"specialty_type", # <quality_payment>
"specialty_cat", # <quality_payment>
"ind_specialty_code", # <quality_payment>
"org_name", # <quality_payment>
"org_address", # <quality_payment>
"org_city", # <quality_payment>
"org_zip", # <quality_payment>
"y", # <reassignments>
"individual_state_code", # <reassignments>
"group_state_code", # <reassignments>
Expand Down
15 changes: 11 additions & 4 deletions R/quality_eligibility.R
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@
#' 1144544834))
#'
#' # Multiple NPIs/years
#'
#' 2017:2023 |>
#' purrr::map(\(x)
#' quality_eligibility(year = x,
Expand All @@ -105,12 +104,20 @@
#' 1144544834))) |>
#' purrr::list_rbind()
#'
#' # Quality Stats
#' # Same as
#' quality_eligibility_(npi = c(aff_npis[1:5],
#' 1234567893,
#' 1043477615,
#' 1144544834))
#'
#' # Quality Stats
#' 2017:2023 |>
#' purrr::map(\(x) quality_eligibility(year = x, stats = TRUE)) |>
#' purrr::list_rbind()
#'
#' # Same as
#' quality_eligibility_(stats = TRUE)
#'
#' @autoglobal
#' @export
quality_eligibility <- function(year,
Expand Down Expand Up @@ -378,7 +385,7 @@ cols_qelig <- function(df, type = c('tidyup', 'top', 'apms', 'ind', 'grp')) {
# 'years_in_medicare' = 'yearsInMedicare',
# 'pecos_year' = 'pecosEnrollmentDate',
'newly_enrolled' = 'newlyEnrolled',
'specialty' = 'specialty.specialtyDescription',
'specialty_desc' = 'specialty.specialtyDescription',
'specialty_type' = 'specialty.typeDescription',
'specialty_cat' = 'specialty.categoryReference',
'is_maqi' = 'isMaqi',
Expand Down Expand Up @@ -501,7 +508,7 @@ cols_qelig <- function(df, type = c('tidyup', 'top', 'apms', 'ind', 'grp')) {
'first_approved_date',
'years_in_medicare',
'newly_enrolled',
'specialty',
'specialty_desc',
'specialty_type',
'specialty_cat',
'is_maqi',
Expand Down
111 changes: 81 additions & 30 deletions R/quality_payment.R
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ quality_payment <- function(year,
"extreme_hardship_cost")) |>
cols_qpp("tidy") |>
dplyr::mutate(participation_type = fct_part(participation_type),
org_state = fct_stabb(org_state))
state = fct_stabb(state))

if (nest) {
pcol <- list(q = c('quality_measure_id_', 'quality_measure_score_') %s+% rep(1:10, each = 2),
Expand All @@ -176,7 +176,7 @@ quality_payment <- function(year,
values_to = "val") |>
dplyr::filter(!is.na(val)) |>
dplyr::mutate(x = NULL,
cat_id = NULL) |> #print(n = Inf)
cat_id = NULL) |>
tidyr::pivot_wider(names_from = set,
values_from = val,
values_fn = list) |>
Expand Down Expand Up @@ -215,32 +215,11 @@ quality_payment <- function(year,
dplyr::ungroup()

if (eligibility) {
by = dplyr::join_by(year, npi, org_id)
npi <- unique(results$npi)
elig <- quality_eligibility(year = year, npi = c(npi))
results <- dplyr::left_join(results, elig,
by = dplyr::join_by(year, npi, org_id, specialty, org_state)) |>
dplyr::select(year,
npi,
npi_type,
first,
middle,
last,
first_approved_date,
years_in_medicare,
participation_type,
specialty,
specialty_type,
specialty_cat,
specialty_code = ind_specialty_code,
org_id,
org_name,
org_address,
org_city,
org_state,
org_zip,
org_size,
dplyr::everything())

results <- dplyr::left_join(results, elig, by) |>
cols_qcomb()
}
}
}
Expand All @@ -259,6 +238,79 @@ quality_payment_ <- function(year = qpp_years(), ...) {
.options = furrr::furrr_options(seed = NULL))
}

#' @autoglobal
#' @noRd
cols_qcomb <- function(df) {

cols <- c('year',
'npi',
'npi_type',
'first',
'middle',
'last',
'state',
'first_approved_date',
'years_in_medicare',
'participation_type',
'beneficiaries',
'services',
'charges' = 'allowed_charges',
'final_score',
'pay_adjust',
'quality_score',
'pi_score',
'ia_score',
'cost_score',
'complex_bonus',
'qi_bonus',
'qp_status',
'qp_score_type',
'ams_mips_eligible',
'newly_enrolled',
'is_maqi',

'org_id',
'org_size',
'org_name',
'org_address',
'org_city',
'org_state',
'org_zip',
'org_hosp_vbp_name',
'org_facility_based',

'apms_id',
'apms_name',
'apms_entity_name',
'apms_sub_id',
'apms_sub_name',
'apms_relationship',

'ind_lvt_status_code',
'ind_lvt_status_desc',
'ind_hosp_vbp_score',

'specialty',

'specialty_desc',
'specialty_type',
'specialty_cat',

'ind_specialty_code',
'ind_specialty_desc',
'ind_specialty_type',
'ind_specialty_cat',

'qpp_status',
'qpp_measures',
'ind_status',
'grp_status',
'apms_status'
)

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

}

#' @autoglobal
#' @noRd
Expand All @@ -268,7 +320,7 @@ cols_qpp <- function(df, step = c("tidy", "nest")) {

cols <- c('year',
'npi',
'org_state' = 'practice_state_or_us_territory',
'state' = 'practice_state_or_us_territory',
'org_size' = 'practice_size',
'specialty' = 'clinician_specialty',
#'med_years' = 'years_in_medicare',
Expand Down Expand Up @@ -318,10 +370,10 @@ cols_qpp <- function(df, step = c("tidy", "nest")) {

cols <- c('year',
'npi',
'org_state',
'state',
'org_size',
'specialty',
'med_years',
# 'med_years',
'participation_type',
'beneficiaries',
'services',
Expand All @@ -337,6 +389,5 @@ cols_qpp <- function(df, step = c("tidy", "nest")) {
'qpp_status',
'qpp_measures')
}

df |> dplyr::select(dplyr::any_of(cols))
}
4 changes: 3 additions & 1 deletion man/add_counties.Rd

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

11 changes: 9 additions & 2 deletions man/quality_eligibility.Rd

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

6 changes: 3 additions & 3 deletions tests/testthat/test-cols.R
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ test_that("cols_qpp() works", {
y <- dplyr::tibble(
year = 1,
npi = 1,
org_state = 1,
state = 1,
org_size = 1,
specialty = 1,
# med_years = 1,
Expand Down Expand Up @@ -481,7 +481,7 @@ test_that("cols_qpp() works", {
z <- dplyr::tibble(
year = 1,
npi = 1,
org_state = 1,
state = 1,
org_size = 1,
specialty = 1,
# med_years = 1,
Expand All @@ -504,7 +504,7 @@ test_that("cols_qpp() works", {
zz <- dplyr::tibble(
year = 1,
npi = 1,
org_state = 1,
state = 1,
org_size = 1,
specialty = 1,
# med_years = 1,
Expand Down
Loading

0 comments on commit cba09b8

Please sign in to comment.