Skip to content

Commit

Permalink
Add ethnicity description
Browse files Browse the repository at this point in the history
  • Loading branch information
milanwiedemann committed Oct 3, 2024
1 parent 45f7e63 commit 40a7663
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions analysis/measures_definition_pf_codes_conditions.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,24 @@
"pharmacy_first_service": ["983341000000102"],
}

ethnicity = (
registration = practice_registrations.for_patient_on(INTERVAL.end_date)

latest_ethnicity_category_num = (
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
.snomedct_code.to_category(ethnicity_codelist)
)

ethnicity = ethnicity.to_category(ethnicity_codelist)

registration = practice_registrations.for_patient_on(INTERVAL.end_date)
latest_ethnicity_category_desc = case(
when(latest_ethnicity_category_num == "1").then("White"),
when(latest_ethnicity_category_num == "2").then("Mixed"),
when(latest_ethnicity_category_num == "3").then("Asian or Asian British"),
when(latest_ethnicity_category_num == "4").then("Black or Black British"),
when(latest_ethnicity_category_num == "5").then("Chinese or Other Ethnic Groups"),
when(latest_ethnicity_category_num.is_null()).then("Missing"),
)

# Age bands for age breakdown
age = patients.age_on(INTERVAL.start_date)
Expand All @@ -60,7 +67,6 @@
otherwise="Missing",
)


# 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 All @@ -72,13 +78,12 @@
"sex": patients.sex,
"imd": imd_quintile,
"region": registration.practice_nuts1_region_name,
"ethnicity": ethnicity,
"ethnicity": latest_ethnicity_category_desc,
}

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


# Create measures for pharmacy first services
for pharmacy_first_event, codelist in pharmacy_first_event_codes.items():
condition_events = selected_events.where(
Expand Down

0 comments on commit 40a7663

Please sign in to comment.