CohortExplorer

 view release on metacpan or  search on metacpan

lib/CohortExplorer/Application/Opal/Datasource.pm  view on Meta::CPAN

sub authenticate {
 my ( $self, %opts ) = @_;
 my $ds_name = $self->name;
 require LWP::UserAgent;
 require MIME::Base64;

 # Authenticate using Opal url
 # Default Opal url is http://localhost:8080
 my $ua = LWP::UserAgent->new( timeout => 10, ssl_opts => { verify_hostname => 0 } );
(my $url = $self->url || 'http://localhost:8080' ) =~ s/\/$//;
 my $req = HTTP::Request->new( GET => $url . "/ws/datasource/$ds_name" );
 $req->header(
             Authorization => "X-Opal-Auth "
               . MIME::Base64::encode( join ':', @opts{qw/username password/} ),
             Accept => "application/json"
 );
 my $res  = $ua->request($req);
 my $code = $res->code;
 if ( $code == 200 ) {
  my $json = decode_json( $res->decoded_content );
  if ( $json->{type} ne 'mongodb' ) {

lib/CohortExplorer/Application/Opal/Datasource.pm  view on Meta::CPAN

  # id_visit_separator and visit_max is undefined for standard datasources
  @param{qw/id_visit_separator visit_max static_tables/} =
    ( undef, undef, $param{allowed_tables} );
 }

 # Get list of allowed variables from each table
 my $ua = LWP::UserAgent->new( timeout => 10, ssl_opts => { verify_hostname => 0 } );
(my $url = $self->url || 'http://localhost:8080' ) =~ s/\/$//;
 for my $t ( @{ $param{allowed_tables} } ) {
  my $entity_req =
    HTTP::Request->new(
                    GET => $url . "/ws/datasource/$ds_name/table/$t/entities" );
  $entity_req->header(
             Authorization => "X-Opal-Auth "
               . MIME::Base64::encode( join ':', @opts{qw/username password/} ),
             Accept => "application/json"
  );
  my $entity_res = $ua->request($entity_req);

  # Get the first identifier
  if ( $entity_res->code == 200 ) {
   my $decoded_json = decode_json( $entity_res->decoded_content );
   my $var_req =
     HTTP::Request->new(   GET => $url
                         . "/ws/datasource/$ds_name/table/$t/valueSet/"
                         . ( $decoded_json->[0]->{identifier} || '' ) );
   $var_req->header(
             Authorization => "X-Opal-Auth "
               . MIME::Base64::encode( join ':', @opts{qw/username password/} ),
             Accept => "application/json"
   );
   my $var_res = $ua->request($var_req);

   # Get all variables with accessible values



( run in 0.921 second using v1.01-cache-2.11-cpan-de7293f3b23 )