Ejemplo n.º 1
0
        private IEnumerable ChildrenGetter(object model)
        {
            var containerTask = model as AggregationContainerTask;

            if (containerTask != null)
            {
                //ensure we listen for state change on the root
                return(containerTask.Container.GetOrderedContents().Cast <IMapsDirectlyToDatabaseTable>().Select(c => Compiler.AddTask(c, _globals)).ToArray());
            }

            var joinableColection = model as JoinableCollectionNode;

            if (joinableColection != null)
            {
                return(_cic.GetAllJoinables().Select(j => Compiler.AddTask(j, _globals)).ToArray());
            }

            if (model is CohortIdentificationHeader)
            {
                return new[] { Compiler.AddTask(_root, _globals) }
            }
            ;

            return(null);
        }
Ejemplo n.º 2
0
        public ICompileable Run(CancellationToken token)
        {
            try
            {
                var globals = _cic.GetAllParameters();

                //clear compiler list
                Compiler.CancelAllTasks(true);

                SetPhase(Phase.RunningJoinableTasks);

                Parallel.ForEach(_cic.GetAllJoinables(), (j) => Compiler.AddTask(j, globals));

                Compiler.CancelAllTasks(false);

                RunAsync(Compiler.Tasks.Keys.Where(c => c is JoinableTask && c.State == CompilationState.NotScheduled), token);

                SetPhase(Phase.CachingJoinableTasks);

                CacheAsync(Compiler.Tasks.Keys.OfType <JoinableTask>().Where(c => c.State == CompilationState.Finished && c.IsCacheableWhenFinished()), token);

                SetPhase(Phase.RunningAggregateTasks);

                // Add all aggregates
                Parallel.ForEach(_cic.RootCohortAggregateContainer.GetAllAggregateConfigurationsRecursively(), (c) => Compiler.AddTask(c, globals));

                Compiler.CancelAllTasks(false);

                RunAsync(Compiler.Tasks.Keys.Where(c => c is AggregationTask && c.IsEnabled() && c.State == CompilationState.NotScheduled), token);

                SetPhase(Phase.CachingAggregateTasks);

                CacheAsync(Compiler.Tasks.Keys.OfType <AggregationTask>().Where(c => c.State == CompilationState.Finished && c.IsCacheableWhenFinished()), token);

                SetPhase(Phase.RunningFinalTotals);

                var toReturn = Compiler.AddTask(_cic.RootCohortAggregateContainer, globals);

                if (RunSubcontainers)
                {
                    Parallel.ForEach(
                        _cic.RootCohortAggregateContainer.GetAllSubContainersRecursively().Where(c => !c.IsDisabled),
                        (a) => Compiler.AddTask(a, globals));
                }


                Compiler.CancelAllTasks(false);

                RunAsync(Compiler.Tasks.Keys.Where(c => c.State == CompilationState.NotScheduled && c.IsEnabled()), token);

                SetPhase(Phase.Finished);

                return(toReturn);
            }
            catch (OperationCanceledException)
            {
                SetPhase(Phase.None);
                return(null);
            }
        }
        public override void Execute()
        {
            base.Execute();

            var cacheManager = new CachedAggregateConfigurationResultsManager(_cic.QueryCachingServer);
            int deleted      = 0;

            foreach (var ag in _cic.RootCohortAggregateContainer.GetAllAggregateConfigurationsRecursively())
            {
                // just incase they changed the role or something wierd we should nuke all it's roles
                deleted += cacheManager.DeleteCacheEntryIfAny(ag, AggregateOperation.IndexedExtractionIdentifierList) ? 1 : 0;
                deleted += cacheManager.DeleteCacheEntryIfAny(ag, AggregateOperation.JoinableInceptionQuery) ? 1:0;
            }
            foreach (var joinable in _cic.GetAllJoinables())
            {
                // just incase they changed the role or something wierd we should nuke all it's roles
                deleted += cacheManager.DeleteCacheEntryIfAny(joinable.AggregateConfiguration, AggregateOperation.IndexedExtractionIdentifierList) ? 1 : 0;
                deleted += cacheManager.DeleteCacheEntryIfAny(joinable.AggregateConfiguration, AggregateOperation.JoinableInceptionQuery) ? 1 : 0;
            }

            Show("Cache Entries Cleared", $"Deleted {deleted} cache entries");
        }
Ejemplo n.º 4
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);
        }
Ejemplo n.º 5
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);
        }
Ejemplo n.º 6
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);
        }