generated from opensafely/research-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstudy_definition_prevax_extf.py
95 lines (80 loc) · 2.79 KB
/
study_definition_prevax_extf.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
# Import statements
## Set seed
import numpy as np
np.random.seed(123456)
## Cohort extractor
from cohortextractor import (
StudyDefinition,
patients,
codelist_from_csv,
codelist,
filter_codes_by_category,
combine_codelists,
)
## Codelists from codelist.py (which pulls them from the codelist folder)
from codelists import *
## Datetime functions
from datetime import date
## Study definition helper
import study_definition_helper_functions as helpers
# Specify index date for MH prevax
## Import common variables function
from common_variables import generate_common_variables
(
dynamic_variables
) = generate_common_variables(index_date_variable="index_date_cohort", exposure_end_date_variable="end_date_exposure", outcome_end_date_variable="end_date_outcome")
## Variables for deriving JCVI groups
from grouping_variables import (
study_dates,
jcvi_variables,
start_date,
end_date,
pandemic_start
)
study = StudyDefinition(
# Specify study dates
index_date_cohort = patients.with_value_from_file(
f_path = 'output/index_dates.csv.gz',
returning = 'index_prevax',
returning_type = 'date',
date_format = 'YYYY-MM-DD',
),
end_date_exposure = patients.with_value_from_file(
f_path = 'output/index_dates.csv.gz',
returning = 'end_prevax',
returning_type = 'date',
date_format = 'YYYY-MM-DD',
),
end_date_outcome = patients.with_value_from_file(
f_path = 'output/index_dates.csv.gz',
returning = 'end_prevax_extf',
returning_type = 'date',
date_format = 'YYYY-MM-DD',
),
# Configure the expectations framework
default_expectations={
"date": {"earliest": study_dates["earliest_expec"], "latest": "today"},
"rate": "uniform",
"incidence": 0.5,
},
# Define the study population
# NB: all inclusions and exclusions are performed in stage 1
population = patients.all(),
# Define sex
# NB: this is required for JCVI variables hence is defined here
cov_cat_sex = patients.with_value_from_file(
f_path = 'output/index_dates.csv.gz',
returning = 'cov_cat_sex',
returning_type = 'str',
),
## Any covid vaccination, identified by target disease
vax_date_covid_1 = patients.with_value_from_file(
f_path = 'output/index_dates.csv.gz',
returning = 'vax_date_covid_1',
returning_type = 'date'
),
# Define vaccine eligibility variables
**jcvi_variables,
# Define common variables (e.g., exposures, outcomes, covariates) that require dynamic dates
**dynamic_variables
)