Skip to content

Commit

Permalink
added breakdown by IMD
Browse files Browse the repository at this point in the history
  • Loading branch information
viv3ckj committed Sep 27, 2024
1 parent b92b58a commit 170181d
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 1 deletion.
36 changes: 35 additions & 1 deletion analysis/measures_definition_pf_codes_conditions.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from ehrql import INTERVAL, create_measures, months, codelist_from_csv, case, when
from ehrql.tables.tpp import clinical_events, practice_registrations, patients
from ehrql.tables.tpp import clinical_events, practice_registrations, patients, addresses

measures = create_measures()
measures.configure_dummy_data(population_size=1000)
Expand Down Expand Up @@ -28,6 +28,7 @@

registration = practice_registrations.for_patient_on(INTERVAL.end_date)

# Age bands for age breakdown
age = patients.age_on(INTERVAL.start_date)
age_band = case(
when((age >= 0) & (age < 20)).then("0-19"),
Expand All @@ -38,6 +39,17 @@
when(age.is_null()).then("Missing"),
)

# IMD groupings for IMD breakdown
imd = addresses.for_patient_on(INTERVAL.start_date).imd_rounded
imd_quintile = case(
when((imd >=0) & (imd < int(32844 * 1 / 5))).then("1 (most deprived)"),
when(imd < int(32844 * 2 / 5)).then("2"),
when(imd < int(32844 * 3 / 5)).then("3"),
when(imd < int(32844 * 4 / 5)).then("4"),
when(imd < int(32844 * 5 / 5)).then("5 (least deprived)"),
otherwise="unknown"
)

# Select clinical events in interval date range
selected_events = clinical_events.where(
clinical_events.date.is_on_or_between(INTERVAL.start_date, INTERVAL.end_date)
Expand Down Expand Up @@ -83,6 +95,17 @@
intervals=months(monthly_intervals).starting_on(start_date),
)

# Measures for IMD breakdown of clinical services
measures.define_measure(
name=f"count_{pharmacy_first_event}_by_imd",
numerator=numerator,
denominator=denominator,
group_by={
"imd": imd_quintile,
},
intervals=months(monthly_intervals).starting_on(start_date),
)

# Create measures for pharmacy first conditions
pharmacy_first_conditions_codes = {}
for codes, term in pharmacy_first_conditions_codelist.items():
Expand Down Expand Up @@ -128,3 +151,14 @@
},
intervals=months(monthly_intervals).starting_on(start_date),
)

# Measures for imd breakdown of clinical conditions
measures.define_measure(
name=f"count_{condition_name}_by_imd",
numerator=numerator,
denominator=denominator,
group_by={
"imd": imd_quintile,
},
intervals=months(monthly_intervals).starting_on(start_date),
)
47 changes: 47 additions & 0 deletions reports/pharmacy_first_report.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,17 @@ pf_clinical_condition_dict_by_sex <- c(
"count_uncomplicated_urinary_tract_infection_by_sex" = "UTI"
)
# Define the custom labels for clinical conditions by IMD
pf_clinical_condition_dict_by_imd <- c(
"count_acute_otitis_media_by_imd" = "Acute Otitis Media",
"count_herpes_zoster_by_imd" = "Herpes Zoster",
"count_acute_sinusitis_by_imd" = "Acute Sinusitis",
"count_impetigo_by_imd" = "Impetigo",
"count_infected_insect_bite_by_imd" = "Infected Insect Bite",
"count_acute_pharyngitis_by_imd" = "Acute Pharyngitis",
"count_uncomplicated_urinary_tract_infection_by_imd" = "UTI"
)
# Define the custom labels for clinical services
pf_clinical_service_dict <- c(
"count_blood_pressure_service" = "Blood Pressure Service",
Expand All @@ -80,6 +91,14 @@ pf_clinical_service_dict_by_sex <- c(
"count_consultation_service_by_sex" = "Consultation Service",
"count_pharmacy_first_service_by_sex" = "Pharmacy First Service"
)
# Define the custom labels for clinical services by IMD
pf_clinical_service_dict_by_imd <- c(
"count_blood_pressure_service_by_imd" = "Blood Pressure Service",
"count_contraception_service_by_imd" = "Contraception Service",
"count_consultation_service_by_imd" = "Consultation Service",
"count_pharmacy_first_service_by_imd" = "Pharmacy First Service"
)
```

# Background
Expand Down Expand Up @@ -140,6 +159,20 @@ plot_measures(df_measures,
rotate_x_labels = TRUE
)
```

### Clinical Services by IMD

```{r, message=FALSE, warning=FALSE}
plot_measures(df_measures,
title = "Number of consultations for each clinical service by IMD per month",
measure_names = names(pf_clinical_service_dict_by_imd),
custom_labels = pf_clinical_service_dict_by_imd,
y_label = "Number of codes for consultations",
facet_var = "imd",
rotate_x_labels = TRUE
)
```
## Clinical Pathways

This section focuses on the Clinical Pathways element of that Pharmacy First service.
Expand Down Expand Up @@ -184,4 +217,18 @@ plot_measures(df_measures,
facet_var = "sex",
rotate_x_labels = TRUE
)
```

### Clinical Conditions by IMD

```{r, message=FALSE, warning=FALSE}
plot_measures(df_measures,
title = "Number of consultations for each clinical condition by IMD per month",
measure_names = names(pf_clinical_condition_dict_by_imd),
custom_labels = pf_clinical_condition_dict_by_imd,
y_label = "Number of codes for consultations",
facet_var = "imd",
rotate_x_labels = TRUE
)
```

0 comments on commit 170181d

Please sign in to comment.