public override void Execute()
        {
            base.Execute();

            if (_aggregateConfiguration == null)
            {
                _aggregateConfiguration = SelectOne <AggregateConfiguration>(BasicActivator.RepositoryLocator.CatalogueRepository);
            }

            if (_aggregateConfiguration == null)
            {
                return;
            }

            if (_aggregateConfiguration.IsJoinablePatientIndexTable())
            {
                if (!BasicActivator.YesNo("Would you like to constrain the records to only those in a committed cohort?", "Cohort Records Only", out bool chosen))
                {
                    return;
                }

                if (chosen)
                {
                    _cohort = SelectOne <ExtractableCohort>(BasicActivator.RepositoryLocator.DataExportRepository);

                    if (_cohort == null)
                    {
                        return;
                    }
                }

                if (_cohort != null)
                {
                    var externalData = _cohort.GetExternalData();
                    if (externalData != null)
                    {
                        var projNumber = externalData.ExternalProjectNumber;
                        var projs      = BasicActivator.RepositoryLocator.DataExportRepository.GetAllObjects <Project>().Where(p => p.ProjectNumber == projNumber).ToArray();
                        if (projs.Length == 1)
                        {
                            ProjectSpecific = projs[0];
                        }
                    }
                }
            }

            _table = SelectTable(true, "Choose destination table name");

            if (_table == null)
            {
                return;
            }

            var useCase = new CreateTableFromAggregateUseCase(_aggregateConfiguration, _cohort, _table);

            var runner = BasicActivator.GetPipelineRunner(useCase, null /*TODO inject Pipeline in CLI constructor*/);

            runner.PipelineExecutionFinishedsuccessfully += ui_PipelineExecutionFinishedsuccessfully;

            runner.Run(BasicActivator.RepositoryLocator, null, null, null);
        }
Exemplo n.º 2
0
        public DataExportChildProvider(IRDMPPlatformRepositoryServiceLocator repositoryLocator, IChildProvider[] pluginChildProviders, ICheckNotifier errorsCheckNotifier, DataExportChildProvider previousStateIfKnown) : base(repositoryLocator.CatalogueRepository, pluginChildProviders, errorsCheckNotifier, previousStateIfKnown)
        {
            BlackListedSources   = previousStateIfKnown?.BlackListedSources ?? new List <ExternalCohortTable>();
            _errorsCheckNotifier = errorsCheckNotifier;
            dataExportRepository = repositoryLocator.DataExportRepository;

            AllProjectAssociatedCics = GetAllObjects <ProjectCohortIdentificationConfigurationAssociation>(dataExportRepository);

            _cicAssociations = new HashSet <int>(AllProjectAssociatedCics.Select(a => a.CohortIdentificationConfiguration_ID));

            CohortSources       = GetAllObjects <ExternalCohortTable>(dataExportRepository);
            ExtractableDataSets = GetAllObjects <ExtractableDataSet>(dataExportRepository);

            AddToDictionaries(new HashSet <object>(AllCohortIdentificationConfigurations.Where(cic => _cicAssociations.Contains(cic.ID))), new DescendancyList(AllProjectCohortIdentificationConfigurationsNode));
            AddToDictionaries(new HashSet <object>(AllCohortIdentificationConfigurations.Where(cic => !_cicAssociations.Contains(cic.ID))), new DescendancyList(AllFreeCohortIdentificationConfigurationsNode));

            _selectedDataSetsWithNoIsExtractionIdentifier = new HashSet <ISelectedDataSets>(dataExportRepository.GetSelectedDatasetsWithNoExtractionIdentifiers());

            SelectedDataSets = GetAllObjects <SelectedDataSets>(dataExportRepository);
            ReportProgress("Fetching data export objects");

            var dsDictionary = ExtractableDataSets.ToDictionary(ds => ds.ID, d => d);

            foreach (SelectedDataSets s in SelectedDataSets)
            {
                s.InjectKnown(dsDictionary[s.ExtractableDataSet_ID]);
            }

            ReportProgress("Injecting SelectedDataSets");

            //This means that the ToString method in ExtractableDataSet doesn't need to go lookup catalogue info
            var catalogueIdDict = AllCatalogues.ToDictionary(c => c.ID, c2 => c2);

            foreach (ExtractableDataSet ds in ExtractableDataSets)
            {
                if (catalogueIdDict.TryGetValue(ds.Catalogue_ID, out Catalogue cata))
                {
                    ds.InjectKnown(cata);
                }
            }

            ReportProgress("Injecting ExtractableDataSet");

            AllPackages = GetAllObjects <ExtractableDataSetPackage>(dataExportRepository);

            Projects = GetAllObjects <Project>(dataExportRepository);
            ExtractionConfigurations = GetAllObjects <ExtractionConfiguration>(dataExportRepository);

            ReportProgress("Get Projects and Configurations");

            ExtractionConfigurationsByProject = ExtractionConfigurations.GroupBy(k => k.Project_ID).ToDictionary(gdc => gdc.Key, gdc => gdc.ToList());

            ReportProgress("Grouping Extractions by Project");

            AllGlobalExtractionFilterParameters = GetAllObjects <GlobalExtractionFilterParameter>(dataExportRepository);

            AllContainers = GetAllObjects <FilterContainer>(dataExportRepository).ToDictionary(o => o.ID, o => o);
            AllDeployedExtractionFilters = GetAllObjects <DeployedExtractionFilter>(dataExportRepository);
            _allParameters = GetAllObjects <DeployedExtractionFilterParameter>(dataExportRepository);

            ReportProgress("Getting Filters");

            //if we are using a database repository then we can make use of the caching class DataExportFilterManagerFromChildProvider to speed up
            //filter contents
            var dbRepo = dataExportRepository as DataExportRepository;

            _dataExportFilterManager = dbRepo == null ? dataExportRepository.FilterManager : new DataExportFilterManagerFromChildProvider(dbRepo, this);

            ReportProgress("Building FilterManager");

            Cohorts            = GetAllObjects <ExtractableCohort>(dataExportRepository);
            _cohortsByOriginId = new Dictionary <int, HashSet <ExtractableCohort> >();

            foreach (ExtractableCohort c in Cohorts)
            {
                if (!_cohortsByOriginId.ContainsKey(c.OriginID))
                {
                    _cohortsByOriginId.Add(c.OriginID, new HashSet <ExtractableCohort>());
                }

                _cohortsByOriginId[c.OriginID].Add(c);
            }

            _configurationToDatasetMapping = new Dictionary <ExtractionConfiguration, List <SelectedDataSets> >();

            ReportProgress("Fetching Cohorts");

            GetCohortAvailability();

            ReportProgress("GetCohortAvailability");

            var configToSds = SelectedDataSets.GroupBy(k => k.ExtractionConfiguration_ID).ToDictionary(gdc => gdc.Key, gdc => gdc.ToList());

            foreach (ExtractionConfiguration configuration in ExtractionConfigurations)
            {
                if (configToSds.TryGetValue(configuration.ID, out List <SelectedDataSets> result))
                {
                    _configurationToDatasetMapping.Add(configuration, result);
                }
            }

            ReportProgress("Mapping configurations to datasets");

            RootCohortsNode = new AllCohortsNode();
            AddChildren(RootCohortsNode, new DescendancyList(RootCohortsNode));

            foreach (ExtractableDataSetPackage package in AllPackages)
            {
                AddChildren(package, new DescendancyList(package));
            }

            ReportProgress("Packages and Cohorts");

            foreach (Project p in Projects)
            {
                AddChildren(p, new DescendancyList(p));
            }

            ReportProgress("Projects");

            //work out all the Catalogues that are extractable (Catalogues are extractable if there is an ExtractableDataSet with the Catalogue_ID that matches them)
            var cataToEds = new Dictionary <int, ExtractableDataSet>(ExtractableDataSets.ToDictionary(k => k.Catalogue_ID));

            //inject extractability into Catalogues
            foreach (Catalogue catalogue in AllCatalogues)
            {
                if (cataToEds.TryGetValue(catalogue.ID, out ExtractableDataSet result))
                {
                    catalogue.InjectKnown(result.GetCatalogueExtractabilityStatus());
                }
                else
                {
                    catalogue.InjectKnown(new CatalogueExtractabilityStatus(false, false));
                }
            }

            ReportProgress("Catalogue extractability injection");

            try
            {
                AddPipelineUseCases(new Dictionary <string, PipelineUseCase>
                {
                    { "File Import", UploadFileUseCase.DesignTime() },
                    { "Extraction", ExtractionPipelineUseCase.DesignTime() },
                    { "Release", ReleaseUseCase.DesignTime() },
                    { "Cohort Creation", CohortCreationRequest.DesignTime() },
                    { "Caching", CachingPipelineUseCase.DesignTime() },
                    { "Aggregate Committing", CreateTableFromAggregateUseCase.DesignTime(repositoryLocator.CatalogueRepository) }
                });
            }
            catch (Exception ex)
            {
                _errorsCheckNotifier.OnCheckPerformed(new CheckEventArgs("Failed to build DesignTime PipelineUseCases", CheckResult.Fail, ex));
            }

            ReportProgress("Pipeline adding");
        }
        public override void Execute()
        {
            base.Execute();

            if (_aggregateConfiguration == null)
            {
                _aggregateConfiguration = SelectOne <AggregateConfiguration>(Activator.RepositoryLocator.CatalogueRepository);
            }

            if (_aggregateConfiguration == null)
            {
                return;
            }

            if (_aggregateConfiguration.IsJoinablePatientIndexTable())
            {
                var dr = MessageBox.Show("Would you like to constrain the records to only those in a committed cohort?", "Cohort Records Only", MessageBoxButtons.YesNoCancel);

                if (dr == DialogResult.Cancel)
                {
                    return;
                }

                if (dr == DialogResult.Yes)
                {
                    _cohort = SelectOne <ExtractableCohort>(Activator.RepositoryLocator.DataExportRepository);

                    if (_cohort == null)
                    {
                        return;
                    }
                }

                if (_cohort != null)
                {
                    var externalData = _cohort.GetExternalData();
                    if (externalData != null)
                    {
                        var projNumber = externalData.ExternalProjectNumber;
                        var projs      = Activator.RepositoryLocator.DataExportRepository.GetAllObjects <Project>().Where(p => p.ProjectNumber == projNumber).ToArray();
                        if (projs.Length == 1)
                        {
                            _projectSpecific = projs[0];
                        }
                    }
                }
            }

            _table = SelectTable(true, "Choose destination table name");

            if (_table == null)
            {
                return;
            }

            var useCase = new CreateTableFromAggregateUseCase(_aggregateConfiguration, _cohort, _table);

            var ui = new ConfigureAndExecutePipelineUI(useCase, Activator);

            ui.PipelineExecutionFinishedsuccessfully += ui_PipelineExecutionFinishedsuccessfully;

            Activator.ShowWindow(ui, true);
        }