diff --git a/CHANGELOG.md b/CHANGELOG.md index 65a407f7d0..9f0bf1c0d4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [9.2.0] - Unreleased - Add Internal Note to Catalogue +- Fix issue with using Internal Catalogues in Cohort Identification Configurations ## [9.1.2] - Unreleased - Automatically fetch user settings from previous versions of RDMP when installing the latest version diff --git a/Rdmp.Core.Tests/CohortCreation/CohortCompilerTests.cs b/Rdmp.Core.Tests/CohortCreation/CohortCompilerTests.cs index 48d582cf81..001d2a7cd3 100644 --- a/Rdmp.Core.Tests/CohortCreation/CohortCompilerTests.cs +++ b/Rdmp.Core.Tests/CohortCreation/CohortCompilerTests.cs @@ -197,4 +197,24 @@ public void TestCompilerAddAllTasks(TestCompilerAddAllTasksTestCase testCase, bo aggregate5.DeleteInDatabase(); } } + + [Test] + public void TestCompilerWithInternalCatalogues() + { + var compiler = new CohortCompiler(cohortIdentificationConfiguration); + testData.catalogue.IsInternalDataset = true; + testData.catalogue.SaveToDatabase(); + + rootcontainer.AddChild(aggregate1, 1); + rootcontainer.AddChild(container1); + container1.Order = 2; + container1.SaveToDatabase(); + + cohortIdentificationConfiguration.RootCohortAggregateContainer_ID = rootcontainer.ID; + cohortIdentificationConfiguration.SaveToDatabase(); + + compiler.AddAllTasks(true); + Assert.That(compiler.Tasks.Keys.Select(k => k.State).Where(s => s == CompilationState.Crashed).ToList(), Has.Count.EqualTo(3)); + Assert.That(compiler.Tasks.Keys.Where(s => s.State == CompilationState.Crashed).Select(k => k.CrashMessage.Message).ToList().Any(m => m.Contains(" is marked as Internal. Internal Catalogues cannot be used in Cohort Identification Configurations."))); + } } \ No newline at end of file diff --git a/Rdmp.Core/CohortCreation/Execution/CohortCompiler.cs b/Rdmp.Core/CohortCreation/Execution/CohortCompiler.cs index a1f92685de..f78d2b065c 100644 --- a/Rdmp.Core/CohortCreation/Execution/CohortCompiler.cs +++ b/Rdmp.Core/CohortCreation/Execution/CohortCompiler.cs @@ -320,6 +320,28 @@ public ICompileable AddTask(IMapsDirectlyToDatabaseTable runnable, ISqlParameter task.State = CompilationState.Crashed; } + if(task.Child is CohortAggregateContainer cac) + { + foreach (var cacac in cac.GetAggregateConfigurations()) + { + if (cacac.Catalogue != null && cacac.Catalogue.IsInternalDataset) + { + task.CrashMessage = new ArgumentException($"Catalogue {cacac.Catalogue.Name} is marked as Internal. Internal Catalogues cannot be used in Cohort Identification Configurations."); + task.State = CompilationState.Crashed; + break; + } + } + } + + if (task.Child is AggregateConfiguration ac) + { + if (ac.Catalogue != null && ac.Catalogue.IsInternalDataset) + { + task.CrashMessage = new ArgumentException($"Catalogue {ac.Catalogue.Name} is marked as Internal. Internal Catalogues cannot be used in Cohort Identification Configurations."); + task.State = CompilationState.Crashed; + } + } + task.Log = queryBuilder?.Results?.Log; diff --git a/Rdmp.Core/CommandExecution/AtomicCommands/ExecuteCommandAddCatalogueToCohortIdentificationSetContainer.cs b/Rdmp.Core/CommandExecution/AtomicCommands/ExecuteCommandAddCatalogueToCohortIdentificationSetContainer.cs index 114cd2974e..97bb8a6219 100644 --- a/Rdmp.Core/CommandExecution/AtomicCommands/ExecuteCommandAddCatalogueToCohortIdentificationSetContainer.cs +++ b/Rdmp.Core/CommandExecution/AtomicCommands/ExecuteCommandAddCatalogueToCohortIdentificationSetContainer.cs @@ -58,6 +58,12 @@ public ExecuteCommandAddCatalogueToCohortIdentificationSetContainer(IBasicActiva { _catalogueCombineable = new CatalogueCombineable(catalogue); + if(catalogue.IsInternalDataset) + { + SetImpossible($"Catalogue '{catalogue}' is an Internal dataset and cannot be added to a Cohort Identification Set Container"); + return; + } + if (identifierColumn != null) { if (!identifierColumn.IsExtractionIdentifier) diff --git a/Rdmp.UI/CommandExecution/Proposals/ProposeExecutionWhenTargetIsAggregateConfiguration.cs b/Rdmp.UI/CommandExecution/Proposals/ProposeExecutionWhenTargetIsAggregateConfiguration.cs index fe16f2a209..f28c1d401c 100644 --- a/Rdmp.UI/CommandExecution/Proposals/ProposeExecutionWhenTargetIsAggregateConfiguration.cs +++ b/Rdmp.UI/CommandExecution/Proposals/ProposeExecutionWhenTargetIsAggregateConfiguration.cs @@ -8,6 +8,7 @@ using Rdmp.Core.CommandExecution.AtomicCommands; using Rdmp.Core.CommandExecution.Combining; using Rdmp.Core.Curation.Data.Aggregation; +using Rdmp.Core.Curation.Data.Cohort; using Rdmp.UI.AggregationUIs.Advanced; using Rdmp.UI.CommandExecution.AtomicCommands; using Rdmp.UI.ItemActivation; @@ -55,6 +56,7 @@ public override ICommandExecution ProposeExecution(ICombineToMakeCommand cmd, BasedOn = efps.ParameterSet.ExtractionFilter, ParameterSet = efps.ParameterSet }, + CatalogueCombineable catalogueCombineable => new ExecuteCommandAddCatalogueToCohortIdentificationSetContainer(ItemActivator,targetAggregateConfiguration.GetCohortAggregateContainerIfAny(),catalogueCombineable.Catalogue), _ => null }; } diff --git a/Rdmp.UI/CommandExecution/Proposals/ProposeExecutionWhenTargetIsCohortAggregateContainer.cs b/Rdmp.UI/CommandExecution/Proposals/ProposeExecutionWhenTargetIsCohortAggregateContainer.cs index 9bc5dff18c..aade7ff557 100644 --- a/Rdmp.UI/CommandExecution/Proposals/ProposeExecutionWhenTargetIsCohortAggregateContainer.cs +++ b/Rdmp.UI/CommandExecution/Proposals/ProposeExecutionWhenTargetIsCohortAggregateContainer.cs @@ -43,6 +43,7 @@ public override ICommandExecution ProposeExecution(ICombineToMakeCommand cmd, //source is catalogue case CatalogueCombineable sourceCatalogueCombineable: { + if (sourceCatalogueCombineable.Catalogue.IsInternalDataset) return null; if (sourceCatalogueCombineable.Catalogue.IsProjectSpecific(ItemActivator.RepositoryLocator.DataExportRepository)) { var dx = (DataExportChildProvider)ItemActivator.CoreChildProvider;