Skip to content

Commit

Permalink
Import data depending on backend
Browse files Browse the repository at this point in the history
We want to use data from the action if we run this using the OpenSAFELY pipeline/backend. But this also allows us to use released ouputs to generate the report if we run this code in our local development environment.
  • Loading branch information
milanwiedemann committed Oct 15, 2024
1 parent 9653d35 commit 13d082b
Showing 1 changed file with 28 additions and 17 deletions.
45 changes: 28 additions & 17 deletions reports/pharmacy_first_report.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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
)
Expand Down Expand Up @@ -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") %>%
Expand Down Expand Up @@ -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") %>%
Expand Down

0 comments on commit 13d082b

Please sign in to comment.