Skip to content

Commit ed865e7

Browse files
committed
Modified legend key and created dictionary for codelist
1 parent 7a80e1f commit ed865e7

File tree

4 files changed

+444
-181
lines changed

4 files changed

+444
-181
lines changed

analysis/report_measures.py

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -15,34 +15,28 @@
1515
# Pharmacy First service (qualifier value)
1616
"pharmacy_first_service": ["983341000000102"],
1717
}
18-
# The following codes come from codelists/user-chriswood-pharmacy-first-clinical-pathway-conditions.csv file.
19-
# Currently written as a hardcoded dictionary to allow for easy for looping (ln66-83), but will be imported from codelist csv in future commits.
20-
# Pharmacy First seven clinical conditions codelist
21-
pharmacy_first_conditions_codes = {
22-
# Community Pharmacy (CP) Blood Pressure (BP) Check Service (procedure)
23-
"acute_otitis_media": ["3110003"],
24-
# Community Pharmacy (CP) Contraception Service (procedure)
25-
"herpes_zoster": ["4740000"],
26-
# Community Pharmacist (CP) Consultation Service for minor illness (procedure)
27-
"acute_sinusitis": ["15805002"],
28-
# Pharmacy First service (qualifier value)
29-
"impetigo": ["48277006"],
30-
# Community Pharmacy (CP) Contraception Service (procedure)
31-
"infected_insect_bite": ["262550002"],
32-
# Community Pharmacist (CP) Consultation Service for minor illness (procedure)
33-
"acute_pharyngitis": ["363746003"],
34-
# Pharmacy First service (qualifier value)
35-
"uncomplicated_urinary_tract_infection": ["1090711000000102"],
36-
}
3718

19+
# Import the codelist from CSV
20+
pharmacy_first_codelist = codelist_from_csv(
21+
"codelists/user-chriswood-pharmacy-first-clinical-pathway-conditions.csv",
22+
column="code", category_column = "term"
23+
)
24+
25+
pharmacy_first_conditions_codes = {}
26+
# Iterate through codelist, forming a dictionary
27+
for codes, term in pharmacy_first_codelist.items():
28+
normalised_term = term.lower().replace(" ", "_")
29+
codes = [codes]
30+
pharmacy_first_conditions_codes[normalised_term] = codes
31+
3832
registration = practice_registrations.for_patient_on(INTERVAL.end_date)
3933

4034
# Select clinical events in interval date range
4135
selected_events = clinical_events.where(
4236
clinical_events.date.is_on_or_between(INTERVAL.start_date, INTERVAL.end_date)
4337
)
4438

45-
# Loop through each condition to create a measure
39+
# Loop through each CLINICAL SERVICE to create a measure
4640
for pharmacy_first_event, codelist in pharmacy_first_event_codes.items():
4741
condition_events = selected_events.where(
4842
clinical_events.snomedct_code.is_in(codelist)
@@ -51,7 +45,6 @@
5145
# Define the numerator as the count of events for the condition
5246
numerator = condition_events.count_for_patient()
5347

54-
5548
# Define the denominator as the number of patients registered
5649
denominator = registration.exists_for_patient()
5750

@@ -62,7 +55,7 @@
6255
intervals=months(8).starting_on("2023-11-01")
6356
)
6457

65-
# Loop through each CLINICAL condition to create a measure
58+
# Loop through each CLINICAL CONDITION to create a measure
6659
for condition_name, condition_code in pharmacy_first_conditions_codes.items():
6760
condition_events = selected_events.where(
6861
clinical_events.snomedct_code.is_in(condition_code)
@@ -71,7 +64,6 @@
7164
# Define the numerator as the count of events for the condition
7265
numerator = condition_events.count_for_patient()
7366

74-
7567
# Define the denominator as the number of patients registered
7668
denominator = registration.exists_for_patient()
7769

analysis/reports/pf_report.Rmd

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,32 @@ df_measures <- readr::read_csv(
9494
here::here("output", "report", "conditions_measures.csv")
9595
)
9696
97+
# Define the custom labels for clinical conditions
98+
clinical_measure_labels <- c(
99+
"count_acute_otitis_media" = "Acute Otitis Media",
100+
"count_herpes_zoster" = "Herpes Zoster",
101+
"count_acute_sinusitis" = "Acute Sinusitis",
102+
"count_impetigo" = "Impetigo",
103+
"count_infected_insect_bite" = "Infected Insect Bite",
104+
"count_acute_pharyngitis" = "Acute Pharyngitis",
105+
"count_uncomplicated_urinary_tract_infection" = "UTI"
106+
)
107+
108+
# Define the custom labels for clinical services
109+
clinical_service_labels <- c(
110+
"count_blood_pressure_service" = "Blood Pressure Service",
111+
"count_contraception_service" = "Contraception Service",
112+
"count_consultation_service" = "Consultation Service",
113+
"count_pharmacy_first_service" = "Pharmacy First Service"
114+
)
115+
116+
```
117+
118+
```{r, message=FALSE, warning=FALSE}
97119
plot_services <- plot_measures(df_measures,
98120
title = "Number of consultations for each clinical service per month",
99-
measure_names = c("count_blood_pressure_service",
100-
"count_contraception_service",
101-
"count_consultation_service",
102-
"count_pharmacy_first_service"),
121+
measure_names = names(clinical_service_labels),
122+
custom_labels = clinical_service_labels,
103123
y_label = "Number of codes for consultations",
104124
)
105125
print(plot_services)
@@ -123,13 +143,8 @@ Here we show the number of consultations for each of the Pharmacy First Clinical
123143
124144
plot_conditions <- plot_measures(df_measures,
125145
title = "Number of consultations for each clinical condition per month",
126-
measure_names = c("count_acute_otitis_media",
127-
"count_herpes_zoster",
128-
"count_acute_sinusitis",
129-
"count_impetigo",
130-
"count_infected_insect_bite",
131-
"count_acute_pharyngitis",
132-
"count_uncomplicated_urinary_tract_infection"),
146+
measure_names = names(clinical_measure_labels),
147+
custom_labels = clinical_measure_labels,
133148
y_label = "Number of codes for consultations",
134149
)
135150
print(plot_conditions)

analysis/reports/pf_report.html

Lines changed: 393 additions & 147 deletions
Large diffs are not rendered by default.

lib/functions/function_plot_measures.R

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#'
55
#' @param data A dataframe containing the data to plot.
66
#' @param measure_names Strings specifiying the names of measure columns to be plotted.
7+
#' @param custom_labels Strings specifying the names of legend labels.
78
#' @param title A string specifying the title of the plot. Default is NULL.
89
#' @param x_label A string specifying the label for the x-axis. Default is NULL.
910
#' @param y_label A string specifying the label for the y-axis. Default is NULL.
@@ -18,6 +19,7 @@
1819
plot_measures <- function(
1920
data,
2021
measure_names,
22+
custom_labels = NULL,
2123
date_col = "interval_end",
2224
value_col = "numerator",
2325
measure_col = "measure",
@@ -49,6 +51,12 @@ plot_measures <- function(
4951
data <- data %>%
5052
filter(!!measure_sym %in% measure_names)
5153

54+
# Apply custom labels if provided
55+
if (!is.null(custom_labels)) {
56+
data <- data %>%
57+
mutate(!!measure_sym := factor(!!measure_sym, levels = measure_names, labels = custom_labels))
58+
}
59+
5260
# Create plot
5361
plot1 <- ggplot(
5462
data,
@@ -66,6 +74,8 @@ plot_measures <- function(
6674
y = y_label,
6775
color = color_label
6876
) +
77+
geom_point() +
78+
geom_line(alpha = .5) +
6979
scale_y_continuous(
7080
limits = c(0, NA),
7181
) +

0 commit comments

Comments
 (0)