Skip to content

Commit 685dfc5

Browse files
Merge pull request #40 from opensafely/milanwiedemann/update-import-data
Import data depending on backend
2 parents 9653d35 + 13d082b commit 685dfc5

File tree

1 file changed

+28
-17
lines changed

1 file changed

+28
-17
lines changed

reports/pharmacy_first_report.Rmd

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,18 @@ library(readr)
1919
source(here::here("lib", "functions", "function_tidy_measures.R"))
2020
source(here::here("lib", "functions", "function_plot_measures.R"))
2121
22-
# Load data
23-
df_measures <- readr::read_csv(
24-
here::here("output", "measures", "pf_codes_conditions_measures.csv")
25-
)
22+
# Load data based on environment
23+
if (Sys.getenv("OPENSAFELY_BACKEND") != "") {
24+
# Load data from generate_pf_measures action
25+
df_measures <- readr::read_csv(
26+
here::here("output", "measures", "pf_codes_conditions_measures.csv")
27+
)
28+
} else {
29+
# Load data from released_output directory
30+
df_measures <- readr::read_csv(
31+
here::here("released_output", "measures", "pf_codes_conditions_measures.csv")
32+
)
33+
}
2634
2735
# Define dictionaries with tidy names and mappings for measures
2836
pf_measures_name_dict <- list(
@@ -72,26 +80,32 @@ df_measures <- tidy_measures(
7280
7381
df_measures$ethnicity <- factor(
7482
df_measures$ethnicity,
75-
levels = c("White", "Mixed", "Asian or Asian British",
76-
"Black or Black British", "Chinese or Other Ethnic Groups",
77-
"Missing"),
83+
levels = c(
84+
"White", "Mixed", "Asian or Asian British",
85+
"Black or Black British", "Chinese or Other Ethnic Groups",
86+
"Missing"
87+
),
7888
ordered = TRUE
7989
)
8090
8191
df_measures$age_band <- factor(
8292
df_measures$age_band,
83-
levels = c("0-19", "20-39", "40-59",
84-
"60-79", "80+",
85-
"Missing"),
93+
levels = c(
94+
"0-19", "20-39", "40-59",
95+
"60-79", "80+",
96+
"Missing"
97+
),
8698
ordered = TRUE
8799
)
88100
89101
df_measures$region <- factor(
90102
df_measures$region,
91-
levels = c("East", "East Midlands", "London",
92-
"North East", "North West", "South East",
93-
"South West", "West Midlands", "Yorkshire and The Humber",
94-
"Missing"),
103+
levels = c(
104+
"East", "East Midlands", "London",
105+
"North East", "North West", "South East",
106+
"South West", "West Midlands", "Yorkshire and The Humber",
107+
"Missing"
108+
),
95109
ordered = TRUE
96110
)
97111
@@ -234,8 +248,6 @@ plot_measures(
234248
### Clinical Services by ethnicity
235249

236250
```{r, message=FALSE, warning=FALSE}
237-
238-
239251
# Select measures and breakdown
240252
df_measures_selected <- df_measures %>%
241253
filter(measure_desc == "pharmacy_first_services") %>%
@@ -372,7 +384,6 @@ plot_measures(
372384
### Clinical Conditions by ethnicity
373385

374386
```{r, message=FALSE, warning=FALSE, fig.height=15, fig.width=8}
375-
376387
# Select measures and breakdown
377388
df_measures_selected <- df_measures %>%
378389
filter(measure_desc == "clinical_condition") %>%

0 commit comments

Comments
 (0)