line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Convert::Pheno::REDCap; |
2
|
|
|
|
|
|
|
|
3
|
6
|
|
|
6
|
|
45
|
use strict; |
|
6
|
|
|
|
|
13
|
|
|
6
|
|
|
|
|
184
|
|
4
|
6
|
|
|
6
|
|
34
|
use warnings; |
|
6
|
|
|
|
|
21
|
|
|
6
|
|
|
|
|
174
|
|
5
|
6
|
|
|
6
|
|
32
|
use autodie; |
|
6
|
|
|
|
|
12
|
|
|
6
|
|
|
|
|
33
|
|
6
|
6
|
|
|
6
|
|
33744
|
use feature qw(say); |
|
6
|
|
|
|
|
27
|
|
|
6
|
|
|
|
|
465
|
|
7
|
6
|
|
|
6
|
|
54
|
use List::Util qw(any); |
|
6
|
|
|
|
|
21
|
|
|
6
|
|
|
|
|
435
|
|
8
|
6
|
|
|
6
|
|
41
|
use Convert::Pheno::Mapping; |
|
6
|
|
|
|
|
17
|
|
|
6
|
|
|
|
|
752
|
|
9
|
6
|
|
|
6
|
|
42
|
use Convert::Pheno::PXF; |
|
6
|
|
|
|
|
10
|
|
|
6
|
|
|
|
|
371
|
|
10
|
6
|
|
|
6
|
|
48
|
use Data::Dumper; |
|
6
|
|
|
|
|
26
|
|
|
6
|
|
|
|
|
381
|
|
11
|
6
|
|
|
6
|
|
40
|
use Scalar::Util qw(looks_like_number); |
|
6
|
|
|
|
|
28
|
|
|
6
|
|
|
|
|
351
|
|
12
|
6
|
|
|
6
|
|
43
|
use Exporter 'import'; |
|
6
|
|
|
|
|
14
|
|
|
6
|
|
|
|
|
15886
|
|
13
|
|
|
|
|
|
|
our @EXPORT = qw(do_redcap2bff); |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
################ |
16
|
|
|
|
|
|
|
################ |
17
|
|
|
|
|
|
|
# REDCAP2BFF # |
18
|
|
|
|
|
|
|
################ |
19
|
|
|
|
|
|
|
################ |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub do_redcap2bff { |
22
|
|
|
|
|
|
|
|
23
|
180
|
|
|
180
|
0
|
404
|
my ( $self, $participant ) = @_; |
24
|
180
|
|
|
|
|
295
|
my $redcap_dict = $self->{data_redcap_dict}; |
25
|
180
|
|
|
|
|
271
|
my $mapping_file = $self->{data_mapping_file}; |
26
|
180
|
|
|
|
|
242
|
my $sth = $self->{sth}; |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
############################## |
29
|
|
|
|
|
|
|
# <Variable> names in REDCap # |
30
|
|
|
|
|
|
|
############################## |
31
|
|
|
|
|
|
|
# |
32
|
|
|
|
|
|
|
# REDCap does not enforce any particular variable name. |
33
|
|
|
|
|
|
|
# Extracted from https://www.ctsi.ufl.edu/wordpress/files/2019/02/Project-Creation-User-Guide.pdf |
34
|
|
|
|
|
|
|
# --- |
35
|
|
|
|
|
|
|
# "Variable Names: Variable names are critical in the data analysis process. If you export your data to a |
36
|
|
|
|
|
|
|
# statistical software program, the variable names are what you or your statistician will use to conduct |
37
|
|
|
|
|
|
|
# the analysis" |
38
|
|
|
|
|
|
|
# |
39
|
|
|
|
|
|
|
# "We always recommend reviewing your variable names with a statistician or whoever will be |
40
|
|
|
|
|
|
|
# analyzing your data. This is especially important if this is the first time you are building a |
41
|
|
|
|
|
|
|
# database" |
42
|
|
|
|
|
|
|
#--- |
43
|
|
|
|
|
|
|
# If variable names are not consensuated, then we need to do the mapping manually "a posteriori". |
44
|
|
|
|
|
|
|
# This is what we are attempting here: |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
#################################### |
47
|
|
|
|
|
|
|
# START MAPPING TO BEACON V2 TERMS # |
48
|
|
|
|
|
|
|
#################################### |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
# $participant = |
51
|
|
|
|
|
|
|
# { |
52
|
|
|
|
|
|
|
# 'abdominal_mass' => 0, |
53
|
|
|
|
|
|
|
# 'abdominal_pain' => 1, |
54
|
|
|
|
|
|
|
# 'age' => 2, |
55
|
|
|
|
|
|
|
# 'age_first_diagnosis' => 0, |
56
|
|
|
|
|
|
|
# 'alcohol' => 4, |
57
|
|
|
|
|
|
|
# } |
58
|
|
|
|
|
|
|
print Dumper $redcap_dict |
59
|
180
|
50
|
33
|
|
|
464
|
if ( defined $self->{debug} && $self->{debug} > 4 ); |
60
|
|
|
|
|
|
|
print Dumper $participant |
61
|
180
|
50
|
33
|
|
|
423
|
if ( defined $self->{debug} && $self->{debug} > 4 ); |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
# *** ABOUT REQUIRED PROPERTIES *** |
64
|
|
|
|
|
|
|
# 'id' and 'sex' are required properties in <individuals> entry type |
65
|
|
|
|
|
|
|
|
66
|
180
|
|
|
|
|
404
|
my @redcap_field_types = ( 'Field Label', 'Field Note', 'Field Type' ); |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
# Getting the field name from mapping file (note that we add _field suffix) |
69
|
180
|
|
|
|
|
295
|
my $sex_field = $mapping_file->{sex}; |
70
|
180
|
|
|
|
|
356
|
my $studyId_field = $mapping_file->{info}{map}{studyId}; |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
# ********************** |
73
|
|
|
|
|
|
|
# *** IMPORTANT STEP *** |
74
|
|
|
|
|
|
|
# ********************** |
75
|
|
|
|
|
|
|
# We need to pass 'sex' info to external array elements from $participant |
76
|
|
|
|
|
|
|
# Thus, we are storing $participant->{sex} in $self !!! |
77
|
180
|
100
|
|
|
|
685
|
if ( defined $participant->{$sex_field} ) { |
78
|
|
|
|
|
|
|
$self->{_info}{ $participant->{study_id} }{$sex_field} = |
79
|
40
|
|
|
|
|
365
|
$participant->{$sex_field}; # Dynamically adding attributes (setter) |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
$participant->{$sex_field} = |
82
|
180
|
|
|
|
|
971
|
$self->{_info}{ $participant->{$studyId_field} }{$sex_field}; |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
# Premature return if fields don't exist |
85
|
|
|
|
|
|
|
return |
86
|
|
|
|
|
|
|
unless ( defined $participant->{$studyId_field} |
87
|
180
|
50
|
33
|
|
|
703
|
&& $participant->{$sex_field} ); |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
# Data structure (hashref) for each individual |
90
|
180
|
|
|
|
|
200
|
my $individual; |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
# Default ontology for a bunch of required terms |
93
|
180
|
|
|
|
|
510
|
my $default_ontology = { id => 'NCIT:NA0000', label => 'NA' }; |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
# More default values |
96
|
180
|
|
|
|
|
258
|
my $default_date = '1900-01-01'; |
97
|
180
|
|
|
|
|
226
|
my $default_duration = 'P999Y'; |
98
|
180
|
|
|
|
|
567
|
my $default_age = { age => { iso8601duration => 'P999Y' } }; |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
# Variable that will allow to perform ad hoc changes for specific projects |
101
|
180
|
|
|
|
|
329
|
my $project_id = $mapping_file->{project}{id}; |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
# ********************** |
104
|
|
|
|
|
|
|
# *** IMPORTANT STEP *** |
105
|
|
|
|
|
|
|
# ********************** |
106
|
|
|
|
|
|
|
# Load the main ontology for the project |
107
|
|
|
|
|
|
|
# <sex> and <ethnicity> project_ontology are fixed, |
108
|
|
|
|
|
|
|
# (can't be changed granulary) |
109
|
|
|
|
|
|
|
|
110
|
180
|
|
|
|
|
286
|
my $project_ontology = $mapping_file->{project}{ontology}; |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
# NB: We don't need to initialize (unless required) |
113
|
|
|
|
|
|
|
# e.g., |
114
|
|
|
|
|
|
|
# $individual->{diseases} = undef; |
115
|
|
|
|
|
|
|
# or |
116
|
|
|
|
|
|
|
# $individual->{diseases} = [] |
117
|
|
|
|
|
|
|
# Otherwise the validator may complain about being empty |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
# ********************** |
120
|
|
|
|
|
|
|
# *** IMPORTANT STEP *** |
121
|
|
|
|
|
|
|
# ********************** |
122
|
|
|
|
|
|
|
# Loading fields that must to be mapped to redcap_dict in bulk |
123
|
|
|
|
|
|
|
my @fields2map = |
124
|
180
|
|
|
|
|
234
|
grep { defined $redcap_dict->{$_}{_labels} } sort keys %{$redcap_dict}; |
|
70555
|
|
|
|
|
112939
|
|
|
180
|
|
|
|
|
42980
|
|
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
# Perform the mapping for this participant |
127
|
180
|
|
|
|
|
3274
|
for my $field (@fields2map) { |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
# *** IMPORTANT *** |
130
|
|
|
|
|
|
|
# First we keep track of the original value (in case need it) |
131
|
|
|
|
|
|
|
# as $field . '_ori' |
132
|
29340
|
|
|
|
|
77679
|
$participant->{ $field . '_ori' } = $participant->{$field}; |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
# Now iwe overwrite the original value with the ditionary one |
135
|
|
|
|
|
|
|
$participant->{$field} = map2redcap_dict( |
136
|
|
|
|
|
|
|
{ |
137
|
|
|
|
|
|
|
redcap_dict => $redcap_dict, |
138
|
|
|
|
|
|
|
participant => $participant, |
139
|
|
|
|
|
|
|
field => $field, |
140
|
|
|
|
|
|
|
labels => 1 |
141
|
|
|
|
|
|
|
} |
142
|
29340
|
100
|
|
|
|
70252
|
) if defined $participant->{$field}; |
143
|
|
|
|
|
|
|
} |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
# ======== |
146
|
|
|
|
|
|
|
# diseases |
147
|
|
|
|
|
|
|
# ======== |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
#$individual->{diseases} = []; |
150
|
|
|
|
|
|
|
# NB: Inflamatory Bowel Disease --- Note the 2 mm in infla-mm-atory |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
# Load hashref with cursors for mapping |
153
|
180
|
|
|
|
|
525
|
my $mapping = remap_mapping_hash( $mapping_file, 'diseases' ); |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
# Start looping over them |
156
|
180
|
|
|
|
|
230
|
for my $field ( @{ $mapping->{fields} } ) { |
|
180
|
|
|
|
|
420
|
|
157
|
180
|
|
|
|
|
219
|
my $disease; |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
# Load a few more variables from mapping file |
160
|
|
|
|
|
|
|
# Start mapping |
161
|
|
|
|
|
|
|
$disease->{ageOfOnset} = |
162
|
|
|
|
|
|
|
map_age_range( $participant->{ $mapping->{map}{ageOfOnset} } ) |
163
|
|
|
|
|
|
|
if ( exists $mapping->{map}{ageOfOnset} |
164
|
180
|
100
|
66
|
|
|
1053
|
&& defined $participant->{ $mapping->{map}{ageOfOnset} } ); |
165
|
|
|
|
|
|
|
$disease->{diseaseCode} = map_ontology( |
166
|
|
|
|
|
|
|
{ |
167
|
|
|
|
|
|
|
query => $field, |
168
|
|
|
|
|
|
|
column => 'label', |
169
|
|
|
|
|
|
|
ontology => $mapping->{ontology}, |
170
|
180
|
|
|
|
|
1089
|
self => $self |
171
|
|
|
|
|
|
|
} |
172
|
|
|
|
|
|
|
); |
173
|
|
|
|
|
|
|
$disease->{familyHistory} = |
174
|
|
|
|
|
|
|
convert2boolean( $participant->{ $mapping->{map}{familyHistory} } ) |
175
|
|
|
|
|
|
|
if ( exists $mapping->{map}{familyHistory} |
176
|
180
|
100
|
66
|
|
|
1124
|
&& defined $participant->{ $mapping->{map}{familyHistory} } ); |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
#$disease->{notes} = undef; |
179
|
180
|
|
|
|
|
421
|
$disease->{severity} = $default_ontology; |
180
|
180
|
|
|
|
|
255
|
$disease->{stage} = $default_ontology; |
181
|
|
|
|
|
|
|
|
182
|
180
|
|
|
|
|
563
|
push @{ $individual->{diseases} }, $disease |
183
|
180
|
50
|
|
|
|
396
|
if defined $disease->{diseaseCode}; |
184
|
|
|
|
|
|
|
} |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
# ========= |
187
|
|
|
|
|
|
|
# ethnicity |
188
|
|
|
|
|
|
|
# ========= |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
# Load field name from mapping file |
191
|
180
|
|
|
|
|
326
|
my $ethnicity_field = $mapping_file->{ethnicity}; |
192
|
|
|
|
|
|
|
$individual->{ethnicity} = map_ethnicity( $participant->{$ethnicity_field} ) |
193
|
180
|
100
|
|
|
|
473
|
if defined $participant->{$ethnicity_field}; |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
# ========= |
196
|
|
|
|
|
|
|
# exposures |
197
|
|
|
|
|
|
|
# ========= |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
#$individual->{exposures} = undef; |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
# Load hashref with cursors for mapping |
202
|
180
|
|
|
|
|
404
|
$mapping = remap_mapping_hash( $mapping_file, 'exposures' ); |
203
|
|
|
|
|
|
|
|
204
|
180
|
|
|
|
|
285
|
for my $field ( @{ $mapping->{fields} } ) { |
|
180
|
|
|
|
|
410
|
|
205
|
1080
|
100
|
|
|
|
2269
|
next unless defined $participant->{$field}; |
206
|
|
|
|
|
|
|
|
207
|
85
|
|
|
|
|
176
|
my $exposure; |
208
|
|
|
|
|
|
|
$exposure->{ageAtExposure} = |
209
|
|
|
|
|
|
|
( exists $mapping->{map}{ageAtExposure} |
210
|
|
|
|
|
|
|
&& defined $participant->{ $mapping->{map}{ageAtExposure} } ) |
211
|
|
|
|
|
|
|
? map_age_range( $participant->{ $mapping->{map}{ageAtExposure} } ) |
212
|
85
|
50
|
33
|
|
|
347
|
: $default_age; |
213
|
|
|
|
|
|
|
$exposure->{date} = |
214
|
|
|
|
|
|
|
exists $mapping->{map}{date} |
215
|
|
|
|
|
|
|
? $participant->{ $mapping->{map}{date} } |
216
|
85
|
50
|
|
|
|
207
|
: $default_date; |
217
|
|
|
|
|
|
|
$exposure->{duration} = |
218
|
|
|
|
|
|
|
exists $mapping->{map}{duration} |
219
|
|
|
|
|
|
|
? $participant->{ $mapping->{map}{duration} } |
220
|
85
|
50
|
|
|
|
211
|
: $default_duration; |
221
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
# Query related |
223
|
|
|
|
|
|
|
my $exposure_query = |
224
|
|
|
|
|
|
|
exists $mapping->{dict}{$field} |
225
|
85
|
50
|
|
|
|
246
|
? $mapping->{dict}{$field} |
226
|
|
|
|
|
|
|
: $field; |
227
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
$exposure->{exposureCode} = map_ontology( |
229
|
|
|
|
|
|
|
{ |
230
|
|
|
|
|
|
|
query => $exposure_query, |
231
|
|
|
|
|
|
|
column => 'label', |
232
|
|
|
|
|
|
|
ontology => $mapping->{ontology}, |
233
|
85
|
|
|
|
|
422
|
self => $self |
234
|
|
|
|
|
|
|
} |
235
|
|
|
|
|
|
|
); |
236
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
# We first extract 'unit' that supposedly will be used in in |
238
|
|
|
|
|
|
|
# <measurementValue> and <referenceRange>?? |
239
|
|
|
|
|
|
|
# e.g. radio.alcohol ? alcohol |
240
|
85
|
100
|
|
|
|
269
|
my $subkey = exists $mapping->{radio}{$field} ? $field : 'dummy'; |
241
|
|
|
|
|
|
|
my $unit = map_ontology( |
242
|
|
|
|
|
|
|
{ |
243
|
|
|
|
|
|
|
# order on the ternary operator matters |
244
|
|
|
|
|
|
|
# 1 - Check for subkey |
245
|
|
|
|
|
|
|
# 2 - Check for field |
246
|
|
|
|
|
|
|
query => $subkey ne 'dummy' |
247
|
|
|
|
|
|
|
|
248
|
|
|
|
|
|
|
# radio.alcohol.Never smoked => Never Smoker |
249
|
|
|
|
|
|
|
? $mapping->{radio}{$field}{ $participant->{$subkey} } |
250
|
|
|
|
|
|
|
: $exposure_query, |
251
|
|
|
|
|
|
|
column => 'label', |
252
|
|
|
|
|
|
|
ontology => $mapping->{ontology}, |
253
|
85
|
100
|
|
|
|
519
|
self => $self |
254
|
|
|
|
|
|
|
} |
255
|
|
|
|
|
|
|
); |
256
|
85
|
|
|
|
|
213
|
$exposure->{unit} = $unit; |
257
|
85
|
|
100
|
|
|
335
|
$exposure->{value} = $participant->{ $field . '_ori' } // -1; |
258
|
85
|
|
|
|
|
239
|
push @{ $individual->{exposures} }, $exposure |
259
|
85
|
50
|
|
|
|
192
|
if defined $exposure->{exposureCode}; |
260
|
|
|
|
|
|
|
} |
261
|
|
|
|
|
|
|
|
262
|
|
|
|
|
|
|
# ================ |
263
|
|
|
|
|
|
|
# geographicOrigin |
264
|
|
|
|
|
|
|
# ================ |
265
|
|
|
|
|
|
|
|
266
|
|
|
|
|
|
|
#$individual->{geographicOrigin} = {}; |
267
|
|
|
|
|
|
|
|
268
|
|
|
|
|
|
|
# == |
269
|
|
|
|
|
|
|
# id |
270
|
|
|
|
|
|
|
# == |
271
|
|
|
|
|
|
|
|
272
|
|
|
|
|
|
|
# Concatenation of the values in @id_fields (mapping file) |
273
|
|
|
|
|
|
|
$individual->{id} = join ':', |
274
|
180
|
|
|
|
|
300
|
map { $participant->{$_} } @{ $mapping_file->{id}{fields} }; |
|
360
|
|
|
|
|
1295
|
|
|
180
|
|
|
|
|
435
|
|
275
|
|
|
|
|
|
|
|
276
|
|
|
|
|
|
|
# ==== |
277
|
|
|
|
|
|
|
# info |
278
|
|
|
|
|
|
|
# ==== |
279
|
|
|
|
|
|
|
|
280
|
|
|
|
|
|
|
# Load hashref with cursors for mapping |
281
|
180
|
|
|
|
|
463
|
$mapping = remap_mapping_hash( $mapping_file, 'info' ); |
282
|
|
|
|
|
|
|
|
283
|
180
|
|
|
|
|
323
|
for my $field ( @{ $mapping->{fields} } ) { |
|
180
|
|
|
|
|
381
|
|
284
|
2880
|
100
|
|
|
|
5487
|
if ( defined $participant->{$field} ) { |
285
|
|
|
|
|
|
|
|
286
|
|
|
|
|
|
|
# Ad hoc for 3TR |
287
|
725
|
50
|
|
|
|
1012
|
if ( $project_id eq '3tr_ibd' ) { |
288
|
|
|
|
|
|
|
$individual->{info}{$field} = |
289
|
|
|
|
|
|
|
$field eq 'age' ? map_age_range( $participant->{$field} ) |
290
|
|
|
|
|
|
|
: $field =~ m/^consent/ ? { |
291
|
|
|
|
|
|
|
value => dotify_and_coerce_number( $participant->{$field} ), |
292
|
840
|
|
|
|
|
3255
|
map { $_ => $redcap_dict->{$field}{$_} } |
293
|
|
|
|
|
|
|
@redcap_field_types |
294
|
|
|
|
|
|
|
} |
295
|
725
|
100
|
|
|
|
2621
|
: $participant->{$field}; |
|
|
100
|
|
|
|
|
|
296
|
|
|
|
|
|
|
} |
297
|
|
|
|
|
|
|
else { |
298
|
0
|
|
|
|
|
0
|
$individual->{info}{$field} = $participant->{$field}; |
299
|
|
|
|
|
|
|
} |
300
|
|
|
|
|
|
|
} |
301
|
|
|
|
|
|
|
} |
302
|
|
|
|
|
|
|
|
303
|
|
|
|
|
|
|
# When we use --test we do not serialize changing (metaData) information |
304
|
180
|
50
|
|
|
|
555
|
$individual->{info}{metaData} = $self->{test} ? undef : get_metaData($self); |
305
|
|
|
|
|
|
|
|
306
|
|
|
|
|
|
|
# ========================= |
307
|
|
|
|
|
|
|
# interventionsOrProcedures |
308
|
|
|
|
|
|
|
# ========================= |
309
|
|
|
|
|
|
|
|
310
|
|
|
|
|
|
|
#$individual->{interventionsOrProcedures} = []; |
311
|
|
|
|
|
|
|
|
312
|
|
|
|
|
|
|
# Load hashref with cursors for mapping |
313
|
180
|
|
|
|
|
374
|
$mapping = remap_mapping_hash( $mapping_file, 'interventionsOrProcedures' ); |
314
|
|
|
|
|
|
|
|
315
|
180
|
|
|
|
|
286
|
for my $field ( @{ $mapping->{fields} } ) { |
|
180
|
|
|
|
|
358
|
|
316
|
2880
|
100
|
|
|
|
5800
|
if ( $participant->{$field} ) { |
317
|
|
|
|
|
|
|
|
318
|
|
|
|
|
|
|
# Why this |
319
|
|
|
|
|
|
|
next |
320
|
|
|
|
|
|
|
if ( exists $mapping->{map}{dateOfProcedure} |
321
|
415
|
100
|
66
|
|
|
1450
|
&& $field eq $mapping->{map}{dateOfProcedure} ); |
322
|
330
|
|
|
|
|
344
|
my $intervention; |
323
|
|
|
|
|
|
|
|
324
|
|
|
|
|
|
|
$intervention->{ageAtProcedure} = |
325
|
|
|
|
|
|
|
( exists $mapping->{map}{ageAtProcedure} |
326
|
|
|
|
|
|
|
&& defined $mapping->{map}{ageAtProcedure} ) |
327
|
|
|
|
|
|
|
? map_age_range( |
328
|
|
|
|
|
|
|
$participant->{ $mapping->{map}{ageAtProcedure} } ) |
329
|
330
|
50
|
33
|
|
|
923
|
: $default_age; |
330
|
|
|
|
|
|
|
|
331
|
|
|
|
|
|
|
$intervention->{bodySite} = |
332
|
330
|
50
|
|
|
|
1016
|
{ "id" => "NCIT:C12736", "label" => "intestine" } |
333
|
|
|
|
|
|
|
if ( $project_id eq '3tr_ibd' ); |
334
|
|
|
|
|
|
|
|
335
|
|
|
|
|
|
|
$intervention->{dateOfProcedure} = |
336
|
|
|
|
|
|
|
( exists $mapping->{map}{dateOfProcedure} |
337
|
|
|
|
|
|
|
&& defined $mapping->{map}{dateOfProcedure} ) |
338
|
|
|
|
|
|
|
? dot_date2iso( |
339
|
|
|
|
|
|
|
$participant->{ $mapping->{map}{dateOfProcedure} } ) |
340
|
330
|
50
|
33
|
|
|
1472
|
: $default_date; |
341
|
|
|
|
|
|
|
|
342
|
|
|
|
|
|
|
$intervention->{procedureCode} = map_ontology( |
343
|
|
|
|
|
|
|
{ |
344
|
|
|
|
|
|
|
query => exists $mapping->{dict}{$field} |
345
|
|
|
|
|
|
|
? $mapping->{dict}{$field} |
346
|
|
|
|
|
|
|
: $field, |
347
|
|
|
|
|
|
|
column => 'label', |
348
|
|
|
|
|
|
|
ontology => $mapping->{ontology}, |
349
|
330
|
100
|
|
|
|
2083
|
self => $self |
|
|
50
|
|
|
|
|
|
350
|
|
|
|
|
|
|
} |
351
|
|
|
|
|
|
|
) if defined $field; |
352
|
330
|
|
|
|
|
789
|
push @{ $individual->{interventionsOrProcedures} }, $intervention |
353
|
330
|
50
|
|
|
|
874
|
if defined $intervention->{procedureCode}; |
354
|
|
|
|
|
|
|
} |
355
|
|
|
|
|
|
|
} |
356
|
|
|
|
|
|
|
|
357
|
|
|
|
|
|
|
# ============= |
358
|
|
|
|
|
|
|
# karyotypicSex |
359
|
|
|
|
|
|
|
# ============= |
360
|
|
|
|
|
|
|
|
361
|
|
|
|
|
|
|
# $individual->{karyotypicSex} = undef; |
362
|
|
|
|
|
|
|
|
363
|
|
|
|
|
|
|
# ======== |
364
|
|
|
|
|
|
|
# measures |
365
|
|
|
|
|
|
|
# ======== |
366
|
|
|
|
|
|
|
|
367
|
180
|
|
|
|
|
350
|
$individual->{measures} = undef; |
368
|
|
|
|
|
|
|
|
369
|
|
|
|
|
|
|
# Load hashref with cursors for mapping |
370
|
180
|
|
|
|
|
406
|
$mapping = remap_mapping_hash( $mapping_file, 'measures' ); |
371
|
|
|
|
|
|
|
|
372
|
180
|
|
|
|
|
255
|
for my $field ( @{ $mapping->{fields} } ) { |
|
180
|
|
|
|
|
355
|
|
373
|
4140
|
100
|
|
|
|
9256
|
next unless defined $participant->{$field}; |
374
|
2785
|
|
|
|
|
2830
|
my $measure; |
375
|
|
|
|
|
|
|
|
376
|
|
|
|
|
|
|
$measure->{assayCode} = map_ontology( |
377
|
|
|
|
|
|
|
{ |
378
|
|
|
|
|
|
|
query => exists $mapping->{dict}{$field} |
379
|
|
|
|
|
|
|
? $mapping->{dict}{$field} |
380
|
|
|
|
|
|
|
: $field, |
381
|
|
|
|
|
|
|
column => 'label', |
382
|
|
|
|
|
|
|
ontology => $mapping->{ontology}, |
383
|
2785
|
100
|
|
|
|
10911
|
self => $self, |
384
|
|
|
|
|
|
|
} |
385
|
|
|
|
|
|
|
); |
386
|
2785
|
|
|
|
|
5504
|
$measure->{date} = $default_date; |
387
|
|
|
|
|
|
|
|
388
|
|
|
|
|
|
|
# We first extract 'unit' and %range' for <measurementValue> |
389
|
2785
|
|
|
|
|
8383
|
my $tmp_str = map2redcap_dict( |
390
|
|
|
|
|
|
|
{ |
391
|
|
|
|
|
|
|
redcap_dict => $redcap_dict, |
392
|
|
|
|
|
|
|
participant => $participant, |
393
|
|
|
|
|
|
|
field => $field, |
394
|
|
|
|
|
|
|
labels => 0 # will get 'Field Note' |
395
|
|
|
|
|
|
|
|
396
|
|
|
|
|
|
|
} |
397
|
|
|
|
|
|
|
); |
398
|
|
|
|
|
|
|
|
399
|
|
|
|
|
|
|
# We can have $participant->{$field} eq '2 - Mild' |
400
|
2785
|
100
|
|
|
|
13557
|
if ( $participant->{$field} =~ m/ \- / ) { |
401
|
90
|
|
|
|
|
327
|
my ( $tmp_val, $tmp_scale ) = split / \- /, $participant->{$field}; |
402
|
90
|
|
|
|
|
172
|
$participant->{$field} = |
403
|
|
|
|
|
|
|
$tmp_val; # should be equal to $participant->{$field.'_ori'} |
404
|
90
|
|
|
|
|
147
|
$tmp_str = $tmp_scale; |
405
|
|
|
|
|
|
|
} |
406
|
|
|
|
|
|
|
|
407
|
|
|
|
|
|
|
my $unit = map_ontology( |
408
|
|
|
|
|
|
|
{ |
409
|
|
|
|
|
|
|
query => exists $mapping->{dict}{$tmp_str} |
410
|
|
|
|
|
|
|
? $mapping->{dict}{$tmp_str} |
411
|
|
|
|
|
|
|
: $tmp_str, |
412
|
|
|
|
|
|
|
column => 'label', |
413
|
|
|
|
|
|
|
ontology => $mapping->{ontology}, |
414
|
2785
|
100
|
|
|
|
12042
|
self => $self |
415
|
|
|
|
|
|
|
} |
416
|
|
|
|
|
|
|
); |
417
|
|
|
|
|
|
|
$measure->{measurementValue} = { |
418
|
|
|
|
|
|
|
quantity => { |
419
|
|
|
|
|
|
|
unit => $unit, |
420
|
2785
|
|
|
|
|
6630
|
value => dotify_and_coerce_number( $participant->{$field} ), |
421
|
|
|
|
|
|
|
referenceRange => map_reference_range( |
422
|
|
|
|
|
|
|
{ |
423
|
|
|
|
|
|
|
unit => $unit, |
424
|
|
|
|
|
|
|
redcap_dict => $redcap_dict, |
425
|
|
|
|
|
|
|
field => $field |
426
|
|
|
|
|
|
|
} |
427
|
|
|
|
|
|
|
) |
428
|
|
|
|
|
|
|
} |
429
|
|
|
|
|
|
|
}; |
430
|
|
|
|
|
|
|
$measure->{notes} = join ' /// ', $field, |
431
|
2785
|
|
|
|
|
6385
|
( map { qq/$_=$redcap_dict->{$field}{$_}/ } @redcap_field_types ); |
|
8355
|
|
|
|
|
25896
|
|
432
|
|
|
|
|
|
|
|
433
|
|
|
|
|
|
|
#$measure->{observationMoment} = undef; # Age |
434
|
|
|
|
|
|
|
$measure->{procedure} = { |
435
|
|
|
|
|
|
|
procedureCode => map_ontology( |
436
|
|
|
|
|
|
|
{ |
437
|
|
|
|
|
|
|
query => $field eq 'calprotectin' ? 'Feces' |
438
|
|
|
|
|
|
|
: $field =~ m/^nancy/ ? 'Histologic' |
439
|
|
|
|
|
|
|
: 'Blood Test Result', |
440
|
|
|
|
|
|
|
column => 'label', |
441
|
|
|
|
|
|
|
ontology => $mapping->{ontology}, |
442
|
2785
|
100
|
|
|
|
14631
|
self => $self |
|
|
100
|
|
|
|
|
|
443
|
|
|
|
|
|
|
} |
444
|
|
|
|
|
|
|
) |
445
|
|
|
|
|
|
|
}; |
446
|
|
|
|
|
|
|
|
447
|
|
|
|
|
|
|
# Add to array |
448
|
2785
|
|
|
|
|
7089
|
push @{ $individual->{measures} }, $measure |
449
|
2785
|
50
|
|
|
|
6824
|
if defined $measure->{assayCode}; |
450
|
|
|
|
|
|
|
} |
451
|
|
|
|
|
|
|
|
452
|
|
|
|
|
|
|
# ========= |
453
|
|
|
|
|
|
|
# pedigrees |
454
|
|
|
|
|
|
|
# ========= |
455
|
|
|
|
|
|
|
|
456
|
|
|
|
|
|
|
#$individual->{pedigrees} = []; |
457
|
|
|
|
|
|
|
|
458
|
|
|
|
|
|
|
# disease, id, members, numSubjects |
459
|
|
|
|
|
|
|
#my @pedigrees = @{ $mapping_file->{pedigrees}{fields} }; |
460
|
|
|
|
|
|
|
#for my $field (@pedigrees) { |
461
|
|
|
|
|
|
|
# |
462
|
|
|
|
|
|
|
# my $pedigree; |
463
|
|
|
|
|
|
|
# $pedigree->{disease} = {}; # P32Y6M1D |
464
|
|
|
|
|
|
|
# $pedigree->{id} = undef; |
465
|
|
|
|
|
|
|
# $pedigree->{members} = []; |
466
|
|
|
|
|
|
|
# $pedigree->{numSubjects} = 0; |
467
|
|
|
|
|
|
|
# |
468
|
|
|
|
|
|
|
# Add to array |
469
|
|
|
|
|
|
|
#push @{ $individual->{pedigrees} }, $pedigree; # SWITCHED OFF on 072622 |
470
|
|
|
|
|
|
|
|
471
|
|
|
|
|
|
|
# } |
472
|
|
|
|
|
|
|
|
473
|
|
|
|
|
|
|
# ================== |
474
|
|
|
|
|
|
|
# phenotypicFeatures |
475
|
|
|
|
|
|
|
# ================== |
476
|
|
|
|
|
|
|
|
477
|
|
|
|
|
|
|
#$individual->{phenotypicFeatures} = []; |
478
|
|
|
|
|
|
|
|
479
|
|
|
|
|
|
|
# Load hashref with cursors for mapping |
480
|
180
|
|
|
|
|
470
|
$mapping = remap_mapping_hash( $mapping_file, 'phenotypicFeatures' ); |
481
|
|
|
|
|
|
|
|
482
|
180
|
|
|
|
|
263
|
for my $field ( @{ $mapping->{fields} } ) { |
|
180
|
|
|
|
|
362
|
|
483
|
3060
|
|
|
|
|
2964
|
my $phenotypicFeature; |
484
|
|
|
|
|
|
|
|
485
|
3060
|
100
|
66
|
|
|
7378
|
if ( defined $participant->{$field} && $participant->{$field} ne '' ) { |
486
|
|
|
|
|
|
|
|
487
|
|
|
|
|
|
|
#$phenotypicFeature->{evidence} = undef; # P32Y6M1D |
488
|
410
|
|
|
|
|
1067
|
my $tmp_var = $redcap_dict->{$field}{'Field Label'}; |
489
|
|
|
|
|
|
|
|
490
|
|
|
|
|
|
|
# *** IMPORTANT *** |
491
|
|
|
|
|
|
|
# Ad hoc change for 3TR |
492
|
410
|
100
|
66
|
|
|
1893
|
if ( $project_id eq '3tr_ibd' && $field =~ m/comorb/i ) { |
493
|
|
|
|
|
|
|
( undef, $tmp_var ) = split / \- /, |
494
|
195
|
|
|
|
|
694
|
$redcap_dict->{$field}{'Field Label'}; |
495
|
|
|
|
|
|
|
} |
496
|
|
|
|
|
|
|
|
497
|
|
|
|
|
|
|
# Excluded (or Included) properties |
498
|
|
|
|
|
|
|
# 1 => included ( == not excluded ) |
499
|
|
|
|
|
|
|
$phenotypicFeature->{excluded} = |
500
|
|
|
|
|
|
|
$participant->{$field} ? JSON::XS::false : JSON::XS::true |
501
|
410
|
100
|
|
|
|
1858
|
if looks_like_number( $participant->{$field} ); |
|
|
100
|
|
|
|
|
|
502
|
|
|
|
|
|
|
|
503
|
|
|
|
|
|
|
#$phenotypicFeature->{excluded_ori} = $participant->{$field}; |
504
|
|
|
|
|
|
|
|
505
|
|
|
|
|
|
|
$phenotypicFeature->{featureType} = map_ontology( |
506
|
|
|
|
|
|
|
{ |
507
|
|
|
|
|
|
|
query => exists $mapping->{dict}{$tmp_var} |
508
|
|
|
|
|
|
|
? $mapping->{dict}{$tmp_var} |
509
|
|
|
|
|
|
|
: $tmp_var, |
510
|
|
|
|
|
|
|
column => 'label', |
511
|
|
|
|
|
|
|
ontology => $mapping->{ontology}, |
512
|
410
|
100
|
|
|
|
2915
|
self => $self |
513
|
|
|
|
|
|
|
|
514
|
|
|
|
|
|
|
} |
515
|
|
|
|
|
|
|
); |
516
|
|
|
|
|
|
|
|
517
|
|
|
|
|
|
|
#$phenotypicFeature->{modifiers} = { id => '', label => '' }; |
518
|
|
|
|
|
|
|
$phenotypicFeature->{notes} = join ' /// ', |
519
|
|
|
|
|
|
|
( |
520
|
|
|
|
|
|
|
$field, |
521
|
410
|
|
|
|
|
964
|
map { qq/$_=$redcap_dict->{$field}{$_}/ } @redcap_field_types |
|
1230
|
|
|
|
|
4292
|
|
522
|
|
|
|
|
|
|
); |
523
|
|
|
|
|
|
|
|
524
|
|
|
|
|
|
|
#$phenotypicFeature->{onset} = { id => '', label => '' }; |
525
|
|
|
|
|
|
|
#$phenotypicFeature->{resolution} = { id => '', label => '' }; |
526
|
|
|
|
|
|
|
#$phenotypicFeature->{severity} = { id => '', label => '' }; |
527
|
|
|
|
|
|
|
|
528
|
|
|
|
|
|
|
# Add to array |
529
|
410
|
|
|
|
|
1268
|
push @{ $individual->{phenotypicFeatures} }, $phenotypicFeature |
530
|
410
|
50
|
|
|
|
969
|
if defined $phenotypicFeature->{featureType}; |
531
|
|
|
|
|
|
|
} |
532
|
|
|
|
|
|
|
} |
533
|
|
|
|
|
|
|
|
534
|
|
|
|
|
|
|
# === |
535
|
|
|
|
|
|
|
# sex |
536
|
|
|
|
|
|
|
# === |
537
|
|
|
|
|
|
|
|
538
|
|
|
|
|
|
|
$individual->{sex} = map_ontology( |
539
|
|
|
|
|
|
|
{ |
540
|
180
|
|
|
|
|
989
|
query => $participant->{$sex_field}, |
541
|
|
|
|
|
|
|
column => 'label', |
542
|
|
|
|
|
|
|
ontology => $project_ontology, |
543
|
|
|
|
|
|
|
self => $self |
544
|
|
|
|
|
|
|
} |
545
|
|
|
|
|
|
|
); |
546
|
|
|
|
|
|
|
|
547
|
|
|
|
|
|
|
# ========== |
548
|
|
|
|
|
|
|
# treatments |
549
|
|
|
|
|
|
|
# ========== |
550
|
|
|
|
|
|
|
|
551
|
|
|
|
|
|
|
#$individual->{treatments} = undef; |
552
|
|
|
|
|
|
|
|
553
|
180
|
|
|
|
|
515
|
$mapping = remap_mapping_hash( $mapping_file, 'treatments' ); |
554
|
|
|
|
|
|
|
|
555
|
180
|
|
|
|
|
295
|
for my $field ( @{ $mapping->{fields} } ) { |
|
180
|
|
|
|
|
357
|
|
556
|
|
|
|
|
|
|
|
557
|
|
|
|
|
|
|
# Getting the right name for the drug (if any) |
558
|
|
|
|
|
|
|
my $treatment_name = |
559
|
|
|
|
|
|
|
exists $mapping->{dict}{$field} |
560
|
1080
|
100
|
|
|
|
2405
|
? $mapping->{dict}{$field} |
561
|
|
|
|
|
|
|
: $field; |
562
|
|
|
|
|
|
|
|
563
|
|
|
|
|
|
|
# FOR ROUTES |
564
|
1080
|
|
|
|
|
1198
|
for my $route ( @{ $mapping->{routesOfAdministration} } ) { |
|
1080
|
|
|
|
|
1594
|
|
565
|
|
|
|
|
|
|
|
566
|
|
|
|
|
|
|
# Ad hoc for 3TR |
567
|
2160
|
|
|
|
|
2432
|
my $tmp_var = $field; |
568
|
2160
|
50
|
|
|
|
3138
|
if ( $project_id eq '3tr_ibd' ) { |
569
|
|
|
|
|
|
|
|
570
|
|
|
|
|
|
|
# Rectal route only happens in some drugs (ad hoc) |
571
|
|
|
|
|
|
|
next |
572
|
|
|
|
|
|
|
if ( |
573
|
1980
|
|
|
1980
|
|
4922
|
$route eq 'rectal' && !any { $_ eq $field } |
574
|
2160
|
100
|
100
|
|
|
6444
|
qw(budesonide asa) |
575
|
|
|
|
|
|
|
); |
576
|
|
|
|
|
|
|
|
577
|
|
|
|
|
|
|
# Discarding if drug_route_status is empty |
578
|
1440
|
100
|
100
|
|
|
5003
|
$tmp_var = |
579
|
|
|
|
|
|
|
( $field eq 'budesonide' || $field eq 'asa' ) |
580
|
|
|
|
|
|
|
? $field . '_' . $route . '_status' |
581
|
|
|
|
|
|
|
: $field . '_status'; |
582
|
|
|
|
|
|
|
next |
583
|
1440
|
100
|
|
|
|
3400
|
unless defined $participant->{$tmp_var}; |
584
|
|
|
|
|
|
|
} |
585
|
|
|
|
|
|
|
|
586
|
|
|
|
|
|
|
# Initialize field $treatment |
587
|
320
|
|
|
|
|
351
|
my $treatment; |
588
|
|
|
|
|
|
|
|
589
|
|
|
|
|
|
|
$treatment->{_info} = { |
590
|
|
|
|
|
|
|
field => $tmp_var, |
591
|
|
|
|
|
|
|
drug => $field, |
592
|
|
|
|
|
|
|
drug_name => $treatment_name, |
593
|
|
|
|
|
|
|
status => $participant->{$tmp_var}, |
594
|
|
|
|
|
|
|
route => $route, |
595
|
|
|
|
|
|
|
value => $participant->{ $tmp_var . '_ori' }, |
596
|
320
|
|
|
|
|
787
|
map { $_ => $participant->{ $field . $_ } } |
|
960
|
|
|
|
|
4522
|
|
597
|
|
|
|
|
|
|
qw(start dose duration) |
598
|
|
|
|
|
|
|
}; # ***** INTERNAL FIELD |
599
|
320
|
|
|
|
|
605
|
$treatment->{ageAtOnset} = $default_age; |
600
|
|
|
|
|
|
|
$treatment->{cumulativeDose} = |
601
|
320
|
|
|
|
|
790
|
{ unit => $default_ontology, value => -1 }; |
602
|
320
|
|
|
|
|
534
|
$treatment->{doseIntervals} = []; |
603
|
|
|
|
|
|
|
$treatment->{routeOfAdministration} = map_ontology( |
604
|
|
|
|
|
|
|
{ |
605
|
|
|
|
|
|
|
query => ucfirst($route) |
606
|
|
|
|
|
|
|
. ' Route of Administration' |
607
|
|
|
|
|
|
|
, # Oral Route of Administration |
608
|
|
|
|
|
|
|
column => 'label', |
609
|
|
|
|
|
|
|
ontology => $mapping->{ontology}, |
610
|
320
|
|
|
|
|
1804
|
self => $self |
611
|
|
|
|
|
|
|
} |
612
|
|
|
|
|
|
|
); |
613
|
|
|
|
|
|
|
|
614
|
|
|
|
|
|
|
$treatment->{treatmentCode} = map_ontology( |
615
|
|
|
|
|
|
|
{ |
616
|
|
|
|
|
|
|
query => $treatment_name, |
617
|
|
|
|
|
|
|
column => 'label', |
618
|
|
|
|
|
|
|
ontology => $mapping->{ontology}, |
619
|
320
|
|
|
|
|
1153
|
self => $self |
620
|
|
|
|
|
|
|
} |
621
|
|
|
|
|
|
|
); |
622
|
320
|
|
|
|
|
788
|
push @{ $individual->{treatments} }, $treatment |
623
|
320
|
50
|
|
|
|
724
|
if defined $treatment->{treatmentCode}; |
624
|
|
|
|
|
|
|
} |
625
|
|
|
|
|
|
|
} |
626
|
|
|
|
|
|
|
|
627
|
|
|
|
|
|
|
################################## |
628
|
|
|
|
|
|
|
# END MAPPING TO BEACON V2 TERMS # |
629
|
|
|
|
|
|
|
################################## |
630
|
|
|
|
|
|
|
|
631
|
180
|
|
|
|
|
2984
|
return $individual; |
632
|
|
|
|
|
|
|
} |
633
|
|
|
|
|
|
|
|
634
|
|
|
|
|
|
|
1; |