lib/UMLS/Association/ErrorHandler.pm

filter: Statementstmt 40.0% 32 / 80 Branchbran 0.0% 0 / 28 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 66.6% 6 / 9 Podpod 0.0% 0 / 1 totaltotal 32.2% 38 / 118 SCAR 45.4
CC
15
Cov
30%
_error
182.0
_checkDbError
6.0
_validCui
6.0
CRAP 93.4
« script/CUICollector.pl ↑ Summary script/umls-association-runDataSet.pl »
1 # UMLS::Association::ErrorHandler
2 #
3 # Perl module that provides a perl interface to the CUI network extracted
4 # from the MetaMapped Medline Baseline
5 #
6 # This program borrows heavily from the UMLS::Interface package.
7 #
8 # Copyright (c) 2015,
9 #
10 # Bridget T. McInnes, Virginia Commonwealth University
11 # btmcinnes at vcu.edu
12 #
13 # Keith Herbert, Virginia Commonwealth University
14 # herbertkb at vcu.edu
15 #
16 # Sam Henry, Virginia Commonwealth University
17 # henryst at vcu.edu
18 #
19 # This program is free software; you can redistribute it and/or
20 # modify it under the terms of the GNU General Public License
21 # as published by the Free Software Foundation; either version 2
22 # of the License, or (at your option) any later version.
23 #
24 # This program is distributed in the hope that it will be useful,
25 # but WITHOUT ANY WARRANTY; without even the implied warranty of
26 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27 # GNU General Public License for more details.
28 #
29 # You should have received a copy of the GNU General Public License
30 # along with this program; if not, write to
31 #
32 # The Free Software Foundation, Inc.,
33 # 59 Temple Place - Suite 330,
34 # Boston, MA 02111-1307, USA.
35  
36 package UMLS::Association::ErrorHandler;
37  
38 1 ▶use Fcntl;
Subroutine BEGIN: called CC=1 SCAR=0.0
39 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
40 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
41 1 ▶use DBI;
Subroutine BEGIN: called CC=1 SCAR=0.0
42 1 ▶use bytes;
Subroutine BEGIN: called CC=1 SCAR=0.0
43  
44 # Errors and their error codes
45 1 my $e1 = "Database error (Error Code 1).";
46 1 my $e2 = "Self is undefined (Error Code 2).";
47 1 my $e3 = "A db is required (Error Code 3).";
48 1 my $e4 = "Undefined input value (Error Code 4).";
49 1 my $e5 = "NPP is zero or less error (Error Code 5).";
50 1 my $e6 = "Invalid CUI (Error Code 6).";
51 1 my $e7 = "UMLS::Association Database Content Error (Error Code 7).";
52 1 my $e8 = "UMLS::Association Package Error (Error Code 8).";
53 1 my $e9 = "Index Error (Error Code 9).";
54 1 my $e10 = "Option Error (Error Code 10).";
55 1 my $e11 = "Unsupported Option Error (Error Code 11).";
56 1 my $e12 = "Input parameter error (Error Code 12).";
57  
58 # throws an error and exits the program
59 # input : $pkg <- package the error originated
60 # $function <- function the error originated
61 # $string <- error message
62 # $errorcode <- error code
63 # output:
64 sub _error {
65  
66 0 ▶ my $self = shift;
Subroutine _error: not called CC=13 SCAR=52.0
67 0 my $pkg = shift;
68 0 my $function = shift;
69 0 my $string = shift;
70 0 my $errorcode = shift;
71
72 0 my $errorstring = "";
73  
74 0 ▶ if($errorcode eq 1) { $errorstring = $e1; }
Branch: 1 branch
BranchTrueFalseTotal
if ($errorcode eq 1) 0 0 0
75 0 ▶ if($errorcode eq 2) { $errorstring = $e2; }
Branch: 1 branch
BranchTrueFalseTotal
if ($errorcode eq 2) 0 0 0
76 0 ▶ if($errorcode eq 3) { $errorstring = $e3; }
Branch: 1 branch
BranchTrueFalseTotal
if ($errorcode eq 3) 0 0 0
77 0 ▶ if($errorcode eq 4) { $errorstring = $e4; }
Branch: 1 branch
BranchTrueFalseTotal
if ($errorcode eq 4) 0 0 0
78 0 ▶ if($errorcode eq 5) { $errorstring = $e5; }
Branch: 1 branch
BranchTrueFalseTotal
if ($errorcode eq 5) 0 0 0
79 0 ▶ if($errorcode eq 6) { $errorstring = $e6; }
Branch: 1 branch
BranchTrueFalseTotal
if ($errorcode eq 6) 0 0 0
80 0 ▶ if($errorcode eq 7) { $errorstring = $e7; }
Branch: 1 branch
BranchTrueFalseTotal
if ($errorcode eq 7) 0 0 0
81 0 ▶ if($errorcode eq 8) { $errorstring = $e8; }
Branch: 1 branch
BranchTrueFalseTotal
if ($errorcode eq 8) 0 0 0
82 0 ▶ if($errorcode eq 9) { $errorstring = $e9; }
Branch: 1 branch
BranchTrueFalseTotal
if ($errorcode eq 9) 0 0 0
83 0 ▶ if($errorcode eq 10) { $errorstring = $e10; }
Branch: 1 branch
BranchTrueFalseTotal
if ($errorcode eq 10) 0 0 0
84 0 ▶ if($errorcode eq 11) { $errorstring = $e11; }
Branch: 1 branch
BranchTrueFalseTotal
if ($errorcode eq 11) 0 0 0
85 0 ▶ if($errorcode eq 12) { $errorstring = $e12; }
Branch: 1 branch
BranchTrueFalseTotal
if ($errorcode eq 12) 0 0 0
86  
87 0 print STDERR "ERROR: $pkg->$function\n";
88 0 print STDERR "$errorstring\n";
89 0 print STDERR "$string\n";
90  
91 0 exit;
92 }
93  
94 # checks the database for an error
95 # input : $pkg => the Finder program
96 # $function => the function in the finder program
97 # $db => the database handler
98 # output:
99 sub _checkDbError {
100  
101 0 ▶ my $self = shift;
Subroutine _checkDbError: not called CC=2 SCAR=17.9
102 0 my $pkg = shift;
103 0 my $function = shift;
104 0 my $db = shift;
105  
106 0 my $errorcode = 1;
107
108 0 ▶ if($db->err()) {
Branch: 1 branch
BranchTrueFalseTotal
if ($db->err) { } 0 0 0
109 0 my $errstring = "Error executing database query: $db->errstr()).";
110 0 $self->_error($pkg, $function, $errstring, $errorcode);
111 }
112 else {
113 0 return;
114 }
115 }
116  
117 # subroutine to check if CUI is valid
118 # input : $concept <- string containing a cui
119 # output: true | false <- integer indicating if the cui is valid
120 sub _validCui {
121  
122 0 ▶ my $self = shift;
Subroutine _validCui: not called CC=2 SCAR=17.9
123 0 my $concept = shift;
124
125 0 ▶ if($concept=~/C[0-9][0-9][0-9][0-9][0-9][0-9][0-9]/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($concept =~ /C[0-9][0-9][0-9][0-9][0-9][0-9][0-9]/) { } 0 0 0
126 0 return 1;
127 }
128 else {
129 0 return 0;
130 }
131 }
132  
133 # sets up the error handler module
134 # input : $parameters <- reference to a hash
135 # output: $self
136 sub new {
137  
138 2 ▶ my $self = {};
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
139 2 my $className = shift;
140
141 # Bless the object.
142 2 bless($self, $className);
143  
144 2 return $self;
145 }
146 1 1;
147 __END__
« script/CUICollector.pl ↑ Summary script/umls-association-runDataSet.pl »