lib/WebService/UMLSKS/ValidateTerm.pm untested

filter: Statementstmt 0.0% 0 / 22 Branchbran 0.0% 0 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 5 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 35 CC 4 SCAR 24.0
CC
4
Cov
0%
validateTerm
20.0
new
2.0
BEGIN
2.0
CRAP 11.0
1  
2 =head1 NAME
3  
4 WebService::UMLSKS::ValidateTerm - Get the query term/CUI from calling program and validate the term/CUI.
5  
6 =head1 SYNOPSIS
7  
8 =head2 Basic Usage
9  
10 use WebService::UMLSKS::ValidateTerm;
11
12 print "\nEnter query term/CUI:";
13 my $term = <>;
14 my $valid = new ValidateTerm;
15 my $isTerm_CUI = $valid->validateTerm($term);
16  
17  
18 =head1 DESCRIPTION
19  
20 This module has package ValidateTerm which has two subroutines 'new' and 'validateTerm'.
21 This module takes the query term from calling program (getUMLSInfo.pl) and validates it.
22 It returns values depending on whether the query is term or CUI.
23  
24  
25 =head1 SUBROUTINES
26  
27 The subroutines are as follows:
28  
29 =cut
30  
31  
32 ###############################################################################
33 ########## CODE STARTS HERE #################################################
34  
35 use warnings;
36 use strict;
37  
38 no warnings qw/redefine/;
39  
40  
41 # This is ValidateTerm package which has two subroutines 'new' and 'validateTerm'.
42 package WebService::UMLSKS::ValidateTerm;
43  
44 # This sub creates a new object of ValidateTerm
45  
46 =head2 new
47  
48 This sub creates a new object of ValidateTerm.
49  
50 =cut
51  
52 sub new {
53 my $class = shift;
54 my $self = {};
55 bless( $self, $class );
56 return $self;
57 }
58  
59 # This sub tekes query term as an argument and validates it.
60 # It returns 2 if term is a valid CUI and returns 3 if term is a query term.
61 # It also displays error messages if the CUI is invalid.
62 # A valid CUI is a string thats starts with capital 'C' and is
63 # followed by seven digits and all digits are not zero at one time
64 # i.e., C0000000 is a invalid CUI.
65  
66 =head2 validateTerm
67  
68 This sub takes the query term from calling program (getUMLSInfo.pl) and validates it.
69 It returns '2' if term is valid CUI.
70 It returns '3' if term is valid term.
71 In the case of both invalid term or invalid CUI, it returns '10'.
72  
73 =cut
74  
75 sub validateTerm {
76  
77 my $self = shift;
78 my $term = shift;
79 if ( $term =~ /^[cC][0-9]/ ) {
80 if ( $term =~ /^C\d{7}$/ ) {
81 if ( $term =~ /C0000000/ ) {
82 #print "It is a invalid CUI.";
83 return 'invalid';
84 }
85 else {
86  
87 #print "it is a CUI";
88 return 'cui';
89 }
90 }
91 else {
92 #print "It is a invalid CUI.";
93 return 'invalid';
94 }
95 }
96 else {
97  
98 #print "term";
99 return 'term';
100 }
101  
102 }
103  
104 1;
105  
106 #-------------------------------PERLDOC STARTS HERE-------------------------------------------------------------
107  
108
109 =head1 SEE ALSO
110  
111 ConnectUMLS.pm GetUserData.pm Query.pm ws-getUMLSInfo.pl
112  
113 =cut
114  
115 =head1 AUTHORS
116  
117 Mugdha Choudhari, University of Minnesota Duluth
118 E<lt>chou0130 at d.umn.eduE<gt>
119  
120 Ted Pedersen, University of Minnesota Duluth
121 E<lt>tpederse at d.umn.eduE<gt>
122  
123  
124  
125  
126 =head1 COPYRIGHT
127  
128 Copyright (C) 2011, Mugdha Choudhari, Ted Pedersen
129  
130 This program is free software; you can redistribute it and/or modify
131 it under the terms of the GNU General Public License as published by
132 the Free Software Foundation; either version 2 of the License, or (at
133 your option) any later version.
134  
135 This program is distributed in the hope that it will be useful, but
136 WITHOUT ANY WARRANTY; without even the implied warranty of
137 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
138 General Public License for more details.
139  
140 You should have received a copy of the GNU General Public License
141 along with this program; if not, write to
142 The Free Software Foundation, Inc.,
143 59 Temple Place - Suite 330,
144 Boston, MA 02111-1307, USA.
145  
146 =cut
147  
148 #---------------------------------PERLDOC ENDS HERE---------------------------------------------------------------