Skip to content

Commit

Permalink
Remove ethnicity_from_sus and comments
Browse files Browse the repository at this point in the history
  • Loading branch information
milanwiedemann committed Oct 3, 2024
1 parent 01af9cf commit 45f7e63
Showing 1 changed file with 16 additions and 34 deletions.
50 changes: 16 additions & 34 deletions analysis/measures_definition_pf_codes_conditions.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
from ehrql import INTERVAL, create_measures, months, case, when
from ehrql.tables.tpp import clinical_events, practice_registrations, patients, addresses, ethnicity_from_sus
from ehrql.tables.tpp import (
clinical_events,
practice_registrations,
patients,
addresses,
)
from codelists import pharmacy_first_conditions_codelist, ethnicity_codelist

measures = create_measures()
Expand All @@ -20,34 +25,12 @@
"pharmacy_first_service": ["983341000000102"],
}

# # Get the latest ethnicity data for each patient
# ethnicity = (
# clinical_events.where(
# clinical_events.snomedct_code.is_in(ethnicity_codelist)
# )
# .sort_by(clinical_events.date)
# .last_for_patient()
# .snomedct_code.to_category(ethnicity_codelist)
# )

# # Get the latest ethnicity data for each patient
# latest_ethnicity_code = (
# clinical_events.where(clinical_events.snomedct_code.is_in(ethnicity_codelist))
# .where(clinical_events.date.is_on_or_before(INTERVAL.start_date))
# .sort_by(clinical_events.date)
# .last_for_patient()
# .snomedct_code
# )

# ethnicity = latest_ethnicity_code.to_category(ethnicity_codelist)

ethnicity = (
clinical_events.where(clinical_events
.snomedct_code.is_in(ethnicity_codelist))
.where(clinical_events.date.is_on_or_before(INTERVAL.start_date))
.sort_by(clinical_events.date)
.last_for_patient()
.snomedct_code
clinical_events.where(clinical_events.snomedct_code.is_in(ethnicity_codelist))
.where(clinical_events.date.is_on_or_before(INTERVAL.start_date))
.sort_by(clinical_events.date)
.last_for_patient()
.snomedct_code
)

ethnicity = ethnicity.to_category(ethnicity_codelist)
Expand All @@ -69,12 +52,12 @@
imd = addresses.for_patient_on(INTERVAL.start_date).imd_rounded
max_imd = 32844
imd_quintile = case(
when((imd >=0) & (imd < int(max_imd * 1 / 5))).then("1"),
when((imd >= 0) & (imd < int(max_imd * 1 / 5))).then("1"),
when(imd < int(max_imd * 2 / 5)).then("2"),
when(imd < int(max_imd * 3 / 5)).then("3"),
when(imd < int(max_imd * 4 / 5)).then("4"),
when(imd <= max_imd).then("5"),
otherwise="Missing"
otherwise="Missing",
)


Expand Down Expand Up @@ -121,7 +104,7 @@
denominator=denominator,
group_by={breakdown: variable},
intervals=months(monthly_intervals).starting_on(start_date),
)
)

# Create measures for pharmacy first conditions
pharmacy_first_conditions_codes = {}
Expand All @@ -144,7 +127,7 @@
numerator=numerator,
denominator=denominator,
intervals=months(monthly_intervals).starting_on(start_date),
)
)

# Nested loop for each breakdown measure in clinical conditions
for breakdown, variable in breakdown_metrics.items():
Expand All @@ -154,5 +137,4 @@
denominator=denominator,
group_by={breakdown: variable},
intervals=months(monthly_intervals).starting_on(start_date),
)

)

0 comments on commit 45f7e63

Please sign in to comment.