Esempio n. 1
0
        /// <summary>
        /// Sets up a new <see cref="AggregateBuilder"/> with all the columns (See <see cref="AggregateDimensions"/>), WHERE logic (See <see cref="RootFilterContainer"/>, Pivot
        /// etc.
        /// </summary>
        /// <remarks>Note that some elements e.g. axis are automatically handles at query generation time and therefore do not have to be injected into the <see cref="AggregateBuilder"/></remarks>
        /// <param name="topX">Maximum number of rows to return, the proper way to do this is via <see cref="AggregateTopX"/></param>
        /// <returns></returns>
        public AggregateBuilder GetQueryBuilder(int?topX = null)
        {
            if (string.IsNullOrWhiteSpace(CountSQL))
            {
                throw new NotSupportedException("Cannot generate an AggregateBuilder because the AggregateConfiguration '" + this + "' has no Count SQL, usually this is the case for 'Cohort Set' Aggregates or 'Patient Index Table' Aggregates.  In either case you should use CohortQueryBuilder instead of AggregateBuilder");
            }

            var allForcedJoins = ForcedJoins.ToArray();

            AggregateBuilder builder;
            var limitationSQLIfAny = topX == null ? null : "TOP " + topX.Value;

            if (allForcedJoins.Any())
            {
                builder = new AggregateBuilder(limitationSQLIfAny, CountSQL, this, allForcedJoins);
            }
            else
            {
                builder = new AggregateBuilder(limitationSQLIfAny, CountSQL, this);
            }

            builder.AddColumnRange(AggregateDimensions.ToArray());
            builder.RootFilterContainer = RootFilterContainer;

            if (PivotOnDimensionID != null)
            {
                builder.SetPivotToDimensionID(PivotDimension);
            }

            return(builder);
        }
Esempio n. 2
0
        /// <summary>
        /// Determines whether the AggregateConfiguration could be used in a <see cref="CohortIdentificationConfiguration"/> to identify a list of patients.  This will be true
        /// if there are no pivot/axis dimensions and one of the <see cref="AggregateDimensions"/> is marked <see cref="AggregateDimension.IsExtractionIdentifier"/>
        /// </summary>
        /// <param name="reason"></param>
        /// <returns></returns>
        public bool IsAcceptableAsCohortGenerationSource(out string reason)
        {
            reason = null;

            var dimensions = AggregateDimensions.ToArray();

            if (dimensions.Count(d => d.IsExtractionIdentifier) != 1)
            {
                reason = "There must be exactly 1 Dimension which is marked IsExtractionIdentifier";
            }

            if (PivotOnDimensionID != null)
            {
                reason = "It cannot contain a pivot";
            }

            if (GetAxisIfAny() != null)
            {
                reason = "It cannot have any axises";
            }

            return(reason == null);
        }