lib/Convert/Pheno/HTTP/Service.pm

filter: Statementstmt 96.5% 422 / 437 Branchbran 74.8% 193 / 258 Conditioncond 54.5% 144 / 264 MC/DCmcdc 26.5% 38 / 143 Subroutinesub 91.4% 43 / 47 Podpod 0.0% 0 / 6 totaltotal 72.7% 840 / 1155 CC 245 SCAR 36.1
CC
245
Cov
79%
execute_files
89.1
_validate_option
74.6
_execute_arguments
53.3
CRAP 36.8
« lib/Convert/Pheno/HTTP/Projects.pm ↑ Summary lib/Convert/Pheno/CDISC/SDTM/Terminology.pm »
1 package Convert::Pheno::HTTP::Service;
2  
3 42 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 42 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 42 ▶use File::Basename qw(dirname);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 42 ▶use File::Spec::Functions qw(catfile);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 42 ▶use JSON::XS;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 42 ▶use MIME::Base64 qw(encode_base64);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 42 ▶use Path::Tiny qw(path);
Subroutine BEGIN: called CC=1 SCAR=0.0
11 42 ▶use Scalar::Util qw(blessed looks_like_number);
Subroutine BEGIN: called CC=1 SCAR=0.0
12 42 ▶use Text::CSV_XS;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 42 ▶use DBI;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 42 ▶use DBD::SQLite::Constants qw(SQLITE_OPEN_READONLY);
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 42 ▶use Convert::Pheno;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 42 ▶use Convert::Pheno::DB::Bundle qw(bundled_database_path);
Subroutine BEGIN: called CC=1 SCAR=0.0
18 42 ▶use Convert::Pheno::Execution::Files qw(execute_file_conversion);
Subroutine BEGIN: called CC=1 SCAR=0.0
19 42 ▶use Convert::Pheno::IO::CSVHandler qw(get_headers);
Subroutine BEGIN: called CC=1 SCAR=0.0
20 42 ▶use Convert::Pheno::OMOP::Definitions qw($omop_headers @omop_supported_tables);
Subroutine BEGIN: called CC=1 SCAR=0.0
21 42 ▶use Convert::Pheno::Operations qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
22 conversion_spec
23 is_http_conversion
24 is_public_conversion
25 public_conversions
26 registry_metadata
27 42 );
28  
29 42 ▶use Exporter 'import';
Subroutine BEGIN: called CC=1 SCAR=0.0
30 42 our @EXPORT_OK = qw(catalog execute execute_files health is_service_error lookup_omop_concept);
31  
32 42 my $JSON = JSON::XS->new->canonical->pretty;
33  
34 11 ▶sub lookup_omop_concept {
Subroutine lookup_omop_concept: called CC=12 SCAR=24.9
Pod undocumented
35 11 my ($id) = @_;
36 11 ▶ _throw(422, 'invalid_concept_id', 'Provide a non-negative OMOP concept ID')
Branch: 1 branch
BranchTrueFalseTotal
unless defined $id and not ref $id and $id =~ /\A\d{1,10}\z/ and $id <= 2147483647 6 5 11
Condition100%9/9
defined $id and not ref $id and $id =~ /\A\d{1,10}\z/ and $id <= 2147483647
!ll&&!rl&&r
515
defined $id and not ref $id and $id =~ /\A\d{1,10}\z/
!ll&&!rl&&r
236
defined $id and not ref $id
!ll&&!rl&&r
119
MC/DC100%4/4
defined $id and not ref $id and $id =~ /\A\d{1,10}\z/ and $id <= 2147483647
defined $id not ref $id $id =~ /\A\d{1,10}\z/ $id <= 2147483647
Truth table100%5/5
A and not(B) and C and D
A= defined $idB= not ref $idC= $id =~ /\A\d{1,10}\z/D= $id <= 2147483647
ABCDresult
0XXX0
10XX0
110X0
11100
11111
37 unless defined($id) && !ref($id) && $id =~ /\A\d{1,10}\z/ && $id <= 2147483647;
38 5 ▶ return {state => 'not_assigned', message => 'OMOP concept ID 0 means no matching concept was assigned.'} if $id == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $id == 0 1 4 5
39 4 my ($available, undef, $paths) = _availability(['ohdsi'], {});
40 4 ▶ return {state => 'unavailable', message => 'The OHDSI database is not installed.'} unless $available;
Branch: 1 branch
BranchTrueFalseTotal
unless $available 1 3 4
41 3 my ($dbh, $result);
42 3 my $ok = eval {
43 # Inspection is an exact, read-only lookup. It must never apply fuzzy
44 # matching, standard-concept remapping, or changes to conversion output.
45 3 $dbh = DBI->connect("dbi:SQLite:dbname=$paths->{ohdsi}", '', '', {
46 sqlite_open_flags => SQLITE_OPEN_READONLY, RaiseError => 1, PrintError => 0,
47 AutoCommit => 1, sqlite_unicode => 1,
48 });
49 3 $dbh->sqlite_busy_timeout(1000);
50 3 my %columns = map { lc($_->{name}) => 1 } @{$dbh->selectall_arrayref('PRAGMA table_info(OHDSI_table)', {Slice => {}})};
51 3 ▶ die 'Missing concept columns' if grep { !$columns{$_} } qw(concept_id label id);
Branch: 1 branch
BranchTrueFalseTotal
if grep {not $columns{$_};} "concept_id", "label", "id" 0 3 3
52 3 my @fields = grep { $columns{$_} } qw(concept_id label id vocabulary_id domain_id concept_class_id standard_concept valid_start_date valid_end_date invalid_reason);
53 3 my $rows = $dbh->selectall_arrayref('SELECT '.join(', ', @fields).' FROM OHDSI_table WHERE concept_id = ? LIMIT 2', {Slice => {}}, 0+$id);
54 3 ▶ die 'Concept identifier is not unique' if @$rows > 1;
Branch: 1 branch
BranchTrueFalseTotal
if @$rows > 1 1 2 3
55 2 ▶ $result = @$rows ? {state => 'found', concept => $rows->[0], database => 'ohdsi'}
Branch: 1 branch
BranchTrueFalseTotal
@$rows ? : 1 1 2
56 : {state => 'not_found', message => 'No matching concept in the installed OHDSI database.'};
57 2 1;
58 };
59 3 ▶ $dbh->disconnect if $dbh;
Branch: 1 branch
BranchTrueFalseTotal
if $dbh 3 0 3
60 3 ▶ return {state => 'unavailable', message => 'The installed OHDSI database could not be queried.'} unless $ok;
Branch: 1 branch
BranchTrueFalseTotal
unless $ok 1 2 3
61 2 return $result;
62 }
63  
64 0 ▶sub health {
Subroutine health: not called CC=1 SCAR=6.9
Pod undocumented
65 return {
66 0 ok => JSON::XS::true,
67 data => {
68 status => 'ok',
69 engine => 'perl',
70 version => $Convert::Pheno::VERSION,
71 },
72 };
73 }
74  
75 36 ▶sub catalog {
Subroutine catalog: called CC=24 SCAR=33.9
Pod undocumented
76 36 my $metadata = registry_metadata();
77 1584 my %concept_fields = map { $_ => 1 }
78 36 grep { /(?:\A|_)concept_id(?:_[12])?\z/ } map { @$_ } values %$omop_headers;
79 36 my @conversions;
80  
81 36 for my $name ( @{ public_conversions() } ) {
82 1584 ▶ next unless is_http_conversion($name);
Branch: 1 branch
BranchTrueFalseTotal
unless is_http_conversion($name) 0 1584 1584
83 1584 my $spec = conversion_spec($name);
84 1584 ▶ my $source = $metadata->{formats}{ $spec->{source} } || {};
Condition50%1/2
$metadata->{'formats'}{$spec->{'source'}} || {}
l!l
15840
MC/DC0%0/1
$metadata->{'formats'}{$spec->{'source'}} || {}
$metadata->{'formats'}{$spec->{'source'}}
Truth table50%1/2
A
A= $metadata->{'formats'}{$spec->{'source'}}
Aresult
11
00
85 1584 ▶ my $target = $metadata->{formats}{ $spec->{target} } || {};
Condition50%1/2
$metadata->{'formats'}{$spec->{'target'}} || {}
l!l
15840
MC/DC0%0/1
$metadata->{'formats'}{$spec->{'target'}} || {}
$metadata->{'formats'}{$spec->{'target'}}
Truth table50%1/2
A
A= $metadata->{'formats'}{$spec->{'target'}}
Aresult
11
00
86 # Source-profile maturity is not the maturity of the HTTP interface.
87 # A route may override its source designation; unmarked routes get no badge.
88 1584 ▶ my $maturity = $spec->{maturity} // $source->{maturity};
Condition66%2/3
$spec->{"maturity"} // $source->{"maturity"}
l!l&&r!l&&!r
0828756
MC/DC50%1/2
$spec->{"maturity"} // $source->{"maturity"}
$spec->{"maturity"} $source->{"maturity"}
Truth table66%2/3
A // B
A= $spec->{"maturity"}B= $source->{"maturity"}
ABresult
1X1
011
000
89 1584 my @required = _required_resources( $name, $metadata );
90 1584 my ( $available, $reason ) = _availability( \@required, $metadata );
91 1584 my @option_names = _applicable_options( $name, $spec, $metadata );
92 1584 my $input = _conversion_input_definition( $spec, $metadata );
93 my @options = map {
94 1584 ▶ +{ name => $_, %{ $metadata->{option_definitions}{$_} || {} } }
Condition50%1/2
$metadata->{'option_definitions'}{$_} || {}
l!l
83520
MC/DC0%0/1
$metadata->{'option_definitions'}{$_} || {}
$metadata->{'option_definitions'}{$_}
Truth table50%1/2
A
A= $metadata->{'option_definitions'}{$_}
Aresult
11
00
95 } @option_names;
96 # OMOP preserves extension-based separators unless explicitly overridden.
97 1584 ▶ delete $_->{default} for grep { $spec->{source} eq 'omop' && $_->{name} eq 'separator' } @options;
Condition100%3/3
$spec->{'source'} eq 'omop' && $_->{'name'} eq 'separator'
!ll&&!rl&&r
784843272
MC/DC100%2/2
$spec->{'source'} eq 'omop' && $_->{'name'} eq 'separator'
$spec->{'source'} eq 'omop' $_->{'name'} eq 'separator'
Truth table100%3/3
A && B
A= $spec->{'source'} eq 'omop'B= $_->{'name'} eq 'separator'
ABresult
0X0
100
111
98 1584 $_->{values} = [@omop_supported_tables] for grep { $_->{name} eq 'omop_tables' } @options;
99 36 push @options, {name=>'stream', %{$metadata->{option_definitions}{stream}}}
100 1584 ▶ if $spec->{streaming};
Branch: 1 branch
BranchTrueFalseTotal
if $spec->{"streaming"} 36 1548 1584
101  
102 push @conversions, {
103 id => $name,
104 omopConceptFields => [sort keys %concept_fields],
105 label => ( $source->{label} || $spec->{source} ) . ' to '
106 . ( $target->{label} || $spec->{target} ),
107 source => {
108 id => $spec->{source},
109 label => $source->{label} || $spec->{source},
110 kind => $source->{kind} || 'json',
111 inputShape => $source->{inputShape} || 'A JSON object',
112 },
113 target => {
114 id => $spec->{target},
115 label => $target->{label} || $spec->{target},
116 kind => $target->{kind} || 'json',
117 },
118 ( defined $maturity ? ( maturity => $maturity ) : () ),
119 options => \@options,
120 streaming => $spec->{streaming} ? JSON::XS::true : JSON::XS::false,
121 input => {
122 1584 ▶ transports => [ @{ $input->{transports} || ['json'] } ],
Condition50%1/2
$input->{'transports'} || ['json']
l!l
15840
MC/DC0%0/1
$input->{'transports'} || ['json']
$input->{'transports'}
Truth table50%1/2
A
A= $input->{'transports'}
Aresult
11
00
123 3024 files => [ map { _public_file_definition($_) }
124 1584 ▶ @{ $input->{files} || [] } ],
Condition50%1/2
$input->{'files'} || []
l!l
15840
MC/DC0%0/1
$input->{'files'} || []
$input->{'files'}
Truth table50%1/2
A
A= $input->{'files'}
Aresult
11
00
125 },
126 entities => {
127 1584 default => [ @{ $spec->{entities}{default} } ],
128 1584 ▶ supported => [ @{ $spec->{entities}{supported} } ],
Branch: 4 branches
BranchTrueFalseTotal
defined $maturity ? : 828 756 1584
$spec->{'streaming'} ? : 36 1548 1584
$available ? : 1164 420 1584
$reason ? : 420 1164 1584
Condition44%8/18
$source->{'label'} || $spec->{'source'}
l!l&&r!l&&!r
158400
$target->{'label'} || $spec->{'target'}
l!l&&r!l&&!r
158400
$source->{'label'} || $spec->{'source'}
l!l&&r!l&&!r
158400
$source->{'kind'} || 'json'
l!l
15840
$source->{'inputShape'} || 'A JSON object'
l!l
936648
$target->{'label'} || $spec->{'target'}
l!l&&r!l&&!r
158400
$target->{'kind'} || 'json'
l!l
15840
MC/DC0%0/2
$source->{'label'} || $spec->{'source'}
$source->{'label'} $spec->{'source'}
MC/DC0%0/2
$target->{'label'} || $spec->{'target'}
$target->{'label'} $spec->{'target'}
MC/DC0%0/2
$source->{'label'} || $spec->{'source'}
$source->{'label'} $spec->{'source'}
MC/DC0%0/1
$source->{'kind'} || 'json'
$source->{'kind'}
MC/DC100%1/1
$source->{'inputShape'} || 'A JSON object'
$source->{'inputShape'}
MC/DC0%0/2
$target->{'label'} || $spec->{'target'}
$target->{'label'} $spec->{'target'}
MC/DC0%0/1
$target->{'kind'} || 'json'
$target->{'kind'}
Truth table33%1/3
A || B
A= $source->{'label'}B= $spec->{'source'}
ABresult
1X1
011
000
Truth table33%1/3
A || B
A= $target->{'label'}B= $spec->{'target'}
ABresult
1X1
011
000
Truth table33%1/3
A || B
A= $source->{'label'}B= $spec->{'source'}
ABresult
1X1
011
000
Truth table50%1/2
A
A= $source->{'kind'}
Aresult
11
00
Truth table100%2/2
A
A= $source->{'inputShape'}
Aresult
11
00
Truth table33%1/3
A || B
A= $target->{'label'}B= $spec->{'target'}
ABresult
1X1
011
000
Truth table50%1/2
A
A= $target->{'kind'}
Aresult
11
00
129 },
130 resources => \@required,
131 available => $available ? JSON::XS::true : JSON::XS::false,
132 ( $reason ? ( unavailableReason => $reason ) : () ),
133 };
134 }
135  
136 return {
137 36 ok => JSON::XS::true,
138 data => \@conversions,
139 meta => { count => scalar @conversions },
140 };
141 }
142  
143 35 ▶sub execute {
Subroutine execute: called CC=7 SCAR=20.1
Pod undocumented
144 35 my ( $conversion, $request, $delivery ) = @_;
145  
146 35 my ( $spec, $metadata, $output, $options ) =
147 _validate_request( $conversion, $request, allow_input => 1 );
148 28 my $input = $request->{input};
149 28 ▶ _throw( 422, 'invalid_request', "Request field 'input' must be an object" )
Branch: 1 branch
BranchTrueFalseTotal
unless ref $input eq "HASH" 0 28 28
150 unless ref($input) eq 'HASH';
151 _throw( 422, 'invalid_request', "Request field 'input.data' is required" )
152 28 ▶ unless exists $input->{data};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $input->{"data"} 0 28 28
153 28 for my $key ( keys %{$input} ) {
154 28 ▶ _throw( 422, 'invalid_request', "Unsupported key '$key' in 'input'" )
Branch: 1 branch
BranchTrueFalseTotal
unless $key eq "data" 0 28 28
155 unless $key eq 'data';
156 }
157 28 _reject_path_values( $input->{data}, 'input.data' );
158 _throw( 422, 'invalid_request',
159 "Request field 'input.data' must be a JSON object or array" )
160 27 ▶ unless ref( $input->{data} ) eq 'HASH' || ref( $input->{data} ) eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $input->{"data"} eq "HASH" or ref $input->{"data"} eq "ARRAY" 0 27 27
Condition66%2/3
ref $input->{"data"} eq "HASH" or ref $input->{"data"} eq "ARRAY"
l!l&&r!l&&!r
13140
MC/DC0%0/2
ref $input->{"data"} eq "HASH" or ref $input->{"data"} eq "ARRAY"
ref $input->{"data"} eq "HASH" ref $input->{"data"} eq "ARRAY"
Truth table66%2/3
A or B
A= ref $input->{"data"} eq "HASH"B= ref $input->{"data"} eq "ARRAY"
ABresult
1X1
011
000
161  
162 return _execute_arguments(
163 $conversion, $spec, $metadata,
164 27 { method => $conversion, data => $input->{data}, %{$output}, %{$options} },
165 {}, $delivery,
166 );
167 }
168  
169 34 ▶sub execute_files {
Subroutine execute_files: called CC=38 SCAR=44.9
Pod undocumented
170 34 my ( $conversion, $request, $files, $arg ) = @_;
171 34 ▶ $request ||= {};
Condition50%1/2
$request ||= {}
l!l
340
MC/DC0%0/1
$request ||= {}
$request
Truth table50%1/2
A
A= $request
Aresult
11
00
172 34 ▶ $arg ||= {};
Condition50%1/2
$arg ||= {}
l!l
340
MC/DC0%0/1
$arg ||= {}
$arg
Truth table50%1/2
A
A= $arg
Aresult
11
00
173 34 my ( $spec, $metadata, $output, $options ) =
174 _validate_request( $conversion, $request, allow_input => 0 );
175 34 ▶ _throw( 422, 'invalid_request', 'Uploaded files must be grouped by role' )
Branch: 1 branch
BranchTrueFalseTotal
unless ref $files eq "HASH" 0 34 34
176 unless ref($files) eq 'HASH';
177  
178 34 my $definition = _conversion_input_definition( $spec, $metadata );
179 _throw( 422, 'invalid_request', "Conversion <$conversion> does not accept file uploads" )
180 34 ▶ unless grep { $_ eq 'multipart' } @{ $definition->{transports} || [] };
Branch: 1 branch
BranchTrueFalseTotal
unless grep {$_ eq "multipart";} @{$definition->{"transports"} or [];} 0 34 34
Condition50%1/2
$definition->{'transports'} || []
l!l
340
MC/DC0%0/1
$definition->{'transports'} || []
$definition->{'transports'}
Truth table50%1/2
A
A= $definition->{'transports'}
Aresult
11
00
181  
182 34 ▶ my %known = map { $_->{name} => $_ } @{ $definition->{files} || [] };
Condition50%1/2
$definition->{'files'} || []
l!l
340
MC/DC0%0/1
$definition->{'files'} || []
$definition->{'files'}
Truth table50%1/2
A
A= $definition->{'files'}
Aresult
11
00
183 34 for my $role ( keys %{$files} ) {
184 _throw( 422, 'invalid_request', "Unsupported upload role '$role' for conversion <$conversion>" )
185 47 ▶ unless $known{$role};
Branch: 1 branch
BranchTrueFalseTotal
unless $known{$role} 0 47 47
186 _throw( 422, 'invalid_request', "Upload role '$role' must contain an array" )
187 47 ▶ unless ref( $files->{$role} ) eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $files->{$role} eq "ARRAY" 0 47 47
188 }
189  
190 34 my ( %file_arguments, %display_paths );
191 34 ▶ for my $role_definition ( @{ $definition->{files} || [] } ) {
Condition50%1/2
$definition->{'files'} || []
l!l
340
MC/DC0%0/1
$definition->{'files'} || []
$definition->{'files'}
Truth table50%1/2
A
A= $definition->{'files'}
Aresult
11
00
192 76 my $role = $role_definition->{name};
193 76 ▶ my $uploads = $files->{$role} || [];
Condition100%2/2
$files->{$role} || []
l!l
4729
MC/DC100%1/1
$files->{$role} || []
$files->{$role}
Truth table100%2/2
A
A= $files->{$role}
Aresult
11
00
194 _throw( 422, 'invalid_request', "Required upload role '$role' is missing" )
195 76 ▶ if $role_definition->{required} && !@{$uploads};
Branch: 1 branch
BranchTrueFalseTotal
if $role_definition->{"required"} and not @{$uploads;} 0 76 76
Condition66%2/3
$role_definition->{"required"} and not @{$uploads;}
!ll&&!rl&&r
34420
MC/DC0%0/2
$role_definition->{"required"} and not @{$uploads;}
$role_definition->{"required"} not @{$uploads;}
Truth table66%2/3
A and not(B)
A= $role_definition->{"required"}B= not @{$uploads;}
ABresult
0X0
100
111
196 76 ▶ my $maximum = $role_definition->{maximum} || ( $role_definition->{multiple} ? 128 : 1 );
Branch: 1 branch
BranchTrueFalseTotal
$role_definition->{'multiple'} ? : 0 0 0
Condition33%1/3
$role_definition->{'maximum'} || ($role_definition->{'multiple'} ? 128 : 1)
l!l&&r!l&&!r
7600
MC/DC0%0/2
$role_definition->{'maximum'} || ($role_definition->{'multiple'} ? 128 : 1)
$role_definition->{'maximum'} ($role_definition->{'multiple'} ? 128 : 1)
Truth table33%1/3
A || B
A= $role_definition->{'maximum'}B= ($role_definition->{'multiple'} ? 128 : 1)
ABresult
1X1
011
000
197 _throw( 422, 'invalid_request', "Upload role '$role' accepts at most $maximum file(s)" )
198 76 ▶ if @{$uploads} > $maximum;
Branch: 1 branch
BranchTrueFalseTotal
if @{$uploads;} > $maximum 0 76 76
199  
200 76 for my $upload ( @{$uploads} ) {
201 _throw( 422, 'invalid_request', "Upload role '$role' contains an invalid file" )
202 unless ref($upload) eq 'HASH'
203 && defined $upload->{path}
204 && (-f $upload->{path} || ($arg->{native} && -d $upload->{path}
205 && $role eq 'source' && $spec->{source} =~ /\A(?:omop|i2b2|pcornet|sentinel|cbioportal)\z/))
206 63 ▶ && defined $upload->{filename} && !ref( $upload->{filename} );
Branch: 1 branch
BranchTrueFalseTotal
unless ref $upload eq "HASH" and defined $upload->{"path"} and -f $upload->{"path"} || $arg->{"native"} && -d $upload->{"path"} && $role eq "source" && $spec->{"source"} =~ /\A(?:omop|i2b2|pcornet|sentinel|cbioportal)\z/ and defined $upload->{"filename"} and not ref $upload->{"filename"} 0 63 63
Condition20%5/24
ref $upload eq "HASH" and defined $upload->{"path"} and -f $upload->{"path"} || $arg->{"native"} && -d $upload->{"path"} && $role eq "source" && $spec->{"source"} =~ /\A(?:omop|i2b2|pcornet|sentinel|cbioportal)\z/ and defined $upload->{"filename"} and not ref $upload->{"filename"}
!ll&&!rl&&r
0063
ref $upload eq "HASH" and defined $upload->{"path"} and -f $upload->{"path"} || $arg->{"native"} && -d $upload->{"path"} && $role eq "source" && $spec->{"source"} =~ /\A(?:omop|i2b2|pcornet|sentinel|cbioportal)\z/ and defined $upload->{"filename"}
!ll&&!rl&&r
0063
ref $upload eq "HASH" and defined $upload->{"path"} and -f $upload->{"path"} || $arg->{"native"} && -d $upload->{"path"} && $role eq "source" && $spec->{"source"} =~ /\A(?:omop|i2b2|pcornet|sentinel|cbioportal)\z/
!ll&&!rl&&r
0063
ref $upload eq "HASH" and defined $upload->{"path"}
!ll&&!rl&&r
0063
-f $upload->{"path"} or $arg->{"native"} and -d $upload->{"path"} and $role eq "source" and $spec->{"source"} =~ /\A(?:omop|i2b2|pcornet|sentinel|cbioportal)\z/
l!l&&r!l&&!r
6300
$arg->{"native"} and -d $upload->{"path"} and $role eq "source" and $spec->{"source"} =~ /\A(?:omop|i2b2|pcornet|sentinel|cbioportal)\z/
!ll&&!rl&&r
000
$arg->{"native"} and -d $upload->{"path"} and $role eq "source"
!ll&&!rl&&r
000
$arg->{"native"} and -d $upload->{"path"}
!ll&&!rl&&r
000
MC/DC0%0/9
ref $upload eq "HASH" and defined $upload->{"path"} and -f $upload->{"path"} || $arg->{"native"} && -d $upload->{"path"} && $role eq "source" && $spec->{"source"} =~ /\A(?:omop|i2b2|pcornet|sentinel|cbioportal)\z/ and defined $upload->{"filename"} and not ref $upload->{"filename"}
ref $upload eq "HASH" defined $upload->{"path"} -f $upload->{"path"} $arg->{"native"} -d $upload->{"path"} $role eq "source" $spec->{"source"} =~ /\A(?:omop|i2b2|pcornet|sentinel|cbioportal)\z/ defined $upload->{"filename"} not ref $upload->{"filename"}
Truth table8%1/12
A and B and C or D and E and F and G and H and not(I)
A= ref $upload eq "HASH"B= defined $upload->{"path"}C= -f $upload->{"path"}D= $arg->{"native"}E= -d $upload->{"path"}F= $role eq "source"G= $spec->{"source"} =~ /\A(?:omop|i2b2|pcornet|sentinel|cbioportal)\z/H= defined $upload->{"filename"}I= not ref $upload->{"filename"}
ABCDEFGHIresult
0XXXXXXXX0
10XXXXXXX0
1100XXXXX0
11010XXXX0
110110XXX0
1101110XX0
111XXXX0X0
11011110X0
111XXXX100
1101111100
111XXXX111
1101111111
207 _throw( 422, 'invalid_request', "File <$upload->{filename}> is not accepted for upload role '$role'" )
208 63 ▶ unless -d $upload->{path} || _accepted_filename( $upload->{filename}, $role_definition->{accept} );
Branch: 1 branch
BranchTrueFalseTotal
unless -d $upload->{"path"} or _accepted_filename($upload->{"filename"}, $role_definition->{"accept"}) 0 63 63
Condition33%1/3
-d $upload->{"path"} or _accepted_filename($upload->{"filename"}, $role_definition->{"accept"})
l!l&&r!l&&!r
0630
MC/DC0%0/2
-d $upload->{"path"} or _accepted_filename($upload->{"filename"}, $role_definition->{"accept"})
-d $upload->{"path"} _accepted_filename($upload->{"filename"}, $role_definition->{"accept"})
Truth table33%1/3
A or B
A= -d $upload->{"path"}B= _accepted_filename($upload->{"filename"}, $role_definition->{"accept"})
ABresult
1X1
011
000
209 63 $display_paths{ $upload->{path} } = $upload->{filename};
210 }
211  
212 76 ▶ next unless @{$uploads};
Branch: 1 branch
BranchTrueFalseTotal
unless @{$uploads;} 29 47 76
213 47 my $argument = $role_definition->{argument};
214 47 ▶ if ( $role_definition->{multiple} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($role_definition->{'multiple'}) { } 9 38 47
215 9 $file_arguments{$argument} = [ map { $_->{path} } @{$uploads} ];
216 }
217 else {
218 38 $file_arguments{$argument} = $uploads->[0]{path};
219 }
220 }
221  
222 34 my %normalized_options = %{$options};
223 $normalized_options{sep} = delete $normalized_options{separator}
224 34 ▶ if exists $normalized_options{separator};
Branch: 1 branch
BranchTrueFalseTotal
if exists $normalized_options{"separator"} 5 29 34
225 34 my $audit = delete $normalized_options{term_audit};
226 34 ▶ if ( defined $audit && $audit ne 'none' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $audit and $audit ne "none") 4 30 34
Condition66%2/3
defined $audit and $audit ne "none"
!ll&&!rl&&r
3004
MC/DC50%1/2
defined $audit and $audit ne "none"
defined $audit $audit ne "none"
Truth table66%2/3
A and B
A= defined $auditB= $audit ne "none"
ABresult
0X0
100
111
227 4 my $workspace = $arg->{workspace};
228 4 ▶ _throw( 500, 'infrastructure_error', 'The upload workspace is unavailable' )
Branch: 1 branch
BranchTrueFalseTotal
unless defined $workspace and -d $workspace 0 4 4
Condition33%1/3
defined $workspace and -d $workspace
!ll&&!rl&&r
004
MC/DC0%0/2
defined $workspace and -d $workspace
defined $workspace -d $workspace
Truth table33%1/3
A and B
A= defined $workspaceB= -d $workspace
ABresult
0X0
100
111
229 unless defined $workspace && -d $workspace;
230 4 $normalized_options{term_audit_file} = "$workspace/term-audit.$audit";
231 }
232 $normalized_options{schema_file} =
233 catfile( $Convert::Pheno::share_dir, 'schema', 'mapping-v2.json' )
234 34 ▶ if $file_arguments{mapping_file};
Branch: 1 branch
BranchTrueFalseTotal
if $file_arguments{"mapping_file"} 9 25 34
235  
236 return _execute_arguments(
237 $conversion, $spec, $metadata,
238 {
239 method => $conversion,
240 in_textfile => 1,
241 %file_arguments,
242 34 %{$output},
243 %normalized_options,
244 },
245 \%display_paths, $arg,
246 );
247 }
248  
249 69 ▶sub _validate_request {
Subroutine _validate_request: called CC=30 SCAR=35.9
250 69 my ( $conversion, $request, %arg ) = @_;
251 69 ▶ _throw( 404, 'unknown_conversion', "Unknown conversion <$conversion>" )
Branch: 1 branch
BranchTrueFalseTotal
unless is_public_conversion($conversion) and is_http_conversion($conversion) 0 69 69
Condition33%1/3
is_public_conversion($conversion) and is_http_conversion($conversion)
!ll&&!rl&&r
0069
MC/DC0%0/2
is_public_conversion($conversion) and is_http_conversion($conversion)
is_public_conversion($conversion) is_http_conversion($conversion)
Truth table33%1/3
A and B
A= is_public_conversion($conversion)B= is_http_conversion($conversion)
ABresult
0X0
100
111
252 unless is_public_conversion($conversion) && is_http_conversion($conversion);
253 69 ▶ _throw( 422, 'invalid_request', 'Request body must be a JSON object' )
Branch: 1 branch
BranchTrueFalseTotal
unless ref $request eq "HASH" 0 69 69
254 unless ref($request) eq 'HASH';
255  
256 69 my %root_allowed = map { $_ => 1 } qw(output options);
257 69 ▶ $root_allowed{input} = 1 if $arg{allow_input};
Branch: 1 branch
BranchTrueFalseTotal
if $arg{"allow_input"} 35 34 69
258 69 for my $key ( keys %{$request} ) {
259 _throw( 422, 'invalid_request', "Unsupported request field '$key'" )
260 158 ▶ unless $root_allowed{$key};
Branch: 1 branch
BranchTrueFalseTotal
unless $root_allowed{$key} 0 158 158
261 }
262  
263 69 ▶ my $output = exists $request->{output} ? $request->{output} : {};
Branch: 1 branch
BranchTrueFalseTotal
exists $request->{'output'} ? : 56 13 69
264 69 ▶ my $options = exists $request->{options} ? $request->{options} : {};
Branch: 1 branch
BranchTrueFalseTotal
exists $request->{'options'} ? : 67 2 69
265 69 ▶ _throw( 422, 'invalid_request', "Request field 'output' must be an object" )
Branch: 1 branch
BranchTrueFalseTotal
unless ref $output eq "HASH" 0 69 69
266 unless ref($output) eq 'HASH';
267 69 ▶ _throw( 422, 'invalid_request', "Request field 'options' must be an object" )
Branch: 1 branch
BranchTrueFalseTotal
unless ref $options eq "HASH" 0 69 69
268 unless ref($options) eq 'HASH';
269  
270 69 my $spec = conversion_spec($conversion);
271 69 my $metadata = registry_metadata();
272 my %allowed_output = $spec->{target} eq 'beacon'
273 69 ▶ ? map { $_ => 1 } qw(entities derived_entity_overrides)
Branch: 1 branch
BranchTrueFalseTotal
$spec->{'target'} eq 'beacon' ? : 48 21 69
274 : ();
275 69 for my $key ( keys %{$output} ) {
276 _throw( 422, 'invalid_request',
277 "Option '$key' is not applicable to conversion <$conversion>" )
278 41 ▶ unless $allowed_output{$key};
Branch: 1 branch
BranchTrueFalseTotal
unless $allowed_output{$key} 0 41 41
279 }
280 69 ▶ if ( $spec->{target} eq 'beacon' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($spec->{"target"} eq "beacon") 48 21 69
281 48 ▶ if ( exists $output->{entities} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $output->{"entities"}) 41 7 48
282 _throw( 422, 'invalid_request', "Output field 'entities' must be an array" )
283 41 ▶ unless ref( $output->{entities} ) eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $output->{"entities"} eq "ARRAY" 0 41 41
284 41 my %supported = map { $_ => 1 } @{ $spec->{entities}{supported} };
285 41 for my $entity ( @{ $output->{entities} } ) {
286 _throw( 422, 'invalid_request', "Unsupported BFF entity '$entity' for conversion <$conversion>" )
287 63 ▶ unless defined $entity && !ref($entity) && $supported{$entity};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $entity and not ref $entity and $supported{$entity} 0 63 63
Condition33%2/6
defined $entity and not ref $entity and $supported{$entity}
!ll&&!rl&&r
0063
defined $entity and not ref $entity
!ll&&!rl&&r
0063
MC/DC0%0/3
defined $entity and not ref $entity and $supported{$entity}
defined $entity not ref $entity $supported{$entity}
Truth table25%1/4
A and not(B) and C
A= defined $entityB= not ref $entityC= $supported{$entity}
ABCresult
0XX0
10X0
1100
1111
288 }
289 _throw( 422, 'invalid_request', "At least one BFF entity must be requested" )
290 41 ▶ unless @{ $output->{entities} };
Branch: 1 branch
BranchTrueFalseTotal
unless @{$output->{"entities"};} 0 41 41
291 }
292 48 ▶ if ( exists $output->{derived_entity_overrides} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $output->{"derived_entity_overrides"}) 0 48 48
293 _throw( 422, 'invalid_request',
294 "Output field 'derived_entity_overrides' must be an object" )
295 0 ▶ unless ref( $output->{derived_entity_overrides} ) eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $output->{"derived_entity_overrides"} eq "HASH" 0 0 0
296 }
297 }
298  
299 69 my %allowed_options = map { $_ => 1 }
300 _applicable_options( $conversion, $spec, $metadata );
301 69 ▶ $allowed_options{stream}=1 if $spec->{streaming};
Branch: 1 branch
BranchTrueFalseTotal
if $spec->{"streaming"} 12 57 69
302 69 $allowed_options{test} = 1; # deterministic fixture mode; not advertised by the UI catalog
303 69 for my $key ( keys %{$options} ) {
304 _throw( 422, 'invalid_request',
305 "Option '$key' is not applicable to conversion <$conversion>" )
306 81 ▶ unless $allowed_options{$key};
Branch: 1 branch
BranchTrueFalseTotal
unless $allowed_options{$key} 1 80 81
307 80 _validate_option( $key, $options->{$key}, $metadata );
308 }
309  
310 64 my @required = _required_resources( $conversion, $metadata );
311 64 ▶ push @required, 'ohdsi' if $spec->{source} eq 'omop' && $options->{ohdsi_db};
Branch: 1 branch
BranchTrueFalseTotal
if $spec->{"source"} eq "omop" and $options->{"ohdsi_db"} 2 62 64
Condition100%3/3
$spec->{"source"} eq "omop" and $options->{"ohdsi_db"}
!ll&&!rl&&r
5392
MC/DC100%2/2
$spec->{"source"} eq "omop" and $options->{"ohdsi_db"}
$spec->{"source"} eq "omop" $options->{"ohdsi_db"}
Truth table100%3/3
A and B
A= $spec->{"source"} eq "omop"B= $options->{"ohdsi_db"}
ABresult
0X0
100
111
312 64 my ( $available, $reason, $resource_paths ) =
313 _availability( \@required, $metadata );
314 64 ▶ _throw( 503, 'resource_unavailable', $reason ) unless $available;
Branch: 1 branch
BranchTrueFalseTotal
unless $available 2 62 64
315  
316 62 return ( $spec, $metadata, $output, $options );
317 }
318  
319 60 ▶sub _execute_arguments {
Subroutine _execute_arguments: called CC=36 SCAR=39.8
320 60 my ( $conversion, $spec, $metadata, $arguments, $display_paths, $delivery ) = @_;
321 60 my @required = _required_resources( $conversion, $metadata );
322 60 ▶ push @required, 'ohdsi' if $spec->{source} eq 'omop' && $arguments->{ohdsi_db};
Branch: 1 branch
BranchTrueFalseTotal
if $spec->{"source"} eq "omop" and $arguments->{"ohdsi_db"} 0 60 60
Condition66%2/3
$spec->{"source"} eq "omop" and $arguments->{"ohdsi_db"}
!ll&&!rl&&r
5190
MC/DC0%0/2
$spec->{"source"} eq "omop" and $arguments->{"ohdsi_db"}
$spec->{"source"} eq "omop" $arguments->{"ohdsi_db"}
Truth table66%2/3
A and B
A= $spec->{"source"} eq "omop"B= $arguments->{"ohdsi_db"}
ABresult
0X0
100
111
323 60 my ( $available, $reason, $resource_paths ) =
324 _availability( \@required, $metadata );
325 60 ▶ _throw( 503, 'resource_unavailable', $reason ) unless $available;
Branch: 1 branch
BranchTrueFalseTotal
unless $available 0 60 60
326  
327 60 ▶ if ( $resource_paths->{ohdsi} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($resource_paths->{"ohdsi"}) 5 55 60
328 5 $arguments->{ohdsi_db} = 1;
329 5 $arguments->{path_to_ohdsi_db} = dirname( $resource_paths->{ohdsi} );
330 }
331 60 ▶ if ( $spec->{source} eq 'omop' && !$delivery->{native} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($spec->{"source"} eq "omop" and not $delivery->{"native"}) 7 53 60
Condition100%3/3
$spec->{"source"} eq "omop" and not $delivery->{"native"}
!ll&&!rl&&r
5127
MC/DC100%2/2
$spec->{"source"} eq "omop" and not $delivery->{"native"}
$spec->{"source"} eq "omop" not $delivery->{"native"}
Truth table100%3/3
A and not(B)
A= $spec->{"source"} eq "omop"B= not $delivery->{"native"}
ABresult
0X0
100
111
332 $arguments->{max_archive_uncompressed_bytes} =
333 7 ▶ $ENV{CONVERT_PHENO_HTTP_MAX_ARCHIVE_BYTES} || 1024 * 1024 * 1024;
Condition50%1/2
$ENV{'CONVERT_PHENO_HTTP_MAX_ARCHIVE_BYTES'} || 1073741824
l!l
07
MC/DC0%0/1
$ENV{'CONVERT_PHENO_HTTP_MAX_ARCHIVE_BYTES'} || 1073741824
$ENV{'CONVERT_PHENO_HTTP_MAX_ARCHIVE_BYTES'}
Truth table50%1/2
A
A= $ENV{'CONVERT_PHENO_HTTP_MAX_ARCHIVE_BYTES'}
Aresult
11
00
334 }
335  
336 60 my @warnings;
337 60 my ( $result, $artifacts, $audit_review );
338 60 my $ok = eval {
339 31 ▶ local $SIG{__WARN__} = sub {
Subroutine __ANON__: called CC=2 SCAR=7.1
340 31 my ($warning) = @_;
341 31 chomp $warning;
342 31 ▶ push @warnings, $warning if length $warning;
Branch: 1 branch
BranchTrueFalseTotal
if length $warning 31 0 31
343 60 };
344 60 ▶ if ($delivery->{directory}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($delivery->{"directory"}) 20 40 60
345 20 $arguments->{out_dir} = $delivery->{directory};
346 my $filename = $spec->{target} eq 'beacon' ? 'individuals.json'
347 : $spec->{target} eq 'pxf' ? 'pxf.json'
348 : $spec->{target} eq 'csv' ? 'result.csv'
349 20 ▶ : $spec->{target} eq 'jsonld' ? 'result.jsonld' : 'result.json';
Branch: 4 branches
BranchTrueFalseTotal
$spec->{'target'} eq 'beacon' ? : 19 1 20
$spec->{'target'} eq 'pxf' ? : 1 0 1
$spec->{'target'} eq 'csv' ? : 0 0 0
$spec->{'target'} eq 'jsonld' ? : 0 0 0
350 20 $arguments->{out_file} = catfile($delivery->{directory}, $filename);
351 20 ▶ $arguments->{entities} ||= $spec->{entities}{default} if $spec->{target} eq 'beacon';
Branch: 1 branch
BranchTrueFalseTotal
if $spec->{"target"} eq "beacon" 19 1 20
Condition33%1/3
$arguments->{"entities"} ||= $spec->{"entities"}{"default"}
l!l&&r!l&&!r
1900
MC/DC0%0/2
$arguments->{"entities"} ||= $spec->{"entities"}{"default"}
$arguments->{"entities"} $spec->{"entities"}{"default"}
Truth table33%1/3
A ||= B
A= $arguments->{"entities"}B= $spec->{"entities"}{"default"}
ABresult
1X1
011
000
352 20 ▶ if (my $audit = delete $arguments->{term_audit}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $audit = delete $arguments->{"term_audit"}) 0 20 20
353 0 ▶ $arguments->{term_audit_file} = catfile($delivery->{directory}, "term-audit.$audit") unless $audit eq 'none';
Branch: 1 branch
BranchTrueFalseTotal
unless $audit eq "none" 0 0 0
354 }
355 }
356 60 my $convert = Convert::Pheno->new($arguments);
357 60 ▶ if ($delivery->{directory}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($delivery->{'directory'}) { } 20 40 60
elsif ($spec->{'target'} eq 'beacon') { } 22 18 40
358 20 execute_file_conversion($convert, $arguments);
359 20 $artifacts = [];
360 20 for my $file (sort { "$a" cmp "$b" } path($delivery->{directory})->children) {
361 37 ▶ next unless $file->is_file;
Branch: 1 branch
BranchTrueFalseTotal
unless $file->is_file 0 37 37
362 37 my $name = $file->basename;
363 37 ▶ next unless $name =~ /\.(json|jsonld|csv|tsv|xlsx)\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless $name =~ /\.(json|jsonld|csv|tsv|xlsx)\z/ 0 37 37
364 37 my $kind = $1;
365 37 ▶ die "Conversion produced an empty structured output file <$name>\n"
Branch: 1 branch
BranchTrueFalseTotal
if $kind eq "json" || $kind eq "jsonld" and not -s $file 0 37 37
Condition66%4/6
$kind eq "json" || $kind eq "jsonld" and not -s $file
!ll&&!rl&&r
2350
$kind eq "json" or $kind eq "jsonld"
l!l&&r!l&&!r
3502
MC/DC0%0/3
$kind eq "json" || $kind eq "jsonld" and not -s $file
$kind eq "json" $kind eq "jsonld" not -s $file
Truth table40%2/5
A or B and not(C)
A= $kind eq "json"B= $kind eq "jsonld"C= not -s $file
ABCresult
00X0
1X00
0100
1X11
0111
366 if ($kind eq 'json' || $kind eq 'jsonld') && !-s $file;
367 37 (my $id = $name) =~ s/\.[^.]+\z//;
368 37 ▶ push @$artifacts, {
Branch: 4 branches
BranchTrueFalseTotal
$kind eq 'json' ? : 35 2 37
$kind eq 'csv' ? : 0 2 2
$kind eq 'tsv' ? : 1 1 2
$kind eq 'jsonld' ? : 0 1 1
369 id => $id, filename => $name, kind => $kind, bytes => -s $file,
370 mediaType => $kind eq 'json' ? 'application/json' : $kind eq 'csv' ? 'text/csv'
371 : $kind eq 'tsv' ? 'text/tab-separated-values' : $kind eq 'jsonld' ? 'application/ld+json'
372 : 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
373 };
374 }
375 }
376 elsif ( $spec->{target} eq 'beacon' ) {
377 22 ▶ my $entities = $arguments->{entities} || $spec->{entities}{default};
Condition33%1/3
$arguments->{'entities'} || $spec->{'entities'}{'default'}
l!l&&r!l&&!r
2200
MC/DC0%0/2
$arguments->{'entities'} || $spec->{'entities'}{'default'}
$arguments->{'entities'} $spec->{'entities'}{'default'}
Truth table33%1/3
A || B
A= $arguments->{'entities'}B= $spec->{'entities'}{'default'}
ABresult
1X1
011
000
378 22 $arguments->{entities} = $entities;
379 22 $convert = Convert::Pheno->new($arguments);
380 22 my $bundle = $convert->_run_bundle_view;
381 $artifacts = [ map {
382 29 _json_artifact( $_, "$_.json", 'application/json', 'json',
383 $bundle->entities($_) )
384 22 } @{$entities} ];
385 }
386 else {
387 18 $result = $convert->$conversion();
388 18 $artifacts = _artifacts_for_result( $conversion, $spec, $result );
389 }
390 60 $audit_review = $convert->term_audit_review;
391 60 1;
392 };
393 60 ▶ unless ($ok) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ok) 0 60 60
394 0 ▶ my $message = $@ || 'Conversion failed';
Condition0%0/2
$@ || 'Conversion failed'
l!l
00
MC/DC0%0/1
$@ || 'Conversion failed'
$@
Truth table0%0/2
A
A= $@
Aresult
11
00
395 0 chomp $message;
396 0 $message = _display_message( $message, $display_paths );
397 0 _throw( 422, 'conversion_error', $message );
398 }
399  
400 60 ▶ if ( !$delivery->{directory} && $arguments->{term_audit_file} && -f $arguments->{term_audit_file} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $delivery->{"directory"} and $arguments->{"term_audit_file"} and -f $arguments->{"term_audit_file"}) 2 58 60
Condition83%5/6
not $delivery->{"directory"} and $arguments->{"term_audit_file"} and -f $arguments->{"term_audit_file"}
!ll&&!rl&&r
5802
not $delivery->{"directory"} and $arguments->{"term_audit_file"}
!ll&&!rl&&r
20382
MC/DC66%2/3
not $delivery->{"directory"} and $arguments->{"term_audit_file"} and -f $arguments->{"term_audit_file"}
not $delivery->{"directory"} $arguments->{"term_audit_file"} -f $arguments->{"term_audit_file"}
Truth table75%3/4
not(A) and B and C
A= not $delivery->{"directory"}B= $arguments->{"term_audit_file"}C= -f $arguments->{"term_audit_file"}
ABCresult
0XX0
10X0
1100
1111
401 2 push @{$artifacts}, _audit_artifact( $arguments->{term_audit_file} );
402 }
403 60 @warnings = map { _display_message( $_, $display_paths ) } @warnings;
404  
405 60 my %meta = ( conversion => $conversion );
406 60 ▶ $meta{terminologyAudit} = _public_audit_review($audit_review)
Branch: 1 branch
BranchTrueFalseTotal
if $audit_review 4 56 60
407 if $audit_review;
408  
409 return {
410 60 ok => JSON::XS::true,
411 artifacts => $artifacts,
412 warnings => \@warnings,
413 meta => \%meta,
414 };
415 }
416  
417 4 ▶sub _public_audit_review {
Subroutine _public_audit_review: called CC=5 SCAR=17.5
418 4 my ($review) = @_;
419 4 ▶ my $settings = $review->{settings} || {};
Condition50%1/2
$review->{'settings'} || {}
l!l
40
MC/DC0%0/1
$review->{'settings'} || {}
$review->{'settings'}
Truth table50%1/2
A
A= $review->{'settings'}
Aresult
11
00
420 return {
421 totalDecisions => $review->{total_decisions},
422 4 ▶ counts => { %{ $review->{counts} || {} } },
Condition50%1/2
$review->{'counts'} || {}
l!l
40
MC/DC0%0/1
$review->{'counts'} || {}
$review->{'counts'}
Truth table50%1/2
A
A= $review->{'counts'}
Aresult
11
00
423 4 ▶ rows => [ @{ $review->{rows} || [] } ],
Branch: 1 branch
BranchTrueFalseTotal
$review->{'truncated'} ? : 4 0 4
Condition50%1/2
$review->{'rows'} || []
l!l
40
MC/DC0%0/1
$review->{'rows'} || []
$review->{'rows'}
Truth table50%1/2
A
A= $review->{'rows'}
Aresult
11
00
424 previewRows => $review->{preview_rows},
425 previewLimitPerAction => $review->{preview_limit_per_action},
426 truncated => $review->{truncated} ? JSON::XS::true : JSON::XS::false,
427 reportArtifactId => 'term-audit',
428 settings => {
429 configuredSearchMode => $settings->{search},
430 textSimilarityMethod => $settings->{text_similarity_method},
431 minTextSimilarityScore => $settings->{min_text_similarity_score},
432 levenshteinWeight => $settings->{levenshtein_weight},
433 },
434 4 };
435 }
436  
437 3024 ▶sub _public_file_definition {
Subroutine _public_file_definition: called CC=1 SCAR=0.0
438 3024 my ($definition) = @_;
439 20988 return { map { $_ => $definition->{$_} }
440 3024 grep { exists $definition->{$_} }
441 qw(name label description required multiple maximum accept) };
442 }
443  
444 1618 ▶sub _conversion_input_definition {
Subroutine _conversion_input_definition: called CC=16 SCAR=28.4
445 1618 my ( $spec, $metadata ) = @_;
446 1618 ▶ my $base = $metadata->{input_definitions}{ $spec->{source} } || {};
Condition50%1/2
$metadata->{'input_definitions'}{$spec->{'source'}} || {}
l!l
16180
MC/DC0%0/1
$metadata->{'input_definitions'}{$spec->{'source'}} || {}
$metadata->{'input_definitions'}{$spec->{'source'}}
Truth table50%1/2
A
A= $metadata->{'input_definitions'}{$spec->{'source'}}
Aresult
11
00
447 1618 ▶ my @transports = @{ $base->{transports} || ['json'] };
Condition50%1/2
$base->{'transports'} || ['json']
l!l
16180
MC/DC0%0/1
$base->{'transports'} || ['json']
$base->{'transports'}
Truth table50%1/2
A
A= $base->{'transports'}
Aresult
11
00
448 1618 ▶ my @files = map { +{%{$_}} } @{ $base->{files} || [] };
Condition50%1/2
$base->{'files'} || []
l!l
16180
MC/DC0%0/1
$base->{'files'} || []
$base->{'files'}
Truth table50%1/2
A
A= $base->{'files'}
Aresult
11
00
449 1618 ▶ if (!@files) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@files) 558 1060 1618
450 558 ▶ push @transports, 'multipart' unless grep { $_ eq 'multipart' } @transports;
Branch: 1 branch
BranchTrueFalseTotal
unless grep {$_ eq "multipart";} @transports 558 0 558
451 558 ▶ push @files, $base->{fileSource} ? {%{$base->{fileSource}}}
Branch: 1 branch
BranchTrueFalseTotal
$base->{'fileSource'} ? : 377 181 558
452 : { name=>'source',label=>'Source document',required=>JSON::XS::true,
453 multiple=>JSON::XS::false,maximum=>1,argument=>'in_file',accept=>[qw(.json .json.gz .yaml .yml)] };
454 }
455  
456 1618 ▶ my $omop_mapping = $spec->{source} eq 'beacon' && $spec->{target} eq 'omop';
Condition100%3/3
$spec->{'source'} eq 'beacon' && $spec->{'target'} eq 'omop'
!ll&&!rl&&r
143714437
MC/DC100%2/2
$spec->{'source'} eq 'beacon' && $spec->{'target'} eq 'omop'
$spec->{'source'} eq 'beacon' $spec->{'target'} eq 'omop'
Truth table100%3/3
A && B
A= $spec->{'source'} eq 'beacon'B= $spec->{'target'} eq 'omop'
ABresult
0X0
100
111
457 1618 ▶ if ( $omop_mapping || ($spec->{target} eq 'beacon' && $base->{metadataMapping}) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($omop_mapping or $spec->{"target"} eq "beacon" and $base->{"metadataMapping"}) 313 1305 1618
Condition100%6/6
$omop_mapping or $spec->{"target"} eq "beacon" and $base->{"metadataMapping"}
l!l&&r!l&&!r
372761305
$spec->{"target"} eq "beacon" and $base->{"metadataMapping"}
!ll&&!rl&&r
1081224276
MC/DC100%3/3
$omop_mapping or $spec->{"target"} eq "beacon" and $base->{"metadataMapping"}
$omop_mapping $spec->{"target"} eq "beacon" $base->{"metadataMapping"}
Truth table100%4/4
A or B and C
A= $omop_mappingB= $spec->{"target"} eq "beacon"C= $base->{"metadataMapping"}
ABCresult
1XX1
0111
00X0
0100
458 push @transports, 'multipart'
459 313 ▶ unless grep { $_ eq 'multipart' } @transports;
Branch: 1 branch
BranchTrueFalseTotal
unless grep {$_ eq "multipart";} @transports 0 313 313
460 0 push @files, { %{ $base->{fileSource} } }
461 313 ▶ if !@files && ref( $base->{fileSource} ) eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if not @files and ref $base->{"fileSource"} eq "HASH" 0 313 313
Condition33%1/3
not @files and ref $base->{"fileSource"} eq "HASH"
!ll&&!rl&&r
31300
MC/DC0%0/2
not @files and ref $base->{"fileSource"} eq "HASH"
not @files ref $base->{"fileSource"} eq "HASH"
Truth table33%1/3
not(A) and B
A= not @filesB= ref $base->{"fileSource"} eq "HASH"
ABresult
0X0
100
111
462 313 ▶ push @files, {
Branch: 2 branches
BranchTrueFalseTotal
$omop_mapping ? : 37 276 313
$omop_mapping ? : 37 276 313
463 name => 'mapping',
464 label => $omop_mapping ? 'Terminology mapping' : 'Dataset and cohort metadata',
465 description => $omop_mapping
466 ? 'Optional Mapping V2 file with reviewed BFF-to-OMOP terminology queries.'
467 : 'Optional compact Mapping V2 YAML or JSON metadata file.',
468 required => JSON::XS::false,
469 multiple => JSON::XS::false,
470 maximum => 1,
471 accept => [qw(.yaml .yml .json)],
472 argument => 'mapping_file',
473 };
474 }
475  
476 return {
477 1618 transports => \@transports,
478 files => \@files,
479 };
480 }
481  
482 63 ▶sub _accepted_filename {
Subroutine _accepted_filename: called CC=4 SCAR=14.1
483 63 my ( $filename, $accepted ) = @_;
484 63 ▶ return 1 unless ref($accepted) eq 'ARRAY' && @{$accepted};
Branch: 1 branch
BranchTrueFalseTotal
unless ref $accepted eq "ARRAY" and @{$accepted;} 0 63 63
Condition33%1/3
ref $accepted eq "ARRAY" and @{$accepted;}
!ll&&!rl&&r
0063
MC/DC0%0/2
ref $accepted eq "ARRAY" and @{$accepted;}
ref $accepted eq "ARRAY" @{$accepted;}
Truth table33%1/3
A and B
A= ref $accepted eq "ARRAY"B= @{$accepted;}
ABresult
0X0
100
111
485 63 my $lower = lc $filename;
486 return scalar grep {
487 192 my $extension = lc $_;
488 192 ▶ length($lower) >= length($extension)
Condition100%3/3
length $lower >= length $extension && substr($lower, -length($extension)) eq $extension
!ll&&!rl&&r
1011963
MC/DC100%2/2
length $lower >= length $extension && substr($lower, -length($extension)) eq $extension
length $lower >= length $extension substr($lower, -length($extension)) eq $extension
Truth table100%3/3
A && B
A= length $lower >= length $extensionB= substr($lower, -length($extension)) eq $extension
ABresult
0X0
100
111
489 && substr( $lower, -length($extension) ) eq $extension
490 63 } @{$accepted};
491 }
492  
493 31 ▶sub _display_message {
Subroutine _display_message: called CC=3 SCAR=13.3
494 31 my ( $message, $display_paths ) = @_;
495 0 ▶ for my $path ( sort { length($b) <=> length($a) } keys %{ $display_paths || {} } ) {
Condition50%1/2
$display_paths || {}
l!l
310
MC/DC0%0/1
$display_paths || {}
$display_paths
Truth table50%1/2
A
A= $display_paths
Aresult
11
00
496 0 my $filename = $display_paths->{$path};
497 0 $message =~ s/\Q$path\E/$filename/g;
498 }
499 31 return $message;
500 }
501  
502 18 ▶sub _artifacts_for_result {
Subroutine _artifacts_for_result: called CC=10 SCAR=23.1
503 18 my ( $conversion, $spec, $result ) = @_;
504 18 my $target = $spec->{target};
505  
506 18 ▶ if ( $target eq 'omop' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($target eq "omop") 5 13 18
507 5 ▶ _throw( 422, 'conversion_error', 'OMOP conversion did not return table data' )
Branch: 1 branch
BranchTrueFalseTotal
unless ref $result eq "HASH" 0 5 5
508 unless ref($result) eq 'HASH';
509 return [ map {
510 22 my $table = $_;
511 _csv_artifact(
512 lc($table), "$table.csv", $omop_headers->{$table},
513 22 $result->{$table}, ';'
514 )
515 5 } sort keys %{$result} ];
516 }
517  
518 13 ▶ if ( $target eq 'csv' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($target eq "csv") 3 10 13
519 3 ▶ my $base = $spec->{source} eq 'beacon' ? 'individuals' : 'pxf';
Branch: 1 branch
BranchTrueFalseTotal
$spec->{'source'} eq 'beacon' ? : 2 1 3
520 3 return [ _csv_artifact( $base, "$base.csv", get_headers($result), $result, ';' ) ];
521 }
522  
523 my ( $id, $filename, $media_type, $kind ) =
524 $target eq 'pxf' ? ( 'pxf', 'pxf.json', 'application/json', 'json' )
525 : $target eq 'jsonf' ? ( $spec->{source},
526 ( $spec->{source} eq 'beacon' ? 'individuals' : 'pxf' ) . '.fold.json',
527 'application/json', 'json' )
528 : $target eq 'jsonld' ? ( $spec->{source},
529 10 ▶ ( $spec->{source} eq 'beacon' ? 'individuals' : 'pxf' ) . '.jsonld',
Branch: 5 branches
BranchTrueFalseTotal
$target eq 'pxf' ? : 6 4 10
$target eq 'jsonf' ? : 2 2 4
$spec->{'source'} eq 'beacon' ? : 1 1 2
$target eq 'jsonld' ? : 2 0 2
$spec->{'source'} eq 'beacon' ? : 1 1 2
530 'application/ld+json', 'jsonld' )
531 : ( 'result', 'result.json', 'application/json', 'json' );
532  
533 10 return [ _json_artifact( $id, $filename, $media_type, $kind, $result ) ];
534 }
535  
536 39 ▶sub _json_artifact {
Subroutine _json_artifact: called CC=1 SCAR=0.0
537 39 my ( $id, $filename, $media_type, $kind, $data ) = @_;
538 return {
539 39 id => $id,
540 filename => $filename,
541 mediaType => $media_type,
542 kind => $kind,
543 encoding => 'utf-8',
544 content => $JSON->encode($data),
545 };
546 }
547  
548 25 ▶sub _csv_artifact {
Subroutine _csv_artifact: called CC=7 SCAR=19.8
549 25 my ( $id, $filename, $headers, $rows, $separator ) = @_;
550 25 ▶ $rows = [$rows] if ref($rows) eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if ref $rows eq "HASH" 0 25 25
551 25 ▶ $rows ||= [];
Condition50%1/2
$rows ||= []
l!l
250
MC/DC0%0/1
$rows ||= []
$rows
Truth table50%1/2
A
A= $rows
Aresult
11
00
552 25 my $content = q{};
553 25 ▶ open my $fh, '>:encoding(UTF-8)', \$content
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, ">:encoding(UTF-8)", \$content or die "Cannot create in-memory CSV artifact: $!" 25 0 25
554 or die "Cannot create in-memory CSV artifact: $!";
555 25 ▶ my $csv = Text::CSV_XS->new(
Branch: 1 branch
BranchTrueFalseTotal
my $csv = "Text::CSV_XS"->new({"binary", 1, "eol", "\n", "sep_char", $separator}) or die "Cannot initialize in-memory CSV writer" 25 0 25
556 { binary => 1, eol => "\n", sep_char => $separator }
557 ) or die 'Cannot initialize in-memory CSV writer';
558 25 $csv->print( $fh, $headers );
559 25 for my $row ( @{$rows} ) {
560 $csv->print( $fh,
561 312 ▶ [ map { exists $row->{$_} ? $row->{$_} : undef } @{$headers} ] );
Branch: 1 branch
BranchTrueFalseTotal
exists $row->{$_} ? : 6235 9454 15689
562 }
563 25 close $fh;
564 return {
565 25 id => $id,
566 filename => $filename,
567 mediaType => 'text/csv; charset=utf-8',
568 kind => 'csv',
569 encoding => 'utf-8',
570 content => $content,
571 };
572 }
573  
574 2 ▶sub _audit_artifact {
Subroutine _audit_artifact: called CC=2 SCAR=7.6
575 2 my ($file) = @_;
576 2 ▶ if ( $file =~ /\.xlsx\z/i ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($file =~ /\.xlsx\z/i) 0 2 2
577 return {
578 0 id => 'term-audit',
579 filename => 'term-audit.xlsx',
580 mediaType => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
581 kind => 'xlsx',
582 encoding => 'base64',
583 content => encode_base64( path($file)->slurp_raw, q{} ),
584 };
585 }
586 return {
587 2 id => 'term-audit',
588 filename => 'term-audit.tsv',
589 mediaType => 'text/tab-separated-values; charset=utf-8',
590 kind => 'tsv',
591 encoding => 'utf-8',
592 content => path($file)->slurp_utf8,
593 };
594 }
595  
596 1653 ▶sub _applicable_options {
Subroutine _applicable_options: called CC=18 SCAR=29.3
597 1653 my ( $name, $spec, $metadata ) = @_;
598 1653 my $profiles = $metadata->{http_profiles};
599 1653 my @names;
600 516 ▶ push @names, @{ $profiles->{bff_output_options} || [] }
Condition50%1/2
$profiles->{'bff_output_options'} || []
l!l
5160
MC/DC0%0/1
$profiles->{'bff_output_options'} || []
$profiles->{'bff_output_options'}
Truth table50%1/2
A
A= $profiles->{'bff_output_options'}
Aresult
11
00
601 1653 ▶ if $spec->{target} eq 'beacon';
Branch: 1 branch
BranchTrueFalseTotal
if $spec->{"target"} eq "beacon" 516 1137 1653
602 1352 ▶ push @names, @{ $profiles->{common_options} || [] }
Condition50%1/2
$profiles->{'common_options'} || []
l!l
13520
MC/DC0%0/1
$profiles->{'common_options'} || []
$profiles->{'common_options'}
Truth table50%1/2
A
A= $profiles->{'common_options'}
Aresult
11
00
603 1653 ▶ unless $spec->{operation} eq 'direct';
Branch: 1 branch
BranchTrueFalseTotal
unless $spec->{"operation"} eq "direct" 1352 301 1653
604 878 ▶ push @names, @{ $profiles->{terminology_options} || [] }
Condition50%1/2
$profiles->{'terminology_options'} || []
l!l
8780
MC/DC0%0/1
$profiles->{'terminology_options'} || []
$profiles->{'terminology_options'}
Truth table50%1/2
A
A= $profiles->{'terminology_options'}
Aresult
11
00
605 if $spec->{target} eq 'omop'
606 1653 ▶ || grep { $_ eq $spec->{source} } @{ $profiles->{terminology_sources} || [] };
Branch: 1 branch
BranchTrueFalseTotal
if $spec->{"target"} eq "omop" or grep {$_ eq $spec->{"source"};} @{$profiles->{"terminology_sources"} or [];} 878 775 1653
Condition80%4/5
$spec->{"target"} eq "omop" or grep {$_ eq $spec->{"source"};} @{$profiles->{"terminology_sources"} or [];}
l!l&&r!l&&!r
438440775
$profiles->{'terminology_sources'} || []
l!l
12150
MC/DC100%2/2
$spec->{"target"} eq "omop" or grep {$_ eq $spec->{"source"};} @{$profiles->{"terminology_sources"} or [];}
$spec->{"target"} eq "omop" grep {$_ eq $spec->{"source"};} @{$profiles->{"terminology_sources"} or [];}
MC/DC0%0/1
$profiles->{'terminology_sources'} || []
$profiles->{'terminology_sources'}
Truth table100%3/3
A or B
A= $spec->{"target"} eq "omop"B= grep {$_ eq $spec->{"source"};} @{$profiles->{"terminology_sources"} or [];}
ABresult
1X1
011
000
Truth table50%1/2
A
A= $profiles->{'terminology_sources'}
Aresult
11
00
607 push @names, 'term_audit'
608 if $spec->{target} eq 'omop'
609 1653 ▶ || grep { $_ eq $spec->{source} } @{ $profiles->{terminology_sources} || [] };
Branch: 1 branch
BranchTrueFalseTotal
if $spec->{"target"} eq "omop" or grep {$_ eq $spec->{"source"};} @{$profiles->{"terminology_sources"} or [];} 878 775 1653
Condition80%4/5
$spec->{"target"} eq "omop" or grep {$_ eq $spec->{"source"};} @{$profiles->{"terminology_sources"} or [];}
l!l&&r!l&&!r
438440775
$profiles->{'terminology_sources'} || []
l!l
12150
MC/DC100%2/2
$spec->{"target"} eq "omop" or grep {$_ eq $spec->{"source"};} @{$profiles->{"terminology_sources"} or [];}
$spec->{"target"} eq "omop" grep {$_ eq $spec->{"source"};} @{$profiles->{"terminology_sources"} or [];}
MC/DC0%0/1
$profiles->{'terminology_sources'} || []
$profiles->{'terminology_sources'}
Truth table100%3/3
A or B
A= $spec->{"target"} eq "omop"B= grep {$_ eq $spec->{"source"};} @{$profiles->{"terminology_sources"} or [];}
ABresult
1X1
011
000
Truth table50%1/2
A
A= $profiles->{'terminology_sources'}
Aresult
11
00
610 push @names, 'separator'
611 1653 ▶ if grep { $_ eq $spec->{source} } @{ $profiles->{separator_sources} || [] };
Branch: 1 branch
BranchTrueFalseTotal
if grep {$_ eq $spec->{"source"};} @{$profiles->{"separator_sources"} or [];} 308 1345 1653
Condition50%1/2
$profiles->{'separator_sources'} || []
l!l
16530
MC/DC0%0/1
$profiles->{'separator_sources'} || []
$profiles->{'separator_sources'}
Truth table50%1/2
A
A= $profiles->{'separator_sources'}
Aresult
11
00
612 87 ▶ push @names, @{ $profiles->{omop_input_options} || [] }
Condition50%1/2
$profiles->{'omop_input_options'} || []
l!l
870
MC/DC0%0/1
$profiles->{'omop_input_options'} || []
$profiles->{'omop_input_options'}
Truth table50%1/2
A
A= $profiles->{'omop_input_options'}
Aresult
11
00
613 1653 ▶ if $spec->{source} eq 'omop';
Branch: 1 branch
BranchTrueFalseTotal
if $spec->{"source"} eq "omop" 87 1566 1653
614 475 ▶ push @names, @{ $profiles->{pxf_output_options} || [] }
Condition50%1/2
$profiles->{'pxf_output_options'} || []
l!l
4750
MC/DC0%0/1
$profiles->{'pxf_output_options'} || []
$profiles->{'pxf_output_options'}
Truth table50%1/2
A
A= $profiles->{'pxf_output_options'}
Aresult
11
00
615 1653 ▶ if $spec->{target} eq 'pxf';
Branch: 1 branch
BranchTrueFalseTotal
if $spec->{"target"} eq "pxf" 475 1178 1653
616 1653 my %seen;
617 1653 return grep { !$seen{$_}++ } @names;
618 }
619  
620 80 ▶sub _validate_option {
Subroutine _validate_option: called CC=33 SCAR=43.1
621 80 my ( $name, $value, $metadata ) = @_;
622 80 ▶ return if $name eq 'test' && blessed($value) && $value->isa('JSON::PP::Boolean');
Branch: 1 branch
BranchTrueFalseTotal
if $name eq "test" and builtin::blessed($value) and $value->isa("JSON::PP::Boolean") 59 21 80
Condition66%4/6
$name eq "test" and builtin::blessed($value) and $value->isa("JSON::PP::Boolean")
!ll&&!rl&&r
21059
$name eq "test" and builtin::blessed($value)
!ll&&!rl&&r
21059
MC/DC33%1/3
$name eq "test" and builtin::blessed($value) and $value->isa("JSON::PP::Boolean")
$name eq "test" builtin::blessed($value) $value->isa("JSON::PP::Boolean")
Truth table50%2/4
A and B and C
A= $name eq "test"B= builtin::blessed($value)C= $value->isa("JSON::PP::Boolean")
ABCresult
0XX0
10X0
1100
1111
623 21 ▶ my $definition = $metadata->{option_definitions}{$name} || {};
Condition50%1/2
$metadata->{'option_definitions'}{$name} || {}
l!l
210
MC/DC0%0/1
$metadata->{'option_definitions'}{$name} || {}
$metadata->{'option_definitions'}{$name}
Truth table50%1/2
A
A= $metadata->{'option_definitions'}{$name}
Aresult
11
00
624 21 ▶ my $kind = $definition->{kind} || q{};
Condition50%1/2
$definition->{'kind'} || ''
l!l
210
MC/DC0%0/1
$definition->{'kind'} || ''
$definition->{'kind'}
Truth table50%1/2
A
A= $definition->{'kind'}
Aresult
11
00
625 21 ▶ if ($name eq 'omop_tables') {
Branch: 1 branch
BranchTrueFalseTotal
if ($name eq "omop_tables") 4 17 21
626 4 my %supported = map { $_ => 1 } @omop_supported_tables;
627 _throw(422, 'invalid_request', "Select supported OMOP input tables")
628 4 ▶ unless ref($value) eq 'ARRAY' && !grep { !defined($_) || ref($_) || !$supported{$_} } @$value;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $value eq "ARRAY" and not grep({not defined $_ or ref $_ or not $supported{$_};} @$value) 3 1 4
Condition88%8/9
ref $value eq "ARRAY" and not grep({not defined $_ or ref $_ or not $supported{$_};} @$value)
!ll&&!rl&&r
121
!defined($_) || ref $_ || !$supported{$_}
l!l&&r!l&&!r
111
not defined $_ or ref $_
l!l&&r!l&&!r
102
MC/DC100%2/2
ref $value eq "ARRAY" and not grep({not defined $_ or ref $_ or not $supported{$_};} @$value)
ref $value eq "ARRAY" not grep({not defined $_ or ref $_ or not $supported{$_};} @$value)
MC/DC66%2/3
!defined($_) || ref $_ || !$supported{$_}
not defined $_ ref $_ !$supported{$_}
Truth table100%3/3
A and not(B)
A= ref $value eq "ARRAY"B= not grep({not defined $_ or ref $_ or not $supported{$_};} @$value)
ABresult
0X0
100
111
Truth table75%3/4
not(A) or B || not(C)
A= not defined $_B= ref $_C= !$supported{$_}
ABCresult
1XX1
01X1
0011
0000
629 1 return;
630 }
631 my $valid =
632 $kind eq 'boolean' ? ( blessed($value) && $value->isa('JSON::PP::Boolean') )
633 : $kind eq 'number' ? ( !ref($value) && defined($value) && looks_like_number($value) )
634 : $kind eq 'integer' ? ( !ref($value) && defined($value) && $value =~ /\A\d+\z/ )
635 : $kind eq 'string' ? ( !ref($value) && defined($value) )
636 : $kind eq 'select' ? ( !ref($value) && defined($value)
637 17 ▶ && grep { $_ eq $value } @{ $definition->{values} || [] } )
Branch: 5 branches
BranchTrueFalseTotal
$kind eq 'boolean' ? : 7 10 17
$kind eq 'number' ? : 0 10 10
$kind eq 'integer' ? : 1 9 10
$kind eq 'string' ? : 5 4 9
$kind eq 'select' ? : 4 0 4
Condition30%8/26
builtin::blessed($value) and $value->isa("JSON::PP::Boolean")
!ll&&!rl&&r
106
not ref $value and defined $value and &looks_like_number($value)
!ll&&!rl&&r
000
not ref $value and defined $value
!ll&&!rl&&r
000
not ref $value and defined $value and $value =~ /\A\d+\z/
!ll&&!rl&&r
001
not ref $value and defined $value
!ll&&!rl&&r
001
not ref $value and defined $value
!ll&&!rl&&r
005
not ref $value and defined $value and grep {$_ eq $value;} @{$definition->{"values"} or [];}
!ll&&!rl&&r
004
not ref $value and defined $value
!ll&&!rl&&r
004
$definition->{'values'} || []
l!l
40
MC/DC50%1/2
builtin::blessed($value) and $value->isa("JSON::PP::Boolean")
builtin::blessed($value) $value->isa("JSON::PP::Boolean")
MC/DC0%0/3
not ref $value and defined $value and &looks_like_number($value)
not ref $value defined $value &looks_like_number($value)
MC/DC0%0/3
not ref $value and defined $value and $value =~ /\A\d+\z/
not ref $value defined $value $value =~ /\A\d+\z/
MC/DC0%0/3
not ref $value and defined $value and grep {$_ eq $value;} @{$definition->{"values"} or [];}
not ref $value defined $value grep {$_ eq $value;} @{$definition->{"values"} or [];}
MC/DC0%0/1
$definition->{'values'} || []
$definition->{'values'}
Truth table66%2/3
A and B
A= builtin::blessed($value)B= $value->isa("JSON::PP::Boolean")
ABresult
0X0
100
111
Truth table0%0/4
not(A) and B and C
A= not ref $valueB= defined $valueC= &looks_like_number($value)
ABCresult
0XX0
10X0
1100
1111
Truth table25%1/4
not(A) and B and C
A= not ref $valueB= defined $valueC= $value =~ /\A\d+\z/
ABCresult
0XX0
10X0
1100
1111
Truth table25%1/4
not(A) and B and C
A= not ref $valueB= defined $valueC= grep {$_ eq $value;} @{$definition->{"values"} or [];}
ABCresult
0XX0
10X0
1100
1111
Truth table50%1/2
A
A= $definition->{'values'}
Aresult
11
00
638 : 1;
639 17 ▶ _throw( 422, 'invalid_request', "Invalid value for option '$name'" )
Branch: 1 branch
BranchTrueFalseTotal
unless $valid 1 16 17
640 unless $valid;
641  
642 16 ▶ if ( ( $kind eq 'number' || $kind eq 'integer' ) && defined $value ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($kind eq "number" || $kind eq "integer" and defined $value) 1 15 16
Condition66%4/6
$kind eq "number" || $kind eq "integer" and defined $value
!ll&&!rl&&r
1501
$kind eq "number" or $kind eq "integer"
l!l&&r!l&&!r
0115
MC/DC33%1/3
$kind eq "number" || $kind eq "integer" and defined $value
$kind eq "number" $kind eq "integer" defined $value
Truth table40%2/5
A or B and C
A= $kind eq "number"B= $kind eq "integer"C= defined $value
ABCresult
00X0
1X00
0100
1X11
0111
643 _throw( 422, 'invalid_request', "Option '$name' is below its minimum" )
644 1 ▶ if defined $definition->{minimum} && $value < $definition->{minimum};
Branch: 1 branch
BranchTrueFalseTotal
if defined $definition->{"minimum"} and $value < $definition->{"minimum"} 0 1 1
Condition33%1/3
defined $definition->{"minimum"} and $value < $definition->{"minimum"}
!ll&&!rl&&r
010
MC/DC0%0/2
defined $definition->{"minimum"} and $value < $definition->{"minimum"}
defined $definition->{"minimum"} $value < $definition->{"minimum"}
Truth table33%1/3
A and B
A= defined $definition->{"minimum"}B= $value < $definition->{"minimum"}
ABresult
0X0
100
111
645 _throw( 422, 'invalid_request', "Option '$name' is above its maximum" )
646 1 ▶ if defined $definition->{maximum} && $value > $definition->{maximum};
Branch: 1 branch
BranchTrueFalseTotal
if defined $definition->{"maximum"} and $value > $definition->{"maximum"} 0 1 1
Condition33%1/3
defined $definition->{"maximum"} and $value > $definition->{"maximum"}
!ll&&!rl&&r
100
MC/DC0%0/2
defined $definition->{"maximum"} and $value > $definition->{"maximum"}
defined $definition->{"maximum"} $value > $definition->{"maximum"}
Truth table33%1/3
A and B
A= defined $definition->{"maximum"}B= $value > $definition->{"maximum"}
ABresult
0X0
100
111
647 }
648 }
649  
650 1708 ▶sub _required_resources {
Subroutine _required_resources: called CC=3 SCAR=11.0
651 1708 my ( $name, $metadata ) = @_;
652 1708 my $spec = conversion_spec($name);
653 1708 ▶ return ('ohdsi') if $spec && $spec->{target} eq 'omop';
Branch: 1 branch
BranchTrueFalseTotal
if $spec and $spec->{"target"} eq "omop" 443 1265 1708
Condition66%2/3
$spec and $spec->{"target"} eq "omop"
!ll&&!rl&&r
01265443
MC/DC50%1/2
$spec and $spec->{"target"} eq "omop"
$spec $spec->{"target"} eq "omop"
Truth table66%2/3
A and B
A= $specB= $spec->{"target"} eq "omop"
ABresult
0X0
100
111
654 1265 return ();
655 }
656  
657 1712 ▶sub _availability {
Subroutine _availability: called CC=8 SCAR=20.9
658 1712 my ( $required, $metadata ) = @_;
659 1712 my %paths;
660 1712 for my $resource ( @{$required} ) {
661 449 ▶ next unless $resource eq 'ohdsi';
Branch: 1 branch
BranchTrueFalseTotal
unless $resource eq "ohdsi" 0 449 449
662 449 my $override = $ENV{CONVERT_PHENO_OHDSI_DB_DIR};
663 my $path = defined $override && length $override
664 ? "$override/ohdsi.db"
665 449 ▶ : eval { bundled_database_path( $Convert::Pheno::share_dir, 'ohdsi' ) };
Branch: 1 branch
BranchTrueFalseTotal
defined $override && length $override ? : 41 408 449
Condition66%2/3
defined $override and length $override
!ll&&!rl&&r
408041
MC/DC50%1/2
defined $override and length $override
defined $override length $override
Truth table66%2/3
A and B
A= defined $overrideB= length $override
ABresult
0X0
100
111
666 449 ▶ unless ( defined $path && -f $path ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $path and -f $path) 423 26 449
Condition66%2/3
defined $path and -f $path
!ll&&!rl&&r
042326
MC/DC50%1/2
defined $path and -f $path
defined $path -f $path
Truth table66%2/3
A and B
A= defined $pathB= -f $path
ABresult
0X0
100
111
667 my $description = $metadata->{resources}{$resource}{description}
668 423 ▶ || 'A required runtime resource is missing.';
Condition100%2/2
$metadata->{'resources'}{$resource}{'description'} || 'A required runtime resource is missing.'
l!l
4221
MC/DC100%1/1
$metadata->{'resources'}{$resource}{'description'} || 'A required runtime resource is missing.'
$metadata->{'resources'}{$resource}{'description'}
Truth table100%2/2
A
A= $metadata->{'resources'}{$resource}{'description'}
Aresult
11
00
669 423 return ( 0, $description, \%paths );
670 }
671 26 $paths{$resource} = $path;
672 }
673 1289 return ( 1, undef, \%paths );
674 }
675  
676 28 ▶sub _reject_path_values {
Subroutine _reject_path_values: called CC=4 SCAR=14.1
677 28 my ( $value, $location ) = @_;
678 28 ▶ return unless !ref($value);
Branch: 1 branch
BranchTrueFalseTotal
if ref $value 27 1 28
679 1 ▶ return unless defined $value;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 0 1 1
680 # Input data may legitimately contain slashes and identifiers. Only reject
681 # a scalar input that is itself shaped like a host path; structured JSON is safe.
682 1 ▶ if ( $value =~ m{\A(?:/|[A-Za-z]:[\\/]|\.\.?[\\/]|~[\\/])} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($value =~ m[\A(?:/|[A-Za-z]:[\\/]|\.\.?[\\/]|~[\\/])]) 1 0 1
683 1 _throw( 422, 'invalid_request',
684 "Filesystem paths are not accepted in $location" );
685 }
686 }
687  
688 14 ▶sub _throw {
Subroutine _throw: called CC=1 SCAR=0.0
689 14 my ( $status, $code, $message ) = @_;
690 14 die bless {
691 status => $status,
692 code => $code,
693 message => $message,
694 }, 'Convert::Pheno::HTTP::Service::Error';
695 }
696  
697 6 ▶sub is_service_error {
Subroutine is_service_error: called CC=2 SCAR=7.6
Pod undocumented
698 6 my ($error) = @_;
699 6 ▶ return ref($error) && eval { $error->isa('Convert::Pheno::HTTP::Service::Error') };
Condition33%1/3
ref $error && eval { do { $error->isa('Convert::Pheno::HTTP::Service::Error') } }
!ll&&!rl&&r
006
MC/DC0%0/2
ref $error && eval { do { $error->isa('Convert::Pheno::HTTP::Service::Error') } }
ref $error eval { do { $error->isa('Convert::Pheno::HTTP::Service::Error') } }
Truth table33%1/3
A && B
A= ref $errorB= eval { do { $error->isa('Convert::Pheno::HTTP::Service::Error') } }
ABresult
0X0
100
111
700 }
701  
702 package Convert::Pheno::HTTP::Service::Error;
703  
704 0 ▶use overload q{""} => sub { return $_[0]->{message} }, fallback => 1;
Subroutine BEGIN: called CC=1 SCAR=0.2
Subroutine __ANON__: not called CC=1 SCAR=0.2
705  
706 8 ▶sub status { return $_[0]->{status} }
Subroutine status: called CC=1 SCAR=0.0
707 0 ▶sub code { return $_[0]->{code} }
Subroutine code: not called CC=1 SCAR=6.9
708 0 ▶sub message { return $_[0]->{message} }
Subroutine message: not called CC=1 SCAR=6.9
709  
710 42 1;
« lib/Convert/Pheno/HTTP/Projects.pm ↑ Summary lib/Convert/Pheno/CDISC/SDTM/Terminology.pm »