lib/Convert/Pheno/OMOP/ToBFF/Individuals.pm

filter: Statementstmt 96.9% 223 / 230 Branchbran 73.8% 93 / 126 Conditioncond 51.1% 23 / 45 MC/DCmcdc 29.6% 8 / 27 Subroutinesub 100% 24 / 24 Podpod 0.0% 0 / 3 totaltotal 81.5% 371 / 455 CC 87 SCAR 25.9
CC
87
Cov
85%
_country_of_birth_query
60.2
_is_country_of_birth_observation
14.5
_map_measures
11.0
CRAP 13.4
« lib/Convert/Pheno/Source/OMOP.pm ↑ Summary lib/Convert/Pheno/PXF/ToBFF/Biosamples.pm »
1 package Convert::Pheno::OMOP::ToBFF::Individuals;
2  
3 138 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 138 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 138 ▶use autodie;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 138 ▶use feature qw(say);
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 138 ▶use Exporter 'import';
Subroutine BEGIN: called CC=1 SCAR=0.0
9 138 ▶use Convert::Pheno::OMOP::Definitions;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 138 ▶use Convert::Pheno::Utils::Default qw(get_defaults);
Subroutine BEGIN: called CC=1 SCAR=0.0
11 138 ▶use Convert::Pheno::Mapping::Shared;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 138 our @EXPORT_OK = qw(map_participant);
14  
15 138 my $DEFAULT = get_defaults();
16  
17 138 ▶use constant DEVEL_MODE => 0;
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 # Initialize global hash for seen_individual entries in --stream
20 138 my %seen_individual = ();
21  
22 19851 ▶sub map_participant {
Subroutine map_participant: called CC=4 SCAR=13.9
Pod undocumented
23 19851 my ( $self, $participant ) = @_;
24  
25 19851 my $ohdsi_dict = $self->{data_ohdsi_dict};
26  
27 19851 my $individual = {};
28 19851 my $person = $participant->{PERSON};
29  
30 19851 ▶ return unless defined $person->{gender_concept_id};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $person->{"gender_concept_id"} 1196 18655 19851
31  
32 18655 _map_person( $self, $participant, $individual, $ohdsi_dict, $person );
33 18654 _map_diseases( $self, $participant, $individual, $person, $ohdsi_dict );
34 18654 _map_exposures( $self, $participant, $individual, $person, $ohdsi_dict );
35 18654 _map_phenotypicFeatures( $self, $participant, $individual, $person, $ohdsi_dict );
36 18654 _map_interventionsOrProcedures( $self, $participant, $individual, $person, $ohdsi_dict );
37 18654 _map_measures( $self, $participant, $individual, $person, $ohdsi_dict );
38 18654 _map_treatments( $self, $participant, $individual, $person, $ohdsi_dict );
39  
40 18654 ▶ return ( $self->{stream} && avoid_seen_individuals($individual) )
Branch: 1 branch
BranchTrueFalseTotal
$self->{'stream'} && avoid_seen_individuals($individual) ? : 22 18632 18654
Condition100%3/3
$self->{"stream"} and avoid_seen_individuals($individual)
!ll&&!rl&&r
11716691622
MC/DC100%2/2
$self->{"stream"} and avoid_seen_individuals($individual)
$self->{"stream"} avoid_seen_individuals($individual)
Truth table100%3/3
A and B
A= $self->{"stream"}B= avoid_seen_individuals($individual)
ABresult
0X0
100
111
41 ? undef
42 : $individual;
43 }
44  
45 18655 ▶sub _map_person {
Subroutine _map_person: called CC=8 SCAR=20.8
46 18655 my ( $self, $participant, $individual, $ohdsi_dict, $person ) = @_;
47  
48 $individual->{ethnicity} = map_ontology_term(
49 {
50 query => $person->{race_source_value},
51 column => 'label',
52 ontology => 'ncit',
53 self => $self
54 }
55 18655 ▶ ) if defined $person->{race_source_value};
Branch: 1 branch
BranchTrueFalseTotal
if defined $person->{"race_source_value"} 11722 6933 18655
56  
57 18655 my $geographic_origin =
58 _map_geographic_origin_from_country_of_birth( $self, $participant, $ohdsi_dict );
59  
60 # Prefer an explicit OMOP OBSERVATION for country of birth. Keep the older
61 # PERSON.ethnicity_source_value fallback when no country-of-birth
62 # observation can be resolved, because many synthetic OMOP fixtures do not
63 # carry that signal in OBSERVATION.
64 18655 ▶ $individual->{geographicOrigin} = $geographic_origin
Branch: 1 branch
BranchTrueFalseTotal
if defined $geographic_origin 1 18654 18655
65 if defined $geographic_origin;
66  
67 18655 ▶ if ( !defined $geographic_origin
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $geographic_origin and defined $person->{"ethnicity_source_value"}) 11707 6948 18655
Condition100%3/3
not defined $geographic_origin and defined $person->{"ethnicity_source_value"}
!ll&&!rl&&r
1694711707
MC/DC100%2/2
not defined $geographic_origin and defined $person->{"ethnicity_source_value"}
not defined $geographic_origin defined $person->{"ethnicity_source_value"}
Truth table100%3/3
not(A) and B
A= not defined $geographic_originB= defined $person->{"ethnicity_source_value"}
ABresult
0X0
100
111
68 && defined $person->{ethnicity_source_value} )
69 {
70 $individual->{geographicOrigin} = map_ontology_term(
71 {
72 query => $person->{ethnicity_source_value},
73 11707 column => 'label',
74 ontology => 'ncit',
75 self => $self
76 }
77 );
78 }
79  
80 18655 $individual->{id} = $person->{person_id};
81 18655 $individual->{id} = qq/$individual->{id}/;
82  
83 18655 my $table = 'PERSON';
84 18655 ▶ $individual->{info}{$table}{OMOP_columns} = $person if _source_info_enabled($self);
Branch: 1 branch
BranchTrueFalseTotal
if _source_info_enabled($self) 18654 1 18655
85 $individual->{info}{dateOfBirth} =
86 18655 map_iso8601_date2timestamp( $person->{birth_datetime} );
87  
88 18655 ▶ unless ( $self->{test} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"test"}) 1 18654 18655
89 1 $individual->{info}{convertPheno} = $self->{convertPheno};
90 }
91  
92 my $sex = map2ohdsi(
93 {
94 ohdsi_dict => $ohdsi_dict,
95 concept_id => $person->{gender_concept_id},
96 18655 self => $self
97 }
98 );
99  
100 $individual->{sex} = map_ontology_term(
101 {
102 query => $sex->{label},
103 18654 ▶ column => 'label',
Branch: 1 branch
BranchTrueFalseTotal
if $sex 18654 0 18654
104 ontology => 'ncit',
105 self => $self
106 }
107 ) if $sex;
108 }
109  
110 18655 ▶sub _map_geographic_origin_from_country_of_birth {
Subroutine _map_geographic_origin_from_country_of_birth: called CC=6 SCAR=18.2
111 18655 my ( $self, $participant, $ohdsi_dict ) = @_;
112 18655 ▶ return unless defined $participant->{OBSERVATION};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $participant->{"OBSERVATION"} 18222 433 18655
113  
114 433 for my $field ( @{ $participant->{OBSERVATION} } ) {
115 633 ▶ next unless _is_country_of_birth_observation( $self, $field, $ohdsi_dict );
Branch: 1 branch
BranchTrueFalseTotal
unless _is_country_of_birth_observation($self, $field, $ohdsi_dict) 632 1 633
116  
117 1 my $query = _country_of_birth_query( $self, $field, $ohdsi_dict );
118 1 ▶ next unless defined $query && length $query;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $query and length $query 0 1 1
Condition33%1/3
defined $query and length $query
!ll&&!rl&&r
001
MC/DC0%0/2
defined $query and length $query
defined $query length $query
Truth table33%1/3
A and B
A= defined $queryB= length $query
ABresult
0X0
100
111
119  
120 1 return map_ontology_term(
121 {
122 query => $query,
123 column => 'label',
124 ontology => 'ncit',
125 self => $self
126 }
127 );
128 }
129  
130 432 return;
131 }
132  
133 1267 ▶sub _is_country_of_birth_observation {
Subroutine _is_country_of_birth_observation: called CC=11 SCAR=26.7
134 1267 my ( $self, $field, $ohdsi_dict ) = @_;
135 1267 my @labels;
136 my $observation_source_value =
137 exists $field->{observation_source_value}
138 ? $field->{observation_source_value}
139 1267 ▶ : undef;
Branch: 1 branch
BranchTrueFalseTotal
exists $field->{'observation_source_value'} ? : 1266 1 1267
140 my $observation_concept_id =
141 exists $field->{observation_concept_id}
142 ? $field->{observation_concept_id}
143 1267 ▶ : undef;
Branch: 1 branch
BranchTrueFalseTotal
exists $field->{'observation_concept_id'} ? : 1267 0 1267
144  
145 1267 ▶ if ( defined $observation_source_value
Branch: 1 branch
BranchTrueFalseTotal
if (defined $observation_source_value and length $observation_source_value and $observation_source_value ne "\\N") 1266 1 1267
Condition66%4/6
defined $observation_source_value and length $observation_source_value and $observation_source_value ne "\\N"
!ll&&!rl&&r
101266
defined $observation_source_value and length $observation_source_value
!ll&&!rl&&r
101266
MC/DC33%1/3
defined $observation_source_value and length $observation_source_value and $observation_source_value ne "\\N"
defined $observation_source_value length $observation_source_value $observation_source_value ne "\\N"
Truth table50%2/4
A and B and C
A= defined $observation_source_valueB= length $observation_source_valueC= $observation_source_value ne "\\N"
ABCresult
0XX0
10X0
1100
1111
146 && length $observation_source_value
147 && $observation_source_value ne '\\N' )
148 {
149 1266 push @labels, $observation_source_value;
150 }
151  
152 1267 ▶ if ( defined $observation_concept_id
Branch: 1 branch
BranchTrueFalseTotal
if (defined $observation_concept_id and $observation_concept_id ne "\\N" and $observation_concept_id != 0) 1267 0 1267
Condition33%2/6
defined $observation_concept_id and $observation_concept_id ne "\\N" and $observation_concept_id != 0
!ll&&!rl&&r
001267
defined $observation_concept_id and $observation_concept_id ne "\\N"
!ll&&!rl&&r
001267
MC/DC0%0/3
defined $observation_concept_id and $observation_concept_id ne "\\N" and $observation_concept_id != 0
defined $observation_concept_id $observation_concept_id ne "\\N" $observation_concept_id != 0
Truth table25%1/4
A and B and C
A= defined $observation_concept_idB= $observation_concept_id ne "\\N"C= $observation_concept_id != 0
ABCresult
0XX0
10X0
1100
1111
153 && $observation_concept_id ne '\\N'
154 && $observation_concept_id != 0 )
155 {
156 1267 my $observation = map2ohdsi(
157 {
158 ohdsi_dict => $ohdsi_dict,
159 concept_id => $observation_concept_id,
160 self => $self
161 }
162 );
163 push @labels, $observation->{label}
164 1267 ▶ if defined $observation && defined $observation->{label};
Branch: 1 branch
BranchTrueFalseTotal
if defined $observation and defined $observation->{"label"} 1267 0 1267
Condition33%1/3
defined $observation and defined $observation->{"label"}
!ll&&!rl&&r
001267
MC/DC0%0/2
defined $observation and defined $observation->{"label"}
defined $observation defined $observation->{"label"}
Truth table33%1/3
A and B
A= defined $observationB= defined $observation->{"label"}
ABresult
0X0
100
111
165 }
166  
167 1267 return scalar grep { _matches_country_of_birth_label($_) } @labels;
168 }
169  
170 1 ▶sub _country_of_birth_query {
Subroutine _country_of_birth_query: called CC=12 SCAR=41.0
171 1 my ( $self, $field, $ohdsi_dict ) = @_;
172 my $value_as_concept_id =
173 exists $field->{value_as_concept_id}
174 ? $field->{value_as_concept_id}
175 1 ▶ : undef;
Branch: 1 branch
BranchTrueFalseTotal
exists $field->{'value_as_concept_id'} ? : 1 0 1
176  
177 1 ▶ if ( defined $value_as_concept_id
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value_as_concept_id and $value_as_concept_id ne "\\N" and $value_as_concept_id != 0) 1 0 1
Condition33%2/6
defined $value_as_concept_id and $value_as_concept_id ne "\\N" and $value_as_concept_id != 0
!ll&&!rl&&r
001
defined $value_as_concept_id and $value_as_concept_id ne "\\N"
!ll&&!rl&&r
001
MC/DC0%0/3
defined $value_as_concept_id and $value_as_concept_id ne "\\N" and $value_as_concept_id != 0
defined $value_as_concept_id $value_as_concept_id ne "\\N" $value_as_concept_id != 0
Truth table25%1/4
A and B and C
A= defined $value_as_concept_idB= $value_as_concept_id ne "\\N"C= $value_as_concept_id != 0
ABCresult
0XX0
10X0
1100
1111
178 && $value_as_concept_id ne '\\N'
179 && $value_as_concept_id != 0 )
180 {
181 1 my $country = map2ohdsi(
182 {
183 ohdsi_dict => $ohdsi_dict,
184 concept_id => $value_as_concept_id,
185 self => $self
186 }
187 );
188 return $country->{label}
189 1 ▶ if defined $country && defined $country->{label};
Branch: 1 branch
BranchTrueFalseTotal
if defined $country and defined $country->{"label"} 1 0 1
Condition33%1/3
defined $country and defined $country->{"label"}
!ll&&!rl&&r
001
MC/DC0%0/2
defined $country and defined $country->{"label"}
defined $country defined $country->{"label"}
Truth table33%1/3
A and B
A= defined $countryB= defined $country->{"label"}
ABresult
0X0
100
111
190 }
191  
192 0 for my $key (qw(value_as_string value_source_value)) {
193 0 ▶ next unless exists $field->{$key};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $field->{$key} 0 0 0
194 0 my $value = $field->{$key};
195 0 ▶ next unless defined $value && length $value;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value and length $value 0 0 0
Condition0%0/3
defined $value and length $value
!ll&&!rl&&r
000
MC/DC0%0/2
defined $value and length $value
defined $value length $value
Truth table0%0/3
A and B
A= defined $valueB= length $value
ABresult
0X0
100
111
196 0 ▶ next if $value eq '\\N';
Branch: 1 branch
BranchTrueFalseTotal
if $value eq "\\N" 0 0 0
197 0 return $value;
198 }
199  
200 0 return;
201 }
202  
203 2533 ▶sub _matches_country_of_birth_label {
Subroutine _matches_country_of_birth_label: called CC=4 SCAR=15.2
204 2533 my ($label) = @_;
205 2533 ▶ return 0 unless defined $label && length $label;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $label and length $label 0 2533 2533
Condition33%1/3
defined $label and length $label
!ll&&!rl&&r
002533
MC/DC0%0/2
defined $label and length $label
defined $label length $label
Truth table33%1/3
A and B
A= defined $labelB= length $label
ABresult
0X0
100
111
206 2533 $label =~ s/\s+/ /g;
207 2533 ▶ return $label =~ /^country of birth(?:\s*\[location\])?$/i
Condition66%2/3
$label =~ /^country of birth(?:\s*\[location\])?$/i || $label =~ /^country of birth\b/i
l!l&&r!l&&!r
402529
MC/DC50%1/2
$label =~ /^country of birth(?:\s*\[location\])?$/i || $label =~ /^country of birth\b/i
$label =~ /^country of birth(?:\s*\[location\])?$/i $label =~ /^country of birth\b/i
Truth table66%2/3
A || B
A= $label =~ /^country of birth(?:\s*\[location\])?$/iB= $label =~ /^country of birth\b/i
ABresult
1X1
011
000
208 || $label =~ /^country of birth\b/i;
209 }
210  
211 18654 ▶sub _map_diseases {
Subroutine _map_diseases: called CC=8 SCAR=21.1
212 18654 my ( $self, $participant, $individual, $person, $ohdsi_dict ) = @_;
213 18654 my $table = 'CONDITION_OCCURRENCE';
214  
215 18654 ▶ if ( defined $participant->{$table} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $participant->{$table}) 625 18029 18654
216 625 for my $field ( @{ $participant->{$table} } ) {
217 3937 my $disease;
218  
219 $disease->{ageOfOnset} = {
220 age => {
221 iso8601duration => get_age_from_date_and_birthday(
222 {
223 date => $field->{condition_start_date},
224 birth_day => $person->{birth_datetime}
225 }
226 )
227 3937 }
228 };
229  
230 $disease->{diseaseCode} = map2ohdsi(
231 {
232 ohdsi_dict => $ohdsi_dict,
233 concept_id => $field->{condition_concept_id},
234 self => $self
235 }
236 3937 ▶ ) if defined $field->{condition_concept_id};
Branch: 1 branch
BranchTrueFalseTotal
if defined $field->{"condition_concept_id"} 3937 0 3937
237  
238 3937 ▶ $disease->{_info}{$table}{OMOP_columns} = $field if _source_info_enabled($self);
Branch: 1 branch
BranchTrueFalseTotal
if _source_info_enabled($self) 3937 0 3937
239 $disease->{stage} = $field->{condition_status_concept_id}
240 ? map2ohdsi(
241 {
242 ohdsi_dict => $ohdsi_dict,
243 concept_id => $field->{condition_status_concept_id},
244 self => $self
245  
246 }
247 )
248 3937 ▶ : $DEFAULT->{ontology_term};
Branch: 1 branch
BranchTrueFalseTotal
$field->{'condition_status_concept_id'} ? : 0 3937 3937
249  
250 3937 ▶ if ( exists $self->{visit_occurrence} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{"visit_occurrence"}) 3937 0 3937
251 my $visit = map_omop_visit_occurrence(
252 {
253 person_id => $field->{person_id},
254 visit_occurrence_id => $field->{visit_occurrence_id},
255 3937 self => $self,
256 ohdsi_dict => $ohdsi_dict
257 }
258 );
259 3937 ▶ $disease->{_visit} = $visit if defined $visit;
Branch: 1 branch
BranchTrueFalseTotal
if defined $visit 33 3904 3937
260 }
261  
262 3937 push @{ $individual->{diseases} }, $disease;
263 }
264 }
265 }
266  
267 18654 ▶sub _map_exposures {
Subroutine _map_exposures: called CC=8 SCAR=21.0
268 18654 my ( $self, $participant, $individual, $person, $ohdsi_dict ) = @_;
269 18654 my $table = 'OBSERVATION';
270  
271 18654 ▶ if ( defined $participant->{$table} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $participant->{$table}) 433 18221 18654
272 433 for my $field ( @{ $participant->{$table} } ) {
273 635 $field->{observation_concept_id} = 35609831 if DEVEL_MODE;
274  
275 635 my $field_observation_concept_id = $field->{observation_concept_id};
276 635 ▶ next unless exists $self->{exposures}{$field_observation_concept_id};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"exposures"}{$field_observation_concept_id} 634 1 635
277 1 my $exposure;
278  
279 $exposure->{ageAtExposure} = {
280 age => {
281 iso8601duration => get_age_from_date_and_birthday(
282 {
283 date => $field->{observation_date},
284 birth_day => $person->{birth_datetime}
285 }
286 )
287 1 }
288 };
289  
290 1 $exposure->{date} = $field->{observation_date};
291 1 $exposure->{duration} = $DEFAULT->{duration_OMOP};
292 1 ▶ $exposure->{_info}{$table}{OMOP_columns} = $field if _source_info_enabled($self);
Branch: 1 branch
BranchTrueFalseTotal
if _source_info_enabled($self) 1 0 1
293  
294 $exposure->{exposureCode} = map2ohdsi(
295 {
296 ohdsi_dict => $ohdsi_dict,
297 concept_id => $field->{observation_concept_id},
298 self => $self
299 }
300 1 ▶ ) if defined $field->{observation_concept_id};
Branch: 1 branch
BranchTrueFalseTotal
if defined $field->{"observation_concept_id"} 1 0 1
301  
302 my $unit = $field->{unit_concept_id}
303 ? map2ohdsi(
304 {
305 ohdsi_dict => $ohdsi_dict,
306 concept_id => $field->{unit_concept_id},
307 self => $self
308  
309 }
310 )
311 1 ▶ : $DEFAULT->{ontology_term};
Branch: 1 branch
BranchTrueFalseTotal
$field->{'unit_concept_id'} ? : 1 0 1
312  
313 1 $exposure->{unit} = $unit;
314 $exposure->{value} =
315 $field->{value_as_number} eq '\\N'
316 ? -1
317 1 ▶ : $field->{value_as_number} + 0;
Branch: 1 branch
BranchTrueFalseTotal
$field->{'value_as_number'} eq '\\N' ? : 1 0 1
318  
319 1 push @{ $individual->{exposures} }, $exposure;
320 }
321 }
322 }
323  
324 18654 ▶sub _map_phenotypicFeatures {
Subroutine _map_phenotypicFeatures: called CC=9 SCAR=22.0
325 18654 my ( $self, $participant, $individual, $person, $ohdsi_dict ) = @_;
326 18654 my $table = 'OBSERVATION';
327  
328 18654 ▶ if ( defined $participant->{$table} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $participant->{$table}) 433 18221 18654
329 433 $individual->{phenotypicFeatures} = [];
330  
331 433 for my $field ( @{ $participant->{$table} } ) {
332 635 my $field_observation_concept_id = $field->{observation_concept_id};
333 635 ▶ next if exists $self->{exposures}{$field_observation_concept_id};
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"exposures"}{$field_observation_concept_id} 1 634 635
334 634 ▶ next if _is_country_of_birth_observation( $self, $field, $ohdsi_dict );
Branch: 1 branch
BranchTrueFalseTotal
if _is_country_of_birth_observation($self, $field, $ohdsi_dict) 1 633 634
335  
336 633 my $phenotypicFeature;
337  
338 $phenotypicFeature->{featureType} = map2ohdsi(
339 {
340 ohdsi_dict => $ohdsi_dict,
341 concept_id => $field->{observation_concept_id},
342 self => $self
343  
344 }
345 633 ▶ ) if defined $field->{observation_concept_id};
Branch: 1 branch
BranchTrueFalseTotal
if defined $field->{"observation_concept_id"} 633 0 633
346  
347 633 ▶ $phenotypicFeature->{_info}{$table}{OMOP_columns} = $field if _source_info_enabled($self);
Branch: 1 branch
BranchTrueFalseTotal
if _source_info_enabled($self) 633 0 633
348  
349 $phenotypicFeature->{onset} = {
350 iso8601duration => get_age_from_date_and_birthday(
351 {
352 date => $field->{observation_date},
353 birth_day => $person->{birth_datetime}
354 }
355 )
356 633 };
357  
358 633 ▶ if ( exists $self->{visit_occurrence} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{"visit_occurrence"}) 633 0 633
359 my $visit = map_omop_visit_occurrence(
360 {
361 person_id => $field->{person_id},
362 visit_occurrence_id => $field->{visit_occurrence_id},
363 633 self => $self,
364 ohdsi_dict => $ohdsi_dict
365 }
366 );
367 633 ▶ $phenotypicFeature->{_visit} = $visit if defined $visit;
Branch: 1 branch
BranchTrueFalseTotal
if defined $visit 89 544 633
368 }
369  
370 633 push @{ $individual->{phenotypicFeatures} }, $phenotypicFeature;
371 }
372 }
373 }
374  
375 18654 ▶sub _map_interventionsOrProcedures {
Subroutine _map_interventionsOrProcedures: called CC=7 SCAR=19.6
376 18654 my ( $self, $participant, $individual, $person, $ohdsi_dict ) = @_;
377 18654 my $table = 'PROCEDURE_OCCURRENCE';
378  
379 18654 ▶ if ( defined $participant->{$table} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $participant->{$table}) 737 17917 18654
380 737 $individual->{interventionsOrProcedures} = [];
381  
382 737 for my $field ( @{ $participant->{$table} } ) {
383 3465 my $intervention;
384  
385 $intervention->{ageAtProcedure} = {
386 age => {
387 iso8601duration => get_age_from_date_and_birthday(
388 {
389 date => $field->{procedure_date},
390 birth_day => $person->{birth_datetime}
391 }
392 )
393 3465 }
394 };
395  
396 3465 $intervention->{bodySite} = $DEFAULT->{ontology_term};
397 3465 $intervention->{dateOfProcedure} = $field->{procedure_date};
398 3465 ▶ $intervention->{_info}{$table}{OMOP_columns} = $field if _source_info_enabled($self);
Branch: 1 branch
BranchTrueFalseTotal
if _source_info_enabled($self) 3465 0 3465
399 $intervention->{procedureCode} = map2ohdsi(
400 {
401 ohdsi_dict => $ohdsi_dict,
402 concept_id => $field->{procedure_concept_id},
403 self => $self
404  
405 }
406 3465 ▶ ) if defined $field->{procedure_concept_id};
Branch: 1 branch
BranchTrueFalseTotal
if defined $field->{"procedure_concept_id"} 3465 0 3465
407  
408 3465 ▶ if ( exists $self->{visit_occurrence} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{"visit_occurrence"}) 3465 0 3465
409 my $visit = map_omop_visit_occurrence(
410 {
411 person_id => $field->{person_id},
412 visit_occurrence_id => $field->{visit_occurrence_id},
413 3465 self => $self,
414 ohdsi_dict => $ohdsi_dict
415 }
416 );
417 3465 ▶ $intervention->{_visit} = $visit if defined $visit;
Branch: 1 branch
BranchTrueFalseTotal
if defined $visit 41 3424 3465
418 }
419  
420 3465 push @{ $individual->{interventionsOrProcedures} }, $intervention;
421 }
422 }
423 }
424  
425 18654 ▶sub _map_measures {
Subroutine _map_measures: called CC=11 SCAR=24.0
426 18654 my ( $self, $participant, $individual, $person, $ohdsi_dict ) = @_;
427 18654 my $table = 'MEASUREMENT';
428  
429 18654 ▶ if ( defined $participant->{$table} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $participant->{$table}) 295 18359 18654
430 295 for my $field ( @{ $participant->{$table} } ) {
431 841 $field->{unit_concept_id} = 18753 if DEVEL_MODE;
432 841 $field->{value_as_number} = 20 if DEVEL_MODE;
433 841 $field->{operator_concept_id} = 4172756 if DEVEL_MODE;
434 841 $field->{measurement_type_concept_id} = 4024958 if DEVEL_MODE;
435 841 $field->{value_as_concept_id} = 18753 if DEVEL_MODE;
436  
437 841 my $measure;
438  
439 841 ▶ if ( $field->{measurement_concept_id} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($field->{'measurement_concept_id'}) { } 840 1 841
440 $measure->{assayCode} = map2ohdsi(
441 {
442 ohdsi_dict => $ohdsi_dict,
443 concept_id => $field->{measurement_concept_id},
444 840 self => $self
445 }
446 );
447 }
448 else {
449 1 $measure = set_default_measure();
450 1 next;
451 }
452  
453 840 $measure->{date} = $field->{measurement_date};
454  
455 my $unit =
456 $field->{unit_concept_id}
457 ? map2ohdsi(
458 {
459 ohdsi_dict => $ohdsi_dict,
460 concept_id => $field->{unit_concept_id},
461 840 ▶ self => $self
Branch: 1 branch
BranchTrueFalseTotal
$field->{'unit_concept_id'} ? : 1 839 840
462 }
463 )
464 : {
465 id => "NCIT:C126101",
466 label => "Not Available"
467 };
468  
469 840 my $measurement_value;
470  
471 840 ▶ if ( $field->{value_as_concept_id} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($field->{'value_as_concept_id'}) { } 1 839 840
472 $measurement_value = map2ohdsi(
473 {
474 ohdsi_dict => $ohdsi_dict,
475 concept_id => $field->{value_as_concept_id},
476 1 self => $self
477 }
478 );
479 }
480 else {
481 839 ▶ if ( $field->{value_as_number} eq '\\N' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($field->{'value_as_number'} eq '\\N') { } 833 6 839
482 833 $measurement_value = { quantity => $DEFAULT->{quantity} };
483 }
484 else {
485 $measurement_value = {
486 quantity => {
487 unit => $unit,
488 value => $field->{value_as_number},
489 referenceRange => $field->{operator_concept_id}
490 ? map_operator_concept_id(
491 {
492 operator_concept_id =>
493 $field->{operator_concept_id},
494 value_as_number =>
495 $field->{value_as_number},
496 6 ▶ unit => $unit
Branch: 1 branch
BranchTrueFalseTotal
$field->{'operator_concept_id'} ? : 0 6 6
497 }
498 )
499 : undef
500 }
501 };
502 }
503 }
504  
505 840 $measure->{measurementValue} = $measurement_value;
506 840 ▶ $measure->{_info}{$table}{OMOP_columns} = $field if _source_info_enabled($self);
Branch: 1 branch
BranchTrueFalseTotal
if _source_info_enabled($self) 840 0 840
507 $measure->{observationMoment} = {
508 age => {
509 iso8601duration => get_age_from_date_and_birthday(
510 {
511 date => $field->{measurement_date},
512 birth_day => $person->{birth_datetime}
513 }
514 )
515 840 }
516 };
517  
518 840 $measure->{procedure}{ageAtProcedure} = $measure->{observationMoment};
519 840 $measure->{procedure}{bodySite} = $DEFAULT->{ontology_term};
520 840 $measure->{procedure}{dateOfProcedure} = $field->{measurement_date};
521 $measure->{procedure}{procedureCode} = map2ohdsi(
522 {
523 ohdsi_dict => $ohdsi_dict,
524 concept_id => $field->{measurement_type_concept_id},
525 840 self => $self
526  
527 }
528 );
529  
530 840 ▶ if ( exists $self->{visit_occurrence} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{"visit_occurrence"}) 834 6 840
531 my $visit = map_omop_visit_occurrence(
532 {
533 person_id => $field->{person_id},
534 visit_occurrence_id => $field->{visit_occurrence_id},
535 834 self => $self,
536 ohdsi_dict => $ohdsi_dict
537 }
538 );
539 834 ▶ $measure->{_visit} = $visit if defined $visit;
Branch: 1 branch
BranchTrueFalseTotal
if defined $visit 2 832 834
540 }
541  
542 840 push @{ $individual->{measures} }, $measure;
543 }
544 }
545 }
546  
547 18654 ▶sub _map_treatments {
Subroutine _map_treatments: called CC=7 SCAR=19.5
548 18654 my ( $self, $participant, $individual, $person, $ohdsi_dict ) = @_;
549 18654 my $table = 'DRUG_EXPOSURE';
550  
551 18654 ▶ if ( defined $participant->{$table} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $participant->{$table}) 7477 11177 18654
552 7477 $individual->{treatments} = [];
553  
554 7477 for my $field ( @{ $participant->{$table} } ) {
555 9997 my $treatment;
556  
557 $treatment->{ageAtOnset} = {
558 age => {
559 iso8601duration => get_age_from_date_and_birthday(
560 {
561 date => $field->{drug_exposure_start_date},
562 birth_day => $person->{birth_datetime}
563 }
564 )
565 9997 }
566 };
567  
568 9997 $treatment->{doseIntervals} = [];
569 9997 ▶ $treatment->{_info}{$table}{OMOP_columns} = $field if _source_info_enabled($self);
Branch: 1 branch
BranchTrueFalseTotal
if _source_info_enabled($self) 9997 0 9997
570 9997 $treatment->{routeOfAdministration} = $DEFAULT->{ontology_term};
571 $treatment->{treatmentCode} = map2ohdsi(
572 {
573 ohdsi_dict => $ohdsi_dict,
574 concept_id => $field->{drug_concept_id},
575 self => $self
576 }
577 9997 ▶ ) if defined $field->{drug_concept_id};
Branch: 1 branch
BranchTrueFalseTotal
if defined $field->{"drug_concept_id"} 9997 0 9997
578  
579 9997 ▶ if ( exists $self->{visit_occurrence} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{"visit_occurrence"}) 6777 3220 9997
580 my $visit = map_omop_visit_occurrence(
581 {
582 person_id => $field->{person_id},
583 visit_occurrence_id => $field->{visit_occurrence_id},
584 6777 self => $self,
585 ohdsi_dict => $ohdsi_dict
586 }
587 );
588 6777 ▶ $treatment->{_visit} = $visit if defined $visit;
Branch: 1 branch
BranchTrueFalseTotal
if defined $visit 33 6744 6777
589 }
590  
591 9997 push @{ $individual->{treatments} }, $treatment;
592 }
593 }
594 }
595  
596 6938 ▶sub avoid_seen_individuals {
Subroutine avoid_seen_individuals: called CC=3 SCAR=11.0
Pod undocumented
597 6938 my $individual = shift;
598 6938 my $id = $individual->{id};
599  
600 6938 my $expected_keys = join( '_', sort qw(id info sex) );
601 6938 my $individual_keys = join( '_', sort keys %$individual );
602 6938 my $key = $id . '_' . $individual_keys;
603  
604 6938 ▶ if ( $individual_keys eq $expected_keys ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($individual_keys eq $expected_keys) 35 6903 6938
605 35 ▶ if ( exists $seen_individual{$key} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $seen_individual{$key}) { } 22 13 35
606 22 return 1;
607 }
608 else {
609 13 $seen_individual{$key} = 1;
610 13 return 0;
611 }
612 }
613 6903 return 0;
614 }
615  
616 1 ▶sub set_default_measure {
Subroutine set_default_measure: called CC=1 SCAR=0.0
Pod undocumented
617 return {
618 assayCode => $DEFAULT->{ontology_term},
619 date => $DEFAULT->{date},
620 measurementValue => $DEFAULT->{quantity},
621 procedure => $DEFAULT->{ontology_term}
622 1 };
623 }
624  
625 37528 ▶sub _source_info_enabled {
Subroutine _source_info_enabled: called CC=2 SCAR=6.9
626 37528 my ($self) = @_;
627 37528 ▶ return !exists $self->{source_info} || $self->{source_info};
Condition100%3/3
!exists $self->{'source_info'} || $self->{'source_info'}
l!l&&r!l&&!r
11375161
MC/DC100%2/2
!exists $self->{'source_info'} || $self->{'source_info'}
!exists $self->{'source_info'} $self->{'source_info'}
Truth table100%3/3
not(A) || B
A= !exists $self->{'source_info'}B= $self->{'source_info'}
ABresult
1X1
011
000
628 }
629  
630 138 1;
« lib/Convert/Pheno/Source/OMOP.pm ↑ Summary lib/Convert/Pheno/PXF/ToBFF/Biosamples.pm »