Skip to content

Commit

Permalink
Create new msoa measures, and add action
Browse files Browse the repository at this point in the history
  • Loading branch information
viv3ckj committed Jan 14, 2025
1 parent 1d073ba commit 9431d0b
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 14 deletions.
2 changes: 0 additions & 2 deletions analysis/measures_definition_pf_breakdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@
otherwise="Missing",
)

msoa_code = addresses.for_patient_on(INTERVAL.start_date).msoa_code
pharmacy_first_ids = select_events(clinical_events, codelist=pf_consultation_events_dict["pf_consultation_services_combined"]).consultation_id

# # Select clinical events in interval date range
Expand All @@ -74,7 +73,6 @@
"imd": imd_quintile,
"region": latest_region,
"ethnicity": ethnicity_combined,
"msoa_code": msoa_code
}

# Define the denominator as the number of patients registered
Expand Down
39 changes: 39 additions & 0 deletions analysis/measures_definition_pf_deciles_table.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
from ehrql import INTERVAL, create_measures, months
from ehrql.tables.tpp import (
clinical_events,
practice_registrations,
patients,
addresses,
)

from codelists import pf_consultation_events_dict
from config import start_date_measure_pf_breakdown, monthly_intervals_measure_pf_breakdown
from pf_variables_library import select_events

measures = create_measures()
measures.configure_dummy_data(population_size=1000)

start_date = start_date_measure_pf_breakdown
monthly_intervals = monthly_intervals_measure_pf_breakdown

registration = practice_registrations.for_patient_on(INTERVAL.end_date)
msoa_code = addresses.for_patient_on(INTERVAL.start_date).msoa_code
pharmacy_first_ids = select_events(clinical_events, codelist=pf_consultation_events_dict["pf_consultation_services_combined"]).consultation_id
# # Select clinical events in interval date range
selected_events = select_events(clinical_events, start_date=INTERVAL.start_date, end_date=INTERVAL.end_date).where(
clinical_events.consultation_id.is_in(pharmacy_first_ids)
)

# Define the denominator as the number of patients registered
denominator = registration.exists_for_patient() & patients.sex.is_in(["male", "female"])

condition_events = select_events(select_events, codelist=pf_consultation_events_dict["pf_consultation_services_combined"])
numerator = condition_events.count_for_patient()

measures.define_measure(
name="count_pf_consultation_services_by_msoa",
numerator=numerator,
denominator=denominator,
group_by=msoa_code,
intervals=months(monthly_intervals).starting_on(start_date),
)
11 changes: 0 additions & 11 deletions lib/functions/plot_measures.R
Original file line number Diff line number Diff line change
Expand Up @@ -161,17 +161,6 @@ save_figure <- function(figure, width = 10, height = 6) {
)
}

compute_deciles <- function(data, column, measure_column, date_column) {
decile_probs <- seq(10, 90, 10)
data %>%
reframe(
measure = first(measure_column),
date = first(date_column),
decile_values = quantile(column, decile_probs),
decile_labels = decile_probs
)
}

# Colour palettes
gradient_palette <- c("#001F4D", "#0056B3", "#007BFF", "#66B3E2", "#A4D8E1", "grey")
region_palette <- c("red", "navy", "#018701", "#ffa600ca", "purple", "brown", "#f4a5b2", "cyan", "green", "grey")
Expand Down
20 changes: 19 additions & 1 deletion project.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,22 @@ actions:
--output output/measures/consultation_med_counts_measures.csv
outputs:
moderately_sensitive:
measure: output/measures/consultation_med_counts_measures.csv
measure: output/measures/consultation_med_counts_measures.csv

generate_measures_deciles_table:
run: >
ehrql:v1 generate-measures analysis/measures_definition_pf_deciles_table.py
--dummy-tables dummy_tables
--output output/measures/deciles_measures.csv
outputs:
highly_sensitive:
cohort: output/measures/deciles_measures.csv

generate_deciles:
run: >
ehrql:v1 generate-measures analysis/measures_definition_pf_consultation_med_counts.py
--dummy-tables dummy_tables
--output output/measures/consultation_med_counts_measures.csv
outputs:
moderately_sensitive:
measure: output/measures/consultation_med_counts_measures.csv

0 comments on commit 9431d0b

Please sign in to comment.