| 1 | |||
| 2 | =head1 NAME | ||
| 3 | |||
| 4 | WebService::UMLSKS::Query - Query UMLS web services with the query arguments like query term and method name. | ||
| 5 | |||
| 6 | =head1 SYNOPSIS | ||
| 7 | |||
| 8 | =head2 Basic Usage | ||
| 9 | |||
| 10 | use WebService::UMLSKS::Query; | ||
| 11 | use WebService::UMLSKS::ConnectUMLS; | ||
| 12 | |||
| 13 | my $query = new Query; | ||
| 14 | my $c = new ConnectUMLS; | ||
| 15 | my $method_name = 'findCUIByExact'; | ||
| 16 | |||
| 17 | $cui = $query->runQuery( | ||
| 18 | $service, | ||
| 19 | $method_name, | ||
| 20 | { | ||
| 21 | casTicket => $c->get_pt(), | ||
| 22 | searchString => SOAP::Data->type(string => $term), | ||
| 23 | language => 'ENG', | ||
| 24 | release => '2010AA', | ||
| 25 | includeSuppressibles => 'false', | ||
| 26 | }, | ||
| 27 | ); | ||
| 28 | |||
| 29 | $query -> runQuery($service, $query_term, $method_name, @params); | ||
| 30 | |||
| 31 | |||
| 32 | =head1 DESCRIPTION | ||
| 33 | |||
| 34 | This module has package Query which has many subroutines like 'new', 'runQuery' and serialization methods. | ||
| 35 | This module takes $service object, query term, method name and different parameters of query as arguments. | ||
| 36 | For valid CUI, it queries UMLS and gets back the hash reference of the information. | ||
| 37 | |||
| 38 | =head2 SUBROUTINES | ||
| 39 | |||
| 40 | The subroutines are as follows: | ||
| 41 | |||
| 42 | =cut | ||
| 43 | |||
| 44 | |||
| 45 | ############################################################################### | ||
| 46 | ########## CODE STARTS HERE ################################################# | ||
| 47 | |||
| 48 | use SOAP::Lite; | ||
| 49 | use warnings; | ||
| 50 | use strict; | ||
| 51 | no warnings qw/redefine/; | ||
| 52 | |||
| 53 | |||
| 54 | package WebService::UMLSKS::Query; | ||
| 55 | |||
| 56 | |||
| 57 | use Log::Message::Simple qw[msg error debug]; | ||
| 58 | |||
| 59 | =head2 new | ||
| 60 | |||
| 61 | This sub creates a new object of Query. | ||
| 62 | |||
| 63 | =cut | ||
| 64 | |||
| 65 | sub new { | ||
| 66 | my $class = shift; | ||
| 67 | my $self = {}; | ||
| 68 | bless( $self, $class ); | ||
| 69 | return $self; | ||
| 70 | } | ||
| 71 | |||
| 72 | |||
| 73 | =head2 runQuery | ||
| 74 | |||
| 75 | This sub takes $service object, query term, method name and different parameters of query as arguments. | ||
| 76 | It returns empty if the term does not exist in database or if the web services are not working correctly. | ||
| 77 | It returns CUI if the query input was a term. | ||
| 78 | If the query input is CUI, it displays preferred term, definitions with source information and CUI for it. | ||
| 79 | |||
| 80 | |||
| 81 | =cut | ||
| 82 | |||
| 83 | sub runQuery { | ||
| 84 | my $self = shift; | ||
| 85 | my $service = shift; | ||
| 86 | my $qterm = shift; | ||
| 87 | |||
| 88 | my $method_name = shift; | ||
| 89 | my @params = @_; | ||
| 90 | |||
| 91 | # added for debugging | ||
| 92 | my $verbose = 0; | ||
| 93 | #warn sprintf "----> %s(%s)\n", $method_name, join(', ', @params); | ||
| 94 | |||
| 95 | use Time::HiRes qw(usleep ualarm gettimeofday tv_interval); | ||
| 96 | |||
| 97 | #open(TIME,">>","time.txt") or die("Error: cannot open file 'time.txt'\n"); | ||
| 98 | |||
| 99 | my $t0 = [gettimeofday]; | ||
| 100 | |||
| 101 | # Calling the UMLSKS Web service and receiving the hash reference. | ||
| 102 | my $object_ref = $service->$method_name(@params); | ||
| 103 | |||
| 104 | my $t0_t1 = tv_interval($t0); | ||
| 105 | msg("\n $qterm : $t0_t1 secs\n",$verbose); | ||
| 106 | |||
| 107 | |||
| 108 | |||
| 109 | # If the returned reference is not defined then display error message. | ||
| 110 | |||
| 111 | if ( !defined $object_ref ) { | ||
| 112 | print "No information for this CUI."; | ||
| 113 | return 'undefined'; | ||
| 114 | } | ||
| 115 | else { | ||
| 116 | |||
| 117 | # If the returned contents array is empty then display error message. | ||
| 118 | |||
| 119 | my $contents_ref = $object_ref->{"contents"}; | ||
| 120 | # my @temp = @$contents_ref; | ||
| 121 | # print "\n contents : @temp"; | ||
| 122 | #if (!defined $contents_ref){ | ||
| 123 | # return 'empty'; | ||
| 124 | #} | ||
| 125 | |||
| 126 | if (!defined $contents_ref | !$contents_ref) { | ||
| 127 | |||
| 128 | # if content_ref is empty | ||
| 129 | #print "There is no information for your query term/CUI in database."; | ||
| 130 | return 'empty'; | ||
| 131 | |||
| 132 | } | ||
| 133 | |||
| 134 | |||
| 135 | # If UMLSKS returns a defined hash reference then, store and print the information received. | ||
| 136 | |||
| 137 | else { | ||
| 138 | |||
| 139 | if ( $method_name =~ /findCUIByExact/ ) { | ||
| 140 | my @cuilist = (); | ||
| 141 | #c 1# $contents_ref = $object_ref->{"contents"}; | ||
| 142 | foreach my $val (@$contents_ref) { | ||
| 143 | while ( my ( $key, $value ) = each(%$val) ) { | ||
| 144 | if ( $key =~ /CUI/ ) { | ||
| 145 | my $cui = $value; | ||
| 146 | if($cui) | ||
| 147 | { | ||
| 148 | push(@cuilist,$cui); | ||
| 149 | # return $cui; | ||
| 150 | |||
| 151 | } | ||
| 152 | #else | ||
| 153 | #{ | ||
| 154 | # return 'empty'; | ||
| 155 | #} | ||
| 156 | |||
| 157 | } | ||
| 158 | } | ||
| 159 | } | ||
| 160 | if($#cuilist != -1){ | ||
| 161 | return \@cuilist; | ||
| 162 | } | ||
| 163 | else | ||
| 164 | { | ||
| 165 | return 'empty'; | ||
| 166 | } | ||
| 167 | |||
| 168 | } | ||
| 169 | else { | ||
| 170 | |||
| 171 | return $object_ref; | ||
| 172 | |||
| 173 | |||
| 174 | } | ||
| 175 | } | ||
| 176 | } | ||
| 177 | } | ||
| 178 | |||
| 179 | #-------Following code is taken from the reference program provided by Olivier B. | ||
| 180 | #-------and is modified according to the need of the application. | ||
| 181 | |||
| 182 | # UMLSKS returns the information of UMLSKS specific type, so we have create | ||
| 183 | # a SOAP serializer for each UMLSKS WS mwthods. | ||
| 184 | |||
| 185 | # serialization -- UMLSKS-specific types | ||
| 186 | |||
| 187 | # NB: create one SOAP::Serializer::as_XXX | ||
| 188 | # for each complex type XXX found in the UMLSKS WS methods | ||
| 189 | # (see the WSDL file) | ||
| 190 | |||
| 191 | =head2 SOAP::Serializer::as_CurrentUMLSRequest | ||
| 192 | |||
| 193 | This is SOAP method for serializing UMLS specific types. | ||
| 194 | |||
| 195 | =cut | ||
| 196 | |||
| 197 | sub SOAP::Serializer::as_CurrentUMLSRequest { | ||
| 198 | my ( $self, $value, $name, $type, $attr ) = @_; | ||
| 199 | return [ $name, { 'xsi:type' => 'CurrentUMLSRequest', %$attr }, $value ]; | ||
| 200 | } | ||
| 201 | |||
| 202 | =head2 SOAP::Serializer::as_ConceptIdExactRequest | ||
| 203 | |||
| 204 | This is SOAP method for serializing UMLS specific types. | ||
| 205 | |||
| 206 | =cut | ||
| 207 | |||
| 208 | sub SOAP::Serializer::as_ConceptIdExactRequest { | ||
| 209 | my ( $self, $value, $name, $type, $attr ) = @_; | ||
| 210 | return [ $name, { 'xsi:type' => 'ConceptIdExactRequest', %$attr }, $value ]; | ||
| 211 | } | ||
| 212 | |||
| 213 | =head2 SOAP::Serializer::as_ConceptIdWordRequest | ||
| 214 | |||
| 215 | This is SOAP method for serializing UMLS specific types. | ||
| 216 | |||
| 217 | =cut | ||
| 218 | |||
| 219 | sub SOAP::Serializer::as_ConceptIdWordRequest { | ||
| 220 | my ( $self, $value, $name, $type, $attr ) = @_; | ||
| 221 | return [ $name, { 'xsi:type' => 'ConceptIdWordRequest', %$attr }, $value ]; | ||
| 222 | } | ||
| 223 | |||
| 224 | =head2 SOAP::Serializer::as_SourceRequest | ||
| 225 | |||
| 226 | This is SOAP method for serializing UMLS specific types. | ||
| 227 | |||
| 228 | =cut | ||
| 229 | |||
| 230 | sub SOAP::Serializer::as_SourceRequest { | ||
| 231 | my ( $self, $value, $name, $type, $attr ) = @_; | ||
| 232 | return [ $name, { 'xsi:type' => 'SourceRequest', %$attr }, $value ]; | ||
| 233 | } | ||
| 234 | |||
| 235 | =head2 SOAP::Serializer::as_RestrictedSearchStringRequest | ||
| 236 | |||
| 237 | This is SOAP method for serializing UMLS specific types. | ||
| 238 | |||
| 239 | =cut | ||
| 240 | |||
| 241 | sub SOAP::Serializer::as_RestrictedSearchStringRequest { | ||
| 242 | my ( $self, $value, $name, $type, $attr ) = @_; | ||
| 243 | return [ | ||
| 244 | $name, { 'xsi:type' => 'RestrictedSearchStringRequest', %$attr }, $value | ||
| 245 | ]; | ||
| 246 | } | ||
| 247 | |||
| 248 | =head2 SOAP::Serializer::as_ConceptRequest | ||
| 249 | |||
| 250 | This is SOAP method for serializing UMLS specific types. | ||
| 251 | |||
| 252 | =cut | ||
| 253 | |||
| 254 | sub SOAP::Serializer::as_ConceptRequest { | ||
| 255 | my ( $self, $value, $name, $type, $attr ) = @_; | ||
| 256 | return [ $name, { 'xsi:type' => 'ConceptRequest', %$attr }, $value ]; | ||
| 257 | } | ||
| 258 | |||
| 259 | =head2 SOAP::Serializer::as_TermGroup | ||
| 260 | |||
| 261 | This is SOAP method for serializing UMLS specific types. | ||
| 262 | |||
| 263 | =cut | ||
| 264 | |||
| 265 | sub SOAP::Serializer::as_TermGroup { | ||
| 266 | my ( $self, $value, $name, $type, $attr ) = @_; | ||
| 267 | return [ $name, { 'xsi:type' => 'TermGroup', %$attr }, $value ]; | ||
| 268 | } | ||
| 269 | |||
| 270 | 1; | ||
| 271 | |||
| 272 | #-------------------------------PERLDOC STARTS HERE------------------------------------------------------------- | ||
| 273 | |||
| 274 | |||
| 275 | =head1 SEE ALSO | ||
| 276 | |||
| 277 | ValidateTerm.pm GetUserData.pm ConnectUMLS.pm ws-getUMLSInfo.pl ws-getAllowablePath.pl | ||
| 278 | |||
| 279 | =cut | ||
| 280 | |||
| 281 | |||
| 282 | =head1 AUTHORS | ||
| 283 | |||
| 284 | Mugdha Choudhari, University of Minnesota Duluth | ||
| 285 | E<lt>chou0130 at d.umn.eduE<gt> | ||
| 286 | |||
| 287 | Ted Pedersen, University of Minnesota Duluth | ||
| 288 | E<lt>tpederse at d.umn.eduE<gt> | ||
| 289 | |||
| 290 | |||
| 291 | |||
| 292 | |||
| 293 | =head1 COPYRIGHT | ||
| 294 | |||
| 295 | Copyright (C) 2011, Mugdha Choudhari, Ted Pedersen | ||
| 296 | |||
| 297 | This program is free software; you can redistribute it and/or modify | ||
| 298 | it under the terms of the GNU General Public License as published by | ||
| 299 | the Free Software Foundation; either version 2 of the License, or (at | ||
| 300 | your option) any later version. | ||
| 301 | |||
| 302 | This program is distributed in the hope that it will be useful, but | ||
| 303 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 304 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 305 | General Public License for more details. | ||
| 306 | |||
| 307 | You should have received a copy of the GNU General Public License | ||
| 308 | along with this program; if not, write to | ||
| 309 | The Free Software Foundation, Inc., | ||
| 310 | 59 Temple Place - Suite 330, | ||
| 311 | Boston, MA 02111-1307, USA. | ||
| 312 | |||
| 313 | =cut | ||
| 314 | |||
| 315 | #---------------------------------PERLDOC ENDS HERE--------------------------------------------------------------- |