lib/WebService/UMLSKS/GetCUIs.pm untested

filter: Statementstmt 0.0% 0 / 116 Branchbran 0.0% 0 / 18 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 23 Podpod 0.0% 0 / 16 totaltotal 0.0% 0 / 173 CC 10 SCAR 24.8
CC
10
Cov
0%
format_object
42.0
format_homogeneous_hash
20.0
extract_object_class
6.0
CRAP 12.0
1  
2 =head1 NAME
3  
4 WebService::UMLSKS::GetCUIs - Get all the preferred terms and CUIs of the input term.
5  
6 =head1 SYNOPSIS
7  
8 =head2 Basic Usage
9  
10  
11 use WebService::UMLSKS::GetCUIs;
12 use WebService::UMLSKS::ConnectUMLS;
13
14 my $getCUIs_obj = new GetCUIs;
15
16 my $CUIs_ref = $getCUIs_obj->get_CUI_info($service,$term,\@sources,$verbose);
17
18  
19 =head1 DESCRIPTION
20  
21 This module has package GetCUIs which has subroutines 'new',get_CUI_info, format _object, format_scalar, format_homogenous_hash, format_homogenous_array and extract_object_class.
22 This module returns the hash of all preferred terms and CUIs for the input Term.
23  
24 =head1 SUBROUTINES
25  
26 The subroutines are as follows:
27  
28 =cut
29  
30 ###############################################################################
31 ########## CODE STARTS HERE #################################################
32  
33 #use lib "/home/mugdha/UMLS-HSO/UMLS-HSO/WebService-UMLSKS-Similarity/lib";
34  
35 use strict;
36 use SOAP::Lite;
37 use warnings;
38 use WebService::UMLSKS::ConnectUMLS;
39 no warnings qw/redefine/;
40 use WebService::UMLSKS::Similarity;
41  
42  
43 package WebService::UMLSKS::GetCUIs;
44  
45  
46 use Log::Message::Simple qw[msg error debug];
47  
48 my $got_term = 0;
49 my $term = "";
50 my $cui = "";
51 my %TermCUI = ();
52  
53  
54  
55  
56  
57  
58 # Creating Connect object to call sub get_pt while forming a query.
59  
60 my $c = WebService::UMLSKS::ConnectUMLS->new;
61 my $verbose;
62  
63 =head2 new
64  
65 This sub creates a new object of GetCUIs.
66  
67 =cut
68  
69 sub new {
70 my $class = shift;
71 my $self = {};
72 bless( $self, $class );
73 return $self;
74 }
75  
76 =head2 get_CUI_info
77  
78 This sub queries 'findCUIByExact' by calling run_query sub.
79  
80 =cut
81  
82 sub get_CUI_info
83 {
84 my $self = shift;
85 my $service = shift;
86 my $query_term = shift;
87 my $s_ref = shift;
88 my $ver = shift;
89
90 $verbose = $ver;
91 %TermCUI = ();
92
93 my @sources = @$s_ref;
94
95 msg("\n In getCUIs sources are : @sources", $verbose);
96 # query
97 $service->readable(1);
98 my $ws_result_ref = run_query($service,
99
100 'findCUIByExact',
101 {
102 casTicket => $c->get_pt(),
103 # use SOAP::Data->type in order to prevent
104 # UTF-8 strings from being encoded into base64
105 # http://cookbook.soaplite.com/#internationalization%20and%20encoding
106 searchString => SOAP::Data->type(string => $query_term),
107 language => 'ENG',
108 release => '2010AB',
109 SABs => [(@sources)],
110 #SABs => [qw( SNOMEDCT )],
111 includeSuppressibles => 'false',
112 },
113 );
114 format_object($ws_result_ref);
115 return(\%TermCUI);
116  
117 }
118  
119  
120 =head2 run_query
121  
122 This sub runs the query to 'findCUIByExact' to get back all the CUIs for term.
123  
124 =cut
125  
126 sub run_query {
127 my $service = shift;
128 my $method_name = shift;
129 my @params = @_;
130  
131 #warn sprintf "----> %s(%s)\n", $method_name, join(', ', @params);
132 my $object_ref = $service->$method_name(@params);
133 return $object_ref;
134
135
136 }
137
138  
139 # This sub formats the structures returned by the web service. It calls
140 # the appropriate subroutines depending on the type of structure
141 # it is called with. If the input reference is a hash reference it calls
142 # format_homogenous_hash method. If input is array reference,
143 # it calls format homogenous array and simillarly for scalar input
144 # reference it calls format_scalar.
145  
146  
147 =head2 format_object
148  
149 This sub calls appropriate formatting sub.
150  
151 =cut
152  
153 sub format_object {
154
155 my $object_ref = shift;
156
157 #print "in format object";
158  
159 unless ( defined $object_ref ) {
160 return 'undefined';
161 }
162 else {
163 if ( $object_ref =~ /HASH/o ) {
164 return format_homogeneous_hash($object_ref);
165 }
166 elsif ( $object_ref =~ /ARRAY/o ) {
167 return format_homogeneous_array($object_ref);
168 }
169 elsif ( $object_ref =~ /SCALAR/o ) {
170 return format_scalar($object_ref);
171 }
172 elsif ( defined $object_ref ) {
173 return $object_ref;
174 }
175 else {
176 return 'term is not present';
177 }
178 }
179 }
180  
181  
182 =head2 format_scalar
183  
184 This sub formats scalar object.
185  
186 =cut
187  
188  
189 sub format_scalar {
190 my $scalar_ref = shift;
191 #my $q = shift;
192
193 #print "\n In format scalar";
194 #print "\n scalar_ref is $$scalar_ref";
195 format_object($$scalar_ref);
196
197 }
198  
199  
200  
201 =head2 format_homogeneous_hash
202  
203 This sub formats hash.
204  
205 =cut
206  
207 sub format_homogeneous_hash {
208
209 my $hash_ref = shift;
210 my @incl_rows = ();
211
212 foreach my $att (keys %$hash_ref) {
213 if($att =~ /\bCN\b/){
214 #print "\n att in hash :$att";
215 #print "\n value at att is $hash_ref->{$att}";
216 $got_term = 1;
217 $term = $hash_ref->{$att};
218
219 }
220 if($att =~ /\bCUI\b/){
221 #print "\n att in hash :$att";
222 #print "\n value at att is $hash_ref->{$att}";
223 $cui = $hash_ref->{$att};
224 if($got_term == 1){
225 $TermCUI{$term} = $cui;
226 $got_term = 0;
227 }
228
229 }
230 format_object($hash_ref->{$att});
231 }
232  
233 }
234  
235  
236  
237 =head2 format_homogeneous_array
238  
239 This sub formats array.
240  
241 =cut
242  
243 sub format_homogeneous_array {
244 my $array_ref = shift;
245 foreach my $val (@$array_ref) {
246 format_object($val);
247 }
248 }
249  
250  
251  
252  
253 =head2 extract_object_class
254  
255 This sub is used to remove exact reference to object.
256  
257 =cut
258  
259 sub extract_object_class {
260 my $object_ref = shift;
261  
262 # remove exact reference
263 $object_ref =~ s/\(0x[\d\w]+\)$//o;
264  
265 my ($class, $type) = split /=/, $object_ref;
266  
267 my $res = undef;
268 if ($type) {
269 $res = $class;
270 } else {
271 $res = $object_ref;
272 }
273  
274 return $res;
275 }
276  
277 =head2 printHash
278  
279 This sub prints argument hash.
280  
281 =cut
282  
283 sub printHash
284 {
285 my $ref = shift;
286 my %hash = %$ref;
287 foreach my $key(keys %hash)
288 {
289 print "\n $key => $hash{$key}";
290 }
291 }
292  
293  
294 #-------Following code is taken from the reference program provided by Olivier B.
295 #-------and is modified according to the need of the application.
296  
297 # UMLSKS returns the information of UMLSKS specific type, so we have create
298 # a SOAP serializer for each UMLSKS WS mwthods.
299  
300 # serialization -- UMLSKS-specific types
301  
302 # NB: create one SOAP::Serializer::as_XXX
303 # for each complex type XXX found in the UMLSKS WS methods
304 # (see the WSDL file)
305  
306 =head2 SOAP::Serializer::as_CurrentUMLSRequest
307  
308 This is SOAP method for serializing UMLS specific types.
309  
310 =cut
311  
312 sub SOAP::Serializer::as_CurrentUMLSRequest {
313 my ( $self, $value, $name, $type, $attr ) = @_;
314 return [ $name, { 'xsi:type' => 'CurrentUMLSRequest', %$attr }, $value ];
315 }
316  
317 =head2 SOAP::Serializer::as_ConceptIdExactRequest
318  
319 This is SOAP method for serializing UMLS specific types.
320  
321 =cut
322  
323 sub SOAP::Serializer::as_ConceptIdExactRequest {
324 my ( $self, $value, $name, $type, $attr ) = @_;
325 return [ $name, { 'xsi:type' => 'ConceptIdExactRequest', %$attr }, $value ];
326 }
327  
328 =head2 SOAP::Serializer::as_ConceptIdWordRequest
329  
330 This is SOAP method for serializing UMLS specific types.
331  
332 =cut
333  
334 sub SOAP::Serializer::as_ConceptIdWordRequest {
335 my ( $self, $value, $name, $type, $attr ) = @_;
336 return [ $name, { 'xsi:type' => 'ConceptIdWordRequest', %$attr }, $value ];
337 }
338  
339 =head2 SOAP::Serializer::as_SourceRequest
340  
341 This is SOAP method for serializing UMLS specific types.
342  
343 =cut
344  
345 sub SOAP::Serializer::as_SourceRequest {
346 my ( $self, $value, $name, $type, $attr ) = @_;
347 return [ $name, { 'xsi:type' => 'SourceRequest', %$attr }, $value ];
348 }
349  
350 =head2 SOAP::Serializer::as_RestrictedSearchStringRequest
351  
352 This is SOAP method for serializing UMLS specific types.
353  
354 =cut
355  
356 sub SOAP::Serializer::as_RestrictedSearchStringRequest {
357 my ( $self, $value, $name, $type, $attr ) = @_;
358 return [
359 $name, { 'xsi:type' => 'RestrictedSearchStringRequest', %$attr }, $value
360 ];
361 }
362  
363 =head2 SOAP::Serializer::as_ConceptRequest
364  
365 This is SOAP method for serializing UMLS specific types.
366  
367 =cut
368  
369 sub SOAP::Serializer::as_ConceptRequest {
370 my ( $self, $value, $name, $type, $attr ) = @_;
371 return [ $name, { 'xsi:type' => 'ConceptRequest', %$attr }, $value ];
372 }
373  
374 =head2 SOAP::Serializer::as_TermGroup
375  
376 This is SOAP method for serializing UMLS specific types.
377  
378 =cut
379  
380 sub SOAP::Serializer::as_TermGroup {
381 my ( $self, $value, $name, $type, $attr ) = @_;
382 return [ $name, { 'xsi:type' => 'TermGroup', %$attr }, $value ];
383 }
384  
385 #undef %TermCUI;
386  
387  
388 #-------------------------------PERLDOC STARTS HERE-------------------------------------------------------------
389  
390  
391  
392  
393 =head1 SEE ALSO
394  
395 ValidateTerm.pm GetUserData.pm Query.pm ws-getUMLSInfo.pl
396  
397 =cut
398  
399 =head1 AUTHORS
400  
401 Mugdha Choudhari, University of Minnesota Duluth
402 E<lt>chou0130 at d.umn.eduE<gt>
403  
404 Ted Pedersen, University of Minnesota Duluth
405 E<lt>tpederse at d.umn.eduE<gt>
406  
407  
408  
409  
410 =head1 COPYRIGHT
411  
412 Copyright (C) 2011, Mugdha Choudhari, Ted Pedersen
413  
414 This program is free software; you can redistribute it and/or modify
415 it under the terms of the GNU General Public License as published by
416 the Free Software Foundation; either version 2 of the License, or (at
417 your option) any later version.
418  
419 This program is distributed in the hope that it will be useful, but
420 WITHOUT ANY WARRANTY; without even the implied warranty of
421 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
422 General Public License for more details.
423  
424 You should have received a copy of the GNU General Public License
425 along with this program; if not, write to
426 The Free Software Foundation, Inc.,
427 59 Temple Place - Suite 330,
428 Boston, MA 02111-1307, USA.
429  
430 =cut
431  
432 #---------------------------------PERLDOC ENDS HERE---------------------------------------------------------------
433 1;