diff --git a/reports/pharmacy_first_report.Rmd b/reports/pharmacy_first_report.Rmd index 6238925..9402a08 100644 --- a/reports/pharmacy_first_report.Rmd +++ b/reports/pharmacy_first_report.Rmd @@ -19,10 +19,18 @@ library(readr) source(here::here("lib", "functions", "function_tidy_measures.R")) source(here::here("lib", "functions", "function_plot_measures.R")) -# Load data -df_measures <- readr::read_csv( - here::here("output", "measures", "pf_codes_conditions_measures.csv") -) +# Load data based on environment +if (Sys.getenv("OPENSAFELY_BACKEND") != "") { + # Load data from generate_pf_measures action + df_measures <- readr::read_csv( + here::here("output", "measures", "pf_codes_conditions_measures.csv") + ) +} else { + # Load data from released_output directory + df_measures <- readr::read_csv( + here::here("released_output", "measures", "pf_codes_conditions_measures.csv") + ) +} # Define dictionaries with tidy names and mappings for measures pf_measures_name_dict <- list( @@ -72,26 +80,32 @@ df_measures <- tidy_measures( df_measures$ethnicity <- factor( df_measures$ethnicity, - levels = c("White", "Mixed", "Asian or Asian British", - "Black or Black British", "Chinese or Other Ethnic Groups", - "Missing"), + levels = c( + "White", "Mixed", "Asian or Asian British", + "Black or Black British", "Chinese or Other Ethnic Groups", + "Missing" + ), ordered = TRUE ) df_measures$age_band <- factor( df_measures$age_band, - levels = c("0-19", "20-39", "40-59", - "60-79", "80+", - "Missing"), + levels = c( + "0-19", "20-39", "40-59", + "60-79", "80+", + "Missing" + ), ordered = TRUE ) df_measures$region <- factor( df_measures$region, - levels = c("East", "East Midlands", "London", - "North East", "North West", "South East", - "South West", "West Midlands", "Yorkshire and The Humber", - "Missing"), + levels = c( + "East", "East Midlands", "London", + "North East", "North West", "South East", + "South West", "West Midlands", "Yorkshire and The Humber", + "Missing" + ), ordered = TRUE ) @@ -234,8 +248,6 @@ plot_measures( ### Clinical Services by ethnicity ```{r, message=FALSE, warning=FALSE} - - # Select measures and breakdown df_measures_selected <- df_measures %>% filter(measure_desc == "pharmacy_first_services") %>% @@ -372,7 +384,6 @@ plot_measures( ### Clinical Conditions by ethnicity ```{r, message=FALSE, warning=FALSE, fig.height=15, fig.width=8} - # Select measures and breakdown df_measures_selected <- df_measures %>% filter(measure_desc == "clinical_condition") %>%