CohortExplorer

 view release on metacpan or  search on metacpan

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

(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' ) {

   # Successful authentication returns tables and views accessible to the user
   my %view = map { $_ => 1 } @{ $json->{view} || [] };
   my @tables = @{ $json->{table} || [] };

   # Get all base tables ( i.e. exclude views )
   my @base_tables =
     defined $json->{view} ? grep { not $view{$_} } @tables : @tables;
   if ( @base_tables == 0 ) {

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

                    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
   if ( $var_res->code == 200 ) {
    $decoded_json = decode_json( $var_res->decoded_content );
    push @{ $param{allowed_variables} },
      map { "$t.$_" } @{ $decoded_json->{variables} };
   }
   else {
    die "Failed to fetch variable list via $url (error "
      . $var_res->code . ")\n";
   }
  }
  else {
   die "Failed to fetch variable list via $url (error "
     . $entity_res->code . ")\n";
  }



( run in 0.306 second using v1.01-cache-2.11-cpan-26ccb49234f )