Skip to content

Commit

Permalink
quality_eligibility nested boolean output (#61)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewallenbruce committed Nov 29, 2023
1 parent c5a6d10 commit 7f6383a
Show file tree
Hide file tree
Showing 6 changed files with 200 additions and 162 deletions.
6 changes: 6 additions & 0 deletions R/globals.R
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,12 @@ utils::globalVariables(c(
"grp", # <quality_eligibility>
"npi_type", # <quality_eligibility>
"org_state", # <quality_eligibility>
"results", # <cols_qelig>
"year", # <cols_qelig>
"npi", # <cols_qelig>
"org_name", # <cols_qelig>
"value", # <cols_qelig>
"name", # <cols_qelig>
"distro", # <quality_payment>
"y", # <quality_payment>
"set", # <quality_payment>
Expand Down
175 changes: 167 additions & 8 deletions R/quality_eligibility.R
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ quality_eligibility <- function(year,
npi,
tidy = TRUE,
unnest = TRUE,
pivot = FALSE,
na.rm = FALSE,
pivot = TRUE,
na.rm = TRUE,
...) {

rlang::check_required(year)
Expand Down Expand Up @@ -169,12 +169,13 @@ quality_eligibility <- function(year,
unnest_if_name('grp.lowVolumeStatusReasons', wide = TRUE) |>
unnest_if_name('grp.isEligible') |>
unnest_if_name('error') |>
cols_qelig()
cols_qelig('tidyup')

results <- tidyup(results,
dtype = 'ymd',
int = c('year',
'years_in_medicare',
'ind_hosp_vbp_score',
# 'apms_lvt_patients',
# 'apms_lvt_year'
'pecos_year'),
Expand Down Expand Up @@ -204,6 +205,7 @@ quality_eligibility <- function(year,
'ind_hospital_based',
'ind_hpsa',
'ind_ia_study',
'ind_opted_in',
'ind_opt_in_eligible',
'ind_mips_switch',
'ind_non_patient',
Expand All @@ -228,6 +230,7 @@ quality_eligibility <- function(year,
'grp_hospital_based',
'grp_hpsa',
'grp_ia_study',
'grp_opted_in',
'grp_opt_in_eligible',
'grp_mips_switch',
'grp_non_patient',
Expand All @@ -238,7 +241,14 @@ quality_eligibility <- function(year,
dplyr::mutate(npi_type = fct_entype(npi_type),
org_state = fct_stabb(org_state))
}
if (pivot) {}
if (pivot) {

results <- cols_qelig(results, 'top') |>
dplyr::left_join(cols_qelig(results, 'apms')) |>
dplyr::left_join(cols_qelig(results, 'ind')) |>
dplyr::left_join(cols_qelig(results, 'grp'))

}
if (na.rm) results <- narm(results)
}
return(results)
Expand All @@ -265,9 +275,12 @@ unnest_if_name <- function(df, name, unpack = TRUE, wide = FALSE) {
}

#' @param df data frame
#' @param type description
#' @autoglobal
#' @noRd
cols_qelig <- function(df) {
cols_qelig <- function(df, type = c('tidyup', 'top', 'apms', 'ind', 'grp')) {

if (type == 'tidyup') {

cols <- c('year' = 'year',
'npi' = 'npi',
Expand All @@ -281,7 +294,7 @@ cols_qelig <- function(df) {
'newly_enrolled' = 'newlyEnrolled',
'specialty_desc' = 'specialty.specialtyDescription',
'specialty_type' = 'specialty.typeDescription',
'specialty_category' = 'specialty.categoryReference',
'specialty_cat' = 'specialty.categoryReference',
'is_maqi' = 'isMaqi',
'org_name' = 'organizations_prvdrOrgName',
'org_hosp_vbp_name' = 'organizations_hospitalVbpName',
Expand Down Expand Up @@ -364,7 +377,7 @@ cols_qelig <- function(df) {
# 'ind_scenario' = 'ind.eligibilityScenario',

'grp_hardship_pi' = 'grp.aciHardship',
'grp_hardship_reweight' = 'grp.aciReweighting',
'grp_reweight_pi' = 'grp.aciReweighting',
'grp_asc' = 'grp.ambulatorySurgicalCenter',
'grp_ext_hardship' = 'grp.extremeHardship',
'grp_ext_hardship_quality' = 'grp.extremeHardshipReasons.quality',
Expand All @@ -388,8 +401,154 @@ cols_qelig <- function(df) {
'grp_eligible' = 'grp.isEligible.group'
# 'grp_agg_level' = 'grp.aggregationLevel',
)
return(df |> dplyr::select(dplyr::any_of(cols)))
}

if (type == 'top') {

cols <- c('year',
'npi',
'npi_type',
'first',
'middle',
'last',
'first_approved_date',
'years_in_medicare',
'pecos_year',
'newly_enrolled',
'specialty_desc',
'specialty_type',
'specialty_cat',
'is_maqi',
'org_name',
'org_hosp_vbp_name',
'org_facility_based',
'org_address',
'org_city',
'org_state',
'org_zip',
'qp_status',
'ams_mips_eligible',
'qp_score_type',
'error_message',
'error_type')

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

}

df |> dplyr::select(dplyr::any_of(cols))
if (type == 'apms') {

apm_flags <- c(
'Advanced APM' = 'apms_advanced',
'Below Low Volume Threshold' ='apms_lvt',
'Small Practice Status' = 'apms_lvt_small',
'MIPS APM' = 'apms_mips_apm',
'Extreme Hardship' = 'apms_ext_hardship',
'Extreme Hardship (Performance Improvement)' = 'apms_ext_hardship_pi',
'Extreme Hardship (Cost)' = 'apms_ext_hardship_cost',
'Extreme Hardship (Improvement Activities)' = 'apms_ext_hardship_ia',
'Extreme Hardship (Quality)' = 'apms_ext_hardship_quality'
)

return(results |>
dplyr::select(year,
npi,
org_name,
dplyr::contains('apms_')) |>
dplyr::rename(dplyr::any_of(apm_flags)) |>
tidyr::pivot_longer(cols = dplyr::any_of(names(apm_flags))) |>
dplyr::filter(!is.na(value)) |>
dplyr::filter(value == TRUE) |>
dplyr::mutate(value = NULL) |>
tidyr::nest(apms_status = name) |>
janitor::remove_empty(which = c("rows", "cols")))

}

if (type == 'ind') {

ind_flags <- c(
'Hardship (Performance Improvement)' = 'ind_hardship_pi',
'Reweighting (Performance Improvement)' = 'ind_reweight_pi',
'Ambulatory Surgical Center' = 'ind_asc',
'Extreme Hardship' = 'ind_ext_hardship',
'Extreme Hardship (Quality)' = 'ind_ext_hardship_quality',
'Extreme Hardship (Improvement Activities)' = 'ind_ext_hardship_ia',
'Extreme Hardship (Performance Improvement)' = 'ind_ext_hardship_pi',
'Extreme Hardship (Cost)' = 'ind_ext_hardship_cost',
'Hospital-based Clinician' = 'ind_hospital_based',
'HPSA Clinician' = 'ind_hpsa',
'Improvement Activities Study' = 'ind_ia_study',
'Has Opted In' = 'ind_opted_in',
'Is Opt-In Eligible' = 'ind_opt_in_eligible',
'MIPS Eligible Clinician' = 'ind_mips_switch',
'Non-Patient Facing' = 'ind_non_patient',
'Rural Clinician' = 'ind_rural',
'Small Group Practitioner' = 'ind_small',
'Below Low Volume Threshold' = 'ind_lvt_switch',
'Has Payment Adjustment CCN' = 'ind_has_payment_adjustment_ccn',
'Has Hospital Value-Based CCN' = 'ind_has_hospital_vbp_ccn',
'Facility-based Clinician' = 'ind_facility',
'Eligible: Individual' = 'ind_eligible_ind',
'Eligible: Group' = 'ind_eligible_group',
'Eligible: APM' = 'ind_eligible_apm',
'Eligible: Virtual Group' = 'ind_eligible_virtual'
)

return(results |>
dplyr::select(year,
npi,
org_name,
dplyr::contains('ind_')) |>
dplyr::rename(dplyr::any_of(ind_flags)) |>
tidyr::pivot_longer(cols = dplyr::any_of(names(ind_flags))) |>
dplyr::filter(!is.na(value)) |>
dplyr::filter(value == TRUE) |>
dplyr::mutate(value = NULL) |>
tidyr::nest(ind_status = name) |>
janitor::remove_empty(which = c("rows", "cols")))

}

if (type == 'grp') {

grp_flags <- c(
'Hardship (Performance Improvement)' = 'grp_hardship_pi',
'Reweighting (Performance Improvement)' = 'grp_reweight_pi',
'Ambulatory Surgical Center' = 'grp_asc',
'Extreme Hardship' = 'grp_ext_hardship',
'Extreme Hardship (Quality)' = 'grp_ext_hardship_quality',
'Extreme Hardship (Improvement Activities)' = 'grp_ext_hardship_ia',
'Extreme Hardship (Performance Improvement)' = 'grp_ext_hardship_pi',
'Extreme Hardship (Cost)' = 'grp_ext_hardship_cost',
'Hospital-based Clinician' = 'grp_hospital_based',
'HPSA Clinician' = 'grp_hpsa',
'Improvement Activities Study' = 'grp_ia_study',
'Has Opted In' = 'grp_opted_in',
'Is Opt-In Eligible' = 'grp_opt_in_eligible',
'MIPS Eligible Clinician' = 'grp_mips_switch',
'Non-Patient Facing' = 'grp_non_patient',
'Rural Clinician' = 'grp_rural',
'Small Group Practitioner' = 'grp_small',
'Below Low Volume Threshold' = 'grp_lvt_switch',
'Eligible: Group' = 'grp_eligible'
)

return(results |>
dplyr::select(year,
npi,
org_name,
dplyr::contains('grp_')) |>
dplyr::rename(dplyr::any_of(grp_flags)) |>
tidyr::pivot_longer(cols = dplyr::any_of(names(grp_flags))) |>
dplyr::filter(!is.na(value)) |>
dplyr::filter(value == TRUE) |>
dplyr::mutate(value = NULL) |>
tidyr::nest(grp_status = name) |>
janitor::remove_empty(which = c("rows", "cols")))

}
}


Expand Down
12 changes: 10 additions & 2 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ knitr::opts_chunk$set(

> Providing easy access to [healthcare provider](https://en.wikipedia.org/wiki/Health_care_provider) data through publicly available APIs.
# :arrow_double_down: Installation
## :arrow_double_down: Installation

You can install __`provider`__ from [GitHub](https://github.com/) with:

Expand All @@ -40,7 +40,7 @@ You can install __`provider`__ from [GitHub](https://github.com/) with:
pak::pak("andrewallenbruce/provider")
```

# :beginner: Usage
## :beginner: Usage

```{r echo=TRUE, message=FALSE, warning=FALSE}
library(provider)
Expand Down Expand Up @@ -191,6 +191,14 @@ select(q, year, measures) |>
unnest(measures)
```

### `quality_eligibility()`

```{r}
quality_eligibility(year = 2021,
npi = 1932365699) |>
dplyr::glimpse()
```

### `reassignments()`

```{r}
Expand Down
14 changes: 12 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ milestone](https://img.shields.io/github/milestones/progress/andrewallenbruce/pr
> provider](https://en.wikipedia.org/wiki/Health_care_provider) data
> through publicly available APIs.
# :arrow_double_down: Installation
## :arrow_double_down: Installation

You can install **`provider`** from [GitHub](https://github.com/) with:

Expand All @@ -32,7 +32,7 @@ You can install **`provider`** from [GitHub](https://github.com/) with:
pak::pak("andrewallenbruce/provider")
```

# :beginner: Usage
## :beginner: Usage

``` r
library(provider)
Expand Down Expand Up @@ -501,6 +501,16 @@ select(q, year, measures) |>
#> 5 2021 Quality 1 0
#> 6 2021 Quality 117 0

### `quality_eligibility()`

``` r
quality_eligibility(year = 2021,
npi = 1932365699) |>
dplyr::glimpse()
```

#> Error in dplyr::select(results, year, npi, org_name, dplyr::contains("apms_")): object 'results' not found

### `reassignments()`

``` r
Expand Down
4 changes: 2 additions & 2 deletions man/quality_eligibility.Rd

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

Loading

0 comments on commit 7f6383a

Please sign in to comment.