lib/Convert/Pheno/Tabular/ToBFF.pm

filter: Statementstmt 97.8% 410 / 419 Branchbran 71.7% 165 / 230 Conditioncond 62.6% 89 / 142 MC/DCmcdc 36.2% 29 / 80 Subroutinesub 100% 45 / 45 Podpod 0.0% 0 / 3 totaltotal 80.3% 738 / 919 CC 194 SCAR 25.6
CC
194
Cov
84%
_map_term
31.9
_map_biosamples
30.6
_map_info
18.6
CRAP 12.9
« lib/Convert/Pheno/PXF/ToBFF/Biosamples.pm ↑ Summary lib/Convert/Pheno/CBioPortal/ToBFF.pm »
1 package Convert::Pheno::Tabular::ToBFF;
2  
3 136 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 136 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 136 ▶use autodie;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 136 ▶use Exporter 'import';
Subroutine BEGIN: called CC=1 SCAR=0.0
8 136 ▶use JSON::XS;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 136 ▶use Scalar::Util qw(blessed looks_like_number);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 136 ▶use Storable qw(dclone);
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 136 ▶use Convert::Pheno::Context;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 136 ▶use Convert::Pheno::Mapping::Shared;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 136 ▶use Convert::Pheno::Model::Bundle;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 136 ▶use Convert::Pheno::Tabular::Record;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 136 ▶use Convert::Pheno::Utils::Default qw(get_defaults);
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 136 our @EXPORT_OK = qw(
19 map_tabular_biosamples
20 map_tabular_individual
21 run_tabular_to_bundle
22 );
23  
24 136 my $DEFAULT = get_defaults();
25 136 my @REDCAP_META_FIELDS = ( 'Field Label', 'Field Note', 'Field Type' );
26  
27 607 ▶sub run_tabular_to_bundle {
Subroutine run_tabular_to_bundle: called CC=6 SCAR=18.7
Pod undocumented
28 607 my ( $self, $participant, $context ) = @_;
29 607 my $mapping = _mapping($self);
30  
31 $context ||= Convert::Pheno::Context->from_self(
32 $self,
33 {
34 source_format => $mapping->{_compiled}{sourceProfile},
35 target_format => 'beacon',
36 607 ▶ entities => $self->{entities} || ['individuals'],
Condition20%1/5
$context ||= "Convert::Pheno::Context"->from_self($self, {"source_format", $mapping->{"_compiled"}{"sourceProfile"}, "target_format", "beacon", "entities", $self->{"entities"} || ["individuals"]})
l!l&&r!l&&!r
60700
$self->{'entities'} || ['individuals']
l!l
00
MC/DC0%0/2
$context ||= "Convert::Pheno::Context"->from_self($self, {"source_format", $mapping->{"_compiled"}{"sourceProfile"}, "target_format", "beacon", "entities", $self->{"entities"} || ["individuals"]})
$context "Convert::Pheno::Context"->from_self($self, {"source_format", $mapping->{"_compiled"}{"sourceProfile"}, "target_format", "beacon", "entities", $self->{"entities"} || ["individuals"]})
MC/DC0%0/1
$self->{'entities'} || ['individuals']
$self->{'entities'}
Truth table33%1/3
A ||= B
A= $contextB= "Convert::Pheno::Context"->from_self($self, {"source_format", $mapping->{"_compiled"}{"sourceProfile"}, "target_format", "beacon", "entities", $self->{"entities"} || ["individuals"]})
ABresult
1X1
011
000
Truth table0%0/2
A
A= $self->{'entities'}
Aresult
11
00
37 }
38 );
39  
40 607 my $bundle = Convert::Pheno::Model::Bundle->new(
41 {
42 context => $context,
43 entities => $context->entities,
44 }
45 );
46  
47 607 my ( $individual, $record ) = _map_individual( $self, $participant, $mapping );
48 607 ▶ return $bundle unless defined $individual;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $individual 0 607 607
49  
50 607 $bundle->add_entity( individuals => $individual );
51  
52 607 ▶ if ( _context_requests_entity( $context, 'biosamples' ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (_context_requests_entity($context, "biosamples")) 2 605 607
53 2 for my $biosample (
54 2 @{ _map_biosamples( $self, $record, $mapping, $individual->{id} ) }
55 )
56 {
57 1 $bundle->add_entity( biosamples => $biosample );
58 }
59 }
60  
61 607 return $bundle;
62 }
63  
64 10 ▶sub map_tabular_individual {
Subroutine map_tabular_individual: called CC=1 SCAR=0.0
Pod undocumented
65 10 my ( $self, $participant ) = @_;
66 10 my ( $individual ) = _map_individual( $self, $participant, _mapping($self) );
67 10 return $individual;
68 }
69  
70 10 ▶sub map_tabular_biosamples {
Subroutine map_tabular_biosamples: called CC=3 SCAR=12.0
Pod undocumented
71 10 my ( $self, $record, $individual_id ) = @_;
72 10 my $mapping = _mapping($self);
73 my $tabular_record = blessed($record) && $record->can('value')
74 ? $record
75 : Convert::Pheno::Tabular::Record->new(
76 {
77 source => $mapping->{_compiled}{recordProfile},
78 10 ▶ raw => $record,
Branch: 1 branch
BranchTrueFalseTotal
builtin::blessed($record) && $record->can('value') ? : 0 10 10
Condition33%1/3
builtin::blessed($record) and $record->can("value")
!ll&&!rl&&r
1000
MC/DC0%0/2
builtin::blessed($record) and $record->can("value")
builtin::blessed($record) $record->can("value")
Truth table33%1/3
A and B
A= builtin::blessed($record)B= $record->can("value")
ABresult
0X0
100
111
79 }
80 );
81  
82 10 return _map_biosamples(
83 $self,
84 $tabular_record,
85 $mapping,
86 $individual_id,
87 );
88 }
89  
90 617 ▶sub _map_individual {
Subroutine _map_individual: called CC=5 SCAR=16.1
91 617 my ( $self, $participant, $mapping ) = @_;
92 617 my $individual_mapping = $mapping->{beacon}{individuals};
93 my $record = blessed($participant) && $participant->can('value')
94 ? $participant
95 : Convert::Pheno::Tabular::Record->new(
96 {
97 source => $mapping->{_compiled}{recordProfile},
98 raw => $participant,
99 redcap_dict => $self->{data_redcap_dict},
100 }
101 617 ▶ );
Branch: 1 branch
BranchTrueFalseTotal
builtin::blessed($participant) && $participant->can('value') ? : 183 434 617
Condition66%2/3
builtin::blessed($participant) and $participant->can("value")
!ll&&!rl&&r
4340183
MC/DC50%1/2
builtin::blessed($participant) and $participant->can("value")
builtin::blessed($participant) $participant->can("value")
Truth table66%2/3
A and B
A= builtin::blessed($participant)B= $participant->can("value")
ABresult
0X0
100
111
102  
103 617 _apply_baseline( $self, $record, $mapping );
104  
105 617 my $id_mapping = $individual_mapping->{id};
106 617 my $primary_key = $id_mapping->{source}{primaryKey};
107 617 my $sex_field = $individual_mapping->{sex}{source}{field};
108 617 ▶ return unless _has_value( $record->value($primary_key) );
Branch: 1 branch
BranchTrueFalseTotal
unless _has_value($record->value($primary_key)) 0 617 617
109 617 ▶ return unless _has_value( $record->value($sex_field) );
Branch: 1 branch
BranchTrueFalseTotal
unless _has_value($record->value($sex_field)) 0 617 617
110  
111 617 my $individual_id = _join_id( $record, $id_mapping );
112 617 my $ctx = {
113 self => $self,
114 mapping => $mapping,
115 record => $record,
116 individual_id => $individual_id,
117 };
118  
119 617 my $individual = { id => $individual_id };
120  
121 617 _map_diseases( $individual, $individual_mapping->{diseases}, $ctx );
122 617 _map_scalar_term( $individual, 'ethnicity', $individual_mapping->{ethnicity}, $ctx );
123 617 _map_exposures( $individual, $individual_mapping->{exposures}, $ctx );
124 617 _map_scalar_term( $individual, 'geographicOrigin', $individual_mapping->{geographicOrigin}, $ctx );
125 617 _map_info( $individual, $individual_mapping->{info}, $ctx );
126 617 _map_procedures( $individual, $individual_mapping->{interventionsOrProcedures}, $ctx );
127 617 _map_scalar_value( $individual, 'karyotypicSex', $individual_mapping->{karyotypicSex}, $ctx );
128 617 _map_measures( $individual, $individual_mapping->{measures}, $ctx );
129 617 _map_phenotypic_features( $individual, $individual_mapping->{phenotypicFeatures}, $ctx );
130 617 _map_scalar_term( $individual, 'sex', $individual_mapping->{sex}, $ctx );
131 617 _map_treatments( $individual, $individual_mapping->{treatments}, $ctx );
132  
133 617 return ( $individual, $record );
134 }
135  
136 627 ▶sub _mapping {
Subroutine _mapping: called CC=3 SCAR=12.0
137 627 my ($self) = @_;
138 627 my $mapping = $self->{data_mapping_file};
139 die "The tabular mapping was not compiled\n"
140 unless ref($mapping) eq 'HASH'
141 627 ▶ && ref( $mapping->{_compiled} ) eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $mapping eq "HASH" and ref $mapping->{"_compiled"} eq "HASH" 0 627 627
Condition33%1/3
ref $mapping eq "HASH" and ref $mapping->{"_compiled"} eq "HASH"
!ll&&!rl&&r
00627
MC/DC0%0/2
ref $mapping eq "HASH" and ref $mapping->{"_compiled"} eq "HASH"
ref $mapping eq "HASH" ref $mapping->{"_compiled"} eq "HASH"
Truth table33%1/3
A and B
A= ref $mapping eq "HASH"B= ref $mapping->{"_compiled"} eq "HASH"
ABresult
0X0
100
111
142 627 return $mapping;
143 }
144  
145 617 ▶sub _apply_baseline {
Subroutine _apply_baseline: called CC=9 SCAR=22.0
146 617 my ( $self, $record, $mapping ) = @_;
147 617 ▶ my $baseline = $mapping->{records}{baseline} or return 1;
Branch: 1 branch
BranchTrueFalseTotal
my $baseline = $mapping->{"records"}{"baseline"} or return 1 602 15 617
148 602 my $id_field = $mapping->{beacon}{individuals}{id}{source}{primaryKey};
149 602 my $id = $record->value($id_field);
150 602 ▶ return 1 unless _has_value($id);
Branch: 1 branch
BranchTrueFalseTotal
unless _has_value($id) 0 602 602
151  
152 602 ▶ my $cache = $self->{_mapping_baseline}{ $mapping->{project}{id} }{$id} ||= {};
Condition100%2/2
$self->{"_mapping_baseline"}{$mapping->{"project"}{"id"}}{$id} ||= {}
l!l
401201
MC/DC100%1/1
$self->{"_mapping_baseline"}{$mapping->{"project"}{"id"}}{$id} ||= {}
$self->{"_mapping_baseline"}{$mapping->{"project"}{"id"}}{$id}
Truth table100%2/2
A
A= $self->{"_mapping_baseline"}{$mapping->{"project"}{"id"}}{$id}
Aresult
11
00
153 602 for my $field ( @{ $baseline->{sourceFields} } ) {
154 36482 my $value = $record->value($field);
155 $cache->{$field} = $value
156 36482 ▶ if _has_value($value) && !exists $cache->{$field};
Branch: 1 branch
BranchTrueFalseTotal
if _has_value($value) and not exists $cache->{$field} 7707 28775 36482
Condition66%2/3
_has_value($value) and not exists $cache->{$field}
!ll&&!rl&&r
2877507707
MC/DC50%1/2
_has_value($value) and not exists $cache->{$field}
_has_value($value) not exists $cache->{$field}
Truth table66%2/3
A and not(B)
A= _has_value($value)B= not exists $cache->{$field}
ABresult
0X0
100
111
157 $record->set_value( $field, $cache->{$field} )
158 36482 ▶ if !_has_value($value) && exists $cache->{$field};
Branch: 1 branch
BranchTrueFalseTotal
if not _has_value($value) and exists $cache->{$field} 23697 12785 36482
Condition100%3/3
not _has_value($value) and exists $cache->{$field}
!ll&&!rl&&r
7707507823697
MC/DC100%2/2
not _has_value($value) and exists $cache->{$field}
not _has_value($value) exists $cache->{$field}
Truth table100%3/3
not(A) and B
A= not _has_value($value)B= exists $cache->{$field}
ABresult
0X0
100
111
159 }
160  
161 602 return 1;
162 }
163  
164 617 ▶sub _join_id {
Subroutine _join_id: called CC=4 SCAR=13.9
165 617 my ( $record, $mapping ) = @_;
166 617 ▶ my $separator = exists $mapping->{separator} ? $mapping->{separator} : ':';
Branch: 1 branch
BranchTrueFalseTotal
exists $mapping->{'separator'} ? : 600 17 617
167 617 ▶ my $missing = exists $mapping->{missingValue} ? $mapping->{missingValue} : 'NA';
Branch: 1 branch
BranchTrueFalseTotal
exists $mapping->{'missingValue'} ? : 600 17 617
168 return join $separator,
169 map {
170 1221 my $value = $record->value($_);
171 1221 ▶ _has_value($value) ? $value : $missing;
Branch: 1 branch
BranchTrueFalseTotal
_has_value($value) ? : 1221 0 1221
172 617 } @{ $mapping->{source}{fields} };
173 }
174  
175 1851 ▶sub _map_scalar_term {
Subroutine _map_scalar_term: called CC=4 SCAR=13.9
176 1851 my ( $individual, $property, $rule, $ctx ) = @_;
177 1851 ▶ return 1 unless ref($rule) eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $rule eq "HASH" 632 1219 1851
178 1219 ▶ return 1 unless _source_matches( $rule->{source}, $ctx->{record} );
Branch: 1 branch
BranchTrueFalseTotal
unless _source_matches($rule->{"source"}, $ctx->{"record"}) 2 1217 1219
179  
180 1217 my $term = _map_term( $rule->{target}, $rule->{source}{field}, $ctx );
181 1217 ▶ $individual->{$property} = $term if defined $term;
Branch: 1 branch
BranchTrueFalseTotal
if defined $term 1217 0 1217
182 1217 return 1;
183 }
184  
185 617 ▶sub _map_scalar_value {
Subroutine _map_scalar_value: called CC=4 SCAR=23.7
186 617 my ( $individual, $property, $rule, $ctx ) = @_;
187 617 ▶ return 1 unless ref($rule) eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $rule eq "HASH" 617 0 617
188 0 ▶ return 1 unless _source_matches( $rule->{source}, $ctx->{record} );
Branch: 1 branch
BranchTrueFalseTotal
unless _source_matches($rule->{"source"}, $ctx->{"record"}) 0 0 0
189  
190 0 my $value = _resolve_value( $rule->{target}, $rule->{source}{field}, $ctx );
191 0 ▶ $individual->{$property} = $value if defined $value;
Branch: 1 branch
BranchTrueFalseTotal
if defined $value 0 0 0
192 0 return 1;
193 }
194  
195 617 ▶sub _map_diseases {
Subroutine _map_diseases: called CC=8 SCAR=20.8
196 617 my ( $individual, $rules, $ctx ) = @_;
197 617 ▶ for my $rule ( @{ $rules || [] } ) {
Condition100%2/2
$rules || []
l!l
60512
MC/DC100%1/1
$rules || []
$rules
Truth table100%2/2
A
A= $rules
Aresult
11
00
198 1085 for my $item_ctx ( @{ _matching_contexts( $rule->{source}, $ctx ) } ) {
199 1088 my $field = $rule->{source}{field};
200 1088 my $target = $rule->{target};
201 1088 my $code = _map_term( $target->{diseaseCode}, $field, $item_ctx );
202 1088 ▶ next unless defined $code;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $code 0 1088 1088
203  
204 my $disease = {
205 diseaseCode => $code,
206 ageOfOnset => exists $target->{ageOfOnset}
207 ? _map_age(
208 _resolve_value( $target->{ageOfOnset}, $field, $item_ctx )
209 )
210 : _clone( $DEFAULT->{age} ),
211 severity => _clone( $DEFAULT->{ontology_term} ),
212 1088 ▶ stage => _clone( $DEFAULT->{ontology_term} ),
Branch: 1 branch
BranchTrueFalseTotal
exists $target->{'ageOfOnset'} ? : 366 722 1088
213 };
214  
215 1088 ▶ if ( exists $target->{familyHistory} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $target->{"familyHistory"}) 360 728 1088
216 my $value = _resolve_value(
217 $target->{familyHistory},
218 360 $field,
219 $item_ctx,
220 );
221 360 ▶ $disease->{familyHistory} = convert2boolean($value)
Branch: 1 branch
BranchTrueFalseTotal
if defined $value 360 0 360
222 if defined $value;
223 }
224  
225 1088 _add_visit( $disease, $item_ctx );
226 1088 push @{ $individual->{diseases} }, $disease;
227 }
228 }
229 617 return 1;
230 }
231  
232 617 ▶sub _map_exposures {
Subroutine _map_exposures: called CC=12 SCAR=25.4
233 617 my ( $individual, $rules, $ctx ) = @_;
234 617 ▶ for my $rule ( @{ $rules || [] } ) {
Condition100%2/2
$rules || []
l!l
60017
MC/DC100%1/1
$rules || []
$rules
Truth table100%2/2
A
A= $rules
Aresult
11
00
235 2640 for my $item_ctx ( @{ _matching_contexts( $rule->{source}, $ctx ) } ) {
236 922 my $field = $rule->{source}{field};
237 922 my $target = $rule->{target};
238 922 my $code = _map_term( $target->{exposureCode}, $field, $item_ctx );
239 922 ▶ next unless defined $code;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $code 0 922 922
240  
241 922 my $source_value = $item_ctx->{record}->value($field);
242 my $value = exists $target->{value}
243 922 ▶ ? _resolve_value( $target->{value}, $field, $item_ctx )
Branch: 1 branch
BranchTrueFalseTotal
exists $target->{'value'} ? : 0 922 922
244 : $source_value;
245  
246 my $exposure = {
247 exposureCode => $code,
248 ageAtExposure => exists $target->{ageAtExposure}
249 ? _map_age(
250 _resolve_value(
251 $target->{ageAtExposure}, $field, $item_ctx
252 )
253 )
254 : _clone( $DEFAULT->{age} ),
255 unit => _map_term( $target->{unit}, $field, $item_ctx ),
256 value => defined $value && looks_like_number($value)
257 ? dotify_and_coerce_number($value)
258 : -1,
259 date => exists $target->{date}
260 ? _resolve_value( $target->{date}, $field, $item_ctx )
261 : $DEFAULT->{date},
262 duration => exists $target->{duration}
263 ? _resolve_value( $target->{duration}, $field, $item_ctx )
264 : $DEFAULT->{duration},
265 922 ▶ };
Branch: 4 branches
BranchTrueFalseTotal
exists $target->{'ageAtExposure'} ? : 192 730 922
defined $value && &looks_like_number($value) ? : 10 912 922
exists $target->{'date'} ? : 0 922 922
exists $target->{'duration'} ? : 0 922 922
Condition66%2/3
defined $value and &looks_like_number($value)
!ll&&!rl&&r
091210
MC/DC50%1/2
defined $value and &looks_like_number($value)
defined $value &looks_like_number($value)
Truth table66%2/3
A and B
A= defined $valueB= &looks_like_number($value)
ABresult
0X0
100
111
266 $exposure->{_info} = $field
267 922 ▶ if _source_info_enabled( $item_ctx->{self} );
Branch: 1 branch
BranchTrueFalseTotal
if _source_info_enabled($item_ctx->{"self"}) 922 0 922
268 922 _add_visit( $exposure, $item_ctx );
269 922 push @{ $individual->{exposures} }, $exposure;
270 }
271 }
272 617 return 1;
273 }
274  
275 617 ▶sub _map_info {
Subroutine _map_info: called CC=17 SCAR=29.3
276 617 my ( $individual, $rule, $ctx ) = @_;
277 617 ▶ $rule ||= { source => { fields => [] } };
Condition100%2/2
$rule ||= {"source", {"fields", []}}
l!l
6134
MC/DC100%1/1
$rule ||= {"source", {"fields", []}}
$rule
Truth table100%2/2
A
A= $rule
Aresult
11
00
278 617 ▶ $individual->{info} ||= {};
Condition50%1/2
$individual->{"info"} ||= {}
l!l
0617
MC/DC0%0/1
$individual->{"info"} ||= {}
$individual->{"info"}
Truth table50%1/2
A
A= $individual->{"info"}
Aresult
11
00
279  
280 617 ▶ for my $field ( @{ $rule->{source}{fields} || [] } ) {
Condition50%1/2
$rule->{'source'}{'fields'} || []
l!l
6170
MC/DC0%0/1
$rule->{'source'}{'fields'} || []
$rule->{'source'}{'fields'}
Truth table50%1/2
A
A= $rule->{'source'}{'fields'}
Aresult
11
00
281 5773 ▶ next unless defined $ctx->{record}->working_value($field);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $ctx->{"record"}->working_value($field) 1770 4003 5773
282 my $value = $ctx->{record}->can('info_value')
283 ? $ctx->{record}->info_value($field)
284 4003 ▶ : $ctx->{record}->value($field);
Branch: 1 branch
BranchTrueFalseTotal
$ctx->{'record'}->can('info_value') ? : 1998 2005 4003
285 4003 $individual->{info}{$field} = $value;
286  
287 4003 my $meta = $ctx->{record}->field_meta($field);
288 4003 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if (not ref $value and ref $meta eq "HASH" and exists $meta->{"Field Label"}) 3273 730 4003
Condition66%4/6
not ref $value and ref $meta eq "HASH" and exists $meta->{"Field Label"}
!ll&&!rl&&r
73003273
not ref $value and ref $meta eq "HASH"
!ll&&!rl&&r
07303273
MC/DC33%1/3
not ref $value and ref $meta eq "HASH" and exists $meta->{"Field Label"}
not ref $value ref $meta eq "HASH" exists $meta->{"Field Label"}
Truth table50%2/4
not(A) and B and C
A= not ref $valueB= ref $meta eq "HASH"C= exists $meta->{"Field Label"}
ABCresult
0XX0
10X0
1100
1111
289 !ref($value)
290 && ref($meta) eq 'HASH'
291 && exists $meta->{'Field Label'}
292 )
293 {
294 $individual->{info}{objects}{ $field . '_obj' } = {
295 value => dotify_and_coerce_number($value),
296 3273 map { $_ => $meta->{$_} } @REDCAP_META_FIELDS,
297 };
298 }
299 }
300  
301 617 ▶ if ( exists $rule->{target}{ageRange} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $rule->{"target"}{"ageRange"}) 360 257 617
302 360 my $value = _resolve_value( $rule->{target}{ageRange}, undef, $ctx );
303 360 my $age = _map_age($value);
304 $individual->{info}{ageRange} = $age->{ageRange}
305 360 ▶ if ref($age) eq 'HASH' && exists $age->{ageRange};
Branch: 1 branch
BranchTrueFalseTotal
if ref $age eq "HASH" and exists $age->{"ageRange"} 360 0 360
Condition33%1/3
ref $age eq "HASH" and exists $age->{"ageRange"}
!ll&&!rl&&r
00360
MC/DC0%0/2
ref $age eq "HASH" and exists $age->{"ageRange"}
ref $age eq "HASH" exists $age->{"ageRange"}
Truth table33%1/3
A and B
A= ref $age eq "HASH"B= exists $age->{"ageRange"}
ABresult
0X0
100
111
306 }
307  
308 $individual->{info}{convertPheno} = $ctx->{self}{convertPheno}
309 617 ▶ if !$ctx->{self}{test} && defined $ctx->{self}{convertPheno};
Branch: 1 branch
BranchTrueFalseTotal
if not $ctx->{"self"}{"test"} and defined $ctx->{"self"}{"convertPheno"} 0 617 617
Condition33%1/3
not $ctx->{"self"}{"test"} and defined $ctx->{"self"}{"convertPheno"}
!ll&&!rl&&r
61700
MC/DC0%0/2
not $ctx->{"self"}{"test"} and defined $ctx->{"self"}{"convertPheno"}
not $ctx->{"self"}{"test"} defined $ctx->{"self"}{"convertPheno"}
Truth table33%1/3
not(A) and B
A= not $ctx->{"self"}{"test"}B= defined $ctx->{"self"}{"convertPheno"}
ABresult
0X0
100
111
310  
311 617 my $mapping = $ctx->{mapping};
312 $individual->{info}{project} = {
313 id => $mapping->{project}{id},
314 source => $mapping->{_compiled}{sourceProfile},
315 ontology => $mapping->{defaults}{ontology},
316 version => $mapping->{project}{version},
317 617 };
318 $individual->{info}{project}{description} = $mapping->{project}{description}
319 617 ▶ if defined $mapping->{project}{description};
Branch: 1 branch
BranchTrueFalseTotal
if defined $mapping->{"project"}{"description"} 613 4 617
320  
321 _add_source_provenance( $individual->{info}, $ctx )
322 617 ▶ if _source_info_enabled( $ctx->{self} );
Branch: 1 branch
BranchTrueFalseTotal
if _source_info_enabled($ctx->{"self"}) 616 1 617
323  
324 617 return 1;
325 }
326  
327 617 ▶sub _map_procedures {
Subroutine _map_procedures: called CC=8 SCAR=20.9
328 617 my ( $individual, $rules, $ctx ) = @_;
329 617 ▶ for my $rule ( @{ $rules || [] } ) {
Condition100%2/2
$rules || []
l!l
362255
MC/DC100%1/1
$rules || []
$rules
Truth table100%2/2
A
A= $rules
Aresult
11
00
330 5402 for my $item_ctx ( @{ _matching_contexts( $rule->{source}, $ctx ) } ) {
331 4500 my $field = $rule->{source}{field};
332 4500 my $target = $rule->{target};
333 4500 my $code = _map_term( $target->{procedureCode}, $field, $item_ctx );
334 4500 ▶ next unless defined $code;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $code 0 4500 4500
335  
336 my $procedure = {
337 procedureCode => $code,
338 ageAtProcedure => exists $target->{ageAtProcedure}
339 ? _map_age(
340 _resolve_value(
341 $target->{ageAtProcedure}, $field, $item_ctx
342 )
343 )
344 : _clone( $DEFAULT->{age} ),
345 bodySite => exists $target->{bodySite}
346 ? _map_term( $target->{bodySite}, $field, $item_ctx )
347 : _clone( $DEFAULT->{ontology_term} ),
348 dateOfProcedure => _mapped_date(
349 4500 ▶ $target->{dateOfProcedure}, $field, $item_ctx
Branch: 2 branches
BranchTrueFalseTotal
exists $target->{'ageAtProcedure'} ? : 0 4500 4500
exists $target->{'bodySite'} ? : 3240 1260 4500
350 ),
351 };
352 $procedure->{_info} = $field
353 4500 ▶ if _source_info_enabled( $item_ctx->{self} );
Branch: 1 branch
BranchTrueFalseTotal
if _source_info_enabled($item_ctx->{"self"}) 4500 0 4500
354 4500 _add_visit( $procedure, $item_ctx );
355 4500 push @{ $individual->{interventionsOrProcedures} }, $procedure;
356 }
357 }
358 617 return 1;
359 }
360  
361 617 ▶sub _map_measures {
Subroutine _map_measures: called CC=5 SCAR=16.1
362 617 my ( $individual, $rules, $ctx ) = @_;
363 617 ▶ for my $rule ( @{ $rules || [] } ) {
Condition100%2/2
$rules || []
l!l
60017
MC/DC100%1/1
$rules || []
$rules
Truth table100%2/2
A
A= $rules
Aresult
11
00
364 9240 for my $item_ctx ( @{ _matching_contexts( $rule->{source}, $ctx ) } ) {
365 6530 my $measure = _map_measure_rule( $rule, $item_ctx );
366 6530 ▶ push @{ $individual->{measures} }, $measure if defined $measure;
Branch: 1 branch
BranchTrueFalseTotal
if defined $measure 6530 0 6530
367 }
368 }
369 617 return 1;
370 }
371  
372 6531 ▶sub _map_measure_rule {
Subroutine _map_measure_rule: called CC=9 SCAR=22.7
373 6531 my ( $rule, $ctx ) = @_;
374 6531 ▶ return unless _source_matches( $rule->{source}, $ctx->{record} );
Branch: 1 branch
BranchTrueFalseTotal
unless _source_matches($rule->{"source"}, $ctx->{"record"}) 0 6531 6531
375 6531 my $field = $rule->{source}{field};
376 6531 my $target = $rule->{target};
377 6531 my $value = $ctx->{record}->working_value($field);
378 6531 my $field_note = $ctx->{record}->field_note($field);
379  
380 6531 ▶ if ( defined $value && $value =~ / \- / ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value and $value =~ / \- /) 0 6531 6531
Condition33%1/3
defined $value and $value =~ / \- /
!ll&&!rl&&r
065310
MC/DC0%0/2
defined $value and $value =~ / \- /
defined $value $value =~ / \- /
Truth table33%1/3
A and B
A= defined $valueB= $value =~ / \- /
ABresult
0X0
100
111
381 0 ( $value, $field_note ) = split / \- /, $value, 2;
382 }
383  
384 6531 my $quantity_rule = $target->{measurementValue}{quantity};
385 my $unit = _map_term(
386 $quantity_rule->{unit},
387 6531 $field,
388 $ctx,
389 field_note => $field_note,
390 );
391 my $mapped_value = exists $quantity_rule->{value}
392 6531 ▶ ? _resolve_value( $quantity_rule->{value}, $field, $ctx )
Branch: 1 branch
BranchTrueFalseTotal
exists $quantity_rule->{'value'} ? : 1 6530 6531
393 : $value;
394  
395 my $reference_range = _reference_range(
396 6531 $quantity_rule->{referenceRange}, $unit, $field, $ctx
397 );
398  
399 my $measure = {
400 assayCode => _map_term( $target->{assayCode}, $field, $ctx ),
401 date => $DEFAULT->{date},
402 6531 measurementValue => {
403 quantity => {
404 unit => $unit,
405 value => dotify_and_coerce_number($mapped_value),
406 referenceRange => $reference_range,
407 },
408 },
409 };
410 6531 ▶ return unless defined $measure->{assayCode};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $measure->{"assayCode"} 0 6531 6531
411  
412 6531 ▶ if ( exists $target->{procedure} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $target->{"procedure"}) 6531 0 6531
413 $measure->{procedure} = {
414 procedureCode => _map_term(
415 6531 $target->{procedure}{procedureCode}, $field, $ctx
416 ),
417 };
418 }
419  
420 6531 ▶ if ( $ctx->{mapping}{_compiled}{recordProfile} eq 'redcap' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ctx->{"mapping"}{"_compiled"}{"recordProfile"} eq "redcap") 5570 961 6531
421 5570 ▶ my $meta = $ctx->{record}->field_meta($field) || {};
Condition50%1/2
$ctx->{'record'}->field_meta($field) || {}
l!l
55700
MC/DC0%0/1
$ctx->{'record'}->field_meta($field) || {}
$ctx->{'record'}->field_meta($field)
Truth table50%1/2
A
A= $ctx->{'record'}->field_meta($field)
Aresult
11
00
422 $measure->{notes} = join ' /// ', $field,
423 5570 map { qq/$_=$meta->{$_}/ } @REDCAP_META_FIELDS;
424 }
425  
426 6531 _add_visit( $measure, $ctx );
427 6531 return $measure;
428 }
429  
430 6531 ▶sub _reference_range {
Subroutine _reference_range: called CC=4 SCAR=13.9
431 6531 my ( $rule, $unit, $field, $ctx ) = @_;
432 6531 ▶ return _clone( $DEFAULT->{referenceRange} ) unless ref($rule) eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $rule eq "HASH" 0 6531 6531
433  
434 6531 ▶ if ( ( $rule->{from} || q{} ) eq 'redcapDictionary' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (($rule->{"from"} || "") eq "redcapDictionary") 5570 961 6531
Condition100%2/2
$rule->{'from'} || ''
l!l
5570961
MC/DC100%1/1
$rule->{'from'} || ''
$rule->{'from'}
Truth table100%2/2
A
A= $rule->{'from'}
Aresult
11
00
435 return map_reference_range(
436 {
437 unit => $unit,
438 redcap_dict => $ctx->{self}{data_redcap_dict},
439 5570 field => $field,
440 source => 'redcap',
441 }
442 );
443 }
444  
445 return map_reference_range_csv(
446 $unit,
447 { low => $rule->{low}, high => $rule->{high} },
448 961 );
449 }
450  
451 617 ▶sub _map_phenotypic_features {
Subroutine _map_phenotypic_features: called CC=11 SCAR=24.3
452 617 my ( $individual, $rules, $ctx ) = @_;
453 617 ▶ for my $rule ( @{ $rules || [] } ) {
Condition100%2/2
$rules || []
l!l
60017
MC/DC100%1/1
$rules || []
$rules
Truth table100%2/2
A
A= $rules
Aresult
11
00
454 6600 for my $item_ctx ( @{ _matching_contexts( $rule->{source}, $ctx ) } ) {
455 2750 my $field = $rule->{source}{field};
456 2750 my $raw = $item_ctx->{record}->working_value($field);
457 2750 ▶ next unless defined $raw && $raw ne q{};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $raw and $raw ne "" 0 2750 2750
Condition33%1/3
defined $raw and $raw ne ""
!ll&&!rl&&r
002750
MC/DC0%0/2
defined $raw and $raw ne ""
defined $raw $raw ne ""
Truth table33%1/3
A and B
A= defined $rawB= $raw ne ""
ABresult
0X0
100
111
458  
459 my $feature = {
460 excluded_ori => dotify_and_coerce_number($raw),
461 excluded => looks_like_number($raw)
462 ? ( $raw ? JSON::XS::false : JSON::XS::true )
463 : JSON::XS::false,
464 featureType => _map_term(
465 $rule->{target}{featureType},
466 2750 ▶ $field,
Branch: 2 branches
BranchTrueFalseTotal
&looks_like_number($raw) ? : 2270 480 2750
$raw ? : 190 2080 2270
467 $item_ctx,
468 ),
469 };
470 2750 ▶ next unless defined $feature->{featureType};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $feature->{"featureType"} 0 2750 2750
471  
472 2750 ▶ if ( $item_ctx->{mapping}{_compiled}{recordProfile} eq 'redcap' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($item_ctx->{"mapping"}{"_compiled"}{"recordProfile"} eq "redcap") 2270 480 2750
473 2270 ( my $dictionary_field = $field ) =~ s/___\w+\z//;
474 my $meta =
475 2270 ▶ $item_ctx->{record}->field_meta($dictionary_field) || {};
Condition50%1/2
$item_ctx->{'record'}->field_meta($dictionary_field) || {}
l!l
22700
MC/DC0%0/1
$item_ctx->{'record'}->field_meta($dictionary_field) || {}
$item_ctx->{'record'}->field_meta($dictionary_field)
Truth table50%1/2
A
A= $item_ctx->{'record'}->field_meta($dictionary_field)
Aresult
11
00
476 $feature->{notes} = join ' /// ', $dictionary_field,
477 2270 map { qq/$_=$meta->{$_}/ } @REDCAP_META_FIELDS;
478 }
479  
480 2750 _add_visit( $feature, $item_ctx );
481 2750 push @{ $individual->{phenotypicFeatures} }, $feature;
482 }
483 }
484 617 return 1;
485 }
486  
487 617 ▶sub _map_treatments {
Subroutine _map_treatments: called CC=11 SCAR=24.7
488 617 my ( $individual, $rules, $ctx ) = @_;
489 617 ▶ for my $rule ( @{ $rules || [] } ) {
Condition100%2/2
$rules || []
l!l
60017
MC/DC100%1/1
$rules || []
$rules
Truth table100%2/2
A
A= $rules
Aresult
11
00
490 2040 for my $item_ctx ( @{ _matching_contexts( $rule->{source}, $ctx ) } ) {
491 970 my $field = $rule->{source}{field};
492 970 my $target = $rule->{target};
493 970 my $code = _map_term( $target->{treatmentCode}, $field, $item_ctx );
494 970 ▶ next unless defined $code;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $code 0 970 970
495  
496 my $treatment = {
497 treatmentCode => $code,
498 ageAtOnset => exists $target->{ageAtOnset}
499 ? _map_age(
500 _resolve_value( $target->{ageAtOnset}, $field, $item_ctx )
501 )
502 970 ▶ : _clone( $DEFAULT->{age} ),
Branch: 1 branch
BranchTrueFalseTotal
exists $target->{'ageAtOnset'} ? : 0 970 970
503 };
504  
505 $treatment->{routeOfAdministration} = _map_term(
506 $target->{routeOfAdministration}, $field, $item_ctx
507 )
508 970 ▶ if exists $target->{routeOfAdministration};
Branch: 1 branch
BranchTrueFalseTotal
if exists $target->{"routeOfAdministration"} 970 0 970
509  
510 $treatment->{cumulativeDose} = _map_quantity(
511 $target->{cumulativeDose}, $field, $item_ctx, 0
512 )
513 970 ▶ if exists $target->{cumulativeDose};
Branch: 1 branch
BranchTrueFalseTotal
if exists $target->{"cumulativeDose"} 970 0 970
514  
515 970 ▶ if ( exists $target->{doseIntervals} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $target->{"doseIntervals"}) 970 0 970
516 my $quantity = _map_quantity(
517 970 $target->{doseIntervals}{quantity}, $field, $item_ctx, 1
518 );
519 $treatment->{doseIntervals} = [
520 {
521 interval => _clone( $DEFAULT->{interval} ),
522 quantity => $quantity,
523 970 scheduleFrequency => _clone( $DEFAULT->{ontology_term} ),
524 }
525 ];
526 }
527  
528 970 ▶ if ( _source_info_enabled( $item_ctx->{self} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (_source_info_enabled($item_ctx->{"self"})) 970 0 970
529 $treatment->{_info} = {
530 field => $field,
531 value => $item_ctx->{record}->value($field),
532 drug_name => $code->{label},
533 route => exists $treatment->{routeOfAdministration}
534 ? $treatment->{routeOfAdministration}{label}
535 : undef,
536 970 ▶ };
Branch: 1 branch
BranchTrueFalseTotal
exists $treatment->{'routeOfAdministration'} ? : 970 0 970
537 }
538  
539 970 _add_visit( $treatment, $item_ctx );
540 970 push @{ $individual->{treatments} }, $treatment;
541 }
542 }
543 617 return 1;
544 }
545  
546 1940 ▶sub _map_quantity {
Subroutine _map_quantity: called CC=5 SCAR=16.2
547 1940 my ( $rule, $field, $ctx, $with_range ) = @_;
548 my $value = exists $rule->{value}
549 ? _resolve_value( $rule->{value}, $field, $ctx )
550 1940 ▶ : $ctx->{record}->value($field);
Branch: 1 branch
BranchTrueFalseTotal
exists $rule->{'value'} ? : 1940 0 1940
551 1940 ▶ $value = defined $value && looks_like_number($value)
Branch: 1 branch
BranchTrueFalseTotal
defined $value && &looks_like_number($value) ? : 1120 820 1940
Condition66%2/3
defined $value and &looks_like_number($value)
!ll&&!rl&&r
82001120
MC/DC50%1/2
defined $value and &looks_like_number($value)
defined $value &looks_like_number($value)
Truth table66%2/3
A and B
A= defined $valueB= &looks_like_number($value)
ABresult
0X0
100
111
552 ? dotify_and_coerce_number($value)
553 : -1;
554  
555 1940 my $unit = _map_term( $rule->{unit}, $field, $ctx );
556 1940 my $quantity = { value => $value, unit => $unit };
557 $quantity->{referenceRange} = _clone( $DEFAULT->{referenceRange} )
558 1940 ▶ if $with_range;
Branch: 1 branch
BranchTrueFalseTotal
if $with_range 970 970 1940
559 1940 return $quantity;
560 }
561  
562 12 ▶sub _map_biosamples {
Subroutine _map_biosamples: called CC=26 SCAR=34.2
563 12 my ( $self, $record, $mapping, $individual_id ) = @_;
564 12 my $config = $mapping->{beacon}{biosamples};
565 12 ▶ return [] unless ref($config) eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $config eq "HASH" 0 12 12
566  
567 12 my $ctx = {
568 self => $self,
569 mapping => $mapping,
570 record => $record,
571 individual_id => $individual_id,
572 };
573 12 my @biosamples;
574  
575 12 ▶ for my $rule ( @{ $config->{mappings} || [] } ) {
Condition50%1/2
$config->{'mappings'} || []
l!l
120
MC/DC0%0/1
$config->{'mappings'} || []
$config->{'mappings'}
Truth table50%1/2
A
A= $config->{'mappings'}
Aresult
11
00
576 12 for my $item_ctx ( @{ _matching_contexts( $rule->{source}, $ctx ) } ) {
577 11 my $field = $rule->{source}{field};
578 11 my $target = $rule->{target};
579 11 my $id = _resolve_value( $target->{id}, $field, $item_ctx );
580 11 ▶ next unless _has_value($id);
Branch: 1 branch
BranchTrueFalseTotal
unless _has_value($id) 0 11 11
581  
582 my $biosample = {
583 id => "$id",
584 biosampleStatus => _map_term(
585 $target->{biosampleStatus}, $field, $item_ctx
586 ),
587 sampleOriginType => _map_term(
588 11 $target->{sampleOriginType}, $field, $item_ctx
589 ),
590 };
591 $biosample->{individualId} = exists $target->{individualId}
592 11 ▶ ? _resolve_value( $target->{individualId}, $field, $item_ctx )
Branch: 1 branch
BranchTrueFalseTotal
exists $target->{'individualId'} ? : 11 0 11
593 : $individual_id;
594  
595 11 for my $property (qw(collectionDate notes)) {
596 22 ▶ next unless exists $target->{$property};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $target->{$property} 20 2 22
597 my $value = _resolve_value(
598 2 $target->{$property},
599 $field,
600 $item_ctx,
601 );
602 2 ▶ next unless defined $value;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 0 2 2
603 2 ▶ $biosample->{$property} = $property eq 'collectionDate'
Branch: 1 branch
BranchTrueFalseTotal
$property eq 'collectionDate' ? : 1 1 2
604 ? convert_date_to_iso8601($value)
605 : $value;
606 }
607  
608 11 for my $property (qw(sampleOriginDetail)) {
609 $biosample->{$property} = _map_term(
610 $target->{$property}, $field, $item_ctx
611 )
612 11 ▶ if exists $target->{$property};
Branch: 1 branch
BranchTrueFalseTotal
if exists $target->{$property} 0 11 11
613 }
614  
615 11 ▶ if ( exists $target->{obtentionProcedure} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $target->{"obtentionProcedure"}) 1 10 11
616 $biosample->{obtentionProcedure} = {
617 procedureCode => _map_term(
618 $target->{obtentionProcedure}{procedureCode},
619 1 $field,
620 $item_ctx,
621 ),
622 };
623 }
624  
625 11 ▶ for my $measure_rule ( @{ $target->{measurements} || [] } ) {
Condition100%2/2
$target->{'measurements'} || []
l!l
110
MC/DC100%1/1
$target->{'measurements'} || []
$target->{'measurements'}
Truth table100%2/2
A
A= $target->{'measurements'}
Aresult
11
00
626 1 for my $measure_ctx (
627 1 @{ _matching_contexts( $measure_rule->{source}, $item_ctx ) }
628 )
629 {
630 1 my $measure = _map_measure_rule(
631 $measure_rule,
632 $measure_ctx,
633 );
634 1 ▶ push @{ $biosample->{measurements} }, $measure
Branch: 1 branch
BranchTrueFalseTotal
if defined $measure 1 0 1
635 if defined $measure;
636 }
637 }
638  
639 11 ▶ if ( exists $target->{info} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $target->{"info"}) 11 0 11
640 11 for my $info_field ( @{ $target->{info}{sourceFields} } ) {
641 21 my $item_record = $item_ctx->{record};
642 21 ▶ $biosample->{info}{$info_field} = $item_record->can('info_value')
Branch: 2 branches
BranchTrueFalseTotal
if defined $item_record->raw_value($info_field) 21 0 21
$item_record->can('info_value') ? : 0 21 21
643 ? $item_record->info_value($info_field)
644 : $item_record->value($info_field)
645 if defined $item_record->raw_value($info_field);
646 }
647 }
648  
649 11 ▶ if ( _source_info_enabled($self) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (_source_info_enabled($self)) 11 0 11
650 11 ▶ $biosample->{info} ||= {};
Condition50%1/2
$biosample->{"info"} ||= {}
l!l
110
MC/DC0%0/1
$biosample->{"info"} ||= {}
$biosample->{"info"}
Truth table50%1/2
A
A= $biosample->{"info"}
Aresult
11
00
651 11 _add_source_provenance( $biosample->{info}, $item_ctx );
652 }
653 $biosample->{info}{convertPheno} = $self->{convertPheno}
654 11 ▶ if !$self->{test} && defined $self->{convertPheno};
Branch: 1 branch
BranchTrueFalseTotal
if not $self->{"test"} and defined $self->{"convertPheno"} 0 11 11
Condition33%1/3
not $self->{"test"} and defined $self->{"convertPheno"}
!ll&&!rl&&r
1100
MC/DC0%0/2
not $self->{"test"} and defined $self->{"convertPheno"}
not $self->{"test"} defined $self->{"convertPheno"}
Truth table33%1/3
not(A) and B
A= not $self->{"test"}B= defined $self->{"convertPheno"}
ABresult
0X0
100
111
655  
656 11 push @biosamples, $biosample;
657 }
658 }
659  
660 12 return \@biosamples;
661 }
662  
663 38135 ▶sub _map_term {
Subroutine _map_term: called CC=23 SCAR=34.6
664 38135 my ( $rule, $source_field, $ctx, %arg ) = @_;
665 38135 ▶ return unless ref($rule) eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $rule eq "HASH" 0 38135 38135
666 38135 my $source_value = $ctx->{record}->raw_value($source_field);
667 38135 my $source_label = $ctx->{record}->value($source_field);
668 38135 ▶ my $ontology = $rule->{ontology} || $ctx->{mapping}{defaults}{ontology};
Condition66%2/3
$rule->{'ontology'} || $ctx->{'mapping'}{'defaults'}{'ontology'}
l!l&&r!l&&!r
480376550
MC/DC0%0/2
$rule->{'ontology'} || $ctx->{'mapping'}{'defaults'}{'ontology'}
$rule->{'ontology'} $ctx->{'mapping'}{'defaults'}{'ontology'}
Truth table66%2/3
A || B
A= $rule->{'ontology'}B= $ctx->{'mapping'}{'defaults'}{'ontology'}
ABresult
1X1
011
000
669 38135 ▶ if ( exists $rule->{term} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $rule->{"term"}) 36 38099 38135
670 36 my $term = _clone( $rule->{term} );
671 record_term_audit(
672 {
673 self => $ctx->{self},
674 36 source_field => $source_field,
675 source_value => $source_value,
676 source_label => $source_label,
677 ontology => $ontology,
678 term => $term,
679 match_status => 'configured',
680 match_source => 'mapping',
681 lookup_resolution => 'direct_term',
682 fallback_action => 'none',
683 }
684 );
685 36 return $term;
686 }
687  
688 38099 my $query_rule = $rule->{query};
689 38099 my $query = $source_label;
690 38099 ▶ if ( ref($query_rule) eq 'HASH' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $query_rule eq "HASH") 38097 2 38099
691 38097 ▶ if ( exists $query_rule->{literal} ) {
Branch: 3 branches
BranchTrueFalseTotal
if (exists $query_rule->{'literal'}) { } 27592 10505 38097
elsif (($query_rule->{'from'} // '') eq 'field') { } 0 10505 10505
elsif (($query_rule->{'from'} // '') eq 'fieldNote') { } 5570 4935 10505
692 27592 $query = $query_rule->{literal};
693 }
694 ▶ elsif ( ( $query_rule->{from} // q{} ) eq 'field' ) {
Condition50%1/2
$query_rule->{"from"} // ""
l!l
105050
MC/DC0%0/1
$query_rule->{"from"} // ""
$query_rule->{"from"}
Truth table50%1/2
A
A= $query_rule->{"from"}
Aresult
11
00
695 0 $query = $source_field;
696 }
697 ▶ elsif ( ( $query_rule->{from} // q{} ) eq 'fieldNote' ) {
Condition50%1/2
$query_rule->{"from"} // ""
l!l
105050
MC/DC0%0/1
$query_rule->{"from"} // ""
$query_rule->{"from"}
Truth table50%1/2
A
A= $query_rule->{"from"}
Aresult
11
00
698 $query = exists $arg{field_note}
699 ? $arg{field_note}
700 5570 ▶ : $ctx->{record}->field_note($source_field);
Branch: 1 branch
BranchTrueFalseTotal
exists $arg{'field_note'} ? : 5570 0 5570
701 }
702 }
703  
704 38099 my $direct_key;
705 38099 ▶ if ( ref( $rule->{terms} ) eq 'HASH' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $rule->{"terms"} eq "HASH") 11 38088 38099
706 11 my %seen;
707 11 for my $candidate ( $query, $source_label, $source_value ) {
708 11 ▶ next if !defined $candidate || ref($candidate) || $seen{$candidate}++;
Branch: 1 branch
BranchTrueFalseTotal
if not defined $candidate or ref $candidate or $seen{$candidate}++ 0 11 11
Condition33%2/6
not defined $candidate or ref $candidate or $seen{$candidate}++
l!l&&r!l&&!r
0011
not defined $candidate or ref $candidate
l!l&&r!l&&!r
0011
MC/DC0%0/3
not defined $candidate or ref $candidate or $seen{$candidate}++
not defined $candidate ref $candidate $seen{$candidate}++
Truth table25%1/4
not(A) or B or C
A= not defined $candidateB= ref $candidateC= $seen{$candidate}++
ABCresult
1XX1
01X1
0011
0000
709 11 ▶ if ( exists $rule->{terms}{$candidate} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $rule->{"terms"}{$candidate}) 11 0 11
710 11 $direct_key = $candidate;
711 11 last;
712 }
713 }
714 }
715 38099 ▶ if ( defined $direct_key ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $direct_key) 11 38088 38099
716 11 my $term = _clone( $rule->{terms}{$direct_key} );
717 record_term_audit(
718 {
719 self => $ctx->{self},
720 11 source_field => $source_field,
721 source_value => $source_value,
722 source_label => $source_label,
723 ontology => $ontology,
724 term => $term,
725 match_status => 'configured',
726 match_source => 'mapping',
727 lookup_resolution => 'direct_term',
728 fallback_action => 'none',
729 }
730 );
731 11 return $term;
732 }
733  
734 38088 ▶ unless ( ref($query_rule) eq 'HASH' && defined $query && !ref($query) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $query_rule eq "HASH" and defined $query and not ref $query) 0 38088 38088
Condition33%2/6
ref $query_rule eq "HASH" and defined $query and not ref $query
!ll&&!rl&&r
0038088
ref $query_rule eq "HASH" and defined $query
!ll&&!rl&&r
0038088
MC/DC0%0/3
ref $query_rule eq "HASH" and defined $query and not ref $query
ref $query_rule eq "HASH" defined $query not ref $query
Truth table25%1/4
A and B and not(C)
A= ref $query_rule eq "HASH"B= defined $queryC= not ref $query
ABCresult
0XX0
10X0
1100
1111
735 0 my $term = _clone( $DEFAULT->{ontology_term} );
736 record_term_audit(
737 {
738 self => $ctx->{self},
739 0 source_field => $source_field,
740 source_value => $source_value,
741 source_label => $source_label,
742 ontology => $ontology,
743 term => $term,
744 match_status => 'not_found',
745 match_source => 'fallback_na',
746 lookup_resolution => 'fallback_na',
747 fallback_action => 'na',
748 }
749 );
750 0 return $term;
751 }
752  
753 $query = $query_rule->{aliases}{$query}
754 if exists $query_rule->{aliases}
755 38088 ▶ && exists $query_rule->{aliases}{$query};
Branch: 1 branch
BranchTrueFalseTotal
if exists $query_rule->{"aliases"} and exists $query_rule->{"aliases"}{$query} 7054 31034 38088
Condition100%3/3
exists $query_rule->{"aliases"} and exists $query_rule->{"aliases"}{$query}
!ll&&!rl&&r
301169187054
MC/DC100%2/2
exists $query_rule->{"aliases"} and exists $query_rule->{"aliases"}{$query}
exists $query_rule->{"aliases"} exists $query_rule->{"aliases"}{$query}
Truth table100%3/3
A and B
A= exists $query_rule->{"aliases"}B= exists $query_rule->{"aliases"}{$query}
ABresult
0X0
100
111
756  
757 return map_ontology_term(
758 {
759 query => $query,
760 column => 'label',
761 ontology => $ontology,
762 self => $ctx->{self},
763 38088 source_field => $source_field,
764 source_value => $source_value,
765 source_label => $source_label,
766 }
767 );
768 }
769  
770 3503 ▶sub _resolve_value {
Subroutine _resolve_value: called CC=6 SCAR=18.3
771 3503 my ( $rule, $source_field, $ctx ) = @_;
772 3503 ▶ return unless ref($rule) eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $rule eq "HASH" 0 3503 3503
773 3503 ▶ return $rule->{literal} if exists $rule->{literal};
Branch: 1 branch
BranchTrueFalseTotal
if exists $rule->{"literal"} 0 3503 3503
774 return $ctx->{record}->value( $rule->{sourceField} )
775 3503 ▶ if exists $rule->{sourceField};
Branch: 1 branch
BranchTrueFalseTotal
if exists $rule->{"sourceField"} 3490 13 3503
776 return $ctx->{individual_id}
777 13 ▶ if ( $rule->{from} || q{} ) eq 'individualId';
Branch: 1 branch
BranchTrueFalseTotal
if ($rule->{"from"} || "") eq "individualId" 1 12 13
Condition50%1/2
$rule->{'from'} || ''
l!l
130
MC/DC0%0/1
$rule->{'from'} || ''
$rule->{'from'}
Truth table50%1/2
A
A= $rule->{'from'}
Aresult
11
00
778 12 return $ctx->{record}->value($source_field);
779 }
780  
781 32558 ▶sub _source_matches {
Subroutine _source_matches: called CC=9 SCAR=22.0
782 32558 my ( $source, $record ) = @_;
783 32558 my $field = $source->{field};
784 32558 my $working = $record->working_value($field);
785 32558 ▶ return 0 unless defined $working;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $working 6680 25878 32558
786  
787 25878 my $when = $source->{when};
788 25878 ▶ return 1 unless ref($when) eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $when eq "HASH" 21075 4803 25878
789 4803 my $value = $record->value($field);
790 4803 ▶ return 0 if $when->{nonEmpty} && !_has_value($value);
Branch: 1 branch
BranchTrueFalseTotal
if $when->{"nonEmpty"} and not _has_value($value) 0 4803 4803
Condition66%2/3
$when->{"nonEmpty"} and not _has_value($value)
!ll&&!rl&&r
300018030
MC/DC0%0/2
$when->{"nonEmpty"} and not _has_value($value)
$when->{"nonEmpty"} not _has_value($value)
Truth table66%2/3
A and not(B)
A= $when->{"nonEmpty"}B= not _has_value($value)
ABresult
0X0
100
111
791 return 0
792 if exists $when->{values}
793 4803 ▶ && !_value_in( $value, $when->{values} );
Branch: 1 branch
BranchTrueFalseTotal
if exists $when->{"values"} and not _value_in($value, $when->{"values"}) 1070 3733 4803
Condition100%3/3
exists $when->{"values"} and not _value_in($value, $when->{"values"})
!ll&&!rl&&r
30037301070
MC/DC100%2/2
exists $when->{"values"} and not _value_in($value, $when->{"values"})
exists $when->{"values"} not _value_in($value, $when->{"values"})
Truth table100%3/3
A and not(B)
A= exists $when->{"values"}B= not _value_in($value, $when->{"values"})
ABresult
0X0
100
111
794 return 0
795 if exists $when->{notValues}
796 3733 ▶ && _value_in( $value, $when->{notValues} );
Branch: 1 branch
BranchTrueFalseTotal
if exists $when->{"notValues"} and _value_in($value, $when->{"notValues"}) 288 3445 3733
Condition100%3/3
exists $when->{"notValues"} and _value_in($value, $when->{"notValues"})
!ll&&!rl&&r
2533912288
MC/DC100%2/2
exists $when->{"notValues"} and _value_in($value, $when->{"notValues"})
exists $when->{"notValues"} _value_in($value, $when->{"notValues"})
Truth table100%3/3
A and B
A= exists $when->{"notValues"}B= _value_in($value, $when->{"notValues"})
ABresult
0X0
100
111
797 3445 return 1;
798 }
799  
800 27020 ▶sub _matching_contexts {
Subroutine _matching_contexts: called CC=5 SCAR=16.1
801 27020 my ( $source, $ctx ) = @_;
802 27020 my $record = $ctx->{record};
803 my $views = blessed($record) && $record->can('views_for')
804 ? $record->views_for( $source->{field} )
805 27020 ▶ : [$record];
Branch: 1 branch
BranchTrueFalseTotal
builtin::blessed($record) && $record->can('views_for') ? : 12063 14957 27020
Condition66%2/3
builtin::blessed($record) and $record->can("views_for")
!ll&&!rl&&r
01495712063
MC/DC50%1/2
builtin::blessed($record) and $record->can("views_for")
builtin::blessed($record) $record->can("views_for")
Truth table66%2/3
A and B
A= builtin::blessed($record)B= $record->can("views_for")
ABresult
0X0
100
111
806  
807 27020 my @contexts;
808 27020 for my $view ( @{$views} ) {
809 24808 ▶ next unless _source_matches( $source, $view );
Branch: 1 branch
BranchTrueFalseTotal
unless _source_matches($source, $view) 8036 16772 24808
810 16772 push @contexts, { %{$ctx}, record => $view };
811 }
812 27020 return \@contexts;
813 }
814  
815 627 ▶sub _add_source_provenance {
Subroutine _add_source_provenance: called CC=9 SCAR=22.3
816 627 my ( $info, $ctx ) = @_;
817 627 my $mapping = $ctx->{mapping};
818 627 my $record = $ctx->{record};
819 627 my $record_profile = $mapping->{_compiled}{recordProfile};
820 627 my $source_profile = $mapping->{_compiled}{sourceProfile};
821  
822 627 ▶ if ( $record_profile eq 'redcap' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($record_profile eq 'redcap') { } 360 267 627
elsif ($source_profile eq 'csv') { } 244 23 267
823 360 $info->{REDCap_columns} = $record->columns_snapshot;
824 }
825 elsif ( $source_profile eq 'csv' ) {
826 244 $info->{CSV_columns} = $record->columns_snapshot;
827 }
828  
829 627 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($source_profile eq "cdisc-odm" and builtin::blessed($record) and $record->can("odm_provenance") and $record_profile ne "redcap" || $record->can("has_repeated_fields") && $record->has_repeated_fields) 3 624 627
Condition66%10/15
$source_profile eq "cdisc-odm" and builtin::blessed($record) and $record->can("odm_provenance") and $record_profile ne "redcap" || $record->can("has_repeated_fields") && $record->has_repeated_fields
!ll&&!rl&&r
4441803
$source_profile eq "cdisc-odm" and builtin::blessed($record) and $record->can("odm_provenance")
!ll&&!rl&&r
4440183
$source_profile eq "cdisc-odm" and builtin::blessed($record)
!ll&&!rl&&r
4440183
$record_profile ne "redcap" or $record->can("has_repeated_fields") and $record->has_repeated_fields
l!l&&r!l&&!r
30180
$record->can("has_repeated_fields") and $record->has_repeated_fields
!ll&&!rl&&r
01800
MC/DC33%2/6
$source_profile eq "cdisc-odm" and builtin::blessed($record) and $record->can("odm_provenance") and $record_profile ne "redcap" || $record->can("has_repeated_fields") && $record->has_repeated_fields
$source_profile eq "cdisc-odm" builtin::blessed($record) $record->can("odm_provenance") $record_profile ne "redcap" $record->can("has_repeated_fields") $record->has_repeated_fields
Truth table42%3/7
A and B and C and D or E and F
A= $source_profile eq "cdisc-odm"B= builtin::blessed($record)C= $record->can("odm_provenance")D= $record_profile ne "redcap"E= $record->can("has_repeated_fields")F= $record->has_repeated_fields
ABCDEFresult
0XXXXX0
10XXXX0
110XXX0
11100X0
1110100
1111XX1
1110111
830 $source_profile eq 'cdisc-odm'
831 && blessed($record)
832 && $record->can('odm_provenance')
833 && (
834 $record_profile ne 'redcap'
835 || ( $record->can('has_repeated_fields')
836 && $record->has_repeated_fields )
837 )
838 )
839 {
840 3 $info->{CDISC_ODM} = $record->odm_provenance;
841 }
842 627 return 1;
843 }
844  
845 3000 ▶sub _value_in {
Subroutine _value_in: called CC=3 SCAR=11.2
846 3000 my ( $value, $values ) = @_;
847 3000 ▶ return 0 unless defined $value;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 0 3000 3000
848 3000 ▶ return scalar grep { defined $_ && "$value" eq "$_" } @{$values};
Condition66%2/3
defined $_ && "$value" eq "$_"
!ll&&!rl&&r
049821018
MC/DC50%1/2
defined $_ && "$value" eq "$_"
defined $_ "$value" eq "$_"
Truth table66%2/3
A && B
A= defined $_B= "$value" eq "$_"
ABresult
0X0
100
111
849 }
850  
851 918 ▶sub _map_age {
Subroutine _map_age: called CC=2 SCAR=7.1
852 918 my ($value) = @_;
853 918 ▶ return _clone( $DEFAULT->{age} ) unless _has_value($value);
Branch: 1 branch
BranchTrueFalseTotal
unless _has_value($value) 0 918 918
854 918 return map_age_range($value);
855 }
856  
857 4500 ▶sub _mapped_date {
Subroutine _mapped_date: called CC=3 SCAR=11.0
858 4500 my ( $rule, $field, $ctx ) = @_;
859 4500 ▶ return $DEFAULT->{date} unless ref($rule) eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $rule eq "HASH" 4240 260 4500
860 260 my $value = _resolve_value( $rule, $field, $ctx );
861 260 ▶ return $DEFAULT->{date} unless _has_value($value);
Branch: 1 branch
BranchTrueFalseTotal
unless _has_value($value) 90 170 260
862 170 return convert_date_to_iso8601($value);
863 }
864  
865 16761 ▶sub _add_visit {
Subroutine _add_visit: called CC=3 SCAR=11.0
866 16761 my ( $item, $ctx ) = @_;
867 16761 ▶ my $visit = $ctx->{mapping}{records}{visitId} or return 1;
Branch: 1 branch
BranchTrueFalseTotal
my $visit = $ctx->{"mapping"}{"records"}{"visitId"} or return 1 16752 9 16761
868 16752 my $value = $ctx->{record}->value( $visit->{sourceField} );
869 16752 ▶ return 1 unless defined $value;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 0 16752 16752
870  
871 16752 $item->{_visit}{id} = dotify_and_coerce_number($value);
872 16752 my $composite = join '.', grep { length } $ctx->{individual_id}, $value;
873 16752 $item->{_visit}{composite} = $composite;
874 $item->{_visit}{occurrence_id} = allocate_surrogate_integer(
875 $ctx->{self},
876 16752 'bff_visit_occurrence_id',
877 $composite,
878 );
879 16752 return 1;
880 }
881  
882 607 ▶sub _context_requests_entity {
Subroutine _context_requests_entity: called CC=1 SCAR=0.0
883 607 my ( $context, $entity ) = @_;
884 607 return scalar grep { $_ eq $entity } @{ $context->entities };
885 }
886  
887 7020 ▶sub _source_info_enabled {
Subroutine _source_info_enabled: called CC=2 SCAR=7.1
888 7020 my ($self) = @_;
889 7020 ▶ return !exists $self->{source_info} || $self->{source_info};
Condition66%2/3
!exists $self->{'source_info'} || $self->{'source_info'}
l!l&&r!l&&!r
070191
MC/DC50%1/2
!exists $self->{'source_info'} || $self->{'source_info'}
!exists $self->{'source_info'} $self->{'source_info'}
Truth table66%2/3
not(A) || B
A= !exists $self->{'source_info'}B= $self->{'source_info'}
ABresult
1X1
011
000
890 }
891  
892 79013 ▶sub _has_value {
Subroutine _has_value: called CC=3 SCAR=11.4
893 79013 my ($value) = @_;
894 79013 ▶ return defined $value && !ref($value) && length "$value";
Condition66%4/6
defined $value && !ref($value) && length "$value"
!ll&&!rl&&r
57640021373
defined $value and not ref $value
!ll&&!rl&&r
57640021373
MC/DC33%1/3
defined $value && !ref($value) && length "$value"
defined $value not ref $value length "$value"
Truth table50%2/4
A and not(B) && C
A= defined $valueB= not ref $valueC= length "$value"
ABCresult
0XX0
10X0
1100
1111
895 }
896  
897 13315 ▶sub _clone {
Subroutine _clone: called CC=2 SCAR=7.2
898 13315 my ($value) = @_;
899 13315 ▶ return ref($value) ? dclone($value) : $value;
Branch: 1 branch
BranchTrueFalseTotal
ref $value ? : 13315 0 13315
900 }
901  
902 136 1;
« lib/Convert/Pheno/PXF/ToBFF/Biosamples.pm ↑ Summary lib/Convert/Pheno/CBioPortal/ToBFF.pm »