Пример #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
        private void cbxCohort_SelectedIndexChanged(object sender, EventArgs e)
        {
            var cic = cbxCohort.SelectedItem as CohortIdentificationConfiguration;

            if (cic != null)
            {
                Cursor.Current = Cursors.WaitCursor;
                try
                {
                    ragCic.Reset();

                    tbCohortName.Text = cic.ToString();

                    var source = new CohortIdentificationConfigurationSource();
                    source.Timeout = 5;
                    source.PreInitialize(cic, new ThrowImmediatelyDataLoadEventListener());
                    source.Check(ragCic);

                    ClearFile();
                }
                finally
                {
                    Cursor.Current = Cursors.Default;
                }
            }

            gbFile.Enabled = cic == null;
        }
Пример #3
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);
        }