CohortExplorer/Application/OpenClinica/Datasource.pm

filter: Statementstmt 23.4% 11 / 47 Branchbran 0.0% 0 / 10 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 33.3% 3 / 9 Podpod 100% 6 / 6 totaltotal 26.6% 20 / 75 CC 7 SCAR 21.0
CC
7
Cov
19%
authenticate
20.0
additional_params
6.0
entity_structure
6.0
CRAP 8.2
« CohortExplorer/Command/Menu.pm ↑ Summary CohortExplorer.pm »
1 package CohortExplorer::Application::OpenClinica::Datasource;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 our $VERSION = 0.14;
7  
8 1 ▶use base qw(CohortExplorer::Datasource);
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 #-------
11 0 ▶sub authenticate {
Subroutine authenticate: not called CC=4 SCAR=30.0
Pod documented
12 0 my ( $self, %opts ) = @_;
13  
14 0 require HTTP::Cookies;
15 0 require LWP::UserAgent;
16 0 my $cookie = HTTP::Cookies->new();
17  
18 # Authenticate using REDCap url
19 # Default OpenCLinica url is http://localhost:8080
20 0 my $ua = LWP::UserAgent->new( timeout => 10, cookie_jar => $cookie, ssl_opts => { verify_hostname => 0 } );
21 0 ▶(my $url = $self->url || 'http://localhost:8080/OpenClinica' ) =~ s/\/$//;
Condition0%0/2
$self->url || 'http://localhost:8080/OpenClinica'
l!l
00
MC/DC0%0/1
$self->url || 'http://localhost:8080/OpenClinica'
$self->url
Truth table0%0/2
A
A= $self->url
Aresult
11
00
22 my $res = $ua->post(
23 $url . '/j_spring_security_check',
24 [
25 j_username => $opts{username},
26 j_password => $opts{password}
27 0 ]
28 );
29 0 ▶ if ( $cookie->as_string =~ /(JSESSIONID=[^;]+);/i ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cookie->as_string =~ /(JSESSIONID=[^;]+);/i) { } 0 0 0
30 0 ▶ if ( $res->header('Location') =~ /$1$/i ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($res->header('Location') =~ /$1$/i) { } 0 0 0
31 0 my $dialect = $self->dialect;
32 $self->dbh->selectrow_hashref( 'SELECT s.study_id, '
33 . $dialect->aggregate( "DISTINCT sur.role_name" ) . ' AS role_name, '
34 . $dialect->aggregate( "DISTINCT crf.oc_oid" ) . ' AS tables '
35 0 . " FROM study AS s INNER JOIN study_user_role AS sur ON s.study_id = sur.study_id inner join crf on crf.source_study_id = s.study_id where s.oc_oid = ? AND sur.user_name = ? AND crf.status_id = 1 AND s.status_id = 1 group by s.study_id", undef, @{opts}{qw/datasource username/} );
36 }
37 else {
38 0 return;
39 }
40 }
41 else {
42 0 die "Failed to connect to OpenClinica server using '$url' ("
43 . $res->status_line . ")\n";
44 }
45 }
46  
47 0 ▶sub additional_params {
Subroutine additional_params: not called CC=2 SCAR=17.9
Pod documented
48 0 my ( $self, $res, %opts ) = @_;
49  
50 0 my %param = %$res;
51 0 my $dynamic_tables = $self->dbh->selectcol_arrayref('SELECT crf.oc_oid FROM crf INNER JOIN event_definition_crf AS edcrf ON crf.crf_id = edcrf.crf_id WHERE edcrf.study_id = ? AND crf.status_id = 1 AND edcrf.status_id = 1 GROUP BY crf.oc_oid HAVING COUNT( crf.oc_oid ) > 1', undef, $param{study_id});
52  
53 0 ▶ if ( $dynamic_tables ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dynamic_tables) { } 0 0 0
54 0 my %dynamic_tables = map { $_ => 1 } @$dynamic_tables;
55 0 @param{ qw/type static_tables/ } = ( 'longitudinal', [ grep { !$dynamic_tables{$_} } split ( ',', $param{tables} ) ] );
56 }
57 else {
58 0 $param{type} = 'standard';
59 }
60  
61 0 return \%param;
62 }
63  
64 0 ▶sub entity_structure {
Subroutine entity_structure: not called CC=2 SCAR=17.9
Pod documented
65 0 my ($self) = @_;
66 0 my %struct = (
67 -columns => [
68 entity_id => 'ss.label',
69 variable => 'i.oc_oid',
70 value => 'id.value',
71 table => 'crf.oc_oid'
72 ],
73 -from => [
74 -join => qw/item|i <=>{item_id=item_id} item_data|id <=>{event_crf_id=event_crf_id} event_crf|ecrf <=>{study_event_id=study_event_id} study_event|se <=>{ecrf.crf_version_id=crf_version_id} crf_version|crfv <=>{crf_id=crf_id} crf|crf <=>{se.study_event_definition_id=study_event_definition_id} study_event_definition|sed <=>{ecrf.study_subject_id=study_subject_id} study_subject|ss/
75 ],
76 -where => {
77 'sed.study_id' => $self->study_id,
78 'sed.status_id' => 1,
79 'ecrf.date_validate_completed' => { '!=', undef },
80 'se.status_id' => { -not_in, [ 5, 6, 7, 9 ] }
81 }
82 );
83  
84 0 ▶ if ( $self->type eq 'longitudinal' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->type eq "longitudinal") 0 0 0
85 0 push @{ $struct{-columns} }, visit => "CONCAT( sed.oc_oid, '_', se.sample_ordinal )";
86 }
87  
88 0 return \%struct;
89 }
90  
91 0 ▶sub table_structure {
Subroutine table_structure: not called CC=1 SCAR=6.9
Pod documented
92 0 my ($self) = @_;
93 0 my $dialect = $self->dialect;
94  
95 return {
96 0 -columns => [
97 table => 'crf.oc_oid',
98 variable_count => 'COUNT(DISTINCT ifmd.item_id )',
99 label => $dialect->aggregate( 'DISTINCT crf.name' ),
100 description => $dialect->aggregate( 'DISTINCT crf.description' ),
101 version => $dialect->aggregate( 'DISTINCT crfv.name' ),
102 events => $dialect->aggregate( "DISTINCT CONCAT( sed.name, '(repeat = ', sed.repeating, ', required = ', edcrf.required_crf, ')' )", ', ' )
103 ],
104 -from => [
105 -join =>
106 qw/crf|crf <=>{crf_id=crf_id} crf_version|crfv <=>{crf_version_id=crf_version_id} item_form_metadata|ifmd <=>{crf.crf_id=crf_id} event_definition_crf|edcrf <=>{study_event_definition_id=study_event_definition_id} study_event_definition|sed/
107 ],
108 -group_by => 'crf.oc_oid',
109 -where => {
110 'crf.status_id' => 1,
111 'crfv.status_id' => 1,
112 'sed.status_id' => 1,
113 'edcrf.status_id' => 1,
114 'sed.study_id' => $self->study_id
115 }
116 };
117 }
118  
119 0 ▶sub variable_structure {
Subroutine variable_structure: not called CC=2 SCAR=17.9
Pod documented
120 0 my ($self) = @_;
121  
122 # Table containing category information for categorical variables
123 0 my $category_table = '( SELECT response_set_id, ' . $self->dialect->aggregate( "CONCAT( TRIM(values), ',', TRIM(text) )", '\n' ) . " AS category FROM ( SELECT rs.response_set_id, REGEXP_SPLIT_TO_TABLE(rs.options_text, ',') AS text, REGEXP_SPLIT_TO_TABLE( rs.options_values, ',') AS values FROM response_set AS rs INNER JOIN response_type AS rt ON rs.response_type_id = rt.response_type_id WHERE rt.name IN ('radio', 'single-select', 'multi-select') GROUP BY rs.response_set_id, rs.options_text, rs.options_values ) AS res WHERE text != '' and values != '' GROUP BY res.response_set_id ) AS cat";
124  
125 return {
126 0 ▶ -columns => [
Branch: 1 branch
BranchTrueFalseTotal
$self->role_name =~ /^(?:director|admin)$/ ? : 0 0 0
127 variable => 'i.oc_oid',
128 table => 'crf.oc_oid',
129 type => 'idt.code',
130 default_value => 'ifmd.default_value',
131 description => 'i.description',
132 unit => 'i.units',
133 category => 'cat.category',
134 label => 'CONCAT( ifmd.question_number_label, ifmd.left_item_text )'
135 ],
136 -from => [
137 -join => (
138 'item|i', '<=>{item_data_type_id=item_data_type_id}',
139 'item_data_type|idt', '<=>{i.item_id=item_id}',
140 'item_group_metadata|igmd', '<=>{i.item_id=item_id}',
141 'item_form_metadata|ifmd', '<=>{crf_version_id=crf_version_id}',
142 'crf_version|crfv', '<=>{crf_id=crf_id}',
143 'crf|crf', '=>{ifmd.response_set_id=cat.response_set_id}',
144 $category_table
145 )
146 ],
147 -order_by => [ qw/crf.oc_oid i.item_id/ ],
148 -where => {
149 'crf.source_study_id' => $self->study_id,
150 'crf.status_id' => 1,
151 'crfv.status_id' => 1,
152 'i.status_id' => 1,
153 ( $self->role_name =~ /^(?:director|admin)$/ ? ( -bool => 'i.phi_status' ) : ( -not_bool => 'i.phi_status' ) )
154 }
155
156 };
157 }
158  
159 0 ▶sub datatype_map {
Subroutine datatype_map: not called CC=1 SCAR=6.9
Pod documented
160 return {
161 0 'INT' => 'integer',
162 'REAL' => 'decimal',
163 'DATE' => 'date',
164 };
165 }
166  
167 #-------
168 1 1;
169 __END__
« CohortExplorer/Command/Menu.pm ↑ Summary CohortExplorer.pm »