generated from opensafely/research-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
measures_type.py
76 lines (56 loc) · 1.84 KB
/
measures_type.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
###################################################
# This script creates monthly counts/rates of opioid
# prescribing for any opioid prescribing by mode of administration
###################################################
from ehrql import Dataset, case, when, months, days, years, INTERVAL, Measures
from ehrql.tables.beta.tpp import (
patients,
medications,
addresses,
practice_registrations,
clinical_events)
import codelists
from dataset_definition import make_dataset_opioids
##########
from argparse import ArgumentParser
parser = ArgumentParser()
parser.add_argument("--start-date", type=str)
parser.add_argument("--intervals", type=int)
args = parser.parse_args()
start_date = args.start_date
intervals = args.intervals
##########
index_date = INTERVAL.start_date
dataset = make_dataset_opioids(index_date=index_date, end_date=INTERVAL.end_date)
##########
measures = Measures()
measures.define_defaults(intervals=months(intervals).starting_on(start_date))
denominator = (
(patients.age_on(index_date) >= 18)
& (patients.age_on(index_date) < 110)
& ((patients.sex == "male") | (patients.sex == "female"))
& (patients.date_of_death.is_after(index_date) | patients.date_of_death.is_null())
& (practice_registrations.for_patient_on(index_date).exists_for_patient())
)
#########################
## Overall
measures.define_measure(
name="oral_opioid",
numerator=dataset.oral_opioid_any,
denominator=denominator
)
measures.define_measure(
name="trans_opioid",
numerator=dataset.trans_opioid_any,
denominator=denominator
)
measures.define_measure(
name="par_opioid",
numerator=dataset.par_opioid_any,
denominator=denominator
)
measures.define_measure(
name="oth_opioid",
numerator=dataset.oth_opioid_any,
denominator=denominator
)