示例#1
0
        public void TestIPluginCohortCompiler_PopulatesCacheCorrectly()
        {
            var activator = new ConsoleInputManager(RepositoryLocator, new ThrowImmediatelyCheckNotifier())
            {
                DisallowInput = true
            };

            // create a cohort config
            var cic = new CohortIdentificationConfiguration(CatalogueRepository, "mycic");

            cic.QueryCachingServer_ID = externalDatabaseServer.ID;
            cic.SaveToDatabase();

            // this special Catalogue will be detected by ExamplePluginCohortCompiler and interpreted as an API call
            var myApi = new Catalogue(CatalogueRepository, ExamplePluginCohortCompiler.ExampleAPIName);

            // add it to the cohort config
            cic.CreateRootContainerIfNotExists();

            // create a use of the API as an AggregateConfiguration
            var cmd = new ExecuteCommandAddCatalogueToCohortIdentificationSetContainer(activator, new CatalogueCombineable(myApi), cic.RootCohortAggregateContainer);

            Assert.IsFalse(cmd.IsImpossible, cmd.ReasonCommandImpossible);
            cmd.Execute();

            // run the cic
            var source = new CohortIdentificationConfigurationSource();

            source.PreInitialize(cic, new ThrowImmediatelyDataLoadEventListener());
            var dt = source.GetChunk(new ThrowImmediatelyDataLoadEventListener(), new GracefulCancellationToken());

            // 5 random chi numbers
            Assert.AreEqual(5, dt.Rows.Count);

            // test stale
            cmd.AggregateCreatedIfAny.Description = "2";
            cmd.AggregateCreatedIfAny.SaveToDatabase();

            // run the cic again
            source = new CohortIdentificationConfigurationSource();
            source.PreInitialize(cic, new ThrowImmediatelyDataLoadEventListener());
            dt = source.GetChunk(new ThrowImmediatelyDataLoadEventListener(), new GracefulCancellationToken());

            // because the rules changed to generate 2 chis only there should be a new result
            Assert.AreEqual(2, dt.Rows.Count);

            var results = new[] { (string)dt.Rows[0][0], (string)dt.Rows[1][0] };

            // run the cic again with no changes, the results should be unchanged since there is no config changed
            // I.e. no new chis should be generated and the cached values returned
            source = new CohortIdentificationConfigurationSource();
            source.PreInitialize(cic, new ThrowImmediatelyDataLoadEventListener());
            dt = source.GetChunk(new ThrowImmediatelyDataLoadEventListener(), new GracefulCancellationToken());

            Assert.AreEqual(2, dt.Rows.Count);
            var results2 = new[] { (string)dt.Rows[0][0], (string)dt.Rows[1][0] };

            Assert.AreEqual(results[0], results2[0]);
            Assert.AreEqual(results[1], results2[1]);
        }
示例#2
0
        public void Test_AggregateConfigurationOrder_TwoAggregates()
        {
            GetObjects(out Catalogue cata, out CohortIdentificationConfiguration cic);

            //we should be able to add it
            var cmd = new ExecuteCommandAddCatalogueToCohortIdentificationSetContainer(ItemActivator, new CatalogueCommand(cata), cic.RootCohortAggregateContainer);

            AssertCommandIsPossible(cmd);

            cmd.Execute();

            var ac1 = (AggregateConfiguration)(cic.RootCohortAggregateContainer.GetOrderedContents().First());

            Assert.AreEqual(0, ac1.Order);

            //add another one
            var cmd2 = new ExecuteCommandAddCatalogueToCohortIdentificationSetContainer(ItemActivator, new CatalogueCommand(cata), cic.RootCohortAggregateContainer);

            AssertCommandIsPossible(cmd2);
            cmd2.Execute();

            //the added ones should have sensible order (no collisions)
            var all = cic.RootCohortAggregateContainer.GetOrderedContents().ToArray();

            ac1 = (AggregateConfiguration)all[0];
            var ac2 = (AggregateConfiguration)all[1];

            Assert.AreEqual(0, ac1.Order);
            Assert.AreEqual(1, ac2.Order);
        }
示例#3
0
        public void Test_AggregateConfigurationOrder_MovingAggregatesBetweenContainers()
        {
            GetObjects(out Catalogue cata, out CohortIdentificationConfiguration cic);

            //we should be able to add it to root container
            var cmd = new ExecuteCommandAddCatalogueToCohortIdentificationSetContainer(ItemActivator, new CatalogueCommand(cata), cic.RootCohortAggregateContainer);

            cmd.Execute();


            //create a subcontainer
            var subcontainer = new CohortAggregateContainer(Repository, SetOperation.INTERSECT);

            cic.RootCohortAggregateContainer.AddChild(subcontainer);

            //add the second ac to the subcontainer
            var cmd2 = new ExecuteCommandAddCatalogueToCohortIdentificationSetContainer(ItemActivator, new CatalogueCommand(cata), subcontainer);

            cmd2.Execute();

            //should now look like this:
            //Root
            //  INTERSECT
            //      Ac2
            //  Ac 1
            //

            var all = cic.RootCohortAggregateContainer.GetOrderedContents().ToArray();

            var ac1       = (AggregateConfiguration)all[1];
            var ac2       = (AggregateConfiguration)subcontainer.GetOrderedContents().Single();
            var intersect = (CohortAggregateContainer)all[0];

            Assert.AreEqual(0, intersect.Order);
            Assert.AreEqual(1, ac1.Order);
            Assert.AreEqual(0, ac2.Order);

            //now move the Ac2 to Root (problematic since both Ac 2 and the INTERSECT have Order 0 - in their own separate containers)
            var cmd3 = new ExecuteCommandMoveAggregateIntoContainer(ItemActivator, new AggregateConfigurationCommand(ac2), cic.RootCohortAggregateContainer);

            cmd3.Execute();

            all = cic.RootCohortAggregateContainer.GetOrderedContents().ToArray();

            //should now look like this
            //Root
            //  Ac2
            //  INTERSECT (empty)
            //  Ac 1

            ac2       = (AggregateConfiguration)all[0];
            intersect = (CohortAggregateContainer)all[1];
            ac1       = (AggregateConfiguration)all[2];

            Assert.AreEqual(0, ac2.Order);
            Assert.AreEqual(1, intersect.Order);
            Assert.AreEqual(2, ac1.Order);
        }
示例#4
0
        public void CreateCohortSet(CohortIdentificationConfiguration cic, CohortAggregateContainer targetContainer, int order)
        {
            var cata = cbxCatalogues.SelectedItem as Catalogue;

            if (cata == null)
            {
                throw new Exception("Catalogue has not been picked!");
            }

            var cataCommand = new CatalogueCombineable(cata);

            //use this one
            cataCommand.ResolveMultipleExtractionIdentifiers = (s, e) => cbxColumns.SelectedItem as ExtractionInformation;

            var cmd = new ExecuteCommandAddCatalogueToCohortIdentificationSetContainer(_activator, cataCommand, targetContainer);

            cmd.SkipMandatoryFilterCreation = true;
            cmd.Execute();

            var aggregate = cmd.AggregateCreatedIfAny;

            var filterOp = (FilterContainerOperation)ddAndOr.SelectedItem;

            IContainer filterContainer;

            if (aggregate.RootFilterContainer_ID != null)
            {
                //this is the case if there are mandatory filters in the dataset
                filterContainer           = aggregate.RootFilterContainer;
                filterContainer.Operation = filterOp;
                filterContainer.SaveToDatabase();
            }
            else
            {
                filterContainer = new AggregateFilterContainer(_activator.RepositoryLocator.CatalogueRepository, filterOp);
            }

            aggregate.Order = order;
            aggregate.RootFilterContainer_ID = filterContainer.ID;
            aggregate.SaveToDatabase();

            List <IFilter> filtersAddedSoFar = new List <IFilter>();

            foreach (var ui in _filterUIs)
            {
                var f = ui.CreateFilter(new AggregateFilterFactory(_activator.RepositoryLocator.CatalogueRepository), filterContainer, filtersAddedSoFar.ToArray());
                filtersAddedSoFar.Add(f);
            }
        }
示例#5
0
        private void AddCatalogues()
        {
            SelectIMapsDirectlyToDatabaseTableDialog dialog = new SelectIMapsDirectlyToDatabaseTableDialog(_activator, RepositoryLocator.CatalogueRepository.GetAllObjects <Catalogue>(), false, false);

            dialog.AllowMultiSelect = true;

            if (dialog.ShowDialog() == DialogResult.OK)
            {
                if (!dialog.MultiSelected.Any())
                {
                    return;
                }

                PopupChecksUI checks = new PopupChecksUI("Adding Catalogues", true);


                foreach (Catalogue catalogue in dialog.MultiSelected)
                {
                    try
                    {
                        var cmd          = new CatalogueCombineable(catalogue);
                        var cmdExecution = new ExecuteCommandAddCatalogueToCohortIdentificationSetContainer(_activator, cmd, _container);
                        if (cmdExecution.IsImpossible)
                        {
                            checks.OnCheckPerformed(
                                new CheckEventArgs(
                                    "Could not add Catalogue " + catalogue + " because of Reason:" +
                                    cmdExecution.ReasonCommandImpossible, CheckResult.Fail));
                        }
                        else
                        {
                            cmdExecution.Execute();
                            checks.OnCheckPerformed(new CheckEventArgs("Successfully added Catalogue " + catalogue, CheckResult.Success));
                        }
                    }
                    catch (Exception e)
                    {
                        checks.OnCheckPerformed(new CheckEventArgs("Failed to add Catalogue " + catalogue + "(see Exception for details)", CheckResult.Fail, e));
                    }
                }
            }
        }
示例#6
0
        public void TestIPluginCohortCompiler_APIsCantHavePatientIndexTables()
        {
            var activator = new ConsoleInputManager(RepositoryLocator, new ThrowImmediatelyCheckNotifier())
            {
                DisallowInput = true
            };

            // create a cohort config
            var cic = new CohortIdentificationConfiguration(CatalogueRepository, "mycic");

            cic.QueryCachingServer_ID = externalDatabaseServer.ID;
            cic.SaveToDatabase();

            // this special Catalogue will be detected by ExamplePluginCohortCompiler and interpreted as an API call
            var myApi = new Catalogue(CatalogueRepository, ExamplePluginCohortCompiler.ExampleAPIName);

            // add it to the cohort config
            cic.CreateRootContainerIfNotExists();

            // We need something in the root container otherwise the cic won't build
            var cmd = new ExecuteCommandAddCatalogueToCohortIdentificationSetContainer(activator, new CatalogueCombineable(myApi), cic.RootCohortAggregateContainer);

            Assert.IsFalse(cmd.IsImpossible, cmd.ReasonCommandImpossible);
            cmd.Execute();
            var regularAggregate = cmd.AggregateCreatedIfAny;

            // The thing we are wanting to test - creating a use of the API as a patient index table
            var cmd2 = new ExecuteCommandAddCatalogueToCohortIdentificationAsPatientIndexTable(
                activator, new CatalogueCombineable(myApi), cic);

            Assert.IsFalse(cmd2.IsImpossible, cmd2.ReasonCommandImpossible);
            cmd2.Execute();

            var joinables = cic.GetAllJoinables();

            // make them join one another
            var ex = Assert.Throws <NotSupportedException>(() =>
                                                           new JoinableCohortAggregateConfigurationUse(CatalogueRepository, regularAggregate, joinables[0]));

            Assert.AreEqual("API calls cannot join with PatientIndexTables (The API call must be self contained)", ex.Message);
        }
示例#7
0
        public void TestIPluginCohortCompiler_TestCloneCic()
        {
            var activator = new ConsoleInputManager(RepositoryLocator, new ThrowImmediatelyCheckNotifier())
            {
                DisallowInput = true
            };

            // create a cohort config
            var cic = new CohortIdentificationConfiguration(CatalogueRepository, "mycic");

            cic.QueryCachingServer_ID = externalDatabaseServer.ID;
            cic.SaveToDatabase();

            // this special Catalogue will be detected by ExamplePluginCohortCompiler and interpreted as an API call
            var myApi = new Catalogue(CatalogueRepository, ExamplePluginCohortCompiler.ExampleAPIName);

            // add it to the cohort config
            cic.CreateRootContainerIfNotExists();

            // create a use of the API as an AggregateConfiguration
            var cmd = new ExecuteCommandAddCatalogueToCohortIdentificationSetContainer(activator, new CatalogueCombineable(myApi), cic.RootCohortAggregateContainer);

            Assert.IsFalse(cmd.IsImpossible, cmd.ReasonCommandImpossible);
            cmd.Execute();
            cmd.AggregateCreatedIfAny.Description = "33";
            cmd.AggregateCreatedIfAny.SaveToDatabase();

            // clone the cic
            var cmd2 = new ExecuteCommandCloneCohortIdentificationConfiguration(activator, cic);

            Assert.IsFalse(cmd2.IsImpossible, cmd2.ReasonCommandImpossible);
            cmd2.Execute();

            var cloneAc = cmd2.CloneCreatedIfAny.RootCohortAggregateContainer.GetAggregateConfigurations()[0];

            Assert.AreEqual("33", cloneAc.Description);
        }
示例#8
0
        public void TestIPluginCohortCompiler_AsPatientIndexTable()
        {
            var activator = new ConsoleInputManager(RepositoryLocator, new ThrowImmediatelyCheckNotifier())
            {
                DisallowInput = true
            };

            // Create a regular normal boring old table that will join into the results of the API call
            var db = GetCleanedServer(DatabaseType.MicrosoftSQLServer);

            using DataTable dt = new DataTable();
            dt.Columns.Add("chi");
            dt.Rows.Add("0101010101");

            var tbl   = db.CreateTable("RegularBoringOldTable", dt);
            var cata  = (Catalogue)Import(tbl);
            var eiChi = cata.GetAllExtractionInformation()[0];

            eiChi.IsExtractionIdentifier = true;
            eiChi.SaveToDatabase();

            // create a cohort config
            var cic = new CohortIdentificationConfiguration(CatalogueRepository, "mycic");

            cic.QueryCachingServer_ID = externalDatabaseServer.ID;
            cic.SaveToDatabase();

            // this special Catalogue will be detected by ExamplePluginCohortCompiler and interpreted as an API call
            var myApi = new Catalogue(CatalogueRepository, ExamplePluginCohortCompiler.ExampleAPIName);

            // add it to the cohort config
            cic.CreateRootContainerIfNotExists();

            // Add the regular table
            var cmd = new ExecuteCommandAddCatalogueToCohortIdentificationSetContainer(activator, new CatalogueCombineable(cata), cic.RootCohortAggregateContainer);

            Assert.IsFalse(cmd.IsImpossible, cmd.ReasonCommandImpossible);
            cmd.Execute();
            var regularAggregate = cmd.AggregateCreatedIfAny;

            // The thing we are wanting to test - creating a use of the API as a patient index table
            var cmd2 = new ExecuteCommandAddCatalogueToCohortIdentificationAsPatientIndexTable(
                activator, new CatalogueCombineable(myApi), cic);

            Assert.IsFalse(cmd2.IsImpossible, cmd2.ReasonCommandImpossible);
            cmd2.Execute();

            var joinables = cic.GetAllJoinables();

            Assert.AreEqual(1, joinables.Length);

            // make them join one another
            new JoinableCohortAggregateConfigurationUse(CatalogueRepository, regularAggregate, joinables[0]);

            // run the cic again
            var source = new CohortIdentificationConfigurationSource();

            source.PreInitialize(cic, new ThrowImmediatelyDataLoadEventListener());
            var result = source.GetChunk(new ThrowImmediatelyDataLoadEventListener(), new GracefulCancellationToken());

            Assert.AreEqual(1, result.Rows.Count);
        }