Esempio n. 1
0
        public async Task <Result> GetConceptDatasetAsync(QueryRef queryRef, IPanelItemDTO panelitem, long?early, long?late, CancellationToken cancel)
        {
            log.LogInformation("ConceptDataset extraction starting. ConceptRef:{@ConceptRef}, PanelItem:{@PanelItem}, Early:{@Early}, Late:{@Late}", queryRef, panelitem, early, late);

            var request = new ConceptDatasetExecutionRequest(queryRef, panelitem, early, late);
            var result  = new Result();

            var validationContext = await contextProvider.GetCompilerContextAsync(request);

            log.LogInformation("ConceptDataset compiler validation context. Context:{@Context}", validationContext);

            result.Context = validationContext;
            if (validationContext.State != CompilerContextState.Ok)
            {
                log.LogError("ConceptDatasetCompilerContext error. State:{State}", validationContext.State);
                return(result);
            }
            var exeContext = conceptDatasetSqlCompiler.BuildConceptDatasetSql(validationContext.Context);

            log.LogInformation("Compiled ConceptDataset execution context. Context:{@Context}", exeContext);

            var data = await executor.ExecuteDatasetAsync(exeContext, cancel);

            log.LogInformation("ConceptDataset complete. Patients:{Patients} Records:{Records}", data.Results.Keys.Count, data.Results.Sum(d => d.Value.Count()));

            result.Dataset = data;

            return(result);
        }
Esempio n. 2
0
        /// <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);
        }
Esempio n. 3
0
        public async Task <Result> GetPanelDatasetAsync(QueryRef queryRef, int panelIdx, CancellationToken cancel)
        {
            log.LogInformation("PanelDataset extraction starting. PanelIndex:{@PanelIndex} Query:{@QueryRef}", queryRef, panelIdx);

            var result = new Result();

            var validationContext = await contextProvider.GetCompilerContextAsync(queryRef, panelIdx);

            log.LogInformation("PanelDataset compiler validation context. Context:{@Context}", validationContext);

            result.Context = validationContext;
            if (validationContext.State != CompilerContextState.Ok)
            {
                log.LogError("PanelDatasetCompilerContext error. State:{State}", validationContext.State);
                return(result);
            }
            var exeContext = sqlCompiler.BuildPanelDatasetSql(validationContext.Context);

            log.LogInformation("Compiled PanelDataset execution context. Context:{@Context}", exeContext);

            var data = await executor.ExecuteDatasetAsync(exeContext, cancel);

            log.LogInformation("PanelDataset complete. Patients:{Patients} Records:{Records}", data.Results.Keys.Count, data.Results.Sum(d => d.Value.Count()));

            result.Dataset = data;

            return(result);
        }
Esempio n. 4
0
        public async Task <PanelDatasetCompilerContext> GetCompilerContextAsync(QueryRef queryRef, int panelIdx)
        {
            var hydrator = GetContextHydrator(queryRef);
            var context  = await hydrator(queryRef, panelIdx);

            return(context);
        }
Esempio n. 5
0
        /// <summary>
        /// Retrieves the demographics for patients in the specified query.
        /// </summary>
        /// <returns>A demographic result, which, if the request was valid, contains the demographics.</returns>
        /// <param name="query">Query reference value.</param>
        /// <param name="token">Cancellation token.</param>
        /// <exception cref="LeafDbException"/>
        /// <exception cref="OperationCanceledException"/>
        /// <exception cref="LeafCompilerException"/>
        /// <exception cref="ArgumentNullException"/>
        public async Task <Result> Demographics(QueryRef query, CancellationToken token)
        {
            Ensure.NotNull(query, nameof(query));
            var result = new Result();

            var validationContext = await queryService.GetDemographicQueryCompilerContext(query);

            result.Context = validationContext;
            if (validationContext.State != CompilerContextState.Ok)
            {
                return(result);
            }

            var ctx = await demographicService.GetDemographicsAsync(validationContext.Context, token);

            var stats = new DemographicAggregator(ctx).Aggregate();

            result.Demographics = new Demographic
            {
                Patients   = ctx.Exported,
                Statistics = stats
            };

            return(result);
        }
Esempio n. 6
0
        /// <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);
        }
Esempio n. 7
0
        public async Task <DemographicCompilerContext> GetCompilerContextAsync(QueryRef queryRef)
        {
            var hydrator = GetContextHydrator(queryRef);
            var context  = await hydrator(queryRef);

            return(context);
        }
Esempio n. 8
0
        /// <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);
        }
Esempio n. 9
0
        /// <summary>
        /// Retrieves the demographics for patients in the specified query.
        /// </summary>
        /// <returns>A demographic result, which, if the request was valid, contains the demographics.</returns>
        /// <param name="query">Query reference value.</param>
        /// <param name="token">Cancellation token.</param>
        /// <exception cref="LeafRPCException"/>
        /// <exception cref="OperationCanceledException"/>
        /// <exception cref="LeafCompilerException"/>
        /// <exception cref="ArgumentNullException"/>
        /// <exception cref="System.Data.Common.DbException"/>
        public async Task <Result> GetDemographicsAsync(QueryRef query, CancellationToken token)
        {
            Ensure.NotNull(query, nameof(query));
            var result = new Result();

            var validationContext = await contextProvider.GetCompilerContextAsync(query);

            result.Context = validationContext;
            if (validationContext.State != CompilerContextState.Ok)
            {
                return(result);
            }

            token.ThrowIfCancellationRequested();

            var exeContext = compiler.BuildDemographicSql(validationContext.Context, user.Anonymize());

            log.LogInformation("Compiled Demographic Execution Context. Context:{@Context}", exeContext);

            var ctx = await executor.ExecuteDemographicsAsync(exeContext, token);

            var stats = new DemographicAggregator(ctx).Aggregate();

            result.Demographics = new Demographic
            {
                Patients   = ctx.Exported,
                Statistics = stats
            };

            return(result);
        }
Esempio n. 10
0
 Hydrator GetContextHydrator(QueryRef queryRef)
 {
     if (queryRef.UseUniversalId())
     {
         return(ByQueryUId);
     }
     return(ByQueryId);
 }
Esempio n. 11
0
        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));
            }
        }
Esempio n. 12
0
        public async Task <ActionResult <Demographic> > Demographics(
            string queryid,
            [FromServices] DemographicProvider provider,
            CancellationToken cancelToken)
        {
            try
            {
                var queryRef = new QueryRef(queryid);
                var result   = await provider.GetDemographicsAsync(queryRef, cancelToken);

                if (result.Context.State != CompilerContextState.Ok)
                {
                    return(NotFound(new CompilerErrorDTO(result.Context.State)));
                }

                return(Ok(result.Demographics));
            }
            catch (ArgumentNullException ane)
            {
                log.LogError("Missing argument. Error:{Error}", ane.Message);
                return(BadRequest());
            }
            catch (FormatException fe)
            {
                log.LogWarning("Malformed query identifiers. QueryId:{QueryID} Error:{Error}", queryid, fe.Message);
                return(BadRequest("QueryID is malformed."));
            }
            catch (OperationCanceledException)
            {
                log.LogInformation("Request cancelled. QueryID:{QueryID}", queryid);
                return(NoContent());
            }
            catch (LeafRPCException lde)
            {
                return(StatusCode(lde.StatusCode));
            }
            catch (LeafCompilerException)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError));
            }
            catch (Exception ex)
            {
                log.LogError("Failed to fetch demographics. QueryID:{QueryID} Error:{Error}", queryid, ex.ToString());
                return(StatusCode(StatusCodes.Status500InternalServerError));
            }
        }
Esempio n. 13
0
 Hydrator GetContextHydrator(QueryRef queryRef, ConceptRef conceptRef)
 {
     if (queryRef.UseUniversalId())
     {
         if (conceptRef.UseUniversalId())
         {
             return(ByQueryUIdConceptUId);
         }
         return(ByQueryUIdConceptId);
     }
     else
     {
         if (conceptRef.UseUniversalId())
         {
             return(ByQueryIdConceptUId);
         }
     }
     return(ByQueryIdConceptId);
 }
Esempio n. 14
0
        async Task <DemographicCompilerContext> ByQueryUId(QueryRef queryRef)
        {
            log.LogInformation("Getting DemographicQueryCompilerContext by QueryUId");
            var queryuid = queryRef.UniversalId.ToString();

            using (var cn = new SqlConnection(opts.ConnectionString))
            {
                await cn.OpenAsync();

                var grid = await cn.QueryMultipleAsync(
                    contextByUId,
                    new { queryuid, user = user.UUID, groups = GroupMembership.From(user), admin = user.IsAdmin },
                    commandType : CommandType.StoredProcedure,
                    commandTimeout : opts.DefaultTimeout
                    );

                return(ReadContextGrid(grid));
            }
        }
Esempio n. 15
0
        async Task <PanelDatasetCompilerContext> ByQueryId(QueryRef queryRef, int panelIdx)
        {
            log.LogInformation("Getting PanelDatasetCompilerContext by QueryId");
            var queryid = queryRef.Id.Value;

            using (var cn = new SqlConnection(opts.ConnectionString))
            {
                await cn.OpenAsync();

                var grid = await cn.QueryMultipleAsync(
                    contextById,
                    new { queryid, user = user.UUID, groups = GroupMembership.From(user), admin = user.IsAdmin },
                    commandType : CommandType.StoredProcedure,
                    commandTimeout : opts.DefaultTimeout
                    );

                return(ReadContextGrid(grid, panelIdx));
            }
        }
Esempio n. 16
0
        public async Task <ActionResult <DatasetDTO> > ConceptPanelDataset(
            string queryid,
            [FromQuery] long?early,
            [FromQuery] long?late,
            [FromQuery] string panelItem,
            [FromServices] ConceptDatasetProvider provider,
            CancellationToken cancelToken)
        {
            try
            {
                var queryRef = new QueryRef(queryid);
                var pi       = JsonConvert.DeserializeObject <PanelItemDTO>(panelItem);
                var result   = await provider.GetConceptDatasetAsync(queryRef, pi, early, late, cancelToken);

                return(Ok(new DatasetDTO(result.Dataset)));
            }
            catch (FormatException fe)
            {
                log.LogWarning("Malformed concept identifier. Error:{Error}", fe.Message);
                return(BadRequest());
            }
            catch (OperationCanceledException)
            {
                log.LogInformation("Request cancelled. QueryID:{QueryID} PanelItem:{PanelItem}", queryid, panelItem);
                return(NoContent());
            }
            catch (LeafRPCException lde)
            {
                return(StatusCode(lde.StatusCode));
            }
            catch (LeafCompilerException)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError));
            }
            catch (Exception ex)
            {
                log.LogError("Failed to fetch concept dataset. QueryID:{QueryID} PanelItem:{PanelItem} Error:{Error}", queryid, panelItem, ex.ToString());
                return(StatusCode(StatusCodes.Status500InternalServerError));
            }
        }
Esempio n. 17
0
        /// <summary>
        /// Retrieves the demographics for patients in the specified query.
        /// </summary>
        /// <returns>A demographic result, which, if the request was valid, contains the demographics.</returns>
        /// <param name="query">Query reference value.</param>
        /// <param name="token">Cancellation token.</param>
        /// <exception cref="LeafRPCException"/>
        /// <exception cref="OperationCanceledException"/>
        /// <exception cref="LeafCompilerException"/>
        /// <exception cref="ArgumentNullException"/>
        /// <exception cref="System.Data.Common.DbException"/>
        public async Task <Result> GetDemographicsAsync(QueryRef query, CancellationToken token)
        {
            log.LogInformation("Demographics starting. QueryRef:{QueryRef}", query);
            Ensure.NotNull(query, nameof(query));
            ThrowIfSettingsInvalid();
            var result = new Result();

            var validationContext = await contextProvider.GetCompilerContextAsync(query);

            log.LogInformation("Demographics compiler validation context. Context:{@Context}", validationContext);

            result.Context = validationContext;
            if (validationContext.State != CompilerContextState.Ok)
            {
                log.LogError("Demographics compiler context error. State:{State}", validationContext.State);
                return(result);
            }

            token.ThrowIfCancellationRequested();

            var deidentify = deidentOpts.Patient.Enabled && user.Anonymize();
            var exeContext = compiler.BuildDemographicSql(validationContext.Context, deidentify);

            log.LogInformation("Compiled demographic execution context. Context:{@Context}", exeContext);

            var ctx = await executor.ExecuteDemographicsAsync(exeContext, token);

            var stats = new DemographicAggregator(ctx).Aggregate();

            log.LogInformation("Demographics complete. Exported:{Exported} Total:{Total}", ctx.Exported.Count(), ctx.Cohort.Count());

            result.Demographics = new Demographic
            {
                Patients   = GetDemographicsWithSettings(ctx.Exported),
                Statistics = GetStatisticsWithSettings(stats)
            };

            return(result);
        }
Esempio n. 18
0
        public async Task <ActionResult <DatasetDTO> > PanelDataset(
            string queryid,
            [FromQuery] int panelIdx,
            [FromServices] PanelDatasetProvider provider,
            CancellationToken cancelToken)
        {
            try
            {
                var queryRef = new QueryRef(queryid);
                var result   = await provider.GetPanelDatasetAsync(queryRef, panelIdx, cancelToken);

                return(Ok(new DatasetDTO(result.Dataset)));
            }
            catch (FormatException fe)
            {
                log.LogWarning("Malformed panel dataset identifiers. Error:{Error}", fe.Message);
                return(BadRequest());
            }
            catch (OperationCanceledException)
            {
                log.LogInformation("Request cancelled. QueryID:{QueryID} PanelIndex:{PanelIndex}", queryid, panelIdx);
                return(NoContent());
            }
            catch (LeafRPCException lde)
            {
                return(StatusCode(lde.StatusCode));
            }
            catch (LeafCompilerException)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError));
            }
            catch (Exception ex)
            {
                log.LogError("Failed to fetch panel dataset. QueryID:{QueryID} PanelIndex:{PanelIdx} Error:{Error}", queryid, panelIdx, ex.ToString());
                return(StatusCode(StatusCodes.Status500InternalServerError));
            }
        }
Esempio n. 19
0
        public void Errors_Queries_Should_Have_Data_If_Not_Ok()
        {
            var first = new QueryRef {
                UniversalId = QueryUrn.From("urn:leaf:query:d7359679-df0d-4604-a2d9-1d3d04417dc2:123456")
            };
            var second = new QueryRef {
                UniversalId = QueryUrn.From("urn:leaf:query:d7359668-df0d-4604-a2d9-1d3d04417dc2:563423")
            };
            var pr = new PreflightResources(new QueryRef[] { })
            {
                DirectConceptsCheck = new PreflightConcepts
                {
                    PreflightCheck = new ConceptPreflightCheck
                    {
                        Results = new ConceptPreflightCheckResult[]
                        {
                            new ConceptPreflightCheckResult
                            {
                                Id           = Guid.NewGuid(),
                                UniversalId  = ConceptUrn.From("urn:leaf:concept:diag:codeset=ICD9+code=123.42"),
                                IsPresent    = true,
                                IsAuthorized = true
                            },
                            new ConceptPreflightCheckResult
                            {
                                Id           = Guid.NewGuid(),
                                UniversalId  = ConceptUrn.From("urn:leaf:concept:diag:codeset=ICD9+code=123.45"),
                                IsPresent    = true,
                                IsAuthorized = true
                            }
                        }
                    }
                },
                DirectQueriesCheck = new PreflightQueries
                {
                    Results = new QueryPreflightCheckResult[]
                    {
                        new QueryPreflightCheckResult
                        {
                            QueryRef     = first,
                            IsPresent    = false,
                            IsAuthorized = false,
                            ConceptCheck = new ConceptPreflightCheck
                            {
                                Results = new ConceptPreflightCheckResult[]
                                {
                                    new ConceptPreflightCheckResult
                                    {
                                        Id           = Guid.NewGuid(),
                                        UniversalId  = ConceptUrn.From("urn:leaf:concept:diag:codeset=ICD9+code=123.42"),
                                        IsPresent    = true,
                                        IsAuthorized = true
                                    },
                                    new ConceptPreflightCheckResult
                                    {
                                        Id           = Guid.NewGuid(),
                                        UniversalId  = ConceptUrn.From("urn:leaf:concept:diag:codeset=ICD9+code=123.45"),
                                        IsPresent    = true,
                                        IsAuthorized = true
                                    }
                                }
                            }
                        },
                        new QueryPreflightCheckResult
                        {
                            QueryRef     = second,
                            IsPresent    = true,
                            IsAuthorized = true,
                            ConceptCheck = new ConceptPreflightCheck
                            {
                                Results = new ConceptPreflightCheckResult[]
                                {
                                    new ConceptPreflightCheckResult
                                    {
                                        Id           = Guid.NewGuid(),
                                        UniversalId  = ConceptUrn.From("urn:leaf:concept:diag:codeset=ICD9+code=123.41"),
                                        IsPresent    = true,
                                        IsAuthorized = true
                                    },
                                    new ConceptPreflightCheckResult
                                    {
                                        Id           = Guid.NewGuid(),
                                        UniversalId  = ConceptUrn.From("urn:leaf:concept:diag:codeset=ICD9+code=123.50"),
                                        IsPresent    = true,
                                        IsAuthorized = true
                                    }
                                }
                            }
                        }
                    }
                }
            };

            var errors = pr.Errors();

            Assert.False(errors.ConceptErrors.Any());
            Assert.True(errors.QueryErrors.Any());
        }
Esempio n. 20
0
        public void Concepts_Should_Match_Count_If_Ok()
        {
            var first = new QueryRef {
                Id = Guid.NewGuid(), UniversalId = QueryUrn.From("urn:leaf:query:d7359679-df0d-4604-a2d9-1d3d04417dc2:123456")
            };
            var second = new QueryRef {
                Id = Guid.NewGuid(), UniversalId = QueryUrn.From("urn:leaf:query:d7359668-df0d-4604-a2d9-1d3d04417dc2:563423")
            };
            var errorUid = ConceptUrn.From("urn:leaf:concept:diag:codeset=ICD9+code=123.42");

            var c12342 = Guid.NewGuid();
            var c12345 = Guid.NewGuid();
            var c12341 = Guid.NewGuid();
            var c12344 = Guid.NewGuid();
            var c12340 = Guid.NewGuid();
            var c12350 = Guid.NewGuid();

            var pr = new PreflightResources(new QueryRef[] { first, second })
            {
                DirectConceptsCheck = new PreflightConcepts
                {
                    PreflightCheck = new ConceptPreflightCheck
                    {
                        Results = new ConceptPreflightCheckResult[]
                        {
                            new ConceptPreflightCheckResult
                            {
                                Id           = c12342,
                                UniversalId  = ConceptUrn.From("urn:leaf:concept:diag:codeset=ICD9+code=123.42"),
                                IsPresent    = true,
                                IsAuthorized = true
                            },
                            new ConceptPreflightCheckResult
                            {
                                Id           = c12345,
                                UniversalId  = ConceptUrn.From("urn:leaf:concept:diag:codeset=ICD9+code=123.45"),
                                IsPresent    = true,
                                IsAuthorized = true
                            }
                        }
                    },
                    Concepts = new Concept[]
                    {
                        new Concept
                        {
                            Id          = c12342,
                            UniversalId = ConceptUrn.From("urn:leaf:concept:diag:codeset=ICD9+code=123.42"),
                        },
                        new Concept
                        {
                            Id          = c12345,
                            UniversalId = ConceptUrn.From("urn:leaf:concept:diag:codeset=ICD9+code=123.45"),
                        }
                    }
                },
                DirectQueriesCheck = new PreflightQueries
                {
                    Results = new QueryPreflightCheckResult[]
                    {
                        new QueryPreflightCheckResult
                        {
                            QueryRef     = first,
                            IsPresent    = true,
                            IsAuthorized = true,
                            ConceptCheck = new ConceptPreflightCheck
                            {
                                Results = new ConceptPreflightCheckResult[]
                                {
                                    new ConceptPreflightCheckResult
                                    {
                                        Id           = c12341,
                                        UniversalId  = ConceptUrn.From("urn:leaf:concept:diag:codeset=ICD9+code=123.41"),
                                        IsPresent    = true,
                                        IsAuthorized = true
                                    },
                                    new ConceptPreflightCheckResult
                                    {
                                        Id           = c12344,
                                        UniversalId  = ConceptUrn.From("urn:leaf:concept:diag:codeset=ICD9+code=123.44"),
                                        IsPresent    = true,
                                        IsAuthorized = true
                                    }
                                }
                            }
                        },
                        new QueryPreflightCheckResult
                        {
                            QueryRef     = second,
                            IsPresent    = true,
                            IsAuthorized = true,
                            ConceptCheck = new ConceptPreflightCheck
                            {
                                Results = new ConceptPreflightCheckResult[]
                                {
                                    new ConceptPreflightCheckResult
                                    {
                                        Id           = c12340,
                                        UniversalId  = ConceptUrn.From("urn:leaf:concept:diag:codeset=ICD9+code=123.40"),
                                        IsPresent    = true,
                                        IsAuthorized = true
                                    },
                                    new ConceptPreflightCheckResult
                                    {
                                        Id           = c12350,
                                        UniversalId  = ConceptUrn.From("urn:leaf:concept:diag:codeset=ICD9+code=123.50"),
                                        IsPresent    = true,
                                        IsAuthorized = true
                                    }
                                }
                            }
                        }
                    }
                }
            };

            var concepts = pr.Concepts(new Model.Options.CompilerOptions {
                Alias = "@", FieldPersonId = "person_id"
            });

            Assert.True(concepts.Count() == 4);
            Assert.Contains(concepts, c => c.Id == c12342);
            Assert.Contains(concepts, c => c.Id == c12345);
            Assert.Contains(concepts, c => c.Id == first.Id.Value);
            Assert.Contains(concepts, c => c.Id == second.Id.Value);
        }
Esempio n. 21
0
        public void DirectQueries_Should_Return_MatchingSet()
        {
            var first = new QueryRef {
                UniversalId = QueryUrn.From("urn:leaf:query:d7359679-df0d-4604-a2d9-1d3d04417dc2:123456")
            };
            var second = new QueryRef {
                UniversalId = QueryUrn.From("urn:leaf:query:d7359668-df0d-4604-a2d9-1d3d04417dc2:563423")
            };

            var direct = new QueryRef[] { first, second };

            var qpc = new PreflightQueries
            {
                Results = new QueryPreflightCheckResult[]
                {
                    new QueryPreflightCheckResult
                    {
                        QueryRef     = first,
                        IsPresent    = true,
                        IsAuthorized = true,
                        ConceptCheck = new ConceptPreflightCheck
                        {
                            Results = new ConceptPreflightCheckResult[]
                            {
                                new ConceptPreflightCheckResult
                                {
                                    Id           = Guid.NewGuid(),
                                    UniversalId  = ConceptUrn.From("urn:leaf:concept:diag:codeset=ICD9+code=123.42"),
                                    IsPresent    = true,
                                    IsAuthorized = true
                                },
                                new ConceptPreflightCheckResult
                                {
                                    Id           = Guid.NewGuid(),
                                    UniversalId  = ConceptUrn.From("urn:leaf:concept:diag:codeset=ICD9+code=123.45"),
                                    IsPresent    = true,
                                    IsAuthorized = true
                                }
                            }
                        }
                    },
                    new QueryPreflightCheckResult
                    {
                        QueryRef     = second,
                        IsPresent    = true,
                        IsAuthorized = true,
                        ConceptCheck = new ConceptPreflightCheck
                        {
                            Results = new ConceptPreflightCheckResult[]
                            {
                                new ConceptPreflightCheckResult
                                {
                                    Id           = Guid.NewGuid(),
                                    UniversalId  = ConceptUrn.From("urn:leaf:concept:diag:codeset=ICD9+code=123.41"),
                                    IsPresent    = true,
                                    IsAuthorized = true
                                },
                                new ConceptPreflightCheckResult
                                {
                                    Id           = Guid.NewGuid(),
                                    UniversalId  = ConceptUrn.From("urn:leaf:concept:diag:codeset=ICD9+code=123.50"),
                                    IsPresent    = true,
                                    IsAuthorized = true
                                }
                            }
                        }
                    }
                }
            };
            var results = qpc.DirectQueries(direct);

            Assert.True(results.Count() == 2);
            Assert.Equal(direct, results, new QueryRefEqualityComparer());
        }
Esempio n. 22
0
        public IEnumerator <object[]> GetEnumerator()
        {
            var first = new QueryRef {
                UniversalId = QueryUrn.From("urn:leaf:query:d7359679-df0d-4604-a2d9-1d3d04417dc2:123456")
            };
            var second = new QueryRef {
                UniversalId = QueryUrn.From("urn:leaf:query:d7359668-df0d-4604-a2d9-1d3d04417dc2:563423")
            };

            yield return(new object[]
            {
                new PreflightResources(new QueryRef[] { })
                {
                    DirectConceptsCheck = new PreflightConcepts
                    {
                        PreflightCheck = new ConceptPreflightCheck
                        {
                            Results = new ConceptPreflightCheckResult[]
                            {
                                new ConceptPreflightCheckResult
                                {
                                    Id = Guid.NewGuid(),
                                    UniversalId = ConceptUrn.From("urn:leaf:concept:diag:codeset=ICD9+code=123.42"),
                                    IsPresent = true,
                                    IsAuthorized = true
                                },
                                new ConceptPreflightCheckResult
                                {
                                    Id = Guid.NewGuid(),
                                    UniversalId = ConceptUrn.From("urn:leaf:concept:diag:codeset=ICD9+code=123.45"),
                                    IsPresent = true,
                                    IsAuthorized = true
                                }
                            }
                        }
                    },
                    DirectQueriesCheck = new PreflightQueries
                    {
                        Results = new QueryPreflightCheckResult[]
                        {
                            new QueryPreflightCheckResult
                            {
                                QueryRef = first,
                                IsPresent = true,
                                IsAuthorized = true,
                                ConceptCheck = new ConceptPreflightCheck
                                {
                                    Results = new ConceptPreflightCheckResult[]
                                    {
                                        new ConceptPreflightCheckResult
                                        {
                                            Id = Guid.NewGuid(),
                                            UniversalId = ConceptUrn.From("urn:leaf:concept:diag:codeset=ICD9+code=123.42"),
                                            IsPresent = true,
                                            IsAuthorized = true
                                        },
                                        new ConceptPreflightCheckResult
                                        {
                                            Id = Guid.NewGuid(),
                                            UniversalId = ConceptUrn.From("urn:leaf:concept:diag:codeset=ICD9+code=123.45"),
                                            IsPresent = true,
                                            IsAuthorized = true
                                        }
                                    }
                                }
                            },
                            new QueryPreflightCheckResult
                            {
                                QueryRef = second,
                                IsPresent = true,
                                IsAuthorized = true,
                                ConceptCheck = new ConceptPreflightCheck
                                {
                                    Results = new ConceptPreflightCheckResult[]
                                    {
                                        new ConceptPreflightCheckResult
                                        {
                                            Id = Guid.NewGuid(),
                                            UniversalId = ConceptUrn.From("urn:leaf:concept:diag:codeset=ICD9+code=123.41"),
                                            IsPresent = true,
                                            IsAuthorized = true
                                        },
                                        new ConceptPreflightCheckResult
                                        {
                                            Id = Guid.NewGuid(),
                                            UniversalId = ConceptUrn.From("urn:leaf:concept:diag:codeset=ICD9+code=123.50"),
                                            IsPresent = true,
                                            IsAuthorized = true
                                        }
                                    }
                                }
                            }
                        }
                    }
                },
                true
            });

            yield return(new object[]
            {
                new PreflightResources(new QueryRef[] { })
                {
                    DirectConceptsCheck = new PreflightConcepts
                    {
                        PreflightCheck = new ConceptPreflightCheck
                        {
                            Results = new ConceptPreflightCheckResult[]
                            {
                                new ConceptPreflightCheckResult
                                {
                                    Id = Guid.NewGuid(),
                                    UniversalId = ConceptUrn.From("urn:leaf:concept:diag:codeset=ICD9+code=123.42"),
                                    IsPresent = false,
                                    IsAuthorized = false
                                },
                                new ConceptPreflightCheckResult
                                {
                                    Id = Guid.NewGuid(),
                                    UniversalId = ConceptUrn.From("urn:leaf:concept:diag:codeset=ICD9+code=123.45"),
                                    IsPresent = true,
                                    IsAuthorized = true
                                }
                            }
                        }
                    },
                    DirectQueriesCheck = new PreflightQueries
                    {
                        Results = new QueryPreflightCheckResult[]
                        {
                            new QueryPreflightCheckResult
                            {
                                QueryRef = first,
                                IsPresent = true,
                                IsAuthorized = true,
                                ConceptCheck = new ConceptPreflightCheck
                                {
                                    Results = new ConceptPreflightCheckResult[]
                                    {
                                        new ConceptPreflightCheckResult
                                        {
                                            Id = Guid.NewGuid(),
                                            UniversalId = ConceptUrn.From("urn:leaf:concept:diag:codeset=ICD9+code=123.42"),
                                            IsPresent = true,
                                            IsAuthorized = true
                                        },
                                        new ConceptPreflightCheckResult
                                        {
                                            Id = Guid.NewGuid(),
                                            UniversalId = ConceptUrn.From("urn:leaf:concept:diag:codeset=ICD9+code=123.45"),
                                            IsPresent = true,
                                            IsAuthorized = true
                                        }
                                    }
                                }
                            },
                            new QueryPreflightCheckResult
                            {
                                QueryRef = second,
                                IsPresent = true,
                                IsAuthorized = true,
                                ConceptCheck = new ConceptPreflightCheck
                                {
                                    Results = new ConceptPreflightCheckResult[]
                                    {
                                        new ConceptPreflightCheckResult
                                        {
                                            Id = Guid.NewGuid(),
                                            UniversalId = ConceptUrn.From("urn:leaf:concept:diag:codeset=ICD9+code=123.41"),
                                            IsPresent = true,
                                            IsAuthorized = true
                                        },
                                        new ConceptPreflightCheckResult
                                        {
                                            Id = Guid.NewGuid(),
                                            UniversalId = ConceptUrn.From("urn:leaf:concept:diag:codeset=ICD9+code=123.50"),
                                            IsPresent = true,
                                            IsAuthorized = true
                                        }
                                    }
                                }
                            }
                        }
                    }
                },
                false
            });

            yield return(new object[]
            {
                new PreflightResources(new QueryRef[] { })
                {
                    DirectConceptsCheck = new PreflightConcepts
                    {
                        PreflightCheck = new ConceptPreflightCheck
                        {
                            Results = new ConceptPreflightCheckResult[]
                            {
                                new ConceptPreflightCheckResult
                                {
                                    Id = Guid.NewGuid(),
                                    UniversalId = ConceptUrn.From("urn:leaf:concept:diag:codeset=ICD9+code=123.42"),
                                    IsPresent = true,
                                    IsAuthorized = true
                                },
                                new ConceptPreflightCheckResult
                                {
                                    Id = Guid.NewGuid(),
                                    UniversalId = ConceptUrn.From("urn:leaf:concept:diag:codeset=ICD9+code=123.45"),
                                    IsPresent = true,
                                    IsAuthorized = true
                                }
                            }
                        }
                    },
                    DirectQueriesCheck = new PreflightQueries
                    {
                        Results = new QueryPreflightCheckResult[]
                        {
                            new QueryPreflightCheckResult
                            {
                                QueryRef = first,
                                IsPresent = false,
                                IsAuthorized = false,
                                ConceptCheck = new ConceptPreflightCheck
                                {
                                    Results = new ConceptPreflightCheckResult[]
                                    {
                                        new ConceptPreflightCheckResult
                                        {
                                            Id = Guid.NewGuid(),
                                            UniversalId = ConceptUrn.From("urn:leaf:concept:diag:codeset=ICD9+code=123.42"),
                                            IsPresent = true,
                                            IsAuthorized = true
                                        },
                                        new ConceptPreflightCheckResult
                                        {
                                            Id = Guid.NewGuid(),
                                            UniversalId = ConceptUrn.From("urn:leaf:concept:diag:codeset=ICD9+code=123.45"),
                                            IsPresent = true,
                                            IsAuthorized = true
                                        }
                                    }
                                }
                            },
                            new QueryPreflightCheckResult
                            {
                                QueryRef = second,
                                IsPresent = true,
                                IsAuthorized = true,
                                ConceptCheck = new ConceptPreflightCheck
                                {
                                    Results = new ConceptPreflightCheckResult[]
                                    {
                                        new ConceptPreflightCheckResult
                                        {
                                            Id = Guid.NewGuid(),
                                            UniversalId = ConceptUrn.From("urn:leaf:concept:diag:codeset=ICD9+code=123.41"),
                                            IsPresent = true,
                                            IsAuthorized = true
                                        },
                                        new ConceptPreflightCheckResult
                                        {
                                            Id = Guid.NewGuid(),
                                            UniversalId = ConceptUrn.From("urn:leaf:concept:diag:codeset=ICD9+code=123.50"),
                                            IsPresent = true,
                                            IsAuthorized = true
                                        }
                                    }
                                }
                            }
                        }
                    }
                },
                false
            });

            yield return(new object[]
            {
                new PreflightResources(new QueryRef[] { })
                {
                    DirectConceptsCheck = new PreflightConcepts
                    {
                        PreflightCheck = new ConceptPreflightCheck
                        {
                            Results = new ConceptPreflightCheckResult[]
                            {
                                new ConceptPreflightCheckResult
                                {
                                    Id = Guid.NewGuid(),
                                    UniversalId = ConceptUrn.From("urn:leaf:concept:diag:codeset=ICD9+code=123.42"),
                                    IsPresent = true,
                                    IsAuthorized = true
                                },
                                new ConceptPreflightCheckResult
                                {
                                    Id = Guid.NewGuid(),
                                    UniversalId = ConceptUrn.From("urn:leaf:concept:diag:codeset=ICD9+code=123.45"),
                                    IsPresent = true,
                                    IsAuthorized = true
                                }
                            }
                        }
                    },
                    DirectQueriesCheck = new PreflightQueries
                    {
                        Results = new QueryPreflightCheckResult[]
                        {
                            new QueryPreflightCheckResult
                            {
                                QueryRef = first,
                                IsPresent = true,
                                IsAuthorized = true,
                                ConceptCheck = new ConceptPreflightCheck
                                {
                                    Results = new ConceptPreflightCheckResult[]
                                    {
                                        new ConceptPreflightCheckResult
                                        {
                                            Id = Guid.NewGuid(),
                                            UniversalId = ConceptUrn.From("urn:leaf:concept:diag:codeset=ICD9+code=123.42"),
                                            IsPresent = true,
                                            IsAuthorized = true
                                        },
                                        new ConceptPreflightCheckResult
                                        {
                                            Id = Guid.NewGuid(),
                                            UniversalId = ConceptUrn.From("urn:leaf:concept:diag:codeset=ICD9+code=123.45"),
                                            IsPresent = true,
                                            IsAuthorized = true
                                        }
                                    }
                                }
                            },
                            new QueryPreflightCheckResult
                            {
                                QueryRef = second,
                                IsPresent = true,
                                IsAuthorized = true,
                                ConceptCheck = new ConceptPreflightCheck
                                {
                                    Results = new ConceptPreflightCheckResult[]
                                    {
                                        new ConceptPreflightCheckResult
                                        {
                                            Id = Guid.NewGuid(),
                                            UniversalId = ConceptUrn.From("urn:leaf:concept:diag:codeset=ICD9+code=123.41"),
                                            IsPresent = true,
                                            IsAuthorized = true
                                        },
                                        new ConceptPreflightCheckResult
                                        {
                                            Id = Guid.NewGuid(),
                                            UniversalId = ConceptUrn.From("urn:leaf:concept:diag:codeset=ICD9+code=123.50"),
                                            IsPresent = false,
                                            IsAuthorized = false
                                        }
                                    }
                                }
                            }
                        }
                    }
                },
                false
            });
        }
Esempio n. 23
0
        public void QueryRefEqualityComparer_Theory(QueryRef x, QueryRef y, bool expected)
        {
            var equal = new QueryRefEqualityComparer();

            Assert.Equal(expected, equal.Equals(x, y));
        }
Esempio n. 24
0
        public async Task <CompilerValidationContext <DemographicCompilerContext> > GetDemographicQueryCompilerContext(QueryRef queryRef)
        {
            log.LogInformation("Getting DemographicQueryCompilerContext. QueryRef:{@QueryRef}", queryRef);
            var hydrator = GetContextHydrator(queryRef);

            try
            {
                var context = await hydrator(queryRef);

                var state = GetContextState(context);
                return(new CompilerValidationContext <DemographicCompilerContext>
                {
                    Context = context,
                    State = state
                });
            }
            catch (SqlException se)
            {
                log.LogError("Could not get demographic query context. Query:{@QueryRef} Code:{Code} Error:{Error}", queryRef, se.ErrorCode, se.Message);
                se.MapThrow();
                throw;
            }
        }