/// <summary> /// Retrieves the specified dataset for patients in the specified query. /// </summary> /// <returns>A dataset result, which, if the request was valid, contains the dataset.</returns> /// <param name="query">Query reference value.</param> /// <param name="datasetQuery">Dataset query reference value.</param> /// <param name="cancel">Cancelcellation token.</param> /// <param name="early">Early time bound.</param> /// <param name="late">Late time bound.</param> /// <exception cref="LeafRPCException"/> /// <exception cref="OperationCanceledException"/> /// <exception cref="LeafCompilerException"/> /// <exception cref="ArgumentNullException"/> /// <exception cref="System.Data.Common.DbException"/> public async Task <Result> GetDatasetAsync(QueryRef query, DatasetQueryRef datasetQuery, CancellationToken cancel, long?early = null, long?late = null) { log.LogInformation("Dataset starting. QueryRef:{QueryRef} DatasetRef:{DatasetRef}", query, datasetQuery); Ensure.NotNull(query, nameof(query)); Ensure.NotNull(datasetQuery, nameof(datasetQuery)); var request = new DatasetExecutionRequest(query, datasetQuery, early, late); var result = new Result(); log.LogInformation("Dataset execution request. Request:{@Request}", request); var validationContext = await contextProvider.GetCompilerContextAsync(request); log.LogInformation("Dataset compiler validation context. Context:{@Context}", validationContext); result.Context = validationContext; if (validationContext.State != CompilerContextState.Ok) { log.LogError("Dataset compiler context error. State:{State}", validationContext.State); return(result); } cancel.ThrowIfCancellationRequested(); var exeContext = compiler.BuildDatasetSql(validationContext.Context); log.LogInformation("Compiled dataset execution context. Context:{@Context}", exeContext); var data = await executor.ExecuteDatasetAsync(exeContext, cancel); log.LogInformation("Dataset complete. Patients:{Patients} Records:{Records}", data.Results.Keys.Count, data.Results.Sum(d => d.Value.Count())); result.Dataset = data; return(result); }
/// <summary> /// Retrieves the specified dataset for patients in the specified query. /// </summary> /// <returns>A dataset result, which, if the request was valid, contains the dataset.</returns> /// <param name="query">Query reference value.</param> /// <param name="datasetQuery">Dataset query reference value.</param> /// <param name="cancel">Cancelcellation token.</param> /// <param name="early">Early time bound.</param> /// <param name="late">Late time bound.</param> /// <exception cref="LeafPreflightException"/> /// <exception cref="LeafDbException"/> /// <exception cref="OperationCanceledException"/> /// <exception cref="LeafCompilerException"/> /// <exception cref="ArgumentNullException"/> public async Task <Result> Dataset(QueryRef query, DatasetQueryRef datasetQuery, CancellationToken cancel, long?early = null, long?late = null) { Ensure.NotNull(query, nameof(query)); Ensure.NotNull(datasetQuery, nameof(datasetQuery)); var request = new DatasetExecutionRequest(query, datasetQuery, early, late); var result = new Result(); var ctx = await queryService.GetQueryCompilerContext(request); result.Context = ctx; if (ctx.State != CompilerContextState.Ok) { return(result); } cancel.ThrowIfCancellationRequested(); var data = await datasetService.GetDatasetAsync(ctx.Context, cancel); result.Dataset = data; return(result); }
/// <summary> /// Retrieves the specified dataset for patients in the specified query. /// </summary> /// <returns>A dataset result, which, if the request was valid, contains the dataset.</returns> /// <param name="query">Query reference value.</param> /// <param name="datasetQuery">Dataset query reference value.</param> /// <param name="cancel">Cancelcellation token.</param> /// <param name="early">Early time bound.</param> /// <param name="late">Late time bound.</param> /// <exception cref="LeafPreflightException"/> /// <exception cref="LeafRPCException"/> /// <exception cref="OperationCanceledException"/> /// <exception cref="LeafCompilerException"/> /// <exception cref="ArgumentNullException"/> /// <exception cref="System.Data.Common.DbException"/> public async Task <Result> GetDatasetAsync(QueryRef query, DatasetQueryRef datasetQuery, CancellationToken cancel, long?early = null, long?late = null) { Ensure.NotNull(query, nameof(query)); Ensure.NotNull(datasetQuery, nameof(datasetQuery)); var request = new DatasetExecutionRequest(query, datasetQuery, early, late); var result = new Result(); var validationContext = await contextProvider.GetCompilerContextAsync(request); result.Context = validationContext; if (validationContext.State != CompilerContextState.Ok) { return(result); } cancel.ThrowIfCancellationRequested(); var exeContext = compiler.BuildDatasetSql(validationContext.Context); log.LogInformation("Compiled Dataset Execution Context. Context:{@Context}", exeContext); var data = await executor.ExecuteDatasetAsync(exeContext, cancel); result.Dataset = data; return(result); }
public async Task <ActionResult <DatasetDTO> > Dataset( string queryid, [FromQuery] string datasetid, [FromQuery] Shape shape, [FromQuery] long?early, [FromQuery] long?late, [FromServices] DatasetProvider provider, CancellationToken cancelToken ) { try { var queryref = new QueryRef(queryid); var datasetref = new DatasetQueryRef(datasetid, shape); var result = await provider.Dataset(queryref, datasetref, cancelToken, early, late); switch (result.Context.State) { case CompilerContextState.DatasetShapeMismatch: return(BadRequest(new CompilerErrorDTO(result.Context.State))); case CompilerContextState.DatasetNotFound: case CompilerContextState.QueryNotFound: return(NotFound(new CompilerErrorDTO(result.Context.State))); } return(Ok(new DatasetDTO(result.Dataset))); } catch (FormatException fe) { log.LogWarning("Malformed dataset identifiers. Error:{Error}", fe.Message); return(BadRequest()); } catch (LeafPreflightException lpe) { log.LogInformation("Dataset query failed preflight check. Error:{Error}", lpe.Message); return(BadRequest()); } catch (OperationCanceledException) { log.LogInformation("Request cancelled. QueryID:{QueryID} DatasetId:{DatasetId}", queryid, datasetid); return(NoContent()); } catch (LeafDbException lde) { return(StatusCode(lde.StatusCode)); } catch (LeafCompilerException) { return(StatusCode(StatusCodes.Status500InternalServerError)); } catch (Exception ex) { log.LogError("Could not fetch dataset. QueryID:{QueryID} DatasetID:{DatasetID} Error:{Error}", queryid, datasetid, ex.ToString()); return(StatusCode(StatusCodes.Status500InternalServerError)); } }
public Task <DatasetQuery> GetQuery(DatasetQueryRef datasetQueryRef) { log.LogInformation("Getting dataset query. Ref:{@Ref}", datasetQueryRef); throw new NotImplementedException(); }