line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Convert::Pheno::REDCap; |
2
|
|
|
|
|
|
|
|
3
|
6
|
|
|
6
|
|
46
|
use strict; |
|
6
|
|
|
|
|
14
|
|
|
6
|
|
|
|
|
202
|
|
4
|
6
|
|
|
6
|
|
45
|
use warnings; |
|
6
|
|
|
|
|
20
|
|
|
6
|
|
|
|
|
158
|
|
5
|
6
|
|
|
6
|
|
37
|
use autodie; |
|
6
|
|
|
|
|
13
|
|
|
6
|
|
|
|
|
36
|
|
6
|
6
|
|
|
6
|
|
32821
|
use feature qw(say); |
|
6
|
|
|
|
|
19
|
|
|
6
|
|
|
|
|
501
|
|
7
|
6
|
|
|
6
|
|
52
|
use List::Util qw(any); |
|
6
|
|
|
|
|
20
|
|
|
6
|
|
|
|
|
534
|
|
8
|
6
|
|
|
6
|
|
51
|
use Convert::Pheno::Mapping; |
|
6
|
|
|
|
|
24
|
|
|
6
|
|
|
|
|
669
|
|
9
|
6
|
|
|
6
|
|
64
|
use Convert::Pheno::PXF; |
|
6
|
|
|
|
|
13
|
|
|
6
|
|
|
|
|
326
|
|
10
|
6
|
|
|
6
|
|
79
|
use Data::Dumper; |
|
6
|
|
|
|
|
36
|
|
|
6
|
|
|
|
|
311
|
|
11
|
6
|
|
|
6
|
|
48
|
use Scalar::Util qw(looks_like_number); |
|
6
|
|
|
|
|
21
|
|
|
6
|
|
|
|
|
383
|
|
12
|
6
|
|
|
6
|
|
43
|
use Exporter 'import'; |
|
6
|
|
|
|
|
26
|
|
|
6
|
|
|
|
|
15489
|
|
13
|
|
|
|
|
|
|
our @EXPORT = qw(do_redcap2bff); |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
################ |
16
|
|
|
|
|
|
|
################ |
17
|
|
|
|
|
|
|
# REDCAP2BFF # |
18
|
|
|
|
|
|
|
################ |
19
|
|
|
|
|
|
|
################ |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub do_redcap2bff { |
22
|
|
|
|
|
|
|
|
23
|
180
|
|
|
180
|
0
|
322
|
my ( $self, $participant ) = @_; |
24
|
180
|
|
|
|
|
260
|
my $redcap_dict = $self->{data_redcap_dict}; |
25
|
180
|
|
|
|
|
296
|
my $mapping_file = $self->{data_mapping_file}; |
26
|
180
|
|
|
|
|
271
|
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
|
|
|
427
|
if ( defined $self->{debug} && $self->{debug} > 4 ); |
60
|
|
|
|
|
|
|
print Dumper $participant |
61
|
180
|
50
|
33
|
|
|
364
|
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
|
|
|
|
|
375
|
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
|
|
|
|
|
280
|
my $sex_field = $mapping_file->{sex}; |
70
|
180
|
|
|
|
|
365
|
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
|
|
|
|
529
|
if ( defined $participant->{$sex_field} ) { |
78
|
|
|
|
|
|
|
$self->{_info}{ $participant->{study_id} }{$sex_field} = |
79
|
40
|
|
|
|
|
251
|
$participant->{$sex_field}; # Dynamically adding attributes (setter) |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
$participant->{$sex_field} = |
82
|
180
|
|
|
|
|
729
|
$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
|
|
|
707
|
&& $participant->{$sex_field} ); |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
# Data structure (hashref) for each individual |
90
|
180
|
|
|
|
|
197
|
my $individual; |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
# Default ontology for a bunch of required terms |
93
|
180
|
|
|
|
|
436
|
my $default_ontology = { id => 'NCIT:NA0000', label => 'NA' }; |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
# More default values |
96
|
180
|
|
|
|
|
258
|
my $default_date = '1900-01-01'; |
97
|
180
|
|
|
|
|
260
|
my $default_duration = 'P999Y'; |
98
|
180
|
|
|
|
|
531
|
my $default_age = { age => { iso8601duration => 'P999Y' } }; |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
# Variable that will allow to perform ad hoc changes for specific projects |
101
|
180
|
|
|
|
|
358
|
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
|
|
|
|
|
268
|
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
|
|
|
|
|
236
|
grep { defined $redcap_dict->{$_}{_labels} } sort keys %{$redcap_dict}; |
|
70555
|
|
|
|
|
113235
|
|
|
180
|
|
|
|
|
41607
|
|
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
# Perform the mapping for this participant |
127
|
180
|
|
|
|
|
3314
|
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
|
|
|
|
|
68441
|
$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
|
|
|
|
69800
|
) 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
|
|
|
|
|
411
|
my $mapping = remap_mapping_hash( $mapping_file, 'diseases' ); |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
# Start looping over them |
156
|
180
|
|
|
|
|
280
|
for my $field ( @{ $mapping->{fields} } ) { |
|
180
|
|
|
|
|
430
|
|
157
|
180
|
|
|
|
|
237
|
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
|
|
|
993
|
&& defined $participant->{ $mapping->{map}{ageOfOnset} } ); |
165
|
|
|
|
|
|
|
$disease->{diseaseCode} = map_ontology( |
166
|
|
|
|
|
|
|
{ |
167
|
|
|
|
|
|
|
query => $field, |
168
|
|
|
|
|
|
|
column => 'label', |
169
|
|
|
|
|
|
|
ontology => $mapping->{ontology}, |
170
|
180
|
|
|
|
|
1104
|
self => $self |
171
|
|
|
|
|
|
|
} |
172
|
|
|
|
|
|
|
); |
173
|
|
|
|
|
|
|
$disease->{familyHistory} = |
174
|
|
|
|
|
|
|
convert2boolean( $participant->{ $mapping->{map}{familyHistory} } ) |
175
|
|
|
|
|
|
|
if ( exists $mapping->{map}{familyHistory} |
176
|
180
|
100
|
66
|
|
|
1144
|
&& defined $participant->{ $mapping->{map}{familyHistory} } ); |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
#$disease->{notes} = undef; |
179
|
180
|
|
|
|
|
429
|
$disease->{severity} = $default_ontology; |
180
|
180
|
|
|
|
|
267
|
$disease->{stage} = $default_ontology; |
181
|
|
|
|
|
|
|
|
182
|
180
|
|
|
|
|
612
|
push @{ $individual->{diseases} }, $disease |
183
|
180
|
50
|
|
|
|
358
|
if defined $disease->{diseaseCode}; |
184
|
|
|
|
|
|
|
} |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
# ========= |
187
|
|
|
|
|
|
|
# ethnicity |
188
|
|
|
|
|
|
|
# ========= |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
# Load field name from mapping file |
191
|
180
|
|
|
|
|
324
|
my $ethnicity_field = $mapping_file->{ethnicity}; |
192
|
|
|
|
|
|
|
$individual->{ethnicity} = map_ethnicity( $participant->{$ethnicity_field} ) |
193
|
180
|
100
|
|
|
|
505
|
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
|
|
|
|
|
358
|
$mapping = remap_mapping_hash( $mapping_file, 'exposures' ); |
203
|
|
|
|
|
|
|
|
204
|
180
|
|
|
|
|
262
|
for my $field ( @{ $mapping->{fields} } ) { |
|
180
|
|
|
|
|
340
|
|
205
|
1080
|
100
|
|
|
|
2162
|
next unless defined $participant->{$field}; |
206
|
|
|
|
|
|
|
|
207
|
85
|
|
|
|
|
105
|
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
|
|
|
289
|
: $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
|
|
|
|
192
|
: $default_duration; |
221
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
# Query related |
223
|
|
|
|
|
|
|
my $exposure_query = |
224
|
|
|
|
|
|
|
exists $mapping->{dict}{$field} |
225
|
85
|
50
|
|
|
|
226
|
? $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
|
|
|
|
|
372
|
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
|
|
|
|
276
|
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
|
|
|
|
499
|
self => $self |
254
|
|
|
|
|
|
|
} |
255
|
|
|
|
|
|
|
); |
256
|
85
|
|
|
|
|
207
|
$exposure->{unit} = $unit; |
257
|
85
|
|
100
|
|
|
313
|
$exposure->{value} = $participant->{ $field . '_ori' } // -1; |
258
|
85
|
|
|
|
|
235
|
push @{ $individual->{exposures} }, $exposure |
259
|
85
|
50
|
|
|
|
185
|
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
|
|
|
|
|
264
|
map { $participant->{$_} } @{ $mapping_file->{id}{fields} }; |
|
360
|
|
|
|
|
1219
|
|
|
180
|
|
|
|
|
413
|
|
275
|
|
|
|
|
|
|
|
276
|
|
|
|
|
|
|
# ==== |
277
|
|
|
|
|
|
|
# info |
278
|
|
|
|
|
|
|
# ==== |
279
|
|
|
|
|
|
|
|
280
|
|
|
|
|
|
|
# Load hashref with cursors for mapping |
281
|
180
|
|
|
|
|
495
|
$mapping = remap_mapping_hash( $mapping_file, 'info' ); |
282
|
|
|
|
|
|
|
|
283
|
180
|
|
|
|
|
239
|
for my $field ( @{ $mapping->{fields} } ) { |
|
180
|
|
|
|
|
332
|
|
284
|
2880
|
100
|
|
|
|
5633
|
if ( defined $participant->{$field} ) { |
285
|
|
|
|
|
|
|
|
286
|
|
|
|
|
|
|
# Ad hoc for 3TR |
287
|
725
|
50
|
|
|
|
1136
|
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
|
|
|
|
|
2868
|
map { $_ => $redcap_dict->{$field}{$_} } |
293
|
|
|
|
|
|
|
@redcap_field_types |
294
|
|
|
|
|
|
|
} |
295
|
725
|
100
|
|
|
|
2529
|
: $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
|
|
|
|
623
|
$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
|
|
|
|
|
396
|
$mapping = remap_mapping_hash( $mapping_file, 'interventionsOrProcedures' ); |
314
|
|
|
|
|
|
|
|
315
|
180
|
|
|
|
|
277
|
for my $field ( @{ $mapping->{fields} } ) { |
|
180
|
|
|
|
|
381
|
|
316
|
2880
|
100
|
|
|
|
5413
|
if ( $participant->{$field} ) { |
317
|
|
|
|
|
|
|
|
318
|
|
|
|
|
|
|
# Why this |
319
|
|
|
|
|
|
|
next |
320
|
|
|
|
|
|
|
if ( exists $mapping->{map}{dateOfProcedure} |
321
|
415
|
100
|
66
|
|
|
1418
|
&& $field eq $mapping->{map}{dateOfProcedure} ); |
322
|
330
|
|
|
|
|
370
|
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
|
|
|
860
|
: $default_age; |
330
|
|
|
|
|
|
|
|
331
|
|
|
|
|
|
|
$intervention->{bodySite} = |
332
|
330
|
50
|
|
|
|
1026
|
{ "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
|
|
|
1449
|
: $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
|
|
|
|
1910
|
self => $self |
|
|
50
|
|
|
|
|
|
350
|
|
|
|
|
|
|
} |
351
|
|
|
|
|
|
|
) if defined $field; |
352
|
330
|
|
|
|
|
832
|
push @{ $individual->{interventionsOrProcedures} }, $intervention |
353
|
330
|
50
|
|
|
|
839
|
if defined $intervention->{procedureCode}; |
354
|
|
|
|
|
|
|
} |
355
|
|
|
|
|
|
|
} |
356
|
|
|
|
|
|
|
|
357
|
|
|
|
|
|
|
# ============= |
358
|
|
|
|
|
|
|
# karyotypicSex |
359
|
|
|
|
|
|
|
# ============= |
360
|
|
|
|
|
|
|
|
361
|
|
|
|
|
|
|
# $individual->{karyotypicSex} = undef; |
362
|
|
|
|
|
|
|
|
363
|
|
|
|
|
|
|
# ======== |
364
|
|
|
|
|
|
|
# measures |
365
|
|
|
|
|
|
|
# ======== |
366
|
|
|
|
|
|
|
|
367
|
180
|
|
|
|
|
329
|
$individual->{measures} = undef; |
368
|
|
|
|
|
|
|
|
369
|
|
|
|
|
|
|
# Load hashref with cursors for mapping |
370
|
180
|
|
|
|
|
399
|
$mapping = remap_mapping_hash( $mapping_file, 'measures' ); |
371
|
|
|
|
|
|
|
|
372
|
180
|
|
|
|
|
241
|
for my $field ( @{ $mapping->{fields} } ) { |
|
180
|
|
|
|
|
363
|
|
373
|
4140
|
100
|
|
|
|
9111
|
next unless defined $participant->{$field}; |
374
|
2785
|
|
|
|
|
2935
|
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
|
|
|
|
10964
|
self => $self, |
384
|
|
|
|
|
|
|
} |
385
|
|
|
|
|
|
|
); |
386
|
2785
|
|
|
|
|
5795
|
$measure->{date} = $default_date; |
387
|
|
|
|
|
|
|
|
388
|
|
|
|
|
|
|
# We first extract 'unit' and %range' for <measurementValue> |
389
|
2785
|
|
|
|
|
8343
|
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
|
|
|
|
12721
|
if ( $participant->{$field} =~ m/ \- / ) { |
401
|
90
|
|
|
|
|
337
|
my ( $tmp_val, $tmp_scale ) = split / \- /, $participant->{$field}; |
402
|
90
|
|
|
|
|
174
|
$participant->{$field} = |
403
|
|
|
|
|
|
|
$tmp_val; # should be equal to $participant->{$field.'_ori'} |
404
|
90
|
|
|
|
|
138
|
$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
|
|
|
|
11826
|
self => $self |
415
|
|
|
|
|
|
|
} |
416
|
|
|
|
|
|
|
); |
417
|
|
|
|
|
|
|
$measure->{measurementValue} = { |
418
|
|
|
|
|
|
|
quantity => { |
419
|
|
|
|
|
|
|
unit => $unit, |
420
|
2785
|
|
|
|
|
6609
|
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
|
|
|
|
|
5985
|
( map { qq/$_=$redcap_dict->{$field}{$_}/ } @redcap_field_types ); |
|
8355
|
|
|
|
|
24762
|
|
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
|
|
|
|
13936
|
self => $self |
|
|
100
|
|
|
|
|
|
443
|
|
|
|
|
|
|
} |
444
|
|
|
|
|
|
|
) |
445
|
|
|
|
|
|
|
}; |
446
|
|
|
|
|
|
|
|
447
|
|
|
|
|
|
|
# Add to array |
448
|
2785
|
|
|
|
|
7207
|
push @{ $individual->{measures} }, $measure |
449
|
2785
|
50
|
|
|
|
6473
|
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
|
|
|
|
|
469
|
$mapping = remap_mapping_hash( $mapping_file, 'phenotypicFeatures' ); |
481
|
|
|
|
|
|
|
|
482
|
180
|
|
|
|
|
261
|
for my $field ( @{ $mapping->{fields} } ) { |
|
180
|
|
|
|
|
389
|
|
483
|
3060
|
|
|
|
|
2801
|
my $phenotypicFeature; |
484
|
|
|
|
|
|
|
|
485
|
3060
|
100
|
66
|
|
|
6869
|
if ( defined $participant->{$field} && $participant->{$field} ne '' ) { |
486
|
|
|
|
|
|
|
|
487
|
|
|
|
|
|
|
#$phenotypicFeature->{evidence} = undef; # P32Y6M1D |
488
|
410
|
|
|
|
|
913
|
my $tmp_var = $redcap_dict->{$field}{'Field Label'}; |
489
|
|
|
|
|
|
|
|
490
|
|
|
|
|
|
|
# *** IMPORTANT *** |
491
|
|
|
|
|
|
|
# Ad hoc change for 3TR |
492
|
410
|
100
|
66
|
|
|
1857
|
if ( $project_id eq '3tr_ibd' && $field =~ m/comorb/i ) { |
493
|
|
|
|
|
|
|
( undef, $tmp_var ) = split / \- /, |
494
|
195
|
|
|
|
|
632
|
$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
|
|
|
|
1758
|
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
|
|
|
|
2679
|
self => $self |
513
|
|
|
|
|
|
|
|
514
|
|
|
|
|
|
|
} |
515
|
|
|
|
|
|
|
); |
516
|
|
|
|
|
|
|
|
517
|
|
|
|
|
|
|
#$phenotypicFeature->{modifiers} = { id => '', label => '' }; |
518
|
|
|
|
|
|
|
$phenotypicFeature->{notes} = join ' /// ', |
519
|
|
|
|
|
|
|
( |
520
|
|
|
|
|
|
|
$field, |
521
|
410
|
|
|
|
|
939
|
map { qq/$_=$redcap_dict->{$field}{$_}/ } @redcap_field_types |
|
1230
|
|
|
|
|
4172
|
|
522
|
|
|
|
|
|
|
); |
523
|
|
|
|
|
|
|
|
524
|
|
|
|
|
|
|
#$phenotypicFeature->{onset} = { id => '', label => '' }; |
525
|
|
|
|
|
|
|
#$phenotypicFeature->{resolution} = { id => '', label => '' }; |
526
|
|
|
|
|
|
|
#$phenotypicFeature->{severity} = { id => '', label => '' }; |
527
|
|
|
|
|
|
|
|
528
|
|
|
|
|
|
|
# Add to array |
529
|
410
|
|
|
|
|
1217
|
push @{ $individual->{phenotypicFeatures} }, $phenotypicFeature |
530
|
410
|
50
|
|
|
|
1277
|
if defined $phenotypicFeature->{featureType}; |
531
|
|
|
|
|
|
|
} |
532
|
|
|
|
|
|
|
} |
533
|
|
|
|
|
|
|
|
534
|
|
|
|
|
|
|
# === |
535
|
|
|
|
|
|
|
# sex |
536
|
|
|
|
|
|
|
# === |
537
|
|
|
|
|
|
|
|
538
|
|
|
|
|
|
|
$individual->{sex} = map_ontology( |
539
|
|
|
|
|
|
|
{ |
540
|
180
|
|
|
|
|
837
|
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
|
|
|
|
|
468
|
$mapping = remap_mapping_hash( $mapping_file, 'treatments' ); |
554
|
|
|
|
|
|
|
|
555
|
180
|
|
|
|
|
273
|
for my $field ( @{ $mapping->{fields} } ) { |
|
180
|
|
|
|
|
369
|
|
556
|
|
|
|
|
|
|
|
557
|
|
|
|
|
|
|
# Getting the right name for the drug (if any) |
558
|
|
|
|
|
|
|
my $treatment_name = |
559
|
|
|
|
|
|
|
exists $mapping->{dict}{$field} |
560
|
1080
|
100
|
|
|
|
2338
|
? $mapping->{dict}{$field} |
561
|
|
|
|
|
|
|
: $field; |
562
|
|
|
|
|
|
|
|
563
|
|
|
|
|
|
|
# FOR ROUTES |
564
|
1080
|
|
|
|
|
1108
|
for my $route ( @{ $mapping->{routesOfAdministration} } ) { |
|
1080
|
|
|
|
|
1643
|
|
565
|
|
|
|
|
|
|
|
566
|
|
|
|
|
|
|
# Ad hoc for 3TR |
567
|
2160
|
|
|
|
|
2449
|
my $tmp_var = $field; |
568
|
2160
|
50
|
|
|
|
3187
|
if ( $project_id eq '3tr_ibd' ) { |
569
|
|
|
|
|
|
|
|
570
|
|
|
|
|
|
|
# Rectal route only happens in some drugs (ad hoc) |
571
|
|
|
|
|
|
|
next |
572
|
|
|
|
|
|
|
if ( |
573
|
1980
|
|
|
1980
|
|
4820
|
$route eq 'rectal' && !any { $_ eq $field } |
574
|
2160
|
100
|
100
|
|
|
6246
|
qw(budesonide asa) |
575
|
|
|
|
|
|
|
); |
576
|
|
|
|
|
|
|
|
577
|
|
|
|
|
|
|
# Discarding if drug_route_status is empty |
578
|
1440
|
100
|
100
|
|
|
4807
|
$tmp_var = |
579
|
|
|
|
|
|
|
( $field eq 'budesonide' || $field eq 'asa' ) |
580
|
|
|
|
|
|
|
? $field . '_' . $route . '_status' |
581
|
|
|
|
|
|
|
: $field . '_status'; |
582
|
|
|
|
|
|
|
next |
583
|
1440
|
100
|
|
|
|
3304
|
unless defined $participant->{$tmp_var}; |
584
|
|
|
|
|
|
|
} |
585
|
|
|
|
|
|
|
|
586
|
|
|
|
|
|
|
# Initialize field $treatment |
587
|
320
|
|
|
|
|
331
|
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
|
|
|
|
|
833
|
map { $_ => $participant->{ $field . $_ } } |
|
960
|
|
|
|
|
3631
|
|
597
|
|
|
|
|
|
|
qw(start dose duration) |
598
|
|
|
|
|
|
|
}; # ***** INTERNAL FIELD |
599
|
320
|
|
|
|
|
631
|
$treatment->{ageAtOnset} = $default_age; |
600
|
|
|
|
|
|
|
$treatment->{cumulativeDose} = |
601
|
320
|
|
|
|
|
738
|
{ unit => $default_ontology, value => -1 }; |
602
|
320
|
|
|
|
|
515
|
$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
|
|
|
|
|
1706
|
self => $self |
611
|
|
|
|
|
|
|
} |
612
|
|
|
|
|
|
|
); |
613
|
|
|
|
|
|
|
|
614
|
|
|
|
|
|
|
$treatment->{treatmentCode} = map_ontology( |
615
|
|
|
|
|
|
|
{ |
616
|
|
|
|
|
|
|
query => $treatment_name, |
617
|
|
|
|
|
|
|
column => 'label', |
618
|
|
|
|
|
|
|
ontology => $mapping->{ontology}, |
619
|
320
|
|
|
|
|
1135
|
self => $self |
620
|
|
|
|
|
|
|
} |
621
|
|
|
|
|
|
|
); |
622
|
320
|
|
|
|
|
779
|
push @{ $individual->{treatments} }, $treatment |
623
|
320
|
50
|
|
|
|
737
|
if defined $treatment->{treatmentCode}; |
624
|
|
|
|
|
|
|
} |
625
|
|
|
|
|
|
|
} |
626
|
|
|
|
|
|
|
|
627
|
|
|
|
|
|
|
################################## |
628
|
|
|
|
|
|
|
# END MAPPING TO BEACON V2 TERMS # |
629
|
|
|
|
|
|
|
################################## |
630
|
|
|
|
|
|
|
|
631
|
180
|
|
|
|
|
2988
|
return $individual; |
632
|
|
|
|
|
|
|
} |
633
|
|
|
|
|
|
|
|
634
|
|
|
|
|
|
|
1; |