script/ws-getUMLSInfo.pl untested

filter: Statementstmt 0.0% 0 / 143 Branchbran 0.0% 0 / 36 Conditioncond 0.0% 0 / 14 MC/DCmcdc 0.0% 0 / 9 Subroutinesub 0.0% 0 / 14 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 218 CC 1 SCAR 6.9
CC
1
Cov
0%
SOAP::Serializer::as_boolean
2.0
SOAP::Serializer::as_ArrayOf_xsd_string
2.0
BEGIN
2.0
CRAP 2.0
1 #!/usr/bin/env perl
2  
3  
4 #---------------------------PERLDOC STARTS HERE------------------------------------------------------------------
5  
6 =head1 NAME
7  
8 ws-getUMLSInfo
9  
10 =cut
11  
12 #---------------------------------------------------------------------------------------------------------------------
13  
14  
15 =head1 DESCRIPTION
16  
17  
18 This program authenticates user by asking for valid username and password to connect to UMLSKS. Once the user is
19 authenticated he can enter different terms and CUIs and get back the information about them from the UMLSKS
20 Metathesaurus database. The program queries SNOMED-CT database with the term/CUI user enters and displays information
21 like its source, CUI, definitions, etc.
22  
23 =cut
24  
25  
26 =head1 SYNOPSIS
27  
28 =head2 Basic Usuage
29  
30 =pod
31  
32 perl ws-getUMLSInfo.pl --verbose 1 --sources SNOMEDCT,MSH --rels PAR,CHD --config configfilename --login loginfilename
33  
34 --verbose: Sets verbose to true if you give value 1
35 and thus displays debug information in log for the user.
36  
37 --sources : UMLS sources can be specified by providing list of sources seperated
38 by comma. These sources will be used to query and retrieve the information.
39  
40 --rels : UMLS relations can be specified by providing list of relations seperated
41 by comma. These relations will be used to query and retrieve the information.
42  
43 --config : Instead of providing sources and relations on command line, they can be
44 specified using a configuration file, which can be provided with this option.
45 It takes complete path and name of the file. The config file is expected in following format:
46  
47  
48 =over
49  
50 =item SAB :: include SNOMEDCT,MSH
51  
52 =item REL :: include PAR
53
54 =back
55  
56  
57 -login : User can specify login credentials through the file, which should of of form:
58  
59 =over
60  
61 =item username :: xyz
62  
63 =item password :: pqr
64
65 =back
66  
67 Follwing is a sample output of the program
68  
69 =over
70  
71 =item Enter username to connect to UMLSKS:mchoudhari
72  
73 =item Enter password:
74
75 =item Enter query term/CUI:migraine
76  
77 =item Query term:migraine
78
79 =item Prefered Term:Migraine Disorders
80
81 =item DEF:neural condition characterized by a severe recurrent vascular headache, usually on one side of the head, often accompanied by nausea, vomiting, and photophobia, sometimes preceded by sensory disturbances; triggers include allergic reactions, excess carbohydrates or iodine in the diet, alcohol, bright lights or loud noises.
82  
83 =item SAB:CSP
84  
85 =item DEF:A class of disabling primary headache disorders, characterized by recurrent unilateral pulsatile headaches. The two major subtypes are common migraine (without aura) and classic migraine (with aura or neurological symptoms). (International Classification of Headache Disorders, 2nd ed. Cephalalgia 2004: suppl 1)
86  
87 =item SAB:MSH
88  
89 =item CUI/s associated:C0149931
90  
91 =item Enter query term/CUI:stop
92  
93 =back
94  
95  
96 =head2 Modules/Packages
97  
98 =pod
99  
100 This program uses following packages:
101  
102 =over
103
104 =item package ConnectUMLS
105  
106 ->sub ConnectUMLS::get_pt to get the proxy ticket using a web service.
107  
108 ->sub ConnectUMLS::connect_umls to connect to UMLS by sending username
109 and password and getting back a proxy ticket.
110  
111 =item package ValidateTerm
112  
113 ->sub ValidateTerm::validateTerm to accepts input term and validates it
114 for a valid term or a valid CUI.
115  
116 =item package GetUserData
117  
118 ->sub GetUserData::getUserDetails to get username and password from the user.
119  
120 =item package Query
121  
122 ->sub Query::runQuery which takes method name, service and other parameters as argument and calls the web service.
123 It also displays the information received from the web service and other error messages.
124  
125 =back
126  
127 Other subs which provide the serialization of complex types and UMLSKS specific types.
128  
129 =cut
130  
131 #---------------------------------------------------------------------------------------------------------------------------
132  
133 =head2 Structure
134  
135 =pod
136  
137 The authentication process is done by 'authenticate' module and includes four steps:
138  
139 =over
140  
141 =item 1. sub Initialize Authentication service.
142  
143 =item 2. Get username and password from user to get proxy granting ticket.
144  
145 =item 3. Get proxy ticket using the proxy granting ticket.
146  
147 =item 4. Initialize UMLSKS web service using SOAP::Lite.
148  
149 =cut
150  
151 =back
152  
153 =pod
154  
155 This programs reads input from the authenticated user and decides whether the input is a valid medical term or valid CUI.
156 A valid CUI starts with 'C' followed by exactly seven digits and all seven digits cannot be zeros. An invalid term is the
157 one that does not exist in UMLSKS database.It gives an error message if user enters invalid term or CUI.
158 Then it queries the respective web service with source as SNOMED-CT, UMLSKS version as 2009AA, language as English and other parameters. If the input is a medical term, then
159 findCUIByExact web service is called which returns a CUI for the entered term. Then getConceptProperties webservice is
160 called with the returned CUI, which returns the information about the concept. If the user enters a CUI, directly
161 getConceptProperties web service is called to get the information.
162  
163 =cut
164  
165 #------------------------------PERLDOC ENDS HERE------------------------------------------------------------------------------
166  
167  
168 ###############################################################################
169 ########## CODE STARTS HERE #################################################
170  
171  
172 use strict;
173 use warnings;
174 use SOAP::Lite;
175 use Term::ReadKey;
176  
177 #use lib "/home/mugdha/UMLS-HSO/UMLS-HSO/WebService-UMLSKS-Similarity/lib";
178  
179 use WebService::UMLSKS::GetUserData;
180 use WebService::UMLSKS::ValidateTerm;
181 use WebService::UMLSKS::Query;
182 use WebService::UMLSKS::ConnectUMLS;
183 use WebService::UMLSKS::DisplayInfo;
184 use WebService::UMLSKS::Similarity;
185 use Getopt::Long;
186 no warnings qw/redefine/;
187  
188 #Program that connects to UMLSKS and queries the UMLS through the UMLSKS API to return information for an entered term or CUI.
189  
190 # Author : Mugdha
191 # Reference: Program provided by Olivier B., NLM.
192  
193 #use SOAP::Lite +trace => 'debug';
194  
195 # This is a verbose variable which is set using the command line argument.
196 # This is set to true if you use --verbose option.
197 # This is set to false if you use --noverbose option.
198  
199 my $verbose = "";
200 my $sources = "";
201 my $relations = "";
202 my $similarity;
203 my $config_file = "";
204 my $login_file = "";
205 my $service = "";
206 my $cui = "";
207  
208 #GetOptions( 'verbose!' => \$verbose );
209  
210 GetOptions( 'verbose=s' => \$verbose , 'sources=s' => \$sources , 'rels=s' =>\$relations, 'config=s' =>\$config_file,
211 'login=s' => \$login_file );
212  
213 #print "\n sources : $sources";
214  
215 if($config_file ne "")
216 {
217 #print "\n got config file";
218 $similarity = WebService::UMLSKS::Similarity->new({"config" => $config_file});
219
220 }
221  
222 else
223 {
224 if($sources eq "" && $relations eq "")
225 {
226 # use default things
227 #print "\n creating default object of similarity";
228 $similarity = WebService::UMLSKS::Similarity->new();
229 }
230 else{
231  
232 if($sources ne "" && $relations ne "")
233 {
234 # user specified sources through command line
235 my @source_list = split ("," , $sources);
236 my @relation_list = split ("," , $relations);
237 $similarity = WebService::UMLSKS::Similarity->new({"sources" => \@source_list,
238 "rels" => \@relation_list } );
239
240 #$ConfigurationParameters{"SAB"} = \@sources_list;
241 }
242 elsif($relations ne "" )
243 {
244 # user specified rels through command line
245 my @relation_list = split ("," , $relations);
246 $similarity = WebService::UMLSKS::Similarity->new({ "rels" => \@relation_list });
247
248 #$ConfigurationParameters{"REL"} = \@relation_list;
249 }
250 elsif($sources ne "")
251 {
252 #print"\n got a source list";
253 my @source_list = split ("," , $sources);
254 #print "\n sources : @source_list";
255 $similarity = WebService::UMLSKS::Similarity->new({"sources" => \@source_list} );
256
257 }
258  
259 }
260  
261 }
262 my @sources = @{$similarity->{'SAB'}};
263 my @relations = @{$similarity->{'REL'}};
264  
265  
266  
267 # This is used to continue asking for the new term to user unless you enter 'stop'.
268  
269 my $continue = 1;
270 my $object_ref;
271  
272 # Creating object of class GetUserData and call the sub getUserDetails.
273 # Receive a $service object if the user is a valid user.
274  
275 my $g = WebService::UMLSKS::GetUserData->new;
276 #my $service = $g->getUserDetails($verbose);
277  
278 if(defined $login_file && $login_file ne "")
279 {
280 # Login details specified through the file
281 # call sub getService using object of GetUserData
282 # Receive a $service object if the user is a valid user.
283
284 my $username = "";
285 my $pwd = "";
286
287 open( LOGIN, $login_file )
288 or die("Error: cannot open configuration file '$login_file'\n");
289  
290 my @login_details = <LOGIN>;
291 foreach my $detail (@login_details){
292
293 #msg( "\n $detail", $verbose);
294 $detail =~ /\s*(.*)\s*::\s*(.*?)$/;
295 #print "\n $1 \t $2";
296 my $detail_name = $1;
297 my $detail_value = $2;
298 chomp($detail_value);
299 chomp($detail_name);
300 if($detail_name ne "" && $detail_value ne ""){
301 if($detail_name =~ /\b[Uu]sername\b/){
302 $username = $detail_value;
303 }
304 if($detail_name =~ /\b[pP]assword\b|\b[Pp]wd\b/){
305 $pwd = $detail_value;
306 }
307 }
308 else
309 {
310 print "\n Invalid login file";
311 exit;
312 }
313
314 }
315 $service = $g->getService($verbose, $username, $pwd);
316 }
317  
318 else
319 {
320 # call the sub getUserDetails.
321 # Receive a $service object if the user is a valid user.
322  
323 $service = $g->getUserDetails($verbose);
324
325 }
326  
327  
328  
329 # User enetered wrong username or password.
330  
331 if ( $service == 0 ) {
332 $continue = 0;
333 }
334  
335 # Creating Connect object to call sub get_pt while forming a query.
336  
337 my $c = WebService::UMLSKS::ConnectUMLS->new;
338  
339  
340 #print $service;
341  
342 while ( $continue == 1 ) {
343  
344 # After the authentication, accept a query term or CUI from the user.
345  
346 print "\nEnter query term/CUI:";
347 my $term = <>;
348  
349 # Remove white spaces.
350  
351 chomp($term);
352  
353 # If user enters 'stop', exit the program.
354 if ( $term =~ /stop/i ) {
355 exit;
356 }
357  
358 # Else continue with asking the new query term.
359  
360 else {
361  
362 my $qterm = $term;
363  
364 #print "term is $term";
365  
366 # Validate the term by passing it to the sub validateTerm which belongs to class getTerm.
367 # Create object of class getTerm to access the sub validateTerm.
368  
369 my $valid = WebService::UMLSKS::ValidateTerm->new;
370 my $isTerm_CUI = $valid->validateTerm($term);
371  
372 #print $isTerm_CUI;
373
374
375 if($isTerm_CUI eq 'invalid')
376 {
377 print "\n Your input is not valid CUI.";
378 next;
379 }
380  
381 # Depending on the value returned by validateTerm form a query for UMLSKS.
382 # Creating object of query and passing the method name along with parameters.
383  
384 my $query = WebService::UMLSKS::Query->new;
385 my @cui_list = ();
386
387
388
389  
390 # If the input entered by user is term, call findCUIByExact webservice, to get back the CUI.
391  
392 if ( $isTerm_CUI eq 'term' ) {
393 my $cuilist;
394 # following sub describes the details like the method name to be called, term to be searched etc.
395 $service->readable(1);
396 $cuilist = $query->runQuery(
397 $service, $qterm,
398 'findCUIByExact',
399 {
400 casTicket => $c->get_pt(),
401  
402 # use SOAP::Data->type in order to prevent
403 # UTF-8 strings from being encoded into base64
404 # http://cookbook.soaplite.com/#internationalization%20and%20encoding
405 searchString => SOAP::Data->type( string => $qterm ),
406 language => 'ENG',
407 release => '2009AA',
408 #SABs => [( $source )],
409 #SABs => [($sources[0])],
410 SABs => [(@sources)],
411 #SABs => [qw(SNOMEDCT)],
412 includeSuppressibles => 'false',
413 },
414 );
415
416
417  
418 # runQuery returns undefined value if the entered term does not exist in the UMLS database.
419
420 if ($cuilist eq "empty") {
421 print "Term/CUI does not exist in currently configured sources.";
422 next;
423 }
424  
425 # If the term exists in UMLS, set the returned CUI to current query term, and query again
426 # with the CUI to get the information about the CUI.
427  
428 else {
429 if ( $cui =~ /empty|undefined/ ) { # change made , added undefined to return values of run query
430 print "\nThere is no information for your input in UMLS using current configuaration.";
431 next;
432 }
433 else {
434  
435 @cui_list = @$cuilist;
436 $term = $cui_list[0];
437  
438 #print "now term is $cui";
439 $isTerm_CUI = 'cui';
440 }
441 }
442  
443 }
444  
445
446  
447 # If the input entered by the user is a CUI, call getConceptProperties web service and get back the information.
448  
449 if ( $isTerm_CUI eq 'cui' ) {
450  
451 #print"calling getconceptproperties";
452  
453 $service->readable(1);
454 $object_ref = $query->runQuery(
455 $service, $qterm,
456 'getConceptProperties',
457 {
458 casTicket => $c->get_pt(),
459  
460 # use SOAP::Data->type in order to prevent
461 # UTF-8 strings from being encoded into base64
462 # http://cookbook.soaplite.com/#internationalization%20and%20encoding
463 CUI => SOAP::Data->type( string => $term ),
464  
465 # CUI => "asfa",
466 language => 'ENG',
467 release => '2009AA',
468 SABs => [(@sources)],
469 #SABs => [qw( SNOMEDCT )],
470 includeConceptAttrs => 'false',
471 includeSemanticTypes => 'false',
472 includeTerminology => 'false',
473 includeDefinitions => 'true',
474 includeSuppressibles => 'false',
475  
476 # includeRelations => 'true',
477 # relationTypes => [ 'PAR' ],
478 },
479 );
480  
481
482 unless($object_ref =~ /empty/){
483 print "\n Query term:$qterm";
484 my $display_obj = WebService::UMLSKS::DisplayInfo->new;
485 my $object_f = $display_obj->display_object($object_ref);
486 unless(!@cui_list){
487 print "\n CUI/s associated : @cui_list";
488 }
489 print "\n";
490 }
491
492 else
493 {
494 print "\nThere is no information for your input in UMLS using current configuaration.";
495 }
496
497 }
498
499  
500 }
501 }
502  
503 # Serialization subroutines
504  
505 # serialization -- non-Perl types / complex types
506  
507 =head1 SUBROUTINES
508  
509 =head2 SOAP::Serializer::as_boolean
510  
511 subroutine for serialization -- non-Perl types / complex types
512  
513 =cut
514  
515 sub SOAP::Serializer::as_boolean {
516 my ( $self, $value, $name, $type, $attr ) = @_;
517 return [ $name, { 'xsi:type' => 'xsd:boolean', %$attr }, $value ];
518 }
519  
520 =head2 SOAP::Serializer::as_ArrayOf_xsd_string
521  
522 subroutine for serialization -- non-Perl types / complex types
523  
524 =cut
525  
526 sub SOAP::Serializer::as_ArrayOf_xsd_string {
527 my ( $self, $value, $name, $type, $attr ) = @_;
528 return [ $name, { 'xsi:type' => 'array', %$attr }, $value ];
529 }
530  
531 #-------------------------------PERLDOC STARTS HERE-------------------------------------------------------------
532  
533  
534 =head1 SEE ALSO
535  
536 ValidateTerm.pm GetUserData.pm Query.pm ConnectUMLS.pm
537  
538 =cut
539  
540 =head1 AUTHORS
541  
542 Mugdha Choudhari University of Minnesota Duluth
543 E<lt>chou0130 at d.umn.eduE<gt>
544  
545 Ted Pedersen, University of Minnesota Duluth
546 E<lt>tpederse at d.umn.eduE<gt>
547  
548  
549  
550  
551 =head1 COPYRIGHT
552  
553 Copyright (C) 2011, Mugdha Choudhari, Ted Pedersen
554  
555 This program is free software; you can redistribute it and/or modify
556 it under the terms of the GNU General Public License as published by
557 the Free Software Foundation; either version 2 of the License, or (at
558 your option) any later version.
559  
560 This program is distributed in the hope that it will be useful, but
561 WITHOUT ANY WARRANTY; without even the implied warranty of
562 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
563 General Public License for more details.
564  
565 You should have received a copy of the GNU General Public License
566 along with this program; if not, write to
567 The Free Software Foundation, Inc.,
568 59 Temple Place - Suite 330,
569 Boston, MA 02111-1307, USA.
570  
571 =cut
572  
573 #---------------------------------PERLDOC ENDS HERE---------------------------------------------------------------