lib/Convert/Pheno/CDISC/ODM/Detector.pm

filter: Statementstmt 98.4% 64 / 65 Branchbran 70.4% 31 / 44 Conditioncond 42.1% 8 / 19 MC/DCmcdc 8.3% 1 / 12 Subroutinesub 100% 9 / 9 Podpod 0.0% 0 / 2 totaltotal 74.8% 113 / 151 CC 33 SCAR 24.6
CC
33
Cov
80%
detect_odm_document
23.0
attribute_by_namespace
6.2
_detect_vendor
6.1
CRAP 11.7
« lib/Convert/Pheno/BFF/ToOMOP.pm ↑ Summary lib/Convert/Pheno/CDISC/SDTM/ToBFF.pm »
1 package Convert::Pheno::CDISC::ODM::Detector;
2  
3 136 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 136 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 136 ▶use Exporter 'import';
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 136 our @EXPORT_OK = qw(
9 attribute_by_namespace
10 detect_odm_document
11 );
12  
13 my %SUPPORTED = (
14 'http://www.cdisc.org/ns/odm/v1.3' => {
15 adapter => 'v1',
16 136 versions => { map { $_ => 1 } qw(1.3.1 1.3.2) },
17 },
18 'http://www.cdisc.org/ns/odm/v2.0' => {
19 adapter => 'v2',
20 versions => { '2.0' => 1, '2.0.0' => 1 },
21 },
22 );
23  
24 77 ▶sub detect_odm_document {
Subroutine detect_odm_document: called CC=16 SCAR=31.4
Pod undocumented
25 77 my ($document) = @_;
26 77 ▶ die "CDISC-ODM input must contain one ODM root element\n"
Branch: 1 branch
BranchTrueFalseTotal
unless ref $document eq "HASH" 0 77 77
27 unless ref($document) eq 'HASH';
28  
29 77 my ( $root_key, $root ) = _root_element($document);
30 77 ▶ die "CDISC-ODM input must contain one ODM root element\n"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $root_key and ref $root eq "HASH" 0 77 77
Condition33%1/3
defined $root_key and ref $root eq "HASH"
!ll&&!rl&&r
0077
MC/DC0%0/2
defined $root_key and ref $root eq "HASH"
defined $root_key ref $root eq "HASH"
Truth table33%1/3
A and B
A= defined $root_keyB= ref $root eq "HASH"
ABresult
0X0
100
111
31 unless defined $root_key && ref($root) eq 'HASH';
32  
33 77 my $namespace = $root->{'-xmlns'};
34 77 ▶ if ( !defined $namespace && $root_key =~ /\A([^:]+):ODM\z/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $namespace and $root_key =~ /\A([^:]+):ODM\z/) 0 77 77
Condition33%1/3
not defined $namespace and $root_key =~ /\A([^:]+):ODM\z/
!ll&&!rl&&r
7700
MC/DC0%0/2
not defined $namespace and $root_key =~ /\A([^:]+):ODM\z/
not defined $namespace $root_key =~ /\A([^:]+):ODM\z/
Truth table33%1/3
not(A) and B
A= not defined $namespaceB= $root_key =~ /\A([^:]+):ODM\z/
ABresult
0X0
100
111
35 0 $namespace = $root->{ '-xmlns:' . $1 };
36 }
37 77 ▶ die "CDISC-ODM root is missing its ODM namespace\n"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $namespace and length $namespace 0 77 77
Condition33%1/3
defined $namespace and length $namespace
!ll&&!rl&&r
0077
MC/DC0%0/2
defined $namespace and length $namespace
defined $namespace length $namespace
Truth table33%1/3
A and B
A= defined $namespaceB= length $namespace
ABresult
0X0
100
111
38 unless defined $namespace && length $namespace;
39  
40 77 my $supported = $SUPPORTED{$namespace};
41 77 ▶ die "Unsupported CDISC-ODM namespace <$namespace>\n" unless $supported;
Branch: 1 branch
BranchTrueFalseTotal
unless $supported 0 77 77
42  
43 77 my $version = $root->{'-ODMVersion'};
44 77 ▶ die "CDISC-ODM root is missing <ODMVersion>\n"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $version and length $version 0 77 77
Condition33%1/3
defined $version and length $version
!ll&&!rl&&r
0077
MC/DC0%0/2
defined $version and length $version
defined $version length $version
Truth table33%1/3
A and B
A= defined $versionB= length $version
ABresult
0X0
100
111
45 unless defined $version && length $version;
46 die "CDISC-ODM namespace/version mismatch: namespace <$namespace> does not support <ODMVersion=$version>\n"
47 77 ▶ unless $supported->{versions}{$version};
Branch: 1 branch
BranchTrueFalseTotal
unless $supported->{"versions"}{$version} 1 76 77
48  
49 76 ▶ my $file_type = $root->{'-FileType'} // q{};
Condition50%1/2
$root->{"-FileType"} // ""
l!l
760
MC/DC0%0/1
$root->{"-FileType"} // ""
$root->{"-FileType"}
Truth table50%1/2
A
A= $root->{"-FileType"}
Aresult
11
00
50 76 ▶ die "Unsupported CDISC-ODM FileType <$file_type>; only Snapshot input is supported\n"
Branch: 1 branch
BranchTrueFalseTotal
unless lc $file_type eq "snapshot" 1 75 76
51 unless lc($file_type) eq 'snapshot';
52  
53 75 my $namespaces = _namespace_map($root);
54 75 ▶ my $source_system = $root->{'-SourceSystem'} // q{};
Condition100%2/2
$root->{"-SourceSystem"} // ""
l!l
1164
MC/DC100%1/1
$root->{"-SourceSystem"} // ""
$root->{"-SourceSystem"}
Truth table100%2/2
A
A= $root->{"-SourceSystem"}
Aresult
11
00
55 75 my $vendor = _detect_vendor( $source_system, $namespaces );
56  
57 return {
58 adapter => $supported->{adapter},
59 75 ▶ namespace => $namespace,
Branch: 1 branch
BranchTrueFalseTotal
$vendor eq 'redcap' ? : 7 68 75
60 namespaces => $namespaces,
61 odmVersion => $version,
62 recordProfile => $vendor eq 'redcap' ? 'redcap' : 'cdisc-odm',
63 root => $root,
64 sourceSystem => $source_system,
65 vendor => $vendor,
66 };
67 }
68  
69 10353 ▶sub attribute_by_namespace {
Subroutine attribute_by_namespace: called CC=6 SCAR=18.2
Pod undocumented
70 10353 my ( $node, $namespaces, $namespace_match, $local_name ) = @_;
71 10353 ▶ return unless ref($node) eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $node eq "HASH" 0 10353 10353
72  
73 10353 for my $key ( keys %{$node} ) {
74 30988 ▶ next unless $key =~ /\A-([^:]+):\Q$local_name\E\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless $key =~ /\A-([^:]+):\Q$local_name\E\z/ 30613 375 30988
75 375 my $uri = $namespaces->{$1};
76 375 ▶ next unless defined $uri;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $uri 0 375 375
77 375 ▶ return $node->{$key} if _namespace_matches( $uri, $namespace_match );
Branch: 1 branch
BranchTrueFalseTotal
if _namespace_matches($uri, $namespace_match) 375 0 375
78 }
79 9978 return;
80 }
81  
82 77 ▶sub _root_element {
Subroutine _root_element: called CC=3 SCAR=11.6
83 77 my ($document) = @_;
84 77 ▶ my @keys = grep { $_ eq 'ODM' || /:ODM\z/ } keys %{$document};
Condition33%1/3
$_ eq 'ODM' || /:ODM\z/
l!l&&r!l&&!r
7700
MC/DC0%0/2
$_ eq 'ODM' || /:ODM\z/
$_ eq 'ODM' /:ODM\z/
Truth table33%1/3
A || B
A= $_ eq 'ODM'B= /:ODM\z/
ABresult
1X1
011
000
85 77 ▶ return if @keys != 1;
Branch: 1 branch
BranchTrueFalseTotal
if @keys != 1 0 77 77
86 77 return ( $keys[0], $document->{ $keys[0] } );
87 }
88  
89 75 ▶sub _namespace_map {
Subroutine _namespace_map: called CC=4 SCAR=13.9
90 75 my ($root) = @_;
91 75 my %namespaces;
92 75 for my $key ( keys %{$root} ) {
93 739 ▶ next unless $key =~ /\A-xmlns(?::(.+))?\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless $key =~ /\A-xmlns(?::(.+))?\z/ 577 162 739
94 162 ▶ $namespaces{ defined $1 ? $1 : q{} } = $root->{$key};
Branch: 1 branch
BranchTrueFalseTotal
defined $1 ? : 87 75 162
95 }
96 75 return \%namespaces;
97 }
98  
99 75 ▶sub _detect_vendor {
Subroutine _detect_vendor: called CC=6 SCAR=18.0
100 75 my ( $source_system, $namespaces ) = @_;
101 75 ▶ return 'redcap' if $source_system =~ /redcap/i;
Branch: 1 branch
BranchTrueFalseTotal
if $source_system =~ /redcap/i 7 68 75
102 68 ▶ return 'openclinica' if $source_system =~ /openclinica/i;
Branch: 1 branch
BranchTrueFalseTotal
if $source_system =~ /openclinica/i 2 66 68
103  
104 66 for my $uri ( values %{$namespaces} ) {
105 130 ▶ return 'redcap' if $uri =~ m{\Ahttps?://(?:www\.)?projectredcap\.org/?\z}i;
Branch: 1 branch
BranchTrueFalseTotal
if $uri =~ m[\Ahttps?://(?:www\.)?projectredcap\.org/?\z]i 0 130 130
106 130 ▶ return 'openclinica' if $uri =~ /openclinica/i;
Branch: 1 branch
BranchTrueFalseTotal
if $uri =~ /openclinica/i 0 130 130
107 }
108 66 return 'standard';
109 }
110  
111 375 ▶sub _namespace_matches {
Subroutine _namespace_matches: called CC=3 SCAR=11.1
112 375 my ( $uri, $match ) = @_;
113 375 ▶ return $uri eq $match unless ref($match) eq 'Regexp';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $match eq "Regexp" 158 217 375
114 217 ▶ return $uri =~ $match ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$uri =~ /$match/ ? : 217 0 217
115 }
116  
117 136 1;
« lib/Convert/Pheno/BFF/ToOMOP.pm ↑ Summary lib/Convert/Pheno/CDISC/SDTM/ToBFF.pm »