generated from opensafely/sro-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdict_bp_variables.py
269 lines (266 loc) · 8.77 KB
/
dict_bp_variables.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
# Define common variables needed across indicators here
# See https://docs.opensafely.org/study-def-tricks/
import pandas as pd
from config import start_date, end_date
from cohortextractor import patients
from codelists_bp import (
bp_codes,
bp_dec_codes,
)
# Define dictionary of variables needed for blood pressure indicator BP002:
bp002_variables_5y_lookback = dict(
# Denominator Rule Number 1
# Description: Reject patients from the specified population who are
# aged less than 45 years old.
bp002_denominator_r1=patients.satisfying(
"""
age >= 45
"""
),
# Denominator Rule Number 2
# NOTE: This is same as Numerator Rule Number 1
# Description: Select patients passed to this rule who had their blood
# pressure recorded in the 5 year period leading up to and including
# the payment period end date.
bp002_denominator_r2=patients.satisfying(
"""
bp_rec_5y
""",
bp_rec_5y=patients.with_these_clinical_events(
codelist=bp_codes,
between=[
"first_day_of_month(index_date) - 5 years",
"last_day_of_month(index_date)",
],
returning="binary_flag",
return_expectations={"incidence": 0.5},
),
),
# Denominator Rule Number 3
# Description: Reject patients passed to this rule chose not to have
# their blood pressure recorded in the 5 year period leading up to and
# including the payment period end date.
bp002_denominator_r3=patients.satisfying(
"""
NOT bp_dec_5y
""",
bp_dec_5y=patients.with_these_clinical_events(
between=[
"first_day_of_month(index_date) - 5 years",
"last_day_of_month(index_date)",
],
codelist=bp_dec_codes,
returning="binary_flag",
),
),
# Define exclusion variable for denominator rule 3
# to be used as numerator in measures
bp002_excl_denominator_r3=patients.satisfying(
"""
bp_dec_5y
"""
),
# Denominator Rule Number 4
# Description: Reject patients passed to this rule who registered with
# the GP practice in the 3 month period leading up to and including
# the payment period end date.
bp002_denominator_r4=patients.satisfying(
"""
reg_dat_3m
""",
# NOTE: This variable selects patients that were registered with one
# practice in the last 3 months. Therefore, this variable (reg_dat_3m)
# specifies the patients that need to be selected for in the
# denominator.
reg_dat_3m=patients.registered_with_one_practice_between(
start_date="index_date - 3 months",
end_date="index_date",
return_expectations={"incidence": 0.1},
),
),
# Define exclusion variable for denominator rule 4
# to be used as numerator in measures
bp002_excl_denominator_r4=patients.satisfying(
"""
NOT reg_dat_3m
"""
),
# Add flowchart counts for each select / reject rule
# NOTE: Some of these variables are coded as "select" variables
# and not "reject" as specified in the business rules
bp002_denominator_r1_reject=patients.satisfying(
"""
bp002_denominator_r1
"""
),
bp002_denominator_r2_select=patients.satisfying(
"""
bp002_denominator_r1 AND
bp002_denominator_r2
"""
),
bp002_denominator_r3_reject=patients.satisfying(
"""
bp002_denominator_r1 AND
(NOT bp002_denominator_r2) AND
bp_dec_5y
"""
),
bp002_denominator_r4_reject=patients.satisfying(
"""
bp002_denominator_r1 AND
(NOT bp002_denominator_r2) AND
bp002_denominator_r3 AND
(NOT reg_dat_3m)
"""
),
bp002_denominator=patients.satisfying(
"""
bp002_denominator_r1 AND
(bp002_denominator_r2 OR
(bp002_denominator_r3 AND
bp002_denominator_r4)
)
"""
),
bp002_numerator=patients.satisfying(
"""
# Numerator Rule Number 1
# NOTE: This is same as Denominator Rule Number 2
# Description: Select patients from the denominator who had their
# blood pressure recorded in the 5 year period leading up to and
# including the payment period end date. Reject the remaining patients.
bp002_denominator AND
bp002_denominator_r2
"""
),
)
# Define dictionary of variables needed for blood pressure indicator BP002
# with 1 year lookback:
bp002_variables_1y_lookback = dict(
# Denominator Rule Number 1
# Description: Reject patients from the specified population who are
# aged less than 45 years old.
bp002_denominator_r1=patients.satisfying(
"""
age >= 45
"""
),
# Denominator Rule Number 2
# NOTE: This is same as Numerator Rule Number 1
# Description: Select patients passed to this rule who had their blood
# pressure recorded in the *1 year* period leading up to and including
# the payment period end date.
bp002_denominator_r2=patients.satisfying(
"""
bp_rec_1y
""",
bp_rec_1y=patients.with_these_clinical_events(
codelist=bp_codes,
between=[
"first_day_of_month(index_date) - 1 year",
"last_day_of_month(index_date)",
],
returning="binary_flag",
return_expectations={"incidence": 0.5},
),
),
# Denominator Rule Number 3
# Description: Reject patients passed to this rule chose not to have
# their blood pressure recorded in the *1 year* period leading up to and
# including the payment period end date.
bp002_denominator_r3=patients.satisfying(
"""
NOT bp_dec_1y
""",
bp_dec_1y=patients.with_these_clinical_events(
between=[
"first_day_of_month(index_date) - 1 year",
"last_day_of_month(index_date)",
],
codelist=bp_dec_codes,
returning="binary_flag",
),
),
# Define exclusion variable for denominator rule 3
# to be used as numerator in measures
bp002_excl_denominator_r3=patients.satisfying(
"""
bp_dec_1y
"""
),
# Denominator Rule Number 4
# Description: Reject patients passed to this rule who registered with
# the GP practice in the 3 month period leading up to and including
# the payment period end date.
bp002_denominator_r4=patients.satisfying(
"""
reg_dat_3m
""",
# NOTE: This variable selects patients that were registered with one
# practice in the last 3 months. Therefore, this variable (reg_dat_3m)
# specifies the patients that need to be selected for in the
# denominator.
reg_dat_3m=patients.registered_with_one_practice_between(
start_date="index_date - 3 months",
end_date="index_date",
return_expectations={"incidence": 0.1},
),
),
# Define exclusion variable for denominator rule 4
# to be used as numerator in measures
bp002_excl_denominator_r4=patients.satisfying(
"""
NOT reg_dat_3m
"""
),
# Add flowchart counts for each select / reject rule
# NOTE: Some of these variables are coded as "select" variables
# and not "reject" as specified in the business rules
bp002_denominator_r1_reject=patients.satisfying(
"""
bp002_denominator_r1
"""
),
bp002_denominator_r2_select=patients.satisfying(
"""
bp002_denominator_r1 AND
bp002_denominator_r2
"""
),
bp002_denominator_r3_reject=patients.satisfying(
"""
bp002_denominator_r1 AND
(NOT bp002_denominator_r2) AND
bp_dec_1y
"""
),
bp002_denominator_r4_reject=patients.satisfying(
"""
bp002_denominator_r1 AND
(NOT bp002_denominator_r2) AND
bp002_denominator_r3 AND
(NOT reg_dat_3m)
"""
),
bp002_denominator=patients.satisfying(
"""
bp002_denominator_r1 AND
(bp002_denominator_r2 OR
(bp002_denominator_r3 AND
bp002_denominator_r4)
)
"""
),
bp002_numerator=patients.satisfying(
"""
# Numerator Rule Number 1
# NOTE: This is same as Denominator Rule Number 2
# Description: Select patients from the denominator who had their
# blood pressure recorded in the 5 year period leading up to and
# including the payment period end date. Reject the remaining patients.
bp002_denominator AND
bp002_denominator_r2
"""
),
)