WebService-UMLSKS-Similarity

 view release on metacpan or  search on metacpan

lib/WebService/UMLSKS/Query.pm  view on Meta::CPAN


=head1 NAME

WebService::UMLSKS::Query - Query UMLS web services with the query arguments like query term and method name.

=head1 SYNOPSIS

=head2 Basic Usage

  use WebService::UMLSKS::Query;
  use WebService::UMLSKS::ConnectUMLS;

  my $query = new Query;
  my $c = new ConnectUMLS;
  my $method_name = 'findCUIByExact';
  
  $cui = $query->runQuery(
		$service,
		$method_name,
		{
			casTicket => $c->get_pt(),
			searchString => SOAP::Data->type(string => $term),
			language     => 'ENG',
			release      => '2010AA',
			includeSuppressibles => 'false',
		},
	);

  $query -> runQuery($service, $query_term, $method_name, @params);


=head1 DESCRIPTION

This module has package Query which has many subroutines like 'new', 'runQuery' and serialization methods.
This module takes $service object, query term, method name and different parameters of query as arguments.
For valid CUI, it queries UMLS and gets back the hash reference of the information.

=head2 SUBROUTINES

The subroutines are as follows:

=cut


###############################################################################
##########  CODE STARTS HERE  #################################################

use SOAP::Lite;
use warnings;
use strict;
no warnings qw/redefine/;


package WebService::UMLSKS::Query;


use Log::Message::Simple qw[msg error debug];

=head2 new

This sub creates a new object of Query.

=cut

sub new {
	my $class = shift;
	my $self  = {};
	bless( $self, $class );
	return $self;
}


=head2 runQuery

This sub takes $service object, query term, method name and different parameters of query as arguments.
It returns empty if the term does not exist in database or if the web services are not working correctly.
It returns CUI if the query input was a term.
If the query input is CUI, it displays preferred term, definitions with source information and CUI for it.


=cut

sub runQuery {
	my $self        = shift;
	my $service     = shift;
	my $qterm = shift;
	
	my $method_name = shift;
	my @params      = @_;

	# added for debugging
	my $verbose = 0;
	#warn sprintf "----> %s(%s)\n", $method_name, join(', ', @params);

 	use Time::HiRes qw(usleep ualarm gettimeofday tv_interval);
       
	 #open(TIME,">>","time.txt") or die("Error: cannot open file 'time.txt'\n");
	
	my $t0 = [gettimeofday];
	
	# Calling the UMLSKS Web service and receiving the hash reference.
	my $object_ref = $service->$method_name(@params);
	
	my $t0_t1 = tv_interval($t0);        
	  msg("\n $qterm : $t0_t1 secs\n",$verbose);
	  
	 
	  
	# If the returned reference is not defined then display error message.
	
	if ( !defined $object_ref ) {
		print "No information for this CUI.";
		return 'undefined';
	}
	else {

		# If the returned contents array is empty then display error message.

 view all matches for this distribution
 view release on metacpan -  search on metacpan

( run in 0.806 second using v1.00-cache-2.02-grep-82fe00e-cpan-1925d2aa809 )