For the tutorial, we plan to help users work through writing ehrQL queries related to the following QOF rules for diabetes:
DM_REG Patients aged at least 17 years old with an unresolved diabetes diagnosis.
DM_006 The percentage of patients with diabetes, on the register, with a diagnosis of nephropathy (clinical proteinuria) or micro-albuminuria who are currently treated with an ACE-I (or ARBs).
DM014 The percentage of patients newly diagnosed with diabetes, on the register, in the preceding 1 April to 31 March who have a record of being referred to a structured education programme within 9 months after entry on to the diabetes register.
DM020 The percentage of patients with diabetes, on the register, without moderate or severe frailty in whom the last IFCC-HbA1c is 58 mmol/mol or less in the preceding 12 months.
For this, we'll need example data with the following properties:
100 patients
90 patients alive on 31st March 2024
90 patients registered on 31st March 2024
Clinical event codes
all events should be between 1st April 2022 and 31st March 2024
diabetes status:
75 patients with a diabetes diagnosis code and no diabetes resolved code
5 patients with a diabetes diagnosis code followed by a diabetes resolved code
5 patients with a diabetes diagnosis code followed by a diabetes resolved code, followed by another diagnosis code
frailty status:
5 patients with a mild frailty code followed by a moderate frailty code
5 patients with a moderate frailty code followed by a mild frailty code
10 patients with a moderate frailty code
10 patients with a severe frailty code
HbA1c status
20 patients with HbA1c code with "low" value (between 38 and 58)
20 patients with HbA1c code with "high" value (between 58 and 78)
10 patients with HbA1c code with low value followed by HbA1c code with high value
10 patients with HbA1c code with high value followed by HbA1c code with low value
other
10 patients with nephropathy code
10 patients with micro-albuminuria code
20 patients with structured education programme code
Prescriptions
all events should be between 1st April 2022 and 31st March 2024
10 patients with prescription of ARB
10 patients with prescription of ACE-I
For now, we should use arbitrary numbers to be the code for each kind of event/prescription:
diabetes diagnosis 111
diabetes resolved 222
mild frailty 333
moderate frailty 444
severe frailty 555
hba1c 666
nephropath 777
micro-albuminuria 888
structured education programme 999
Here's some example code that could be adapted to create diabetes events.
if random.random() < 0.75:
# patient has a diabetes diagnosis code and no diabetes resolved code
yield "clinical_events", {"date": date, "dmd_code": 111}
elif random.random() < 0.05:
# patient has a diabetes diagnosis code followed by a diabetes resolved code
yield "clinical_events", {"date": date1, "dmd_code": 111}
yield "clinical_events", {"date": date2, "dmd_code": 222}
elif random.random() < 0.05:
# patient has a diabetes diagnosis code followed by a diabetes resolved code, followed by another diagnosis code
yield "clinical_events", {"date": date1, "dmd_code": 111}
yield "clinical_events", {"date": date2, "dmd_code": 222}
yield "clinical_events", {"date": date3, "dmd_code": 111}
For the tutorial, we plan to help users work through writing ehrQL queries related to the following QOF rules for diabetes:
For this, we'll need example data with the following properties:
For now, we should use arbitrary numbers to be the code for each kind of event/prescription:
Here's some example code that could be adapted to create diabetes events.