Skip to content

Commit 2824469

Browse files
committed
Tidied and documented function and measures.
1 parent 988bb1f commit 2824469

File tree

4 files changed

+706
-11
lines changed

4 files changed

+706
-11
lines changed

analysis/report_measures.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from ehrql.tables.tpp import clinical_events, patients, practice_registrations
33

44
measures = create_measures()
5+
measures.configure_dummy_data(population_size=1000)
56

67
# Dictionary of pharmacy first codes
78
pharmacy_first_event_codes = {
@@ -43,8 +44,6 @@
4344
intervals=months(8).starting_on("2023-11-01")
4445
)
4546

46-
measures.configure_dummy_data(population_size=1000)
47-
4847
# # Count pharmacy first codes
4948
# pharmacy_first_code_counts = {}
5049

analysis/reports/pf_report.Rmd

Lines changed: 202 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,202 @@
1+
---
2+
title: "Pharmacy First"
3+
output:
4+
html_document:
5+
toc: true
6+
toc_depth: 4
7+
theme: journal
8+
date: "01-01-2020 through 31-06-2024 by month"
9+
---
10+
```{css, echo=FALSE}
11+
pre {
12+
max-height: 300px;
13+
overflow-y: auto;
14+
}
15+
pre[class] {
16+
max-height: 200px;
17+
}
18+
```
19+
20+
<style>
21+
body {
22+
text-align: justify;
23+
font-size: 11pt}
24+
</style>
25+
26+
27+
28+
```{r setup, include=FALSE}
29+
knitr::opts_chunk$set(echo = FALSE)
30+
31+
library(tidyverse)
32+
library(here)
33+
library(readr)
34+
35+
36+
```
37+
$~$
38+
39+
## Background <a name="background"></a>
40+
41+
Add background here.
42+
43+
$~$
44+
45+
## Methods <a name="methods"></a>
46+
47+
This study used data from OpenSAFELY-TPP, which covers 40% of the population of England. For a description of the representativeness of this sample, please see our manuscript [here](https://wellcomeopenresearch.org/articles/7-191/v1). Individuals were included if they were alive and registered at a TPP practice each month, across the study period. Patients were excluded if their listed age was not between 0 and 120 years.
48+
49+
Counts represent patients with at least one clinical code of relevance in that month. Patients with more than one of the same clinical code in a month were only counted once. Rates divide the count by the included study population and multiply by 1,000 to achieve a rate per 1,000 registered patients.
50+
51+
Counts <=7 have been redacted and all numbers rounded to the nearest 5 to avoid potential re-identification of individuals. The rates displayed were computed with these rounded counts.
52+
53+
Our data relies on a relevant Pharmacy First code being added to a patient's GP record. The Pharmacy First service relies on [GP Connect: Update Record](https://digital.nhs.uk/services/gp-connect/gp-connect-in-your-organisation/gp-connect-update-record) to update a patient's GP record with consultation information from the community pharmacy. Following the launch of the Pharmacy First service, there has been a [gradual roll-out of GP Connect: Update Record](https://cpe.org.uk/our-news/gp-connect-update-record-rollout-and-flow-of-information/) across the approved community pharmacy IT system suppliers.
54+
55+
*Need to complete this*
56+
57+
Links to the codelist for each analysis can be found beneath the relevant section.
58+
59+
This report contains the following sections:
60+
61+
62+
63+
* [Clinical Pathways](#pathways)
64+
* [Clinical condition](#condition)
65+
* [Days of the week](#dotw)
66+
* [NHS region](#region)
67+
* [Ethnicity](#ethnicity)
68+
* [IMD](#imd)
69+
* [Shingles](#shingles)
70+
+ [Sex](#shingles_sex)
71+
+ [Age](#shingles_age)
72+
+ [Ethnicity](#shingles_ethnicity)
73+
+ [IMD](#shingles_imd)
74+
+ [Region](#shingles_region)
75+
+ [Medication supply](#shingles_supply)
76+
* [Urinary tract infection etc.](#urt)
77+
* [Hypertension](#hyp)
78+
* [Age](#hyp_age)
79+
* [Sex](#hyp_sex)
80+
* [Region](#hyp_region)
81+
* [Contraception](#contra)
82+
* [Age](#contra_age)
83+
* [Region](#contra_region)
84+
85+
$~$
86+
87+
## Clinical services
88+
89+
```{r, message=FALSE, warning=FALSE}
90+
# Load plotting function
91+
source(here::here("lib", "functions", "function_plot_measures.R"))
92+
# Load data
93+
df_measures <- readr::read_csv(
94+
here::here("output", "report", "conditions_measures.csv")
95+
)
96+
97+
plot1_conditions <- plot_measures(df_measures,
98+
title = "Number of consultations for each clinical service per month",
99+
x_label = "Month",
100+
y_label = "Number of Consultations",
101+
color_label = "Clinical Service")
102+
print(plot1_conditions)
103+
```
104+
105+
## Clinical Pathways <a name="pathways"></a>
106+
107+
This section focuses on the Clinical Pathways element of that Pharmacy First service.
108+
109+
110+
### Clinical Condition <a name="condition"></a>
111+
112+
This section focuses on the clinical conditions within the Clinical Pathways element of that Pharmacy First service:
113+
114+
#### Counts by clinical condition
115+
Here we show the number of consultations for each of the Pharmacy First Clinical Pathways Clinical Conditions
116+
117+
> LINE CHART WITH COUNT OF EACH CLINICAL CONDITION
118+
119+
### Counts by day of the week <a name="dotw"></a>
120+
Here we show the number of consultations for the Pharmacy First Clinical Pathways by day of the week the consultation was conducted. (Mainly of interest to show what happens at weekends etc e.g. when GP practices are closed).
121+
122+
> BAR CHART WITH COUNT BY DAY OF THE WEEK
123+
124+
### Rates by region <a name="region"></a>
125+
Here we show the rates of consultations for the Pharmacy First Clinical Pathways by the NHS Region in which the patient is registered. (Might not be the region where PF consultation conducted).
126+
127+
> RATES OF ANY PF CLINICAL PATHWAY BY REGION
128+
129+
### Rates by ethnicity <a name="ethnicity"></a>
130+
Here we show the rates of consultations for the Pharmacy First Clinical Pathways by patient ethnicity
131+
132+
> RATES OF ANY PF CLINICAL PATHWAY BY ETHNICITY
133+
134+
### Rates by IMD <a name="imd"></a>
135+
Here we show the rates of consultations for the Pharmacy First Clinical Pathways by IMD (based on patient address)
136+
137+
> RATES OF ANY PF CLINICAL PATHWAY BY IMD
138+
139+
### Shingles <a name="shingles"></a>
140+
Here we show the rates specifically for consultations conducted under the Shingles clinical pathway:
141+
142+
#### Rates by sex <a name="shingles_sex"></a>
143+
Here we show the rates of consultations for the Pharmacy First Shingles Clinical Pathways by sex
144+
145+
> RATES OF SHINGLES CLINICAL PATHWAY BY SEX
146+
147+
#### Rates by age <a name="shingles_age"></a>
148+
Here we show the rates of consultations for the Pharmacy First Shingles Clinical Pathways by age. (Would need to consider age bands as different for each pathway)
149+
150+
> RATES OF SHINGLES CLINICAL PATHWAY BY AGE
151+
152+
#### Rates by ethnicity <a name="shingles_ethnicity"></a>
153+
Here we show the rates of consultations for the Pharmacy First Shingles Clinical Pathways by ethnicity
154+
155+
> RATES OF SHINGLES CLINICAL PATHWAY BY ETHNICITY
156+
157+
#### Rates by IMD <a name="shingles_imd"></a>
158+
Here we show the rates of consultations for the Pharmacy First Shingles Clinical Pathways by IMD
159+
160+
> RATES OF SHINGLES CLINICAL PATHWAY BY IMD
161+
162+
#### Rates by region <a name="shingles_region"></a>
163+
Here we show the rates of consultations for the Pharmacy First Shingles Clinical Pathways by NHS region
164+
165+
> RATES OF SHINGLES CLINICAL PATHWAY BY REGION
166+
167+
#### Rates by medication supply <a name="shingles_supply"></a>
168+
Here we show the percentage of consultations for the Pharmacy First Shingles Clinical Pathways with vs without medication supply. (Could also potentially show details of which medication issued)
169+
170+
> BAR PLOT OF PERCENTAGE OF SHINGLES CLINICAL PATHWAY WITH/WITHOUT MEDICATION SUPPLIED
171+
172+
### Urinary tract infection etc. <a name="urt"></a>
173+
174+
> *placeholder*
175+
176+
## Hypertension <a name="hyp"></a>
177+
178+
*description*
179+
180+
### Age <a name="hyp_age"></a>
181+
182+
> *placeholder*
183+
184+
### Sex <a name="hyp_sex"></a>
185+
186+
> *placeholder*
187+
188+
### Region <a name="hyp_region"></a>
189+
190+
> *placeholder*
191+
192+
## Contraception <a name="contra"></a>
193+
194+
*description*
195+
196+
### Age <a name="contra_age"></a>
197+
198+
> *placeholder*
199+
200+
### Region <a name="contra_region"></a>
201+
202+
> *placeholder*

analysis/reports/pf_report.html

Lines changed: 471 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,36 @@
1+
#' Plot Measures Over Time
2+
#'
3+
#' Creates a line plot of measures over time, with customisable labels and colours.
4+
#'
5+
#' @param data A dataframe containing the data to plot.
6+
#' @param title A string specifying the title of the plot. Default is NULL.
7+
#' @param x_label A string specifying the label for the x-axis. Default is NULL.
8+
#' @param y_label A string specifying the label for the y-axis. Default is NULL.
9+
#' @param color_label A string specifying the label for the color legend. Default is NULL.
10+
#' @param value_col The name of the dataframe column which contains the y-axis values. Default is "numerator".
11+
#' @param measure_col The name of the dataframe column which contains the categorical variable. Default is "measure".
12+
#'
13+
#'
14+
#' @return A ggplot object.
15+
116
plot_measures <- function(
217
data,
18+
date_col = "interval_end",
19+
value_col = "numerator",
20+
measure_col = "measure",
321
title = NULL,
422
x_label = NULL,
5-
y_label = NULL) {
23+
y_label = NULL,
24+
color_label = NULL) {
625

726
# Create plot
8-
plot <- ggplot(
27+
plot1 <- ggplot(
928
data,
1029
aes(
11-
x = interval_end,
12-
y = numerator,
13-
color = measure,
14-
group = measure
30+
x = {{date_col}},
31+
y = {{value_col}},
32+
color = {{measure_col}},
33+
group = {{measure_col}}
1534
)
1635
) +
1736
geom_line() +
@@ -22,10 +41,14 @@ plot_measures <- function(
2241
color = "Condition"
2342
) +
2443
# Setting the minimum y-value
25-
ylim(y_min, NA) +
44+
ylim(0, NA) +
2645
# Applying the minimal theme
27-
theme_minimal()
46+
theme_minimal() +
47+
scale_x_date(
48+
date_breaks = "1 month",
49+
date_labels = "%b %Y",
50+
)
2851

2952
# Return plot
30-
plot
53+
plot1
3154
}

0 commit comments

Comments
 (0)