private ParameterCollectionUIOptions Create(ExtractionConfiguration extractionConfiguration) { var globals = extractionConfiguration.GlobalExtractionFilterParameters; var paramManager = new ParameterManager(globals); foreach (var selectedDatasets in extractionConfiguration.SelectedDataSets) { var rootFilterContainer = selectedDatasets.RootFilterContainer; if (rootFilterContainer != null) { var allFilters = SqlQueryBuilderHelper.GetAllFiltersUsedInContainerTreeRecursively(rootFilterContainer).ToList(); paramManager.AddParametersFor(allFilters);//query level } } return(new ParameterCollectionUIOptions(UseCaseExtractionConfigurationGlobals, extractionConfiguration, ParameterLevel.Global, paramManager, CreateNewParameterForExtractionConfiguration)); }
/// <summary> /// Creates a new CohortAggregateContainer tree containing a clone container for each container in the original tree and a clone AggregateConfiguration for each in the original tree /// but with a rename in which AggregateConfigurations in the first tree are expected to start cic_X where X is the original cohort identification configuration ID, this will be replaced /// with the new clone's ID /// </summary> /// <param name="notifier"></param> /// <param name="original"></param> /// <param name="clone"></param> /// <param name="parentToCloneJoinablesDictionary"></param> public CohortAggregateContainer CloneEntireTreeRecursively(ICheckNotifier notifier, CohortIdentificationConfiguration original, CohortIdentificationConfiguration clone, Dictionary <JoinableCohortAggregateConfiguration, JoinableCohortAggregateConfiguration> parentToCloneJoinablesDictionary) { //what is in us? var contents = GetOrderedContents(); //clone us with same order (in parents) var cloneContainer = new CohortAggregateContainer((ICatalogueRepository)Repository, Operation); cloneContainer.Name = Name; cloneContainer.Order = Order; cloneContainer.SaveToDatabase(); //for each thing in us foreach (IOrderable content in contents) { int order = content.Order; var config = content as AggregateConfiguration; var container = content as CohortAggregateContainer; //its a config, clone the config and add it to the clone container if (config != null) { var configClone = clone.ImportAggregateConfigurationAsIdentifierList(config, null, false); notifier.OnCheckPerformed(new CheckEventArgs("Created clone dataset " + configClone + " with ID " + configClone.ID, CheckResult.Success)); cloneContainer.AddChild(configClone, order); //if the original used any joinable patient index tables var usedJoins = config.PatientIndexJoinablesUsed; //our dictionary should have a record of it along with a clone patient index table we should hook our clone up to foreach (var j in usedJoins) { //for some reason the CohortIdentificationConfiguration didn't properly clone the joinable permission or didn't add it to the dictionary if (!parentToCloneJoinablesDictionary.ContainsKey(j.JoinableCohortAggregateConfiguration)) { throw new KeyNotFoundException("Configuration " + configClone + " uses Patient Index Table " + j.AggregateConfiguration + " but our dictionary did not have the key, why was that joinable not cloned?"); } //we do have a clone copy of the joinable permission, set the clone aggregate var cloneJoinable = parentToCloneJoinablesDictionary[j.JoinableCohortAggregateConfiguration]; var cloneJoinUse = cloneJoinable.AddUser(configClone); cloneJoinUse.JoinType = j.JoinType; cloneJoinUse.SaveToDatabase(); //Now! (brace yourself). Some the filters in the AggregateConfiguration we just cloned might reference a table called ix2934 or whetever, this //is the Joinable we need to do a replace to point them at the correct ix number (although if they are good users they will have aliased any //patient index columns anyway) if (configClone.RootFilterContainer_ID != null) { foreach (var clonedFilter in SqlQueryBuilderHelper.GetAllFiltersUsedInContainerTreeRecursively(configClone.RootFilterContainer)) { var oldTableAlias = j.GetJoinTableAlias(); var newTableAlias = cloneJoinUse.GetJoinTableAlias(); clonedFilter.WhereSQL = clonedFilter.WhereSQL.Replace(oldTableAlias, newTableAlias); clonedFilter.SaveToDatabase(); } } } } //its another container (a subcontainer), recursively call the clone operation on it and add that subtree to teh clone container if (container != null) { var cloneSubContainer = container.CloneEntireTreeRecursively(notifier, original, clone, parentToCloneJoinablesDictionary); notifier.OnCheckPerformed(new CheckEventArgs("Created clone container " + cloneSubContainer + " with ID " + cloneSubContainer.ID, CheckResult.Success)); cloneContainer.AddChild(cloneSubContainer); } } //return the clone we created return(cloneContainer); }