Beispiel #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]);
        }
Beispiel #2
0
        private CohortIdentificationConfiguration CreateCohortIdentificationConfiguration(ExtractionFilter inclusionFilter1)
        {
            //Create the top level configuration object
            var cic = new CohortIdentificationConfiguration(_repos.CatalogueRepository, "Tayside Lung Cancer Cohort");

            //create a UNION container for Inclusion Criteria
            var container = new CohortAggregateContainer(_repos.CatalogueRepository, SetOperation.UNION);

            container.Name = "Inclusion Criteria";
            container.SaveToDatabase();

            cic.RootCohortAggregateContainer_ID = container.ID;
            cic.SaveToDatabase();

            //Create a new cohort set to the 'Inclusion Criteria' based on the filters Catalogue
            var cata = inclusionFilter1.ExtractionInformation.CatalogueItem.Catalogue;
            var ac   = cic.CreateNewEmptyConfigurationForCatalogue(cata, (a, b) => { throw new Exception("Problem encountered with chi column(s)"); }, false);

            container.AddChild(ac, 0);

            //Add the filter to the WHERE logic of the cohort set
            var whereContainer = new AggregateFilterContainer(_repos.CatalogueRepository, FilterContainerOperation.OR);

            ac.Name = "People with " + inclusionFilter1.Name;
            ac.RootFilterContainer_ID = whereContainer.ID;
            cic.EnsureNamingConvention(ac); //this will put cicx at the front and cause implicit SaveToDatabase

            FilterImporter filterImporter = new FilterImporter(new AggregateFilterFactory(_repos.CatalogueRepository), null);
            var            cloneFilter    = filterImporter.ImportFilter(inclusionFilter1, null);

            whereContainer.AddChild(cloneFilter);

            return(cic);
        }
Beispiel #3
0
        public CohortIdentificationConfigurationMenu(RDMPContextMenuStripArgs args, CohortIdentificationConfiguration cic) : base(args, cic)
        {
            _cic = cic;

            Items.Add("View SQL", _activator.CoreIconProvider.GetImage(RDMPConcept.SQL), (s, e) => _activator.Activate <ViewCohortIdentificationConfigurationUI, CohortIdentificationConfiguration>(cic));

            Items.Add(new ToolStripSeparator());

            _executeAndImportCommand = new ExecuteCommandCreateNewCohortByExecutingACohortIdentificationConfiguration(_activator).SetTarget(cic);

            Add(_executeAndImportCommand);

            //associate with project
            Add(new ExecuteCommandAssociateCohortIdentificationConfigurationWithProject(_activator).SetTarget(cic));

            Items.Add(new ToolStripSeparator());

            _executeCommandClone = new ExecuteCommandCloneCohortIdentificationConfiguration(_activator).SetTarget(cic);
            Add(_executeCommandClone);

            Add(new ExecuteCommandFreezeCohortIdentificationConfiguration(_activator, cic, !cic.Frozen));

            Items.Add(new ToolStripSeparator());

            Add(new ExecuteCommandCreateNewCohortIdentificationConfiguration(_activator));

            Add(new ExecuteCommandSetQueryCachingDatabase(_activator, cic));
            Add(new ExecuteCommandCreateNewQueryCacheDatabase(_activator, cic));
        }
Beispiel #4
0
        public CohortIdentificationConfigurationMenu(RDMPContextMenuStripArgs args, CohortIdentificationConfiguration cic): base(args, cic)
        {
            _cic = cic;

            Items.Add("View SQL", _activator.CoreIconProvider.GetImage(RDMPConcept.SQL), (s, e) => _activator.Activate<ViewCohortIdentificationConfigurationUI, CohortIdentificationConfiguration>(cic));
                
            Items.Add(new ToolStripSeparator());

            _executeAndImportCommand = new ExecuteCommandCreateNewCohortByExecutingACohortIdentificationConfiguration(_activator).SetTarget(cic);
            
            Add(_executeAndImportCommand);
            
            //associate with project
            Add(new ExecuteCommandAssociateCohortIdentificationConfigurationWithProject(_activator).SetTarget(cic));
            
            Items.Add(new ToolStripSeparator());

            _executeCommandClone = new ExecuteCommandCloneCohortIdentificationConfiguration(_activator).SetTarget(cic);
            Add(_executeCommandClone);

            Add(new ExecuteCommandFreezeCohortIdentificationConfiguration(_activator, cic, !cic.Frozen));
            
            Items.Add(new ToolStripSeparator());

            Add(new ExecuteCommandCreateNewCohortIdentificationConfiguration(_activator));

            if(_activator.CoreChildProvider is DataExportChildProvider dx)
                AddGoTo(()=>dx.AllProjectAssociatedCics.Where(a=>a.CohortIdentificationConfiguration_ID == cic.ID).Select(a=>a.Project).Distinct(),"Project(s)");
            
        }
Beispiel #5
0
        protected override void SetUp()
        {
            base.SetUp();

            c    = new Catalogue(CatalogueRepository, "MyCata");
            ci   = new CatalogueItem(CatalogueRepository, c, "MyCataItem");
            ci2  = new CatalogueItem(CatalogueRepository, c, "YearColumn");
            t    = new TableInfo(CatalogueRepository, "MyTable");
            col  = new ColumnInfo(CatalogueRepository, "mycol", "varchar(10)", t);
            col2 = new ColumnInfo(CatalogueRepository, "myOtherCol", "varchar(10)", t);


            acCohort  = new AggregateConfiguration(CatalogueRepository, c, CohortIdentificationConfiguration.CICPrefix + "Agg1_Cohort");
            acDataset = new AggregateConfiguration(CatalogueRepository, c, "Agg2_Dataset");

            ei_Year = new ExtractionInformation(CatalogueRepository, ci2, col2, "Year");
            ei_Year.IsExtractionIdentifier = true;
            ei_Year.SaveToDatabase();
            acDataset.AddDimension(ei_Year);
            acDataset.CountSQL = "count(*)";
            acDataset.SaveToDatabase();


            ei_Chi = new ExtractionInformation(CatalogueRepository, ci, col, "CHI");
            ei_Chi.IsExtractionIdentifier = true;
            ei_Chi.SaveToDatabase();

            acCohort.AddDimension(ei_Chi);

            cic = new CohortIdentificationConfiguration(CatalogueRepository, "mycic");
            cic.CreateRootContainerIfNotExists();
            cic.RootCohortAggregateContainer.AddChild(acCohort, 0);
        }
        private void SetupCohort(out DiscoveredDatabase db, out CohortIdentificationConfiguration cic, out DataTable dt)
        {
            dt = new DataTable();
            dt.Columns.Add("PK");

            //add lots of rows
            for (int i = 0; i < 100000; i++)
            {
                dt.Rows.Add(i);
            }

            db = GetCleanedServer(DatabaseType.MicrosoftSQLServer, true);
            var tbl = db.CreateTable("CohortCompilerRunnerTestsTable", dt);

            var cata = Import(tbl);

            var ei = cata.CatalogueItems[0].ExtractionInformation;

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

            var agg = new AggregateConfiguration(CatalogueRepository, cata, "MyAgg");

            agg.CountSQL = null;
            agg.SaveToDatabase();
            var dimension = new AggregateDimension(CatalogueRepository, ei, agg);

            cic = new CohortIdentificationConfiguration(CatalogueRepository, "MyCic");
            cic.CreateRootContainerIfNotExists();
            cic.RootCohortAggregateContainer.AddChild(agg, 0);
        }
Beispiel #7
0
 public ExecuteCommandCreateNewQueryCacheDatabase(IActivateItems activator, CohortIdentificationConfiguration configuration) : base(activator)
 {
     _cic = configuration;
     if (_cic.QueryCachingServer_ID != null)
     {
         SetImpossible("CohortIdentificationConfiguration already has a Query Cache configured");
     }
 }
Beispiel #8
0
        public JoinableTask(JoinableCohortAggregateConfiguration joinable, CohortCompiler compiler) : base(compiler)
        {
            Joinable   = joinable;
            _aggregate = Joinable.AggregateConfiguration;
            _cohortIdentificationConfiguration = _aggregate.GetCohortIdentificationConfigurationIfAny();

            _catalogueName = Joinable.AggregateConfiguration.Catalogue.Name;
            RefreshIsUsedState();
        }
        public void Join_PatientIndexTable_OptionalCacheOnSameServer(DatabaseType dbType, bool createQueryCache)
        {
            /*
             *           Server1
             *         _____________
             *        |Biochemistry|
             *               ↓
             *       ___________________
             *       | Cache (optional) |
             *            ↓ join ↓
             *    _____________________
             *    | Hospital Admissions|
             *
             */

            var db = GetCleanedServer(dbType);
            ExternalDatabaseServer cache = null;

            if (createQueryCache)
            {
                cache = CreateCache(db);
            }

            var r      = new Random(500);
            var people = new PersonCollection();

            people.GeneratePeople(5000, r);

            var cic = new CohortIdentificationConfiguration(CatalogueRepository, "cic");

            var joinable = SetupPatientIndexTable(db, people, r, cic);

            cic.CreateRootContainerIfNotExists();
            cic.QueryCachingServer_ID = cache?.ID;
            cic.SaveToDatabase();

            var hospitalAdmissions = SetupPatientIndexTableUser(db, people, r, cic, joinable);

            cic.RootCohortAggregateContainer.AddChild(hospitalAdmissions, 0);

            var compiler = new CohortCompiler(cic);
            var runner   = new CohortCompilerRunner(compiler, 50000);

            runner.Run(new CancellationToken());

            AssertNoErrors(compiler);

            if (createQueryCache)
            {
                Assert.IsTrue(compiler.Tasks.Any(t => t.Key.GetCachedQueryUseCount().Equals("1/1")), "Expected cache to be used for the joinable");
            }
            else
            {
                Assert.IsTrue(compiler.Tasks.Any(t => t.Key.GetCachedQueryUseCount().Equals("0/1")), "Did not create cache so expected cache usage to be 0");
            }
        }
Beispiel #10
0
        public void TestSimpleMerge()
        {
            var merger = new CohortIdentificationConfigurationMerger(CatalogueRepository);

            var cic1 = new CohortIdentificationConfiguration(CatalogueRepository, "cic1");
            var cic2 = new CohortIdentificationConfiguration(CatalogueRepository, "cic2");

            cic1.CreateRootContainerIfNotExists();
            var root1 = cic1.RootCohortAggregateContainer;

            root1.Name = "Root1";
            root1.SaveToDatabase();
            root1.AddChild(aggregate1, 1);

            cic2.CreateRootContainerIfNotExists();
            var root2 = cic2.RootCohortAggregateContainer;

            root2.Name = "Root2";
            root2.SaveToDatabase();
            root2.AddChild(aggregate2, 2);

            Assert.AreEqual(1, cic1.RootCohortAggregateContainer.GetAllAggregateConfigurationsRecursively().Count);
            Assert.AreEqual(1, cic2.RootCohortAggregateContainer.GetAllAggregateConfigurationsRecursively().Count);

            int numberOfCicsBefore = CatalogueRepository.GetAllObjects <CohortIdentificationConfiguration>().Count();

            var result = merger.Merge(new [] { cic1, cic2 }, SetOperation.UNION);

            //original should still be intact
            Assert.AreEqual(1, cic1.RootCohortAggregateContainer.GetAllAggregateConfigurationsRecursively().Count);
            Assert.AreEqual(1, cic2.RootCohortAggregateContainer.GetAllAggregateConfigurationsRecursively().Count);

            //the new merged set should contain both
            Assert.AreEqual(2, result.RootCohortAggregateContainer.GetAllAggregateConfigurationsRecursively().Count);

            Assert.IsFalse(result.RootCohortAggregateContainer.GetAllAggregateConfigurationsRecursively().Any(c => c.Equals(aggregate1)), "Expected the merge to include clone aggregates not the originals! (aggregate1)");
            Assert.IsFalse(result.RootCohortAggregateContainer.GetAllAggregateConfigurationsRecursively().Any(c => c.Equals(aggregate2)), "Expected the merge to include clone aggregates not the originals! (aggregate2)");

            // Now should be a new one
            Assert.AreEqual(numberOfCicsBefore + 1, CatalogueRepository.GetAllObjects <CohortIdentificationConfiguration>().Count());

            var newCicId = result.ID;

            // Should have the root containers of the old configs
            Assert.AreEqual("Root2", result.RootCohortAggregateContainer.GetSubContainers()[0].Name);
            Assert.AreEqual("Root1", result.RootCohortAggregateContainer.GetSubContainers()[1].Name);

            // And should have
            Assert.AreEqual($"cic_{newCicId}_UnitTestAggregate2", result.RootCohortAggregateContainer.GetSubContainers()[0].GetAggregateConfigurations()[0].Name);
            Assert.AreEqual($"cic_{newCicId}_UnitTestAggregate1", result.RootCohortAggregateContainer.GetSubContainers()[1].GetAggregateConfigurations()[0].Name);

            Assert.AreEqual($"Merged cics (IDs {cic1.ID},{cic2.ID})", result.Name);

            Assert.IsTrue(cic1.Exists());
            Assert.IsTrue(cic2.Exists());
        }
        public override void SetDatabaseObject(IActivateItems activator, CohortIdentificationConfiguration databaseObject)
        {
            base.SetDatabaseObject(activator, databaseObject);
            _configuration = databaseObject;

            RebuildClearCacheCommand();

            gbCicInfo.Text     = $"Name: {_configuration.Name}";
            tbDescription.Text = $"Description: {_configuration.Description}";
            ticket.TicketText  = _configuration.Ticket;

            if (_commonFunctionality == null)
            {
                activator.RefreshBus.Subscribe(this);
                _commonFunctionality = new RDMPCollectionCommonFunctionality();

                _commonFunctionality.SetUp(RDMPCollection.Cohort, tlvCic, activator, olvNameCol, olvNameCol, new RDMPCollectionCommonFunctionalitySettings
                {
                    SuppressActivate   = true,
                    AddFavouriteColumn = false,
                    AddCheckColumn     = false,
                    AllowPinning       = false,
                    AllowSorting       = true, //important, we need sorting on so that we can override sort order with our OrderableComparer
                });
                _commonFunctionality.MenuBuilt += MenuBuilt;
                tlvCic.AddObject(_configuration);
                tlvCic.ExpandAll();
            }

            CommonFunctionality.AddToMenu(cbIncludeCumulative);
            CommonFunctionality.AddToMenu(new ToolStripSeparator());
            CommonFunctionality.AddToMenu(new ExecuteCommandSetQueryCachingDatabase(Activator, _configuration));
            CommonFunctionality.AddToMenu(new ExecuteCommandClearQueryCache(Activator, _configuration));
            CommonFunctionality.AddToMenu(new ExecuteCommandCreateNewQueryCacheDatabase(activator, _configuration));
            CommonFunctionality.AddToMenu(
                new ExecuteCommandSet(activator, _configuration, _configuration.GetType().GetProperty("Description"))
            {
                OverrideIcon =
                    Activator.CoreIconProvider.GetImage(RDMPConcept.CohortIdentificationConfiguration, OverlayKind.Edit)
            });
            CommonFunctionality.AddToMenu(new ToolStripSeparator());
            CommonFunctionality.AddToMenu(new ExecuteCommandShowXmlDoc(activator, "CohortIdentificationConfiguration.QueryCachingServer_ID", "Query Caching"), "Help (What is Query Caching)");
            CommonFunctionality.Add(new ExecuteCommandCreateNewCohortByExecutingACohortIdentificationConfiguration(activator, null).SetTarget(_configuration),
                                    "Commit Cohort",
                                    activator.CoreIconProvider.GetImage(RDMPConcept.ExtractableCohort, OverlayKind.Add));

            foreach (var c in _timeoutControls.GetControls())
            {
                CommonFunctionality.Add(c);
            }

            _queryCachingServer = _configuration.QueryCachingServer;
            Compiler.CohortIdentificationConfiguration = _configuration;
            Compiler.CoreChildProvider = activator.CoreChildProvider;
            RecreateAllTasks();
        }
Beispiel #12
0
        /// <summary>
        /// Returns all <see cref="AggregateConfiguration"/> from the <paramref name="arg"/> where the dataset is the same and there are filters defined
        /// </summary>
        /// <param name="arg"></param>
        /// <returns></returns>
        private IEnumerable <AggregateConfiguration> GetEligibleChildren(CohortIdentificationConfiguration arg)
        {
            if (arg.RootCohortAggregateContainer_ID == null)
            {
                return(new AggregateConfiguration[0]);
            }

            return(arg.RootCohortAggregateContainer.GetAllAggregateConfigurationsRecursively()
                   .Where(ac => ac.Catalogue_ID == _catalogue.ID && ac.RootFilterContainer_ID != null));
        }
 public AggregateConfigurationCombineable GenerateAggregateConfigurationFor(IBasicActivateItems activator,
     CohortIdentificationConfiguration cic, bool importMandatoryFilters = true,
     [CallerMemberName] string caller = null)
 {
     var newAggregate = cic.CreateNewEmptyConfigurationForCatalogue(Catalogue,
         ResolveMultipleExtractionIdentifiers ??
         ((a,b)=> CohortCombineToCreateCommandHelper.PickOneExtractionIdentifier(activator,a, b)),
     importMandatoryFilters);
     return new AggregateConfigurationCombineable(newAggregate);
 }
        private ParameterCollectionUIOptions Create(CohortIdentificationConfiguration cohortIdentificationConfiguration, ICoreChildProvider coreChildProvider)
        {
            var builder = new CohortQueryBuilder(cohortIdentificationConfiguration, coreChildProvider);

            builder.RegenerateSQL();

            var paramManager = builder.ParameterManager;

            return(new ParameterCollectionUIOptions(UseCaseCohortIdentificationConfiguration, cohortIdentificationConfiguration, ParameterLevel.Global, paramManager));
        }
Beispiel #15
0
        private void btnGo_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrWhiteSpace(tbName.Text))
            {
                MessageBox.Show("Enter a name for your Cohort Identification Criteria");
                return;
            }

            if (!Activator.YesNo("Are you sure you are happy with your configuration, this wizard will close after creating?", "Confirm"))
            {
                return;
            }

            var cic = new CohortIdentificationConfiguration(Activator.RepositoryLocator.CatalogueRepository, tbName.Text);

            cic.CreateRootContainerIfNotExists();
            var root = cic.RootCohortAggregateContainer;

            root.Operation = SetOperation.EXCEPT;
            root.Name      = "EXCEPT";
            root.SaveToDatabase();

            var includeContainer = setOperationInclude.CreateCohortAggregateContainer(root);


            inclusionCriteria1.CreateCohortSet(cic, includeContainer, 1);

            if (cbInclusion2.Checked)
            {
                inclusionCriteria2.CreateCohortSet(cic, includeContainer, 2);
            }

            if (cbExclusion1.Checked || cbExclusion2.Checked)
            {
                var excludeContainer = setOperationExclude.CreateCohortAggregateContainer(root);

                if (cbExclusion1.Checked)
                {
                    exclusionCriteria1.CreateCohortSet(cic, excludeContainer, 1);
                }

                if (cbExclusion2.Checked)
                {
                    exclusionCriteria2.CreateCohortSet(cic, excludeContainer, 2);
                }
            }

            Activator.RefreshBus.Publish(this, new RefreshObjectEventArgs(cic));

            CohortIdentificationCriteriaCreatedIfAny = cic;
            DialogResult = DialogResult.OK;

            Close();
        }
        public override IAtomicCommandWithTarget SetTarget(DatabaseEntity target)
        {
            base.SetTarget(target);

            if (target is CohortIdentificationConfiguration)
            {
                _cic = (CohortIdentificationConfiguration)target;
            }

            return(this);
        }
        void OnImportCompletedSuccessfully(object sender, PipelineEngineEventArgs u, CohortIdentificationConfiguration cic)
        {
            //see if we can associate the cic with the project
            var cmd = new ExecuteCommandAssociateCohortIdentificationConfigurationWithProject(BasicActivator).SetTarget((Project)Project).SetTarget(cic);

            //we can!
            if (!cmd.IsImpossible)
            {
                cmd.Execute();
            }
        }
Beispiel #18
0
        public ExecuteCommandSetQueryCachingDatabase(IBasicActivateItems activator, CohortIdentificationConfiguration cic) : base(activator)
        {
            _cic = cic;

            _caches = BasicActivator.RepositoryLocator.CatalogueRepository.GetAllObjects <ExternalDatabaseServer>()
                      .Where(s => s.WasCreatedBy(new QueryCachingPatcher())).ToArray();

            if (!_caches.Any())
            {
                SetImpossible("There are no Query Caching databases set up");
            }
        }
        public void TestImportTree_FromCohortIdentificationConfiguration_ToSelectedDatasets_PreserveOperation()
        {
            var sds = WhenIHaveA <SelectedDataSets>();

            var cata = sds.ExtractableDataSet.Catalogue;

            var cic = new CohortIdentificationConfiguration(Repository, "my cic");

            cic.CreateRootContainerIfNotExists();

            var ac = new AggregateConfiguration(Repository, cata, "myagg");

            ac.CreateRootContainerIfNotExists();
            cic.RootCohortAggregateContainer.AddChild(ac, 1);

            var filterToImport = new AggregateFilter(Repository, "MyFilter")
            {
                WhereSQL = "true"
            };
            var root = ac.RootFilterContainer;

            root.AddChild(filterToImport);
            root.Operation = FilterContainerOperation.OR;
            root.SaveToDatabase();

            // add 2 subcontainers, these should also get cloned and should preserve the Operation correctly
            root.AddChild(new AggregateFilterContainer(Repository, FilterContainerOperation.AND));
            root.AddChild(new AggregateFilterContainer(Repository, FilterContainerOperation.OR));

            //there should be no root container
            Assert.IsNull(sds.RootFilterContainer);

            //run the command
            var mgr = new ConsoleInputManager(RepositoryLocator, new ThrowImmediatelyCheckNotifier());

            mgr.DisallowInput = true;
            var cmd = new ExecuteCommandImportFilterContainerTree(mgr, sds, ac);

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

            sds.ClearAllInjections();
            Assert.AreEqual(FilterContainerOperation.OR, sds.RootFilterContainer.Operation);
            Assert.IsNotNull(sds.RootFilterContainer);
            Assert.AreEqual(1, sds.RootFilterContainer.GetFilters().Length);

            var subContainers = sds.RootFilterContainer.GetSubContainers();

            Assert.AreEqual(2, subContainers.Length);
            Assert.AreEqual(1, subContainers.Count(e => e.Operation == FilterContainerOperation.AND));
            Assert.AreEqual(1, subContainers.Count(e => e.Operation == FilterContainerOperation.OR));
        }
Beispiel #20
0
        public AggregationTask(AggregateConfiguration aggregate, CohortCompiler compiler) : base(compiler)
        {
            Aggregate      = aggregate;
            _catalogueName = aggregate.Catalogue.Name;
            _cohortIdentificationConfiguration = compiler.CohortIdentificationConfiguration;

            var container = aggregate.GetCohortAggregateContainerIfAny();

            if (container != null)
            {
                _allParentContainers = container.GetAllParentContainers().ToList();
                _allParentContainers.Add(container);
            }
        }
        public void TestOrphanCic()
        {
            var memory = new MemoryDataExportRepository();
            var cic    = new CohortIdentificationConfiguration(memory, "Mycic");
            var p      = new Project(memory, "my proj");

            p.AssociateWithCohortIdentification(cic);

            //fetch the instance
            var cicAssoc = memory.GetAllObjects <ProjectCohortIdentificationConfigurationAssociation>().Single();

            //relationship from p should resolve to the association link
            Assert.AreEqual(cicAssoc, p.ProjectCohortIdentificationConfigurationAssociations[0]);

            //relationship from p should resolve to the cic
            Assert.AreEqual(cic, p.GetAssociatedCohortIdentificationConfigurations()[0]);

            //in order to make it an orphan we have to suppress the system default behaviour of cascading across the deletion
            var obscure = memory.ObscureDependencyFinder as CatalogueObscureDependencyFinder;

            if (obscure != null)
            {
                obscure.OtherDependencyFinders.Clear();
            }

            //make the assoc an orphan
            cic.DeleteInDatabase();
            cicAssoc.ClearAllInjections();

            //assoc should still exist
            Assert.AreEqual(cicAssoc, p.ProjectCohortIdentificationConfigurationAssociations[0]);
            Assert.IsNull(p.ProjectCohortIdentificationConfigurationAssociations[0].CohortIdentificationConfiguration);

            //relationship from p should resolve to the cic
            Assert.IsEmpty(p.GetAssociatedCohortIdentificationConfigurations());

            //error should be reported in top right of program
            var ex = Assert.Throws <Exception>(() => new DataExportChildProvider(new RepositoryProvider(memory), null, new ThrowImmediatelyCheckNotifier(), null));

            StringAssert.IsMatch(@"Failed to find Associated Cohort Identification Configuration with ID \d+ which was supposed to be associated with my proj", ex.Message);

            //but UI should still respond
            var childProvider = new DataExportChildProvider(new RepositoryProvider(memory), null, new IgnoreAllErrorsCheckNotifier(), null);

            //the orphan cic should not appear in the tree view under Project=>Cohorts=>Associated Cics
            var cohorts = childProvider.GetChildren(p).OfType <ProjectCohortsNode>().Single();
            var cics    = childProvider.GetChildren(cohorts).OfType <ProjectCohortIdentificationConfigurationAssociationsNode>().First();

            Assert.IsEmpty(childProvider.GetChildren(cics));
        }
        public IAtomicCommandWithTarget SetTarget(DatabaseEntity target)
        {
            if (target is CohortIdentificationConfiguration)
            {
                _cic = (CohortIdentificationConfiguration)target;
            }

            if (target is Project)
            {
                _project = (Project)target;
            }

            return(this);
        }
Beispiel #23
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);
            }
        }
 public ExecuteCommandCreateNewCohortByExecutingACohortIdentificationConfiguration(IBasicActivateItems activator,
                                                                                   [DemandsInitialization("The cohort builder query that should be executed")]
                                                                                   CohortIdentificationConfiguration cic,
                                                                                   [DemandsInitialization(Desc_ExternalCohortTableParameter)]
                                                                                   ExternalCohortTable ect,
                                                                                   [DemandsInitialization(Desc_CohortNameParameter)]
                                                                                   string cohortName,
                                                                                   [DemandsInitialization(Desc_ProjectParameter)]
                                                                                   Project project,
                                                                                   [DemandsInitialization("Pipeline for executing the query, performing any required transforms on the output list and allocating release identifiers")]
                                                                                   IPipeline pipeline) :
     base(activator, ect, cohortName, project, pipeline)
 {
     _cic = cic;
 }
        public void Join_PatientIndexTable_DoNotUseCacheOnDifferentServer(DatabaseType dbType)
        {
            /*
             *           Server1                    Server 2
             *         _____________                _________
             *        |Biochemistry|    →          | Cache  | (cache is still populated but not used in the resulting join).
             *
             *            ↓ join ↓    (do not use cache)
             *    _____________________
             *    | Hospital Admissions|
             *
             */

            //get the data database
            var db = GetCleanedServer(dbType);

            //create the cache on the other server type (doesn't matter what type just as long as it's different).
            var dbCache =
                GetCleanedServer(Enum.GetValues(typeof(DatabaseType)).Cast <DatabaseType>().First(t => t != dbType));

            ExternalDatabaseServer cache = CreateCache(dbCache);

            var r      = new Random(500);
            var people = new PersonCollection();

            people.GeneratePeople(5000, r);

            var cic = new CohortIdentificationConfiguration(CatalogueRepository, "cic");

            var joinable = SetupPatientIndexTable(db, people, r, cic);

            cic.CreateRootContainerIfNotExists();
            cic.QueryCachingServer_ID = cache?.ID;
            cic.SaveToDatabase();

            var hospitalAdmissions = SetupPatientIndexTableUser(db, people, r, cic, joinable);

            cic.RootCohortAggregateContainer.AddChild(hospitalAdmissions, 0);

            var compiler = new CohortCompiler(cic);
            var runner   = new CohortCompilerRunner(compiler, 50000);

            runner.Run(new CancellationToken());

            AssertNoErrors(compiler);

            Assert.IsTrue(compiler.Tasks.Any(t => t.Key.GetCachedQueryUseCount().Equals("1/1")), "Expected cache to be used only for the final UNION");
        }
        public override void SetDatabaseObject(IActivateItems activator, CohortIdentificationConfiguration databaseObject)
        {
            base.SetDatabaseObject(activator, databaseObject);

            if (btnUseCache == null)
            {
                btnUseCache = new ToolStripButton("Use Cache (if available)");
                btnUseCache.CheckOnClick    = true;
                btnUseCache.Checked         = databaseObject.QueryCachingServer_ID.HasValue;
                btnUseCache.CheckedChanged += (s, e) => GenerateQuery();
            }

            btnUseCache.Enabled = databaseObject.QueryCachingServer_ID.HasValue;
            CommonFunctionality.Add(btnUseCache);
            GenerateQuery();
        }
Beispiel #27
0
        public override void SetDatabaseObject(IActivateItems activator, CohortIdentificationConfiguration databaseObject)
        {
            _cic = databaseObject;

            base.SetDatabaseObject(activator, databaseObject);

            foreach (var c in _timeoutControls.GetControls())
            {
                CommonFunctionality.Add(c);
            }

            _queryCachingServer = _cic.QueryCachingServer;
            Compiler.CohortIdentificationConfiguration = _cic;
            CoreIconProvider = activator.CoreIconProvider;
            RecreateAllTasks();
        }
Beispiel #28
0
        public ExecuteCommandConvertAggregateConfigurationToPatientIndexTable(IActivateItems activator, AggregateConfigurationCommand sourceAggregateConfigurationCommand, CohortIdentificationConfiguration cohortIdentificationConfiguration) : base(activator)
        {
            _sourceAggregateConfigurationCommand = sourceAggregateConfigurationCommand;
            _cohortIdentificationConfiguration   = cohortIdentificationConfiguration;

            if (sourceAggregateConfigurationCommand.JoinableDeclarationIfAny != null)
            {
                SetImpossible("Aggregate is already a Patient Index Table");
            }

            if (_sourceAggregateConfigurationCommand.CohortIdentificationConfigurationIfAny != null &&
                _sourceAggregateConfigurationCommand.CohortIdentificationConfigurationIfAny.ID != _cohortIdentificationConfiguration.ID)
            {
                SetImpossible("Aggregate '" + _sourceAggregateConfigurationCommand.Aggregate + "'  belongs to a different Cohort Identification Configuration");
            }
        }
Beispiel #29
0
        /// <summary>
        /// Adds all subqueries and containers that are below the current CohortIdentificationConfiguration as tasks to the compiler
        /// </summary>
        /// <param name="addSubcontainerTasks">The root container is always added to the task list but you could skip subcontainer totals if all you care about is the final total for the cohort
        /// and you don't have a dependant UI etc.  Passing false will add all joinables, subqueries etc and the root container (final answer for who is in cohort) only.</param>
        /// <returns></returns>
        public List <ICompileable> AddAllTasks(bool addSubcontainerTasks = true)
        {
            var toReturn = new List <ICompileable>();
            var globals  = CohortIdentificationConfiguration.GetAllParameters();

            CohortIdentificationConfiguration.CreateRootContainerIfNotExists();

            foreach (var joinable in CohortIdentificationConfiguration.GetAllJoinables())
            {
                toReturn.Add(AddTask(joinable, globals));
            }

            toReturn.AddRange(AddTasksRecursively(globals, CohortIdentificationConfiguration.RootCohortAggregateContainer, addSubcontainerTasks));

            return(toReturn);
        }
Beispiel #30
0
        public override bool ShowCohortWizard(out CohortIdentificationConfiguration cic)
        {
            var wizard = new CreateNewCohortIdentificationConfigurationUI(this);

            if (wizard.ShowDialog() == DialogResult.OK)
            {
                cic = wizard.CohortIdentificationCriteriaCreatedIfAny;
            }
            else
            {
                cic = null;
            }

            // Wizard was shown so that's a thing
            return(true);
        }