Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Viv3ckj/update ethnicity #28

Merged
merged 5 commits into from
Oct 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 36 additions & 9 deletions analysis/measures_definition_pf_codes_conditions.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
practice_registrations,
patients,
addresses,
ethnicity_from_sus,
)
from codelists import pharmacy_first_conditions_codelist, ethnicity_codelist

Expand All @@ -27,23 +28,49 @@

registration = practice_registrations.for_patient_on(INTERVAL.end_date)

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

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"),
latest_ethnicity_from_codes = case(
when(latest_ethnicity_from_codes_category_num == "1").then("White"),
when(latest_ethnicity_from_codes_category_num == "2").then("Mixed"),
when(latest_ethnicity_from_codes_category_num == "3").then(
"Asian or Asian British"
),
when(latest_ethnicity_from_codes_category_num == "4").then(
"Black or Black British"
),
when(latest_ethnicity_from_codes_category_num == "5").then(
"Chinese or Other Ethnic Groups"
),
)

ethnicity_from_sus = case(
when(ethnicity_from_sus.code.is_in(["A", "B", "C"])).then("White"),
when(ethnicity_from_sus.code.is_in(["D", "E", "F", "G"])).then("Mixed"),
when(ethnicity_from_sus.code.is_in(["H", "J", "K", "L"])).then(
"Asian or Asian British"
),
when(ethnicity_from_sus.code.is_in(["M", "N", "P"])).then("Black or Black British"),
when(ethnicity_from_sus.code.is_in(["R", "S"])).then(
"Chinese or Other Ethnic Groups"
),
)

ethnicity_combined = case(
when(latest_ethnicity_from_codes.is_not_null()).then(latest_ethnicity_from_codes),
when(latest_ethnicity_from_codes.is_null() & ethnicity_from_sus.is_not_null()).then(
ethnicity_from_sus
),
otherwise="Missing",
)


# Age bands for age breakdown
age = patients.age_on(INTERVAL.start_date)
age_band = case(
Expand Down Expand Up @@ -85,7 +112,7 @@
"sex": patients.sex,
"imd": imd_quintile,
"region": latest_region,
"ethnicity": latest_ethnicity_category_desc,
"ethnicity": ethnicity_combined,
}

# Define the denominator as the number of patients registered
Expand Down