generated from opensafely/research-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
study_definition_pneumonia.py
58 lines (56 loc) · 1.87 KB
/
study_definition_pneumonia.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
from cohortextractor import (
StudyDefinition,
patients,
codelist,
codelist_from_csv,
combine_codelists,
)
from common_variables import generate_common_variables
from codelists import *
dummy_data_date = "2020-02-01"
common_variables = generate_common_variables(index_date_variable="patient_index_date", admission_variable= "exposure_hospitalisation")
study = StudyDefinition(
default_expectations={
"date": {"earliest": "1980-01-01", "latest": "today"},
"rate": "uniform",
"incidence": 0.7,
},
population=patients.satisfying(
"""
has_follow_up
AND (age >=18 AND age <= 110)
AND (sex = "M" OR sex = "F")
AND imd > 0
AND exposure_hospitalisation
AND NOT stp = ""
""",
has_follow_up=patients.registered_with_one_practice_between(
"patient_index_date - 1 year", "patient_index_date"
),
),
index_date="2019-02-01",
patient_index_date=patients.admitted_to_hospital(
returning="date_discharged",
with_these_diagnoses=pneumonia_codelist,
on_or_after="index_date",
date_format="YYYY-MM-DD",
find_first_match_in_period=True,
return_expectations={"date": {"earliest": "index_date"}},
),
exposure_hospitalisation=patients.admitted_to_hospital(
returning="date_admitted",
with_these_diagnoses=pneumonia_codelist,
on_or_after="index_date",
date_format="YYYY-MM-DD",
find_first_match_in_period=True,
return_expectations={"date": {"earliest": "index_date"}},
),
date_icu_admission=patients.admitted_to_icu(
find_first_match_in_period=True,
on_or_after="index_date",
returning="date_admitted",
date_format="YYYY-MM-DD",
return_expectations={"date": {"earliest": "index_date"}},
),
**common_variables
)