-
Notifications
You must be signed in to change notification settings - Fork 0
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
added breakdown graphs and facet function #11
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Excellet! Code looks like it's doing exactly what we want, but I think we can make some sections a bit shorter
age = patients.age_on(INTERVAL.start_date) | ||
age_band = case( | ||
when((age >= 0) & (age < 20)).then("0-19"), | ||
when((age >= 20) & (age < 40)).then("20-39"), | ||
when((age >= 40) & (age < 60)).then("40-59"), | ||
when((age >= 60) & (age < 80)).then("60-79"), | ||
when(age >= 80).then("80+"), | ||
when(age.is_null()).then("Missing"), | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks great!
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" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
although the code does exactly the same as this suggestions in the tutorial, I'd use something like this because it's a bit easier to review and harder to make a mistake:
imd_rounded = addresses.for_patient_on(
INTERVAL.start_date
).imd_rounded
max_imd = 32844
dataset.imd_quintile = case(
when(imd_rounded < int(max_imd * 1 / 5)).then(1),
when(imd_rounded < int(max_imd * 2 / 5)).then(2),
when(imd_rounded < int(max_imd * 3 / 5)).then(3),
when(imd_rounded < int(max_imd * 4 / 5)).then(4),
when(imd_rounded <= max_imd).then(5),
)
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" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to be consistent with the value for "Missing" data, I'd use the same as for age bands here as well
otherwise="unknown" | |
otherwise="Missing" |
# Measures for age breakdown of clinical services | ||
measures.define_measure( | ||
name=f"count_{pharmacy_first_event}_by_age", | ||
numerator=numerator, | ||
denominator=denominator, | ||
group_by={ | ||
"age_band": age_band, | ||
}, | ||
intervals=months(monthly_intervals).starting_on(start_date), | ||
) | ||
|
||
# Measures for sex breakdown of clinical services | ||
measures.define_measure( | ||
name=f"count_{pharmacy_first_event}_by_sex", | ||
numerator=numerator, | ||
denominator=denominator, | ||
group_by={ | ||
"sex": patients.sex, | ||
}, | ||
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), | ||
) | ||
|
||
# Measures for region breakdown of clinical services | ||
measures.define_measure( | ||
name=f"count_{pharmacy_first_event}_by_region", | ||
numerator=numerator, | ||
denominator=denominator, | ||
group_by={ | ||
"region": registration.practice_nuts1_region_name, | ||
}, | ||
intervals=months(monthly_intervals).starting_on(start_date), | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this looks correct, but I think we can make this much shorter if we group by multiple features, see https://docs.opensafely.org/ehrql/explanation/measures/#grouping-by-multiple-features
# Measures for age breakdown of clinical conditions | ||
measures.define_measure( | ||
name=f"count_{condition_name}_by_age", | ||
numerator=numerator, | ||
denominator=denominator, | ||
group_by={ | ||
"age_band": age_band, | ||
}, | ||
intervals=months(monthly_intervals).starting_on(start_date), | ||
) | ||
|
||
# Measures for age breakdown of clinical conditions | ||
measures.define_measure( | ||
name=f"count_{condition_name}_by_sex", | ||
numerator=numerator, | ||
denominator=denominator, | ||
group_by={ | ||
"sex": patients.sex, | ||
}, | ||
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), | ||
) | ||
|
||
# Measures for region breakdown of clinical conditions | ||
measures.define_measure( | ||
name=f"count_{condition_name}_by_region", | ||
numerator=numerator, | ||
denominator=denominator, | ||
group_by={ | ||
"region": registration.practice_nuts1_region_name, | ||
}, | ||
intervals=months(monthly_intervals).starting_on(start_date), | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see comment above, I think we can make this consierably shorter
Closes #10
Closes #12
Closes #13
Closes #14