lib/Convert/Pheno/Mapping/Compiler.pm

filter: Statementstmt 96.1% 247 / 257 Branchbran 81.8% 113 / 138 Conditioncond 61.7% 76 / 123 MC/DCmcdc 39.7% 29 / 73 Subroutinesub 97.1% 34 / 35 Podpod 0.0% 0 / 4 totaltotal 79.2% 499 / 630 CC 127 SCAR 23.6
CC
127
Cov
84%
_collect_source_fields
23.4
_validate_target
20.3
_normalize_target
15.2
CRAP 10.5
« lib/Convert/Pheno/Runner.pm ↑ Summary lib/Convert/Pheno/CDISC/ODM/Metadata.pm »
1 package Convert::Pheno::Mapping::Compiler;
2  
3 140 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 140 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 140 ▶use autodie;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 140 ▶use Exporter 'import';
Subroutine BEGIN: called CC=1 SCAR=0.0
8 140 ▶use IO::Uncompress::Gunzip qw($GunzipError);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 140 ▶use Path::Tiny qw(path);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 140 ▶use Storable qw(dclone);
Subroutine BEGIN: called CC=1 SCAR=0.0
11 140 ▶use YAML::PP;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 140 our @EXPORT_OK = qw(
14 assert_mapping_version
15 compile_mapping
16 is_metadata_profile
17 load_mapping_document
18 );
19  
20 140 ▶use constant MAPPING_VERSION => 2;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 140 ▶use constant BEACON_SCHEMA_VERSION => '2.0.0';
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 140 my %METADATA_PROFILE = map { $_ => 1 } qw(
24 fhir
25 i2b2
26 omop
27 openehr
28 pcornet
29 pxf
30 sentinel
31 );
32  
33 499 ▶sub is_metadata_profile {
Subroutine is_metadata_profile: called CC=4 SCAR=14.9
Pod undocumented
34 499 my ($profile) = @_;
35 499 ▶ return 0 unless defined $profile && !ref($profile);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $profile and not ref $profile 0 499 499
Condition33%1/3
defined $profile and not ref $profile
!ll&&!rl&&r
00499
MC/DC0%0/2
defined $profile and not ref $profile
defined $profile not ref $profile
Truth table33%1/3
A and not(B)
A= defined $profileB= not ref $profile
ABresult
0X0
100
111
36 499 ▶ return $METADATA_PROFILE{$profile} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$METADATA_PROFILE{$profile} ? : 288 211 499
37 }
38  
39 76 ▶sub load_mapping_document {
Subroutine load_mapping_document: called CC=8 SCAR=25.6
Pod undocumented
40 76 my ($filepath) = @_;
41 76 ▶ die "No mapping file was provided\n"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $filepath and length $filepath 0 76 76
Condition33%1/3
defined $filepath and length $filepath
!ll&&!rl&&r
0076
MC/DC0%0/2
defined $filepath and length $filepath
defined $filepath length $filepath
Truth table33%1/3
A and B
A= defined $filepathB= length $filepath
ABresult
0X0
100
111
42 unless defined $filepath && length $filepath;
43  
44 76 my $content;
45 76 ▶ if ( $filepath =~ /\.gz\z/i ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($filepath =~ /\.gz\z/i) { } 0 76 76
46 0 ▶ my $fh = IO::Uncompress::Gunzip->new($filepath)
Branch: 1 branch
BranchTrueFalseTotal
my $fh = "IO::Uncompress::Gunzip"->new($filepath) or die "Cannot open mapping file <$filepath>: $Convert::Pheno::Mapping::Compiler::GunzipError\n" 0 0 0
47 or die "Cannot open mapping file <$filepath>: $GunzipError\n";
48 0 local $/;
49 0 $content = <$fh>;
50 0 close $fh;
51 0 ▶ utf8::decode($content) unless utf8::is_utf8($content);
Branch: 1 branch
BranchTrueFalseTotal
unless utf8::is_utf8($content) 0 0 0
52 }
53 else {
54 76 $content = path($filepath)->slurp_utf8;
55 }
56  
57 # YAML::PP rejects duplicate mapping keys by default. This matters for
58 # configuration: silently keeping the last duplicate can alter a clinical
59 # mapping while leaving the file apparently valid to a reviewer.
60 74 my $loader = YAML::PP->new(
61 boolean => 'JSON::PP',
62 duplicate_keys => 0,
63 );
64  
65 74 my $mapping = eval { $loader->load_string($content) };
66 74 ▶ if ( my $error = $@ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $error = $@) 2 72 74
67 2 chomp $error;
68 2 die "Cannot parse mapping file <$filepath>: $error\n";
69 }
70  
71 72 ▶ die "Mapping file <$filepath> must contain one object\n"
Branch: 1 branch
BranchTrueFalseTotal
unless ref $mapping eq "HASH" 0 72 72
72 unless ref($mapping) eq 'HASH';
73  
74 72 return $mapping;
75 }
76  
77 123 ▶sub assert_mapping_version {
Subroutine assert_mapping_version: called CC=4 SCAR=13.9
Pod undocumented
78 123 my ($mapping) = @_;
79 123 ▶ die "Expected a mapping object\n" unless ref($mapping) eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $mapping eq "HASH" 0 123 123
80  
81 123 ▶ if ( !exists $mapping->{mappingVersion} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $mapping->{"mappingVersion"}) 1 122 123
82 1 die "This mapping uses the pre-v2 layout. Convert-Pheno requires <mappingVersion: 2>; migrate the mapping before retrying.\n";
83 }
84  
85 122 ▶ die "Unsupported mappingVersion <$mapping->{mappingVersion}>; this Convert-Pheno release supports only <mappingVersion: 2>.\n"
Branch: 1 branch
BranchTrueFalseTotal
unless qq[$mapping->{"mappingVersion"}] eq 2 1 121 122
86 unless "$mapping->{mappingVersion}" eq MAPPING_VERSION;
87  
88 121 return 1;
89 }
90  
91 60 ▶sub compile_mapping {
Subroutine compile_mapping: called CC=12 SCAR=25.7
Pod undocumented
92 60 my ( $mapping, %arg ) = @_;
93 60 assert_mapping_version($mapping);
94  
95 58 my $profile = $arg{source_profile};
96 58 ▶ die "A source profile is required to compile the mapping\n"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $profile and length $profile 0 58 58
Condition33%1/3
defined $profile and length $profile
!ll&&!rl&&r
0058
MC/DC0%0/2
defined $profile and length $profile
defined $profile length $profile
Truth table33%1/3
A and B
A= defined $profileB= length $profile
ABresult
0X0
100
111
97 unless defined $profile && length $profile;
98 58 ▶ my $record_profile = $arg{record_profile} // $profile;
Condition66%2/3
$arg{"record_profile"} // $profile
l!l&&r!l&&!r
11470
MC/DC0%0/2
$arg{"record_profile"} // $profile
$arg{"record_profile"} $profile
Truth table66%2/3
A // B
A= $arg{"record_profile"}B= $profile
ABresult
1X1
011
000
99 58 ▶ die "A record profile is required to compile the mapping\n"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $record_profile and length $record_profile 0 58 58
Condition33%1/3
defined $record_profile and length $record_profile
!ll&&!rl&&r
0058
MC/DC0%0/2
defined $record_profile and length $record_profile
defined $record_profile length $record_profile
Truth table33%1/3
A and B
A= defined $record_profileB= length $record_profile
ABresult
0X0
100
111
100 unless defined $record_profile && length $record_profile;
101  
102 58 _validate_target($mapping);
103 57 _validate_source_profile( $mapping, $record_profile );
104  
105 # Built-in source mappings accept metadata overlays without exposing their
106 # structural conversion rules. SDTM compiles terminology selectors, while
107 # project-specific tabular profiles retain the full authoring mapping.
108 56 ▶ my $compiled =
Branch: 3 branches
BranchTrueFalseTotal
$record_profile eq 'bff' ? : 2 54 56
$record_profile eq 'sdtm' ? : 4 50 54
is_metadata_profile($record_profile) ? : 12 38 50
109 $record_profile eq 'bff' ? dclone($mapping)
110 : $record_profile eq 'sdtm' ? _compile_sdtm_mapping($mapping)
111 : is_metadata_profile($record_profile) ? dclone($mapping)
112 : _compile_authoring_mapping($mapping);
113 $compiled->{_compiled} = {
114 55 sourceProfile => $profile,
115 recordProfile => $record_profile,
116 };
117  
118 55 ▶ if ( exists $arg{headers} && !is_metadata_profile($record_profile) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $arg{"headers"} and not is_metadata_profile($record_profile)) 41 14 55
Condition66%2/3
exists $arg{"headers"} and not is_metadata_profile($record_profile)
!ll&&!rl&&r
14041
MC/DC50%1/2
exists $arg{"headers"} and not is_metadata_profile($record_profile)
exists $arg{"headers"} not is_metadata_profile($record_profile)
Truth table66%2/3
A and not(B)
A= exists $arg{"headers"}B= not is_metadata_profile($record_profile)
ABresult
0X0
100
111
119 41 ▶ if ( $record_profile eq 'sdtm' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($record_profile eq 'sdtm') { } 4 37 41
120 4 _validate_sdtm_source_fields( $compiled, $arg{headers}, $profile );
121 }
122 else {
123 37 _validate_source_fields( $compiled, $arg{headers}, $profile );
124 }
125 }
126  
127 54 return $compiled;
128 }
129  
130 4 ▶sub _compile_sdtm_mapping {
Subroutine _compile_sdtm_mapping: called CC=3 SCAR=11.0
131 4 my ($mapping) = @_;
132 4 my $compiled = dclone($mapping);
133 4 ▶ for my $field ( keys %{ $compiled->{terminology} || {} } ) {
Condition50%1/2
$compiled->{'terminology'} || {}
l!l
40
MC/DC0%0/1
$compiled->{'terminology'} || {}
$compiled->{'terminology'}
Truth table50%1/2
A
A= $compiled->{'terminology'}
Aresult
11
00
134 $compiled->{terminology}{$field} =
135 13 _normalize_term_target( $compiled->{terminology}{$field} );
136 }
137 4 return $compiled;
138 }
139  
140 38 ▶sub _compile_authoring_mapping {
Subroutine _compile_authoring_mapping: called CC=8 SCAR=20.8
141 38 my ($mapping) = @_;
142 38 my $compiled = dclone($mapping);
143 38 my $individuals = $compiled->{beacon}{individuals};
144  
145 38 $individuals->{id} = _compile_id_mapping( $individuals->{id} );
146  
147 38 for my $property (qw(sex ethnicity geographicOrigin)) {
148 114 ▶ next unless exists $individuals->{$property};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $individuals->{$property} 48 66 114
149 $individuals->{$property} = _compile_scalar_term(
150 66 $individuals->{$property},
151 "beacon.individuals.$property",
152 );
153 }
154  
155 38 ▶ if ( exists $individuals->{karyotypicSex} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $individuals->{"karyotypicSex"}) 0 38 38
156 $individuals->{karyotypicSex} = _compile_scalar_value(
157 $individuals->{karyotypicSex},
158 0 'beacon.individuals.karyotypicSex',
159 );
160 }
161  
162 $individuals->{info} = _compile_info_mapping( $individuals->{info} )
163 38 ▶ if exists $individuals->{info};
Branch: 1 branch
BranchTrueFalseTotal
if exists $individuals->{"info"} 29 9 38
164  
165 38 my %collection_kind = (
166 diseases => 'disease',
167 exposures => 'exposure',
168 interventionsOrProcedures => 'procedure',
169 measures => 'measure',
170 phenotypicFeatures => 'phenotypicFeature',
171 treatments => 'treatment',
172 );
173 38 for my $property ( keys %collection_kind ) {
174 227 ▶ next unless exists $individuals->{$property};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $individuals->{$property} 83 144 227
175 $individuals->{$property} = _compile_collection(
176 $individuals->{$property},
177 144 $collection_kind{$property},
178 "beacon.individuals.$property",
179 );
180 }
181  
182 37 ▶ if ( exists $compiled->{beacon}{biosamples} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $compiled->{"beacon"}{"biosamples"}) 14 23 37
183 $compiled->{beacon}{biosamples} = {
184 mappings => _compile_collection(
185 $compiled->{beacon}{biosamples},
186 14 'biosample',
187 'beacon.biosamples',
188 ),
189 };
190 }
191  
192 37 return $compiled;
193 }
194  
195 38 ▶sub _compile_id_mapping {
Subroutine _compile_id_mapping: called CC=4 SCAR=13.9
196 38 my ($config) = @_;
197 38 ▶ die "<beacon.individuals.id> must be an object\n"
Branch: 1 branch
BranchTrueFalseTotal
unless ref $config eq "HASH" 0 38 38
198 unless ref($config) eq 'HASH';
199  
200 my $compiled = {
201 source => {
202 fields => dclone( $config->{sourceFields} ),
203 primaryKey => $config->{primaryKey},
204 },
205 38 };
206 $compiled->{separator} = $config->{separator}
207 38 ▶ if exists $config->{separator};
Branch: 1 branch
BranchTrueFalseTotal
if exists $config->{"separator"} 25 13 38
208 $compiled->{missingValue} = $config->{missingValue}
209 38 ▶ if exists $config->{missingValue};
Branch: 1 branch
BranchTrueFalseTotal
if exists $config->{"missingValue"} 25 13 38
210 38 return $compiled;
211 }
212  
213 66 ▶sub _compile_scalar_term {
Subroutine _compile_scalar_term: called CC=1 SCAR=0.0
214 66 my ( $config, $path ) = @_;
215 66 my ( $source, $target ) = _split_rule( $config, $path );
216 return {
217 66 source => $source,
218 target => _normalize_term_target($target),
219 };
220 }
221  
222 0 ▶sub _compile_scalar_value {
Subroutine _compile_scalar_value: not called CC=1 SCAR=6.9
223 0 my ( $config, $path ) = @_;
224 0 my $source = _source_selector( $config, $path );
225 return {
226 source => $source,
227 0 target => dclone( $config->{value} ),
228 };
229 }
230  
231 29 ▶sub _compile_info_mapping {
Subroutine _compile_info_mapping: called CC=2 SCAR=6.9
232 29 my ($config) = @_;
233 my $compiled = {
234 29 source => { fields => dclone( $config->{sourceFields} ) },
235 };
236 $compiled->{target}{ageRange} = dclone( $config->{ageRange} )
237 29 ▶ if exists $config->{ageRange};
Branch: 1 branch
BranchTrueFalseTotal
if exists $config->{"ageRange"} 12 17 29
238 29 return $compiled;
239 }
240  
241 159 ▶sub _compile_collection {
Subroutine _compile_collection: called CC=5 SCAR=16.3
242 159 my ( $config, $kind, $path ) = @_;
243 die "<$path> must be an object with a <rules> array\n"
244 159 ▶ unless ref($config) eq 'HASH' && ref( $config->{rules} ) eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $config eq "HASH" and ref $config->{"rules"} eq "ARRAY" 0 159 159
Condition33%1/3
ref $config eq "HASH" and ref $config->{"rules"} eq "ARRAY"
!ll&&!rl&&r
00159
MC/DC0%0/2
ref $config eq "HASH" and ref $config->{"rules"} eq "ARRAY"
ref $config eq "HASH" ref $config->{"rules"} eq "ARRAY"
Truth table33%1/3
A and B
A= ref $config eq "HASH"B= ref $config->{"rules"} eq "ARRAY"
ABresult
0X0
100
111
245  
246 159 ▶ my $defaults = $config->{defaults} || {};
Condition100%2/2
$config->{'defaults'} || {}
l!l
10455
MC/DC100%1/1
$config->{'defaults'} || {}
$config->{'defaults'}
Truth table100%2/2
A
A= $config->{'defaults'}
Aresult
11
00
247 159 my @compiled;
248 159 for my $index ( 0 .. $#{ $config->{rules} } ) {
249 1150 my $rule = $config->{rules}[$index];
250 1150 my $rule_path = "$path.rules[$index]";
251 1150 my ( $source, $target ) = _split_rule( $rule, $rule_path );
252 1150 $target = _deep_merge( $defaults, $target );
253 1150 $target = _normalize_target( $target, $kind, $rule_path );
254 1149 push @compiled, { source => $source, target => $target };
255 }
256 158 return \@compiled;
257 }
258  
259 1216 ▶sub _split_rule {
Subroutine _split_rule: called CC=3 SCAR=11.0
260 1216 my ( $rule, $path ) = @_;
261 1216 my $source = _source_selector( $rule, $path );
262 1855 my %target = map { $_ => _clone( $rule->{$_} ) }
263 3323 ▶ grep { $_ ne 'sourceField' && $_ ne 'optional' && $_ ne 'when' }
Condition100%6/6
$_ ne 'sourceField' && $_ ne 'optional' && $_ ne 'when'
!ll&&!rl&&r
12422261855
$_ ne "sourceField" and $_ ne "optional"
!ll&&!rl&&r
1216262081
MC/DC100%3/3
$_ ne 'sourceField' && $_ ne 'optional' && $_ ne 'when'
$_ ne "sourceField" $_ ne "optional" $_ ne 'when'
Truth table100%4/4
A and B && C
A= $_ ne "sourceField"B= $_ ne "optional"C= $_ ne 'when'
ABCresult
0XX0
10X0
1100
1111
264 1216 keys %{$rule};
265 1216 return ( $source, \%target );
266 }
267  
268 1216 ▶sub _source_selector {
Subroutine _source_selector: called CC=6 SCAR=18.6
269 1216 my ( $rule, $path ) = @_;
270 1216 ▶ die "<$path> must be an object\n" unless ref($rule) eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $rule eq "HASH" 0 1216 1216
271 die "<$path.sourceField> is required\n"
272 1216 ▶ unless defined $rule->{sourceField} && length $rule->{sourceField};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $rule->{"sourceField"} and length $rule->{"sourceField"} 0 1216 1216
Condition33%1/3
defined $rule->{"sourceField"} and length $rule->{"sourceField"}
!ll&&!rl&&r
001216
MC/DC0%0/2
defined $rule->{"sourceField"} and length $rule->{"sourceField"}
defined $rule->{"sourceField"} length $rule->{"sourceField"}
Truth table33%1/3
A and B
A= defined $rule->{"sourceField"}B= length $rule->{"sourceField"}
ABresult
0X0
100
111
273  
274 1216 my $source = { field => $rule->{sourceField} };
275 1216 ▶ $source->{optional} = $rule->{optional} if exists $rule->{optional};
Branch: 1 branch
BranchTrueFalseTotal
if exists $rule->{"optional"} 26 1190 1216
276 1216 ▶ $source->{when} = dclone( $rule->{when} ) if exists $rule->{when};
Branch: 1 branch
BranchTrueFalseTotal
if exists $rule->{"when"} 226 990 1216
277 1216 return $source;
278 }
279  
280 1730 ▶sub _deep_merge {
Subroutine _deep_merge: called CC=5 SCAR=16.1
281 1730 my ( $defaults, $overrides ) = @_;
282 1730 my $merged = dclone($defaults);
283  
284 1730 for my $key ( keys %{$overrides} ) {
285 2390 ▶ if ( !defined $overrides->{$key} ) {
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $overrides->{$key}) { } 1 2389 2390
elsif (ref $merged->{$key} eq 'HASH' and ref $overrides->{$key} eq 'HASH') { } 580 1809 2389
286 1 delete $merged->{$key};
287 }
288 ▶ elsif (
Condition66%2/3
ref $merged->{$key} eq "HASH" and ref $overrides->{$key} eq "HASH"
!ll&&!rl&&r
18090580
MC/DC50%1/2
ref $merged->{$key} eq "HASH" and ref $overrides->{$key} eq "HASH"
ref $merged->{$key} eq "HASH" ref $overrides->{$key} eq "HASH"
Truth table66%2/3
A and B
A= ref $merged->{$key} eq "HASH"B= ref $overrides->{$key} eq "HASH"
ABresult
0X0
100
111
289 ref( $merged->{$key} ) eq 'HASH'
290 && ref( $overrides->{$key} ) eq 'HASH'
291 )
292 {
293 $merged->{$key} = _deep_merge(
294 $merged->{$key},
295 580 $overrides->{$key},
296 );
297 }
298 else {
299 1809 $merged->{$key} = _clone( $overrides->{$key} );
300 }
301 }
302 1730 return $merged;
303 }
304  
305 1150 ▶sub _normalize_target {
Subroutine _normalize_target: called CC=15 SCAR=27.2
306 1150 my ( $target, $kind, $path ) = @_;
307  
308 1150 my %term_paths = (
309 disease => [ [qw(diseaseCode)] ],
310 exposure => [ [qw(exposureCode)], [qw(unit)] ],
311 procedure => [ [qw(procedureCode)], [qw(bodySite)] ],
312 measure => [
313 [qw(assayCode)],
314 [qw(measurementValue quantity unit)],
315 [qw(procedure procedureCode)],
316 ],
317 phenotypicFeature => [ [qw(featureType)] ],
318 treatment => [
319 [qw(treatmentCode)],
320 [qw(routeOfAdministration)],
321 [qw(cumulativeDose unit)],
322 [qw(doseIntervals quantity unit)],
323 ],
324 biosample => [
325 [qw(biosampleStatus)],
326 [qw(sampleOriginType)],
327 [qw(sampleOriginDetail)],
328 [qw(obtentionProcedure procedureCode)],
329 ],
330 );
331  
332 1150 ▶ _normalize_term_at( $target, @{$_} ) for @{ $term_paths{$kind} || [] };
Condition50%1/2
$term_paths{$kind} || []
l!l
11500
MC/DC0%0/1
$term_paths{$kind} || []
$term_paths{$kind}
Truth table50%1/2
A
A= $term_paths{$kind}
Aresult
11
00
333  
334 1150 ▶ if ( $kind eq 'biosample' && exists $target->{measurements} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($kind eq "biosample" and exists $target->{"measurements"}) 1 1149 1150
Condition100%3/3
$kind eq "biosample" and exists $target->{"measurements"}
!ll&&!rl&&r
9681811
MC/DC100%2/2
$kind eq "biosample" and exists $target->{"measurements"}
$kind eq "biosample" exists $target->{"measurements"}
Truth table100%3/3
A and B
A= $kind eq "biosample"B= exists $target->{"measurements"}
ABresult
0X0
100
111
335 $target->{measurements} = _compile_collection(
336 $target->{measurements},
337 1 'measure',
338 "$path.measurements",
339 );
340 }
341  
342 1150 my %required_paths = (
343 disease => [ [qw(diseaseCode)] ],
344 exposure => [ [qw(exposureCode)], [qw(unit)] ],
345 procedure => [ [qw(procedureCode)] ],
346 measure => [ [qw(assayCode)], [qw(measurementValue quantity unit)] ],
347 phenotypicFeature => [ [qw(featureType)] ],
348 treatment => [ [qw(treatmentCode)] ],
349 biosample => [ [qw(id)], [qw(biosampleStatus)], [qw(sampleOriginType)] ],
350 );
351 1941 _require_target_path( $target, $path, @{$_} )
352 1150 ▶ for @{ $required_paths{$kind} || [] };
Condition50%1/2
$required_paths{$kind} || []
l!l
11500
MC/DC0%0/1
$required_paths{$kind} || []
$required_paths{$kind}
Truth table50%1/2
A
A= $required_paths{$kind}
Aresult
11
00
353  
354 1149 ▶ if ( $kind eq 'measure' && exists $target->{procedure} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($kind eq "measure" and exists $target->{"procedure"}) 329 820 1149
Condition66%2/3
$kind eq "measure" and exists $target->{"procedure"}
!ll&&!rl&&r
8200329
MC/DC50%1/2
$kind eq "measure" and exists $target->{"procedure"}
$kind eq "measure" exists $target->{"procedure"}
Truth table66%2/3
A and B
A= $kind eq "measure"B= exists $target->{"procedure"}
ABresult
0X0
100
111
355 329 _require_target_path( $target, $path, qw(procedure procedureCode) );
356 }
357 1149 ▶ if ( $kind eq 'treatment' && exists $target->{cumulativeDose} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($kind eq "treatment" and exists $target->{"cumulativeDose"}) 73 1076 1149
Condition66%2/3
$kind eq "treatment" and exists $target->{"cumulativeDose"}
!ll&&!rl&&r
1076073
MC/DC50%1/2
$kind eq "treatment" and exists $target->{"cumulativeDose"}
$kind eq "treatment" exists $target->{"cumulativeDose"}
Truth table66%2/3
A and B
A= $kind eq "treatment"B= exists $target->{"cumulativeDose"}
ABresult
0X0
100
111
358 73 _require_target_path( $target, $path, qw(cumulativeDose unit) );
359 }
360 1149 ▶ if ( $kind eq 'treatment' && exists $target->{doseIntervals} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($kind eq "treatment" and exists $target->{"doseIntervals"}) 73 1076 1149
Condition66%2/3
$kind eq "treatment" and exists $target->{"doseIntervals"}
!ll&&!rl&&r
1076073
MC/DC50%1/2
$kind eq "treatment" and exists $target->{"doseIntervals"}
$kind eq "treatment" exists $target->{"doseIntervals"}
Truth table66%2/3
A and B
A= $kind eq "treatment"B= exists $target->{"doseIntervals"}
ABresult
0X0
100
111
361 73 _require_target_path(
362 $target,
363 $path,
364 qw(doseIntervals quantity unit),
365 );
366 }
367 1149 ▶ if ( $kind eq 'biosample' && exists $target->{obtentionProcedure} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($kind eq "biosample" and exists $target->{"obtentionProcedure"}) 1 1148 1149
Condition100%3/3
$kind eq "biosample" and exists $target->{"obtentionProcedure"}
!ll&&!rl&&r
9671811
MC/DC100%2/2
$kind eq "biosample" and exists $target->{"obtentionProcedure"}
$kind eq "biosample" exists $target->{"obtentionProcedure"}
Truth table100%3/3
A and B
A= $kind eq "biosample"B= exists $target->{"obtentionProcedure"}
ABresult
0X0
100
111
368 1 _require_target_path(
369 $target,
370 $path,
371 qw(obtentionProcedure procedureCode),
372 );
373 }
374  
375 1149 return $target;
376 }
377  
378 2852 ▶sub _normalize_term_at {
Subroutine _normalize_term_at: called CC=6 SCAR=18.0
379 2852 my ( $target, @path ) = @_;
380 2852 my $key = pop @path;
381 2852 my $node = $target;
382 2852 for my $part (@path) {
383 1388 ▶ return unless ref($node) eq 'HASH' && exists $node->{$part};
Branch: 1 branch
BranchTrueFalseTotal
unless ref $node eq "HASH" and exists $node->{$part} 181 1207 1388
Condition66%2/3
ref $node eq "HASH" and exists $node->{$part}
!ll&&!rl&&r
01811207
MC/DC50%1/2
ref $node eq "HASH" and exists $node->{$part}
ref $node eq "HASH" exists $node->{$part}
Truth table66%2/3
A and B
A= ref $node eq "HASH"B= exists $node->{$part}
ABresult
0X0
100
111
384 1207 $node = $node->{$part};
385 }
386 2671 ▶ return unless ref($node) eq 'HASH' && exists $node->{$key};
Branch: 1 branch
BranchTrueFalseTotal
unless ref $node eq "HASH" and exists $node->{$key} 256 2415 2671
Condition66%2/3
ref $node eq "HASH" and exists $node->{$key}
!ll&&!rl&&r
02562415
MC/DC50%1/2
ref $node eq "HASH" and exists $node->{$key}
ref $node eq "HASH" exists $node->{$key}
Truth table66%2/3
A and B
A= ref $node eq "HASH"B= exists $node->{$key}
ABresult
0X0
100
111
387 2415 $node->{$key} = _normalize_term_target( $node->{$key} );
388 2415 return;
389 }
390  
391 2494 ▶sub _normalize_term_target {
Subroutine _normalize_term_target: called CC=3 SCAR=11.0
392 2494 my ($target) = @_;
393 2494 my $normalized = dclone($target);
394 2494 ▶ if ( exists $normalized->{query} && !ref( $normalized->{query} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $normalized->{"query"} and not ref $normalized->{"query"}) 1680 814 2494
Condition100%3/3
exists $normalized->{"query"} and not ref $normalized->{"query"}
!ll&&!rl&&r
1956191680
MC/DC100%2/2
exists $normalized->{"query"} and not ref $normalized->{"query"}
exists $normalized->{"query"} not ref $normalized->{"query"}
Truth table100%3/3
A and not(B)
A= exists $normalized->{"query"}B= not ref $normalized->{"query"}
ABresult
0X0
100
111
395 1680 $normalized->{query} = { literal => $normalized->{query} };
396 }
397 2494 return $normalized;
398 }
399  
400 2417 ▶sub _require_target_path {
Subroutine _require_target_path: called CC=4 SCAR=13.9
401 2417 my ( $target, $rule_path, @path ) = @_;
402 2417 my $node = $target;
403 2417 for my $part (@path) {
404 die "<$rule_path> must define target <" . join( '.', @path ) . ">\n"
405 3624 ▶ unless ref($node) eq 'HASH' && exists $node->{$part};
Branch: 1 branch
BranchTrueFalseTotal
unless ref $node eq "HASH" and exists $node->{$part} 1 3623 3624
Condition66%2/3
ref $node eq "HASH" and exists $node->{$part}
!ll&&!rl&&r
013623
MC/DC50%1/2
ref $node eq "HASH" and exists $node->{$part}
ref $node eq "HASH" exists $node->{$part}
Truth table66%2/3
A and B
A= ref $node eq "HASH"B= exists $node->{$part}
ABresult
0X0
100
111
406 3623 $node = $node->{$part};
407 }
408 2416 return 1;
409 }
410  
411 3664 ▶sub _clone {
Subroutine _clone: called CC=2 SCAR=6.9
412 3664 my ($value) = @_;
413 3664 ▶ return ref($value) ? dclone($value) : $value;
Branch: 1 branch
BranchTrueFalseTotal
ref $value ? : 3344 320 3664
414 }
415  
416 58 ▶sub _validate_target {
Subroutine _validate_target: called CC=13 SCAR=30.1
417 58 my ($mapping) = @_;
418 58 my $target = $mapping->{target};
419 58 ▶ if ( ( $mapping->{source}{profile} // q{} ) eq 'bff' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (($mapping->{"source"}{"profile"} // "") eq "bff") 2 56 58
Condition50%1/2
$mapping->{"source"}{"profile"} // ""
l!l
580
MC/DC0%0/1
$mapping->{"source"}{"profile"} // ""
$mapping->{"source"}{"profile"}
Truth table50%1/2
A
A= $mapping->{"source"}{"profile"}
Aresult
11
00
420 die "BFF terminology mappings require <target.model: omop> and <target.schemaVersion: 5.4>.\n"
421 unless ref($target) eq 'HASH'
422 && ( $target->{model} // q{} ) eq 'omop'
423 2 ▶ && ( $target->{schemaVersion} // q{} ) eq '5.4';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $target eq "HASH" and ($target->{"model"} // "") eq "omop" and ($target->{"schemaVersion"} // "") eq "5.4" 0 2 2
Condition40%4/10
ref $target eq "HASH" and ($target->{"model"} // "") eq "omop" and ($target->{"schemaVersion"} // "") eq "5.4"
!ll&&!rl&&r
002
ref $target eq "HASH" and ($target->{"model"} // "") eq "omop"
!ll&&!rl&&r
002
$target->{"model"} // ""
l!l
20
$target->{"schemaVersion"} // ""
l!l
20
MC/DC0%0/3
ref $target eq "HASH" and ($target->{"model"} // "") eq "omop" and ($target->{"schemaVersion"} // "") eq "5.4"
ref $target eq "HASH" $target->{"model"} $target->{"schemaVersion"}
Truth table25%1/4
A and B and C
A= ref $target eq "HASH"B= $target->{"model"}C= $target->{"schemaVersion"}
ABCresult
0XX0
10X0
1100
1111
424 2 return 1;
425 }
426 56 ▶ die "The mapping must declare <target.model: beacon> and <target.schemaVersion: 2.0.0>.\n"
Branch: 1 branch
BranchTrueFalseTotal
unless ref $target eq "HASH" 0 56 56
427 unless ref($target) eq 'HASH';
428  
429 die "Unsupported mapping target model <$target->{model}>; expected <beacon>.\n"
430 56 ▶ unless defined $target->{model} && lc( $target->{model} ) eq 'beacon';
Branch: 1 branch
BranchTrueFalseTotal
unless defined $target->{"model"} and lc $target->{"model"} eq "beacon" 0 56 56
Condition33%1/3
defined $target->{"model"} and lc $target->{"model"} eq "beacon"
!ll&&!rl&&r
0056
MC/DC0%0/2
defined $target->{"model"} and lc $target->{"model"} eq "beacon"
defined $target->{"model"} lc $target->{"model"} eq "beacon"
Truth table33%1/3
A and B
A= defined $target->{"model"}B= lc $target->{"model"} eq "beacon"
ABresult
0X0
100
111
431  
432 die "Unsupported Beacon target schema version <$target->{schemaVersion}>; this release supports <2.0.0>.\n"
433 unless defined $target->{schemaVersion}
434 56 ▶ && "$target->{schemaVersion}" eq BEACON_SCHEMA_VERSION;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $target->{"schemaVersion"} and qq[$target->{"schemaVersion"}] eq "2.0.0" 1 55 56
Condition66%2/3
defined $target->{"schemaVersion"} and qq[$target->{"schemaVersion"}] eq "2.0.0"
!ll&&!rl&&r
0155
MC/DC50%1/2
defined $target->{"schemaVersion"} and qq[$target->{"schemaVersion"}] eq "2.0.0"
defined $target->{"schemaVersion"} qq[$target->{"schemaVersion"}] eq "2.0.0"
Truth table66%2/3
A and B
A= defined $target->{"schemaVersion"}B= qq[$target->{"schemaVersion"}] eq "2.0.0"
ABresult
0X0
100
111
435  
436 55 return 1;
437 }
438  
439 57 ▶sub _validate_source_profile {
Subroutine _validate_source_profile: called CC=6 SCAR=19.9
440 57 my ( $mapping, $expected_profile ) = @_;
441 57 my $source = $mapping->{source};
442 57 ▶ my $profile = ref($source) eq 'HASH' ? $source->{profile} : undef;
Branch: 1 branch
BranchTrueFalseTotal
ref $source eq 'HASH' ? : 57 0 57
443 57 ▶ die "The mapping must declare one <source.profile> value.\n"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $profile and not ref $profile and length $profile 0 57 57
Condition33%2/6
defined $profile and not ref $profile and length $profile
!ll&&!rl&&r
0057
defined $profile and not ref $profile
!ll&&!rl&&r
0057
MC/DC0%0/3
defined $profile and not ref $profile and length $profile
defined $profile not ref $profile length $profile
Truth table25%1/4
A and not(B) and C
A= defined $profileB= not ref $profileC= length $profile
ABCresult
0XX0
10X0
1100
1111
444 unless defined $profile && !ref($profile) && length $profile;
445  
446 57 ▶ return 1 if $profile eq $expected_profile;
Branch: 1 branch
BranchTrueFalseTotal
if $profile eq $expected_profile 56 1 57
447  
448 1 die "Mapping source profile mismatch: normalized route profile <$expected_profile> does not match <source.profile: $profile>.\n";
449 }
450  
451 37 ▶sub _validate_source_fields {
Subroutine _validate_source_fields: called CC=4 SCAR=13.9
452 37 my ( $mapping, $headers, $profile ) = @_;
453 37 ▶ die "Expected source headers as an array reference\n"
Branch: 1 branch
BranchTrueFalseTotal
unless ref $headers eq "ARRAY" 0 37 37
454 unless ref($headers) eq 'ARRAY';
455  
456 37 my %available = map { $_ => 1 } @{$headers};
457 37 my %required;
458 37 _collect_source_fields( $mapping, \%required );
459  
460 37 ▶ my @missing = sort grep { $required{$_} && !$available{$_} } keys %required;
Condition100%3/3
$required{$_} && !$available{$_}
!ll&&!rl&&r
5024081
MC/DC100%2/2
$required{$_} && !$available{$_}
$required{$_} !$available{$_}
Truth table100%3/3
A && not(B)
A= $required{$_}B= !$available{$_}
ABresult
0X0
100
111
461 37 ▶ return 1 unless @missing;
Branch: 1 branch
BranchTrueFalseTotal
unless @missing 36 1 37
462  
463 1 die "Mapping references source columns not present in the <$profile> input: <"
464 . join( '>, <', @missing ) . ">.\n";
465 }
466  
467 4 ▶sub _validate_sdtm_source_fields {
Subroutine _validate_sdtm_source_fields: called CC=4 SCAR=14.5
468 4 my ( $mapping, $headers, $profile ) = @_;
469 4 ▶ die "Expected SDTM source fields as an array reference\n"
Branch: 1 branch
BranchTrueFalseTotal
unless ref $headers eq "ARRAY" 0 4 4
470 unless ref($headers) eq 'ARRAY';
471  
472 4 my %available = map { $_ => 1 } @{$headers};
473 13 my @missing = sort grep { !$available{$_} }
474 4 ▶ keys %{ $mapping->{terminology} || {} };
Condition50%1/2
$mapping->{'terminology'} || {}
l!l
40
MC/DC0%0/1
$mapping->{'terminology'} || {}
$mapping->{'terminology'}
Truth table50%1/2
A
A= $mapping->{'terminology'}
Aresult
11
00
475 4 ▶ return 1 unless @missing;
Branch: 1 branch
BranchTrueFalseTotal
unless @missing 4 0 4
476  
477 0 die "Mapping references SDTM fields not present in the <$profile> input: <"
478 . join( '>, <', @missing ) . ">.\n";
479 }
480  
481 26702 ▶sub _collect_source_fields {
Subroutine _collect_source_fields: called CC=23 SCAR=31.5
482 26702 my ( $node, $out, $optional ) = @_;
483 26702 ▶ return unless ref $node;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $node 13801 12901 26702
484  
485 12901 ▶ if ( ref($node) eq 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $node eq "ARRAY") 543 12358 12901
486 543 _collect_source_fields( $_, $out, $optional ) for @{$node};
487 543 return;
488 }
489  
490 12358 ▶ return unless ref($node) eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $node eq "HASH" 141 12217 12358
491  
492 12217 ▶ my $node_optional = $optional ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$optional ? : 247 11970 12217
493 $node_optional = 1
494 if exists $node->{source}
495 && ref( $node->{source} ) eq 'HASH'
496 12217 ▶ && $node->{source}{optional};
Branch: 1 branch
BranchTrueFalseTotal
if exists $node->{"source"} and ref $node->{"source"} eq "HASH" and $node->{"source"}{"optional"} 26 12191 12217
Condition83%5/6
exists $node->{"source"} and ref $node->{"source"} eq "HASH" and $node->{"source"}{"optional"}
!ll&&!rl&&r
10900129126
exists $node->{"source"} and ref $node->{"source"} eq "HASH"
!ll&&!rl&&r
1090001317
MC/DC66%2/3
exists $node->{"source"} and ref $node->{"source"} eq "HASH" and $node->{"source"}{"optional"}
exists $node->{"source"} ref $node->{"source"} eq "HASH" $node->{"source"}{"optional"}
Truth table75%3/4
A and B and C
A= exists $node->{"source"}B= ref $node->{"source"} eq "HASH"C= $node->{"source"}{"optional"}
ABCresult
0XX0
10X0
1100
1111
497  
498 12217 ▶ if ( exists $node->{sourceField} && !ref( $node->{sourceField} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $node->{"sourceField"} and not ref $node->{"sourceField"}) 431 11786 12217
Condition66%2/3
exists $node->{"sourceField"} and not ref $node->{"sourceField"}
!ll&&!rl&&r
117860431
MC/DC50%1/2
exists $node->{"sourceField"} and not ref $node->{"sourceField"}
exists $node->{"sourceField"} not ref $node->{"sourceField"}
Truth table66%2/3
A and not(B)
A= exists $node->{"sourceField"}B= not ref $node->{"sourceField"}
ABresult
0X0
100
111
499 431 _register_source_field( $out, $node->{sourceField}, $node_optional );
500 }
501 12217 ▶ if ( exists $node->{sourceFields} && ref( $node->{sourceFields} ) eq 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $node->{"sourceFields"} and ref $node->{"sourceFields"} eq "ARRAY") 208 12009 12217
Condition66%2/3
exists $node->{"sourceFields"} and ref $node->{"sourceFields"} eq "ARRAY"
!ll&&!rl&&r
120090208
MC/DC50%1/2
exists $node->{"sourceFields"} and ref $node->{"sourceFields"} eq "ARRAY"
exists $node->{"sourceFields"} ref $node->{"sourceFields"} eq "ARRAY"
Truth table66%2/3
A and B
A= exists $node->{"sourceFields"}B= ref $node->{"sourceFields"} eq "ARRAY"
ABresult
0X0
100
111
502 _register_source_field( $out, $_, $node_optional )
503 208 for @{ $node->{sourceFields} };
504 }
505  
506 12217 ▶ if ( exists $node->{source} && ref( $node->{source} ) eq 'HASH' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $node->{"source"} and ref $node->{"source"} eq "HASH") 1317 10900 12217
Condition66%2/3
exists $node->{"source"} and ref $node->{"source"} eq "HASH"
!ll&&!rl&&r
1090001317
MC/DC50%1/2
exists $node->{"source"} and ref $node->{"source"} eq "HASH"
exists $node->{"source"} ref $node->{"source"} eq "HASH"
Truth table66%2/3
A and B
A= exists $node->{"source"}B= ref $node->{"source"} eq "HASH"
ABresult
0X0
100
111
507 1317 my $source = $node->{source};
508 _register_source_field( $out, $source->{field}, $node_optional )
509 1317 ▶ if exists $source->{field} && !ref( $source->{field} );
Branch: 1 branch
BranchTrueFalseTotal
if exists $source->{"field"} and not ref $source->{"field"} 1214 103 1317
Condition66%2/3
exists $source->{"field"} and not ref $source->{"field"}
!ll&&!rl&&r
10301214
MC/DC50%1/2
exists $source->{"field"} and not ref $source->{"field"}
exists $source->{"field"} not ref $source->{"field"}
Truth table66%2/3
A and not(B)
A= exists $source->{"field"}B= not ref $source->{"field"}
ABresult
0X0
100
111
510 _register_source_field( $out, $_, $node_optional )
511 1317 ▶ for @{ $source->{fields} || [] };
Condition100%2/2
$source->{'fields'} || []
l!l
661251
MC/DC100%1/1
$source->{'fields'} || []
$source->{'fields'}
Truth table100%2/2
A
A= $source->{'fields'}
Aresult
11
00
512 _register_source_field( $out, $source->{primaryKey}, $node_optional )
513 1317 ▶ if exists $source->{primaryKey} && !ref( $source->{primaryKey} );
Branch: 1 branch
BranchTrueFalseTotal
if exists $source->{"primaryKey"} and not ref $source->{"primaryKey"} 37 1280 1317
Condition66%2/3
exists $source->{"primaryKey"} and not ref $source->{"primaryKey"}
!ll&&!rl&&r
1280037
MC/DC50%1/2
exists $source->{"primaryKey"} and not ref $source->{"primaryKey"}
exists $source->{"primaryKey"} not ref $source->{"primaryKey"}
Truth table66%2/3
A and not(B)
A= exists $source->{"primaryKey"}B= not ref $source->{"primaryKey"}
ABresult
0X0
100
111
514 }
515  
516 12217 _collect_source_fields( $_, $out, $node_optional ) for values %{$node};
517 12217 return;
518 }
519  
520 3578 ▶sub _register_source_field {
Subroutine _register_source_field: called CC=5 SCAR=16.6
521 3578 my ( $out, $field, $optional ) = @_;
522 3578 ▶ return unless defined $field && length $field;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $field and length $field 0 3578 3578
Condition33%1/3
defined $field and length $field
!ll&&!rl&&r
003578
MC/DC0%0/2
defined $field and length $field
defined $field length $field
Truth table33%1/3
A and B
A= defined $fieldB= length $field
ABresult
0X0
100
111
523 3578 ▶ $out->{$field} = 0 unless exists $out->{$field};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $out->{$field} 2459 1119 3578
524 3578 ▶ $out->{$field} = 1 unless $optional;
Branch: 1 branch
BranchTrueFalseTotal
unless $optional 3480 98 3578
525 3578 return;
526 }
527  
528 140 1;
« lib/Convert/Pheno/Runner.pm ↑ Summary lib/Convert/Pheno/CDISC/ODM/Metadata.pm »