File Coverage

blib/lib/UMLS/Association/ErrorHandler.pm
Criterion Covered Total %
statement 19 65 29.2
branch 0 26 0.0
condition n/a
subroutine 6 9 66.6
pod 0 1 0.0
total 25 101 24.7


line stmt bran cond sub pod time code
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             # This program is free software; you can redistribute it and/or
17             # modify it under the terms of the GNU General Public License
18             # as published by the Free Software Foundation; either version 2
19             # of the License, or (at your option) any later version.
20             #
21             # This program is distributed in the hope that it will be useful,
22             # but WITHOUT ANY WARRANTY; without even the implied warranty of
23             # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24             # GNU General Public License for more details.
25             #
26             # You should have received a copy of the GNU General Public License
27             # along with this program; if not, write to
28             #
29             # The Free Software Foundation, Inc.,
30             # 59 Temple Place - Suite 330,
31             # Boston, MA 02111-1307, USA.
32              
33             package UMLS::Association::ErrorHandler;
34              
35 1     1   3 use Fcntl;
  1         1  
  1         181  
36 1     1   5 use strict;
  1         0  
  1         20  
37 1     1   3 use warnings;
  1         1  
  1         16  
38 1     1   3 use DBI;
  1         1  
  1         26  
39 1     1   3 use bytes;
  1         1  
  1         5  
40              
41             # Errors and their error codes
42             my $e1 = "Database error (Error Code 1).";
43             my $e2 = "Self is undefined (Error Code 2).";
44             my $e3 = "A db is required (Error Code 3).";
45             my $e4 = "Undefined input value (Error Code 4).";
46             my $e5 = "NPP is zero or less error (Error Code 5).";
47             my $e6 = "Invalid CUI (Error Code 6).";
48             my $e7 = "UMLS::Association Database Content Error (Error Code 7).";
49             my $e8 = "UMLS::Association Package Error (Error Code 8).";
50             my $e9 = "Index Error (Error Code 9).";
51             my $e10 = "Option Error (Error Code 10).";
52             my $e11 = "Unsupported Option Error (Error Code 11).";
53              
54             # throws an error and exits the program
55             # input : $pkg <- package the error originated
56             # $function <- function the error originated
57             # $string <- error message
58             # $errorcode <- error code
59             # output:
60             sub _error {
61              
62 0     0   0 my $self = shift;
63 0         0 my $pkg = shift;
64 0         0 my $function = shift;
65 0         0 my $string = shift;
66 0         0 my $errorcode = shift;
67            
68 0         0 my $errorstring = "";
69              
70 0 0       0 if($errorcode eq 1) { $errorstring = $e1; }
  0         0  
71 0 0       0 if($errorcode eq 2) { $errorstring = $e2; }
  0         0  
72 0 0       0 if($errorcode eq 3) { $errorstring = $e3; }
  0         0  
73 0 0       0 if($errorcode eq 4) { $errorstring = $e4; }
  0         0  
74 0 0       0 if($errorcode eq 5) { $errorstring = $e5; }
  0         0  
75 0 0       0 if($errorcode eq 6) { $errorstring = $e6; }
  0         0  
76 0 0       0 if($errorcode eq 7) { $errorstring = $e7; }
  0         0  
77 0 0       0 if($errorcode eq 8) { $errorstring = $e8; }
  0         0  
78 0 0       0 if($errorcode eq 9) { $errorstring = $e9; }
  0         0  
79 0 0       0 if($errorcode eq 10) { $errorstring = $e10; }
  0         0  
80 0 0       0 if($errorcode eq 11) { $errorstring = $e11; }
  0         0  
81              
82 0         0 print STDERR "ERROR: $pkg->$function\n";
83 0         0 print STDERR "$errorstring\n";
84 0         0 print STDERR "$string\n";
85              
86 0         0 exit;
87             }
88              
89             # checks the database for an error
90             # input : $pkg => the Finder program
91             # $function => the function in the finder program
92             # $db => the database handler
93             # output:
94             sub _checkDbError {
95              
96 0     0   0 my $self = shift;
97 0         0 my $pkg = shift;
98 0         0 my $function = shift;
99 0         0 my $db = shift;
100              
101 0         0 my $errorcode = 1;
102            
103 0 0       0 if($db->err()) {
104 0         0 my $errstring = "Error executing database query: $db->errstr()).";
105 0         0 $self->_error($pkg, $function, $errstring, $errorcode);
106             }
107             else {
108 0         0 return;
109             }
110             }
111              
112             # subroutine to check if CUI is valid
113             # input : $concept <- string containing a cui
114             # output: true | false <- integer indicating if the cui is valid
115             sub _validCui {
116              
117 0     0   0 my $self = shift;
118 0         0 my $concept = shift;
119            
120 0 0       0 if($concept=~/C[0-9][0-9][0-9][0-9][0-9][0-9][0-9]/) {
121 0         0 return 1;
122             }
123             else {
124 0         0 return 0;
125             }
126             }
127              
128             # sets up the error handler module
129             # input : $parameters <- reference to a hash
130             # output: $self
131             sub new {
132              
133 2     2 0 2 my $self = {};
134 2         3 my $className = shift;
135            
136             # Bless the object.
137 2         3 bless($self, $className);
138              
139 2         7 return $self;
140             }
141             1;
142             __END__