public string DescribeProblem(CohortAggregateContainer container) { //if it's a root container don't check if (_childProvider.AllCohortIdentificationConfigurations.Any(c => c.RootCohortAggregateContainer_ID == container.ID)) { return(null); } //count children that are not disabled, there should be at least 2 var children = _childProvider.GetChildren(container); var enabledChildren = children.Where(o => !(o is IDisableable d) || !d.IsDisabled).ToArray(); if (enabledChildren.Length == 0) { return("Empty SET containers have no effect (and will be ignored)"); } if (enabledChildren.Length == 1) { return("SET container operations have no effect if there is only one child within"); } //are there any children with the same order in this container? if (children.OfType <IOrderable>().GroupBy(o => o.Order).Any(g => g.Count() > 1)) { return("Child order is ambiguous, show the Order column and reorder contents"); } return(null); }
public string DescribeProblem(CohortAggregateContainer container) { // Make sure if the user has the default configuration (Root, Inclusion, Exclusion) that they do not mess up the ordering and get very confused // if the container is inclusion make sure the user hasn't reordered the container to make it act as exclusion instead! if (container.Name?.Contains(ExecuteCommandCreateNewCohortIdentificationConfiguration.InclusionCriteriaName) ?? false) { // if there is a parent container var parents = _childProvider.GetDescendancyListIfAnyFor(container); if (parents != null && parents.Last() is CohortAggregateContainer parentContainer) { // which is EXCEPT if (parentContainer.Operation == SetOperation.EXCEPT) { // then something called 'inclusion criteria' should be the first among them var first = _childProvider.GetChildren(parentContainer).OfType <IOrderable>().OrderBy(o => o.Order).FirstOrDefault(); if (first != null && (!first.Equals(container))) { return($"{container.Name} must be the first container in the parent set. Please re-order it to be the first"); } } } } //count children that are not disabled var children = _childProvider.GetChildren(container); var enabledChildren = children.Where(o => !(o is IDisableable d) || !d.IsDisabled).ToArray(); //are there any children with the same order in this container? if (children.OfType <IOrderable>().GroupBy(o => o.Order).Any(g => g.Count() > 1)) { return("Child order is ambiguous, show the Order column and reorder contents"); } //check if we're looking at a root container if (_childProvider.AllCohortIdentificationConfigurations.Any(c => c.RootCohortAggregateContainer_ID == container.ID)) { //if it's a root container //then UNION should have at least 1 if (enabledChildren.Length < 1 && container.Operation == SetOperation.UNION) { return("You must have at least one element in the root container"); } //Excepts and Intersects must have at least 2 if (enabledChildren.Length < 2 && (container.Operation == SetOperation.EXCEPT || container.Operation == SetOperation.INTERSECT)) { return("EXCEPT and INTERSECT container operations must have at least two elements within"); } } else { //if it's not a root, then there should be at least 2 if (enabledChildren.Length == 0) { return("SET containers cannot be empty"); } if (enabledChildren.Length == 1) { return("SET container operations have no effect if there is only one child within"); } } return(null); }