File Coverage

blib/lib/UMLS/Association/ErrorHandler.pm
Criterion Covered Total %
statement 19 67 28.3
branch 0 28 0.0
condition n/a
subroutine 6 9 66.6
pod 0 1 0.0
total 25 105 23.8


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             # 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     1   5 use Fcntl;
  1         2  
  1         230  
39 1     1   9 use strict;
  1         3  
  1         40  
40 1     1   8 use warnings;
  1         2  
  1         35  
41 1     1   5 use DBI;
  1         1  
  1         33  
42 1     1   5 use bytes;
  1         1  
  1         6  
43              
44             # Errors and their error codes
45             my $e1 = "Database error (Error Code 1).";
46             my $e2 = "Self is undefined (Error Code 2).";
47             my $e3 = "A db is required (Error Code 3).";
48             my $e4 = "Undefined input value (Error Code 4).";
49             my $e5 = "NPP is zero or less error (Error Code 5).";
50             my $e6 = "Invalid CUI (Error Code 6).";
51             my $e7 = "UMLS::Association Database Content Error (Error Code 7).";
52             my $e8 = "UMLS::Association Package Error (Error Code 8).";
53             my $e9 = "Index Error (Error Code 9).";
54             my $e10 = "Option Error (Error Code 10).";
55             my $e11 = "Unsupported Option Error (Error Code 11).";
56             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     0   0 my $self = shift;
67 0         0 my $pkg = shift;
68 0         0 my $function = shift;
69 0         0 my $string = shift;
70 0         0 my $errorcode = shift;
71            
72 0         0 my $errorstring = "";
73              
74 0 0       0 if($errorcode eq 1) { $errorstring = $e1; }
  0         0  
75 0 0       0 if($errorcode eq 2) { $errorstring = $e2; }
  0         0  
76 0 0       0 if($errorcode eq 3) { $errorstring = $e3; }
  0         0  
77 0 0       0 if($errorcode eq 4) { $errorstring = $e4; }
  0         0  
78 0 0       0 if($errorcode eq 5) { $errorstring = $e5; }
  0         0  
79 0 0       0 if($errorcode eq 6) { $errorstring = $e6; }
  0         0  
80 0 0       0 if($errorcode eq 7) { $errorstring = $e7; }
  0         0  
81 0 0       0 if($errorcode eq 8) { $errorstring = $e8; }
  0         0  
82 0 0       0 if($errorcode eq 9) { $errorstring = $e9; }
  0         0  
83 0 0       0 if($errorcode eq 10) { $errorstring = $e10; }
  0         0  
84 0 0       0 if($errorcode eq 11) { $errorstring = $e11; }
  0         0  
85 0 0       0 if($errorcode eq 12) { $errorstring = $e12; }
  0         0  
86              
87 0         0 print STDERR "ERROR: $pkg->$function\n";
88 0         0 print STDERR "$errorstring\n";
89 0         0 print STDERR "$string\n";
90              
91 0         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     0   0 my $self = shift;
102 0         0 my $pkg = shift;
103 0         0 my $function = shift;
104 0         0 my $db = shift;
105              
106 0         0 my $errorcode = 1;
107            
108 0 0       0 if($db->err()) {
109 0         0 my $errstring = "Error executing database query: $db->errstr()).";
110 0         0 $self->_error($pkg, $function, $errstring, $errorcode);
111             }
112             else {
113 0         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     0   0 my $self = shift;
123 0         0 my $concept = shift;
124            
125 0 0       0 if($concept=~/C[0-9][0-9][0-9][0-9][0-9][0-9][0-9]/) {
126 0         0 return 1;
127             }
128             else {
129 0         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     2 0 4 my $self = {};
139 2         4 my $className = shift;
140            
141             # Bless the object.
142 2         4 bless($self, $className);
143              
144 2         7 return $self;
145             }
146             1;
147             __END__