private async Task <Either <ActionResult, TableBuilderResultViewModel> > Query(
            Release release,
            ObservationQueryContext queryContext)
        {
            return(await _statisticsPersistenceHelper.CheckEntityExists <Subject>(queryContext.SubjectId)
                   .OnSuccessDo(CheckCanViewSubjectData)
                   .OnSuccess(async() =>
            {
                var observations = GetObservations(queryContext).AsQueryable();

                if (!observations.Any())
                {
                    return new TableBuilderResultViewModel();
                }

                return await _resultSubjectMetaService
                .GetSubjectMeta(release.Id, SubjectMetaQueryContext.FromObservationQueryContext(queryContext), observations)
                .OnSuccess(subjectMetaViewModel =>
                {
                    return new TableBuilderResultViewModel
                    {
                        SubjectMeta = subjectMetaViewModel,
                        Results = observations.Select(observation =>
                                                      _resultBuilder.BuildResult(observation, queryContext.Indicators))
                    };
                });
            }));
        }
Exemplo n.º 2
0
        private async Task <Either <ActionResult, TableBuilderResultViewModel> > Query(
            Release release,
            ObservationQueryContext queryContext,
            CancellationToken cancellationToken)
        {
            return(await _statisticsPersistenceHelper.CheckEntityExists <Subject>(queryContext.SubjectId)
                   .OnSuccessDo(CheckCanViewSubjectData)
                   .OnSuccess(async() =>
            {
                if (await GetMaximumTableCellCount(queryContext) > _options.MaxTableCellsAllowed)
                {
                    return ValidationUtils.ValidationResult(QueryExceedsMaxAllowableTableSize);
                }

                var matchedObservationIds =
                    (await _observationService.GetMatchedObservations(queryContext, cancellationToken))
                    .Select(row => row.Id);

                var observations = await _context
                                   .Observation
                                   .AsNoTracking()
                                   .Include(o => o.Location)
                                   .Include(o => o.FilterItems)
                                   .Where(o => matchedObservationIds.Contains(o.Id))
                                   .ToListAsync(cancellationToken);

                if (!observations.Any())
                {
                    return new TableBuilderResultViewModel();
                }

                return await _resultSubjectMetaService
                .GetSubjectMeta(
                    release.Id,
                    queryContext,
                    observations)
                .OnSuccess(subjectMetaViewModel =>
                {
                    return new TableBuilderResultViewModel
                    {
                        SubjectMeta = subjectMetaViewModel,
                        Results = observations.Select(observation =>
                                                      _resultBuilder.BuildResult(observation, queryContext.Indicators))
                    };
                });
            }));
        }