/
DefaultTemporalCovariateSettings.R
268 lines (266 loc) · 17 KB
/
DefaultTemporalCovariateSettings.R
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
# Copyright 2024 Observational Health Data Sciences and Informatics
#
# This file is part of FeatureExtraction
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# This file has been autogenerated. Do not change by hand.
#' Create covariate settings
#'
#' @details
#' creates an object specifying how covariates should be constructed from data in the CDM model.
#'
#' @param useDemographicsGender Gender of the subject. (analysis ID 1)
#' @param useDemographicsAge Age of the subject on the index date (in years).
#' (analysis ID 2)
#' @param useDemographicsAgeGroup Age of the subject on the index date (in 5 year age
#' groups) (analysis ID 3)
#' @param useDemographicsRace Race of the subject. (analysis ID 4)
#' @param useDemographicsEthnicity Ethnicity of the subject. (analysis ID 5)
#' @param useDemographicsIndexYear Year of the index date. (analysis ID 6)
#' @param useDemographicsIndexMonth Month of the index date. (analysis ID 7)
#' @param useDemographicsPriorObservationTime Number of days of observation time preceding the
#' index date. (analysis ID 8)
#' @param useDemographicsPostObservationTime Number of days of observation time preceding the
#' index date. (analysis ID 9)
#' @param useDemographicsTimeInCohort Number of days of observation time preceding the
#' index date. (analysis ID 10)
#' @param useDemographicsIndexYearMonth Calendar month of the index date. (analysis ID 11)
#' @param useCareSiteId Care site associated with the cohort start, pulled
#' from the visit_detail, visit_occurrence, or person
#' table, in that order. (analysis ID 12)
#' @param useConditionOccurrence One covariate per condition in the
#' condition_occurrence table starting in the time
#' window. (analysis ID 101)
#' @param useConditionOccurrencePrimaryInpatient One covariate per condition observed as a primary
#' diagnosis in an inpatient setting in the
#' condition_occurrence table starting in the time
#' window. (analysis ID 102)
#' @param useConditionEraStart One covariate per condition in the condition_era
#' table starting in the time window. (analysis ID 201)
#' @param useConditionEraOverlap One covariate per condition in the condition_era
#' table overlapping with any part of the time window.
#' (analysis ID 202)
#' @param useConditionEraGroupStart One covariate per condition era rolled up to SNOMED
#' groups in the condition_era table starting in the
#' time window. (analysis ID 203)
#' @param useConditionEraGroupOverlap One covariate per condition era rolled up to SNOMED
#' groups in the condition_era table overlapping with
#' any part of the time window. (analysis ID 204)
#' @param useDrugExposure One covariate per drug in the drug_exposure table
#' starting in the time window. (analysis ID 301)
#' @param useDrugEraStart One covariate per drug in the drug_era table
#' starting in the time window. (analysis ID 401)
#' @param useDrugEraOverlap One covariate per drug in the drug_era table
#' overlapping with any part of the time window.
#' (analysis ID 402)
#' @param useDrugEraGroupStart One covariate per drug rolled up to ATC groups in
#' the drug_era table starting in the time window.
#' (analysis ID 403)
#' @param useDrugEraGroupOverlap One covariate per drug rolled up to ATC groups in
#' the drug_era table overlapping with any part of
#' the time window. (analysis ID 404)
#' @param useProcedureOccurrence One covariate per procedure in the
#' procedure_occurrence table in the time window.
#' (analysis ID 501)
#' @param useDeviceExposure One covariate per device in the device exposure
#' table starting in the timewindow. (analysis ID 601)
#' @param useMeasurement One covariate per measurement in the measurement
#' table in the time window. (analysis ID 701)
#' @param useMeasurementValue One covariate containing the value per
#' measurement-unit combination in the time window. If
#' multiple values are found, the last is taken.
#' (analysis ID 702)
#' @param useMeasurementRangeGroup Covariates indicating whether measurements are
#' below, within, or above normal range within the time
#' period. (analysis ID 703)
#' @param useObservation One covariate per observation in the observation
#' table in the time window. (analysis ID 801)
#' @param useCharlsonIndex The Charlson comorbidity index (Romano adaptation)
#' using all conditions prior to the window end.
#' (analysis ID 901)
#' @param useDcsi The Diabetes Comorbidity Severity Index (DCSI) using
#' all conditions prior to the window end. (analysis ID
#' 902)
#' @param useChads2 The CHADS2 score using all conditions prior to the
#' window end. (analysis ID 903)
#' @param useChads2Vasc The CHADS2VASc score using all conditions prior to
#' the window end. (analysis ID 904)
#' @param useHfrs The Hospital Frailty Risk Score score using all
#' conditions prior to the window end. (analysis ID
#' 926)
#' @param useDistinctConditionCount The number of distinct condition concepts observed
#' in the time window. (analysis ID 905)
#' @param useDistinctIngredientCount The number of distinct ingredients observed in the
#' time window. (analysis ID 906)
#' @param useDistinctProcedureCount The number of distinct procedures observed in the
#' time window. (analysis ID 907)
#' @param useDistinctMeasurementCount The number of distinct measurements observed in the
#' time window. (analysis ID 908)
#' @param useDistinctObservationCount The number of distinct observations in the time
#' window. (analysis ID 909)
#' @param useVisitCount The number of visits observed in the time window.
#' (analysis ID 910)
#' @param useVisitConceptCount The number of visits observed in the time window,
#' stratified by visit concept ID. (analysis ID 911)
#' @param temporalStartDays A list of integers representing the start of a time
#' period, relative to the index date. 0 indicates the
#' index date, -1 indicates the day before the index
#' date, etc. The start day is included in the time
#' period.
#' @param temporalEndDays A list of integers representing the end of a time
#' period, relative to the index date. 0 indicates the
#' index date, -1 indicates the day before the index
#' date, etc. The end day is included in the time
#' period.
#' @param includedCovariateConceptIds A list of concept IDs that should be used to
#' construct covariates.
#' @param addDescendantsToInclude Should descendant concept IDs be added to the list
#' of concepts to include?
#' @param excludedCovariateConceptIds A list of concept IDs that should NOT be used to
#' construct covariates.
#' @param addDescendantsToExclude Should descendant concept IDs be added to the list
#' of concepts to exclude?
#' @param includedCovariateIds A list of covariate IDs that should be restricted
#' to.
#'
#' @return
#' An object of type \code{covariateSettings}, to be used in other functions.
#'
#' @examples
#' settings <- createTemporalCovariateSettings(
#' useDemographicsGender = TRUE,
#' useDemographicsAge = FALSE,
#' useDemographicsAgeGroup = TRUE,
#' useDemographicsRace = TRUE,
#' useDemographicsEthnicity = TRUE,
#' useDemographicsIndexYear = TRUE,
#' useDemographicsIndexMonth = TRUE,
#' useDemographicsPriorObservationTime = FALSE,
#' useDemographicsPostObservationTime = FALSE,
#' useDemographicsTimeInCohort = FALSE,
#' useDemographicsIndexYearMonth = FALSE,
#' useCareSiteId = FALSE,
#' useConditionOccurrence = FALSE,
#' useConditionOccurrencePrimaryInpatient = FALSE,
#' useConditionEraStart = FALSE,
#' useConditionEraOverlap = FALSE,
#' useConditionEraGroupStart = FALSE,
#' useConditionEraGroupOverlap = TRUE,
#' useDrugExposure = FALSE,
#' useDrugEraStart = FALSE,
#' useDrugEraOverlap = FALSE,
#' useDrugEraGroupStart = FALSE,
#' useDrugEraGroupOverlap = TRUE,
#' useProcedureOccurrence = TRUE,
#' useDeviceExposure = TRUE,
#' useMeasurement = TRUE,
#' useMeasurementValue = FALSE,
#' useMeasurementRangeGroup = TRUE,
#' useObservation = TRUE,
#' useCharlsonIndex = TRUE,
#' useDcsi = TRUE,
#' useChads2 = TRUE,
#' useChads2Vasc = TRUE,
#' useHfrs = FALSE,
#' useDistinctConditionCount = FALSE,
#' useDistinctIngredientCount = FALSE,
#' useDistinctProcedureCount = FALSE,
#' useDistinctMeasurementCount = FALSE,
#' useDistinctObservationCount = FALSE,
#' useVisitCount = FALSE,
#' useVisitConceptCount = FALSE,
#' temporalStartDays = -365:-1,
#' temporalEndDays = -365:-1,
#' includedCovariateConceptIds = c(),
#' addDescendantsToInclude = FALSE,
#' excludedCovariateConceptIds = c(),
#' addDescendantsToExclude = FALSE,
#' includedCovariateIds = c()
#' )
#'
#' @export
createTemporalCovariateSettings <- function(useDemographicsGender = FALSE,
useDemographicsAge = FALSE,
useDemographicsAgeGroup = FALSE,
useDemographicsRace = FALSE,
useDemographicsEthnicity = FALSE,
useDemographicsIndexYear = FALSE,
useDemographicsIndexMonth = FALSE,
useDemographicsPriorObservationTime = FALSE,
useDemographicsPostObservationTime = FALSE,
useDemographicsTimeInCohort = FALSE,
useDemographicsIndexYearMonth = FALSE,
useCareSiteId = FALSE,
useConditionOccurrence = FALSE,
useConditionOccurrencePrimaryInpatient = FALSE,
useConditionEraStart = FALSE,
useConditionEraOverlap = FALSE,
useConditionEraGroupStart = FALSE,
useConditionEraGroupOverlap = FALSE,
useDrugExposure = FALSE,
useDrugEraStart = FALSE,
useDrugEraOverlap = FALSE,
useDrugEraGroupStart = FALSE,
useDrugEraGroupOverlap = FALSE,
useProcedureOccurrence = FALSE,
useDeviceExposure = FALSE,
useMeasurement = FALSE,
useMeasurementValue = FALSE,
useMeasurementRangeGroup = FALSE,
useObservation = FALSE,
useCharlsonIndex = FALSE,
useDcsi = FALSE,
useChads2 = FALSE,
useChads2Vasc = FALSE,
useHfrs = FALSE,
useDistinctConditionCount = FALSE,
useDistinctIngredientCount = FALSE,
useDistinctProcedureCount = FALSE,
useDistinctMeasurementCount = FALSE,
useDistinctObservationCount = FALSE,
useVisitCount = FALSE,
useVisitConceptCount = FALSE,
temporalStartDays = -365:-1,
temporalEndDays = -365:-1,
includedCovariateConceptIds = c(),
addDescendantsToInclude = FALSE,
excludedCovariateConceptIds = c(),
addDescendantsToExclude = FALSE,
includedCovariateIds = c()) {
covariateSettings <- list(
temporal = TRUE,
temporalSequence = FALSE
)
formalNames <- names(formals(createTemporalCovariateSettings))
anyUseTrue <- FALSE
for (name in formalNames) {
value <- get(name)
if (is.null(value)) {
value <- vector()
}
if (grepl("use.*", name)) {
if (value) {
covariateSettings[[sub("use", "", name)]] <- value
anyUseTrue <- TRUE
}
} else {
covariateSettings[[name]] <- value
}
}
if (!anyUseTrue) {
stop("No covariate analysis selected. Must select at least one")
}
attr(covariateSettings, "fun") <- "getDbDefaultCovariateData"
class(covariateSettings) <- "covariateSettings"
return(covariateSettings)
}