NAME
CohortExplorer::Command::Query - CohortExplorer class is an interface to search and compare command classes
DESCRIPTION
This class serves as the base class to search and compare command classes. The class is inherited from CLI::Framework::Command and overrides the following methods:
option_spec()
Returns application option specifications as expected by Getopt::Long::Descriptive
(
[ 'cond|c=s%' => 'impose condition(s)' ],
[ 'out|o=s' => 'provide output directory', { required => 1 } ],
[ 'save-command|s' => 'save command' ],
[ 'stats|S' => 'show summary statistics' ],
[ 'export|e=s@' => 'export tables by name' ],
[ 'export-all|a' => 'export all tables' ]
)
validate( $opts, @args )
This method validates the command options and arguments and throws exception upon validation failure.
run( $opts, @args )
This method is responsible for the overall functioning of the command. The method calls option specific methods for option specific processing.
SUBCLASS HOOKS
get_query_parameters( $opts, $datasource, @args )
This method should return a hash ref with keys, static, dynamic, or both depending on the datasource type and variables supplied in arguments and conditions. As a standard datasource has all static tables so the hash ref should only contain one key, static where as a longitudinal datasource may contain both keys, static and dynamic provided the datasource has static tables. The parameters to the method are as follows:
$opts an options hash with the received command options as keys and their values as hash values.
$datasource is the datasource object.
@args arguments to the command.
process_result_set( $opts, $datasource, $result_set, $dir, $csv, @args )
This method should process the result set obtained after running the SQL query and write a csv file. If the variables provided as part of arguments and conditions belong only to the static tables, then the method should return a ref to list of entities present in the result set. Otherwise, the method should return a hash ref with entity_id as keys and corresponding visit numbers as values. $opts an options hash with the received command options as keys and their values as hash values.
In this method,
$datasource is the datasource object.
$result_set is the output obtained upon SQL execution.
$dir is the directory where results should be exported to.
$csv is the object of Text::CSV_XS.
@args arguments to the command.
process_table( $table, $datasource, $table_data, $dir, $csv, $result_entity )
This method should process the table data returned after running the export SQL query. The method should write the table data in a csv file for all entities present in the result set.
The parameters to the method are:
$table is the name of the table to be exported.
$datasource is the datasource object.
$table_data is the output obtained from executing the export SQL query.
$dir is the export directory specified by the user.
$csv is the object of Text::CSV_XS.
$result_entity is a ref to all entities present in the result-set. If variabes present in cond option and arguments belong to static tables the ref is simply to the list containing entity ids. Otherwise, the reference is to a hash where entity ids are keys and corresponding visit numbers are values.
get_stats_data( $result_set )
This method should generate the data for computing summary statistics. The method should return a hash ref with key as the parameter, the statistics are computed with respect to and values as the hash with variable names as keys and array ref as values.
DIAGNOSTICS
CohortExplorer::Command::Query throws following exceptions imported from CLI::Framework::Exception:
throw_cmd_run_exception: This exception is thrown if one of the following conditions are met:The command history file fails to load. For the save command option to work it is required that the file
$HOME/.CohortExplorer_Historyexists with rwx enabled for CohortExplorer.The
selectmethod from SQL::Abstract::More fails to construct the SQL from the supplied hash ref.The method
executefrom DBI fails to execute the SQL query.The full methods under package Statistics::Descriptive fail to compute statistics.
throw_cmd_validation_exception: This exception is thrown whenever the command options/arguments fail to validate.
DEPENDENCIES
SEE ALSO
CohortExplorer::Command::Describe
CohortExplorer::Command::History
CohortExplorer::Command::Query::Search
CohortExplorer::Command::Query::Compare
LICENSE AND COPYRIGHT
Copyright (c) 2013-2014 Abhishek Dixit (adixit@cpan.org). All rights reserved.
This program is free software: you can redistribute it and/or modify it under the terms of either:
the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version, or
the "Artistic Licence".
AUTHOR
Abhishek Dixit