File Coverage

blib/lib/UMLS/Interface/ErrorHandler.pm
Criterion Covered Total %
statement 19 72 26.3
branch 0 30 0.0
condition n/a
subroutine 6 10 60.0
pod 0 1 0.0
total 25 113 22.1


line stmt bran cond sub pod time code
1             # UMLS::Interface::ErrorHandler
2             # (Last Updated $Id: ErrorHandler.pm,v 1.9 2011/05/10 20:59:43 btmcinnes Exp $)
3             #
4             # Perl module that provides a perl interface to the
5             # Unified Medical Language System (UMLS)
6             #
7             # Copyright (c) 2004-2010,
8             #
9             # Bridget T. McInnes, University of Minnesota, Twin Cities
10             # bthomson at cs.umn.edu
11             #
12             # Siddharth Patwardhan, University of Utah, Salt Lake City
13             # sidd at cs.utah.edu
14             #
15             # Serguei Pakhomov, University of Minnesota, Twin Cities
16             # pakh0002 at umn.edu
17             #
18             # Ted Pedersen, University of Minnesota, Duluth
19             # tpederse at d.umn.edu
20             #
21             # Ying Liu, University of Minnesota, Twin Cities
22             # liux0935 at umn.edu
23             #
24             # This program is free software; you can redistribute it and/or
25             # modify it under the terms of the GNU General Public License
26             # as published by the Free Software Foundation; either version 2
27             # of the License, or (at your option) any later version.
28             #
29             # This program is distributed in the hope that it will be useful,
30             # but WITHOUT ANY WARRANTY; without even the implied warranty of
31             # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32             # GNU General Public License for more details.
33             #
34             # You should have received a copy of the GNU General Public License
35             # along with this program; if not, write to
36             #
37             # The Free Software Foundation, Inc.,
38             # 59 Temple Place - Suite 330,
39             # Boston, MA 02111-1307, USA.
40              
41             package UMLS::Interface::ErrorHandler;
42              
43 24     24   89 use Fcntl;
  24         30  
  24         4146  
44 24     24   100 use strict;
  24         26  
  24         426  
45 24     24   67 use warnings;
  24         31  
  24         503  
46 24     24   70 use DBI;
  24         25  
  24         684  
47 24     24   83 use bytes;
  24         28  
  24         103  
48              
49             # Errors and their error codes
50             my $e1 = "Database error (Error Code 1).";
51             my $e2 = "Self is undefined (Error Code 2).";
52             my $e3 = "A db is required (Error Code 3).";
53             my $e4 = "Undefined input value (Error Code 4).";
54             my $e5 = "Configuration file error (Error Code 5).";
55             my $e6 = "Invalid CUI (Error Code 6).";
56             my $e7 = "UMLS Database Content Error (Error Code 7).";
57             my $e8 = "UMLS Package Error (Error Code 8).";
58             my $e9 = "Index Error (Error Code 9).";
59             my $e10 = "Option Error (Error Code 10).";
60             my $e11 = "Unsupported Option Error (Error Code 11).";
61             my $e12 = "Invalid TUI (Error Code 12).";
62              
63             # throws an error and exits the program
64             # input : $pkg <- package the error originated
65             # $function <- function the error originated
66             # $string <- error message
67             # $errorcode <- error code
68             # output:
69             sub _error {
70              
71 0     0   0 my $self = shift;
72 0         0 my $pkg = shift;
73 0         0 my $function = shift;
74 0         0 my $string = shift;
75 0         0 my $errorcode = shift;
76            
77 0         0 my $errorstring = "";
78              
79 0 0       0 if($errorcode eq 1) { $errorstring = $e1; }
  0         0  
80 0 0       0 if($errorcode eq 2) { $errorstring = $e2; }
  0         0  
81 0 0       0 if($errorcode eq 3) { $errorstring = $e3; }
  0         0  
82 0 0       0 if($errorcode eq 4) { $errorstring = $e4; }
  0         0  
83 0 0       0 if($errorcode eq 5) { $errorstring = $e5; }
  0         0  
84 0 0       0 if($errorcode eq 6) { $errorstring = $e6; }
  0         0  
85 0 0       0 if($errorcode eq 7) { $errorstring = $e7; }
  0         0  
86 0 0       0 if($errorcode eq 8) { $errorstring = $e8; }
  0         0  
87 0 0       0 if($errorcode eq 9) { $errorstring = $e9; }
  0         0  
88 0 0       0 if($errorcode eq 10) { $errorstring = $e10; }
  0         0  
89 0 0       0 if($errorcode eq 11) { $errorstring = $e11; }
  0         0  
90 0 0       0 if($errorcode eq 12) { $errorstring = $e12; }
  0         0  
91              
92 0         0 print STDERR "ERROR: $pkg->$function\n";
93 0         0 print STDERR "$errorstring\n";
94 0         0 print STDERR "$string\n";
95              
96 0         0 exit;
97             }
98              
99             # checks the database for an error
100             # input : $pkg => the Finder program
101             # $function => the function in the finder program
102             # $db => the database handler
103             # output:
104             sub _checkDbError {
105              
106 0     0   0 my $self = shift;
107 0         0 my $pkg = shift;
108 0         0 my $function = shift;
109 0         0 my $db = shift;
110              
111 0         0 my $errorcode = 1;
112            
113 0 0       0 if($db->err()) {
114 0         0 my $errstring = "Error executing database query: $db->errstr()).";
115 0         0 $self->_error($pkg, $function, $errstring, $errorcode);
116             }
117             else {
118 0         0 return;
119             }
120             }
121              
122             # subroutine to check if CUI is valid
123             # input : $concept <- string containing a cui
124             # output: true | false <- integer indicating if the cui is valid
125             sub _validCui {
126              
127 0     0   0 my $self = shift;
128 0         0 my $concept = shift;
129            
130 0 0       0 if($concept=~/C[0-9][0-9][0-9][0-9][0-9][0-9][0-9]/) {
131 0         0 return 1;
132             }
133             else {
134 0         0 return 0;
135             }
136             }
137              
138             # subroutine to check if TUI is valid
139             # input : $tui <- string containing a tui
140             # output: true | false <- integer indicating if the tui is valid
141             sub _validTui {
142              
143 0     0   0 my $self = shift;
144 0         0 my $st = shift;
145            
146 0 0       0 if($st=~/T[0-9][0-9][0-9]/) {
147 0         0 return 1;
148             }
149             else {
150 0         0 return 0;
151             }
152             }
153              
154             # sets up the error handler module
155             # input : $parameters <- reference to a hash
156             # output: $self
157             sub new {
158              
159 44     44 0 64 my $self = {};
160 44         53 my $className = shift;
161            
162             # Bless the object.
163 44         61 bless($self, $className);
164              
165 44         109 return $self;
166             }
167             1;
168             __END__