public IAtomicCommandWithTarget SetTarget(DatabaseEntity target)
        {
            var configuration = target as AggregateConfiguration;

            if (configuration != null)
            {
                _aggregateConfiguration = configuration;
            }

            var cohort = target as ExtractableCohort;

            if (cohort != null)
            {
                _cohort = cohort;
            }

            var project = target as Project;

            if (project != null)
            {
                _projectSpecific = project;
            }

            return(this);
        }
Esempio n. 2
0
        private void lbCohortDatabaseTable_KeyUp(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Delete && lbCohortDatabaseTable.SelectedObject != null)
            {
                var node = (ExtractableCohortDescription)lbCohortDatabaseTable.SelectedObject;

                ExtractableCohort toDelete = node.Cohort;

                if (Activator.YesNo("Are you sure you want to delete " + toDelete + " (ID=" + toDelete.ID + ")", "Confirm Delete"))
                {
                    try
                    {
                        toDelete.DeleteInDatabase();

                        lbCohortDatabaseTable.RemoveObject(node);
                    }
                    catch (Exception exception)
                    {
                        ExceptionViewer.Show(exception);
                    }
                }
                else
                {
                    return;
                }
            }
        }
Esempio n. 3
0
        public ExtractableCohortMenu(RDMPContextMenuStripArgs args, ExtractableCohort cohort)
            : base(args, cohort)
        {
            _cohort = cohort;
            Items.Add("View TOP 100 identifiers", null, (s, e) => ViewTop100());

            Add(new ExecuteCommandDeprecate(args.ItemActivator, cohort, !cohort.IsDeprecated));
        }
        /// <summary>
        /// Creates a non async cohort description, this will block until counts are available for the cohort
        /// </summary>
        /// <param name="cohort"></param>
        public ExtractableCohortDescription(ExtractableCohort cohort)
        {
            Cohort = cohort;

            try
            {
                Count = cohort.Count;
            }
            catch (Exception e)
            {
                Exception = e;
                Count     = -1;
            }

            try
            {
                CountDistinct = cohort.CountDistinct;
            }
            catch (Exception e)
            {
                CountDistinct = -1;
                Exception     = e;
                throw;
            }
            OriginID = cohort.OriginID;



            try
            {
                ReleaseIdentifier = cohort.GetReleaseIdentifier();
            }
            catch (Exception)
            {
                ReleaseIdentifier = "Unknown";
            }

            try
            {
                PrivateIdentifier = cohort.GetPrivateIdentifier();
            }
            catch (Exception)
            {
                PrivateIdentifier = "Unknown";
            }

            var externalData = cohort.GetExternalData();

            SourceName    = externalData.ExternalCohortTableName;
            Version       = externalData.ExternalVersion;
            CreationDate  = externalData.ExternalCohortCreationDate;
            ProjectNumber = externalData.ExternalProjectNumber;
            Description   = externalData.ExternalDescription;
        }
Esempio n. 5
0
        public void SetSelectedCohort(ExtractableCohort toSelect)
        {
            if (toSelect == null)
            {
                lbCohortDatabaseTable.SelectedObject = null;
                return;
            }

            var matchingNode = lbCohortDatabaseTable.Objects.Cast <ExtractableCohortDescription>().SingleOrDefault(c => c.Cohort.ID == toSelect.ID);

            lbCohortDatabaseTable.SelectedObject = matchingNode;
        }
Esempio n. 6
0
        public ExtractableCohortMenu(RDMPContextMenuStripArgs args, ExtractableCohort cohort)
            : base(args, cohort)
        {
            _cohort = cohort;
            Items.Add("View TOP 100 identifiers", null, (s, e) => ViewTop100());

            Add(new ExecuteCommandDeprecate(args.ItemActivator, cohort, !cohort.IsDeprecated));

            if (_activator.CoreChildProvider is DataExportChildProvider dx)
            {
                AddGoTo(dx.ExtractionConfigurations.Where(ec => ec.Cohort_ID == cohort.ID), "Extraction Configurations");
            }
        }
Esempio n. 7
0
        private ICohortCreationRequest GenerateCohortCreationRequestFromNameAndProject(string name, string auditLogDescription, ExternalCohortTable ect)
        {
            var existing = ExtractableCohort.GetImportableCohortDefinitions(ect).Where(d => d.Description.Equals(_explicitCohortName)).ToArray();
            var version  = 1;

            // If the user has used this description before then we can just bump the version by 1
            if (existing != null && existing.Any())
            {
                version = existing.Max(v => v.Version) + 1;
            }

            return(new CohortCreationRequest(Project, new CohortDefinition(null, name, version, Project.ProjectNumber.Value, ect), BasicActivator.RepositoryLocator.DataExportRepository, auditLogDescription));
        }
Esempio n. 8
0
        public SelectWhichCohortToImportUI(IActivateItems activator, ExternalCohortTable source) : base(activator)
        {
            _source = source;
            InitializeComponent();

            if (source == null)
            {
                return;
            }


            DataTable dt = ExtractableCohort.GetImportableCohortDefinitionsTable(source, out _displayMember, out _valueMember, out _versionMemberName, out _projectNumberMemberName);

            dataGridView1.DataSource = dt;
        }
        public ExecuteCommandViewCohortSample(IBasicActivateItems activator,
                                              [DemandsInitialization("The cohort that you want to fetch records for")]
                                              ExtractableCohort cohort,
                                              [DemandsInitialization("Optional. The maximum number of records to retrieve")]
                                              int sample = 100,
                                              [DemandsInitialization("Optional. A file to write the records to instead of the console")]
                                              FileInfo toFile = null,

                                              [DemandsInitialization("True to include the OriginId of the cohort when extracting", DefaultValue = true)]
                                              bool includeCohortID = true) : base(activator)
        {
            Cohort           = cohort;
            Sample           = sample;
            ToFile           = toFile;
            _includeCohortID = includeCohortID;
        }
Esempio n. 10
0
        public ExtractableCohortCombineable(ExtractableCohort extractableCohort)
        {
            Cohort = extractableCohort;

            try
            {
                ExternalProjectNumber = Cohort.GetExternalData().ExternalProjectNumber;
            }
            catch (Exception e)
            {
                ErrorGettingCohortData = e;
                return;
            }

            CompatibleProjects = extractableCohort.Repository.GetAllObjectsWhere <Project>("ProjectNumber", ExternalProjectNumber);
            CompatibleExtractionConfigurations = CompatibleProjects.SelectMany(p => p.ExtractionConfigurations).ToArray();
        }
Esempio n. 11
0
        private void CreateExternalCohortTableReference()
        {
            ExternalCohortTable alreadyExisting = DataExportRepository.GetAllObjects <ExternalCohortTable>()
                                                  .SingleOrDefault(external => external.Name.Equals(ExternalCohortTableNameInCatalogue));

            if (alreadyExisting != null)
            {
                //remove dependencies cohorts
                ExtractableCohort toCleanup = DataExportRepository.GetAllObjects <ExtractableCohort>().SingleOrDefault(ec => ec.OriginID == cohortIDInTestData);


                if (toCleanup != null)
                {
                    //cleanup any configs that use the cohort
                    foreach (
                        var configToCleanup in DataExportRepository.GetAllObjects <ExtractionConfiguration>()
                        .Where(config => config.Cohort_ID == toCleanup.ID))
                    {
                        configToCleanup.DeleteInDatabase();
                    }

                    toCleanup.DeleteInDatabase();
                }

                alreadyExisting.DeleteInDatabase();
            }

            var newExternal = new ExternalCohortTable(DataExportRepository, "TestExternalCohort", DatabaseType.MicrosoftSQLServer)
            {
                Database            = CohortDatabaseName,
                Server              = _cohortDatabase.Server.Name,
                DefinitionTableName = definitionTableName,
                TableName           = cohortTableName,
                Name     = ExternalCohortTableNameInCatalogue,
                Username = _cohortDatabase.Server.ExplicitUsernameIfAny,
                Password = _cohortDatabase.Server.ExplicitPasswordIfAny,
                PrivateIdentifierField         = "PrivateID",
                ReleaseIdentifierField         = "ReleaseID",
                DefinitionTableForeignKeyField = "cohortDefinition_id"
            };

            newExternal.SaveToDatabase();

            _externalCohortTable = newExternal;
        }
        public override IAtomicCommandWithTarget SetTarget(DatabaseEntity target)
        {
            base.SetTarget(target);

            var configuration = target as AggregateConfiguration;

            if (configuration != null)
            {
                _aggregateConfiguration = configuration;
            }

            var cohort = target as ExtractableCohort;

            if (cohort != null)
            {
                _cohort = cohort;
            }

            return(this);
        }
        public override void Execute()
        {
            base.Execute();

            SelectWhichCohortToImportUI importDialog = new SelectWhichCohortToImportUI(Activator, _externalCohortTable);

            if (importDialog.ShowDialog() == DialogResult.OK)
            {
                int toAddID = importDialog.IDToImport;
                try
                {
                    var newCohort = new ExtractableCohort(Activator.RepositoryLocator.DataExportRepository, _externalCohortTable, toAddID);
                    Publish(_externalCohortTable);
                }
                catch (Exception exception)
                {
                    MessageBox.Show(exception.Message);
                }
            }
        }
Esempio n. 14
0
        /// <summary>
        /// Creates a new description based on the async fetch request for all cohorts including row counts etc (which might have already completed btw).  If you
        /// use this constructor then the properties will start out with text like "Loading..." but it will perform much faster, when the fetch completes the
        /// values will be populated.  In general if you want to use this feature you should probably use CohortDescriptionFactory and only use it if you are
        /// trying to get all the cohorts at once.
        ///
        /// </summary>
        /// <param name="cohort"></param>
        /// <param name="fetch"></param>
        public ExtractableCohortDescription(ExtractableCohort cohort, CohortDescriptionDataTableAsyncFetch fetch)
        {
            Cohort        = cohort;
            Fetch         = fetch;
            OriginID      = cohort.OriginID;
            Count         = -1;
            CountDistinct = -1;
            SourceName    = fetch.Source.Name;

            try
            {
                ReleaseIdentifier = cohort.GetReleaseIdentifier(true);
            }
            catch (Exception)
            {
                ReleaseIdentifier = "Unknown";
            }

            try
            {
                PrivateIdentifier = cohort.GetPrivateIdentifier(true);
            }
            catch (Exception)
            {
                PrivateIdentifier = "Unknown";
            }

            ProjectNumber = -1;
            Version       = -1;
            Description   = "Loading...";

            //if it's already finished
            if (fetch.Task != null && fetch.Task.IsCompleted)
            {
                FetchOnFinished();
            }
            else
            {
                fetch.Finished += FetchOnFinished;
            }
        }
Esempio n. 15
0
        public int ImportAsExtractableCohort(bool deprecateOldCohortOnSuccess)
        {
            if (NewCohortDefinition.ID == null)
            {
                throw new NotSupportedException("CohortCreationRequest cannot be imported because it's ID is null, it is likely that it has not been pushed to the server yet");
            }

            var cohort = new ExtractableCohort(_repository, (ExternalCohortTable)NewCohortDefinition.LocationOfCohort, (int)NewCohortDefinition.ID);

            cohort.AppendToAuditLog(DescriptionForAuditLog);

            CohortCreatedIfAny = cohort;

            if (deprecateOldCohortOnSuccess && NewCohortDefinition.CohortReplacedIfAny != null)
            {
                NewCohortDefinition.CohortReplacedIfAny.IsDeprecated = true;
                NewCohortDefinition.CohortReplacedIfAny.SaveToDatabase();
            }

            return(cohort.ID);
        }
Esempio n. 16
0
        private int?GetWhichCohortToImport(ExternalCohortTable ect)
        {
            // the cohorts in the database
            var available = ExtractableCohort.GetImportableCohortDefinitions(ect).Where(c => c.ID.HasValue).ToArray();

            // the ones we already know about
            var existing = new HashSet <int>(BasicActivator.RepositoryLocator.DataExportRepository.GetAllObjects <ExtractableCohort>().Select(c => c.OriginID));

            // new ones we don't know about yet
            available = available.Where(c => !existing.Contains(c.ID.Value)).ToArray();

            // if there are no new ones
            if (!available.Any())
            {
                BasicActivator.Show($"There are no new cohorts");
                return(null);
            }

            // we only care about ones associated to this project
            if (specificProject != null)
            {
                available = available.Where(a => a.ProjectNumber == specificProject.ProjectNumber).ToArray();

                if (!available.Any())
                {
                    BasicActivator.Show($"There are no new cohorts to import for ProjectNumber {specificProject.ProjectNumber}");
                    return(null);
                }
            }

            // pick which one to import
            if (BasicActivator.SelectObject("Import Cohort", available, out CohortDefinition cd))
            {
                return(cd.ID);
            }

            return(null);
        }
Esempio n. 17
0
        public int ImportAsExtractableCohort(bool deprecateOldCohortOnSuccess, bool migrateUsages)
        {
            if (NewCohortDefinition.ID == null)
            {
                throw new NotSupportedException("CohortCreationRequest cannot be imported because it's ID is null, it is likely that it has not been pushed to the server yet");
            }

            var cohort = new ExtractableCohort(_repository, (ExternalCohortTable)NewCohortDefinition.LocationOfCohort, (int)NewCohortDefinition.ID);

            cohort.AppendToAuditLog(DescriptionForAuditLog);

            CohortCreatedIfAny = cohort;

            if (deprecateOldCohortOnSuccess && NewCohortDefinition.CohortReplacedIfAny != null)
            {
                NewCohortDefinition.CohortReplacedIfAny.IsDeprecated = true;
                NewCohortDefinition.CohortReplacedIfAny.SaveToDatabase();
            }

            if (migrateUsages && NewCohortDefinition.CohortReplacedIfAny != null)
            {
                var oldId = NewCohortDefinition.CohortReplacedIfAny.ID;
                var newId = cohort.ID;

                // ExtractionConfigurations that use the old (replaced) cohort
                var liveUsers = _repository.GetAllObjects <ExtractionConfiguration>()
                                .Where(ec => ec.Cohort_ID == oldId && ec.IsReleased == false);

                foreach (var ec in liveUsers)
                {
                    ec.Cohort_ID = newId;
                    ec.SaveToDatabase();
                }
            }

            return(cohort.ID);
        }
Esempio n. 18
0
        public override void SetDatabaseObject(IActivateItems activator, ExtractableCohort databaseObject)
        {
            base.SetDatabaseObject(activator, databaseObject);
            _extractableCohort = databaseObject;

            //if the object passed in was null we set it to "" otherwise we are going to set it to the Name property (unless that is null in which case it's still going to end up as "")
            tbID.Text       = _extractableCohort.ID.ToString();
            tbOriginId.Text = _extractableCohort.OriginID.ToString();
            tbOverrideReleaseIdentifierSQL.Text = _extractableCohort.OverrideReleaseIdentifierSQL;
            auditLogEditor.Text = _extractableCohort.AuditLog;

            tbProjectNumber.Text = _extractableCohort.ExternalProjectNumber.ToString();
            tbVersion.Text       = _extractableCohort.ExternalVersion.ToString();

            GenerateSQLPreview();

            var dx = Activator.CoreChildProvider as DataExportChildProvider;

            if (!_commonFunctionality1.IsSetup)
            {
                _commonFunctionality1.SetUp(RDMPCollection.None, tlvCohortUsage, activator, olvUsedIn, null,
                                            new RDMPCollectionCommonFunctionalitySettings()
                {
                    AddCheckColumn        = false,
                    AddFavouriteColumn    = false,
                    AddIDColumn           = true,
                    AllowPinning          = false,
                    SuppressActivate      = false,
                    SuppressChildrenAdder = true
                }
                                            );
            }

            if (!_commonFunctionality2.IsSetup)
            {
                _commonFunctionality2.SetUp(RDMPCollection.None, tlvPreviousVersions, activator, olvOtherVersions, null,
                                            new RDMPCollectionCommonFunctionalitySettings()
                {
                    AddCheckColumn        = false,
                    AddFavouriteColumn    = false,
                    AddIDColumn           = true,
                    AllowPinning          = false,
                    SuppressActivate      = false,
                    SuppressChildrenAdder = true
                }
                                            );
            }

            if (dx != null)
            {
                tlvCohortUsage.ClearObjects();
                tlvCohortUsage.AddObjects(dx.ExtractionConfigurations.Where(e => e.Cohort_ID == _extractableCohort.ID).ToArray());

                tlvPreviousVersions.ClearObjects();
                tlvPreviousVersions.AddObjects(
                    dx.Cohorts.Where(
                        c =>
                        c.ID != _extractableCohort.ID &&
                        c.ExternalCohortTable_ID == _extractableCohort.ExternalCohortTable_ID &&
                        c.GetExternalData().ExternalDescription ==
                        _extractableCohort.GetExternalData().ExternalDescription&&
                        c.ExternalProjectNumber == _extractableCohort.ExternalProjectNumber).ToArray());
            }

            AssociatedCollection = RDMPCollection.SavedCohorts;
        }
Esempio n. 19
0
        private void btnExecute_Click(object sender, EventArgs e)
        {
            Cursor = Cursors.WaitCursor;

            string problem = AllRequiredDataPresent();

            try
            {
                if (problem != null)
                {
                    MessageBox.Show(problem);
                    return;
                }

                ragExecute.Reset();

                //create the project
                if (_project == null)
                {
                    _project = new Project(Activator.RepositoryLocator.DataExportRepository, tbProjectName.Text);
                }

                _project.ProjectNumber       = int.Parse(tbProjectNumber.Text);
                _project.ExtractionDirectory = tbExtractionDirectory.Text;

                if (!Directory.Exists(_project.ExtractionDirectory))
                {
                    Directory.CreateDirectory(_project.ExtractionDirectory);
                }

                _project.SaveToDatabase();

                if (_configuration == null)
                {
                    _configuration = new ExtractionConfiguration(Activator.RepositoryLocator.DataExportRepository,
                                                                 _project);
                    _configuration.Name = "Cases";
                    _configuration.SaveToDatabase();
                }

                foreach (ExtractableDataSet ds in _selectedDatasets)
                {
                    _configuration.AddDatasetToConfiguration(ds);
                }

                ICommandExecution cmdAssociateCicWithProject = null;

                if (_cohortCreated == null && cbDefineCohort.Checked)
                {
                    var cohortDefinition = new CohortDefinition(null, tbCohortName.Text, 1, _project.ProjectNumber.Value,
                                                                (ExternalCohortTable)ddCohortSources.SelectedItem);

                    //execute the cohort creation bit
                    var cohortRequest = new CohortCreationRequest(_project, cohortDefinition,
                                                                  (DataExportRepository)Activator.RepositoryLocator.DataExportRepository, tbCohortName.Text);

                    ComboBox dd;
                    if (_cohortFile != null)
                    {
                        //execute cohort creation from file.
                        cohortRequest.FileToLoad = new FlatFileToLoad(_cohortFile);
                        dd = ddFilePipeline;
                    }
                    else
                    {
                        //execute cohort creation from cic
                        cohortRequest.CohortIdentificationConfiguration =
                            (CohortIdentificationConfiguration)cbxCohort.SelectedItem;
                        dd = ddCicPipeline;


                        //since we are about to execute a cic and store the results we should associate it with the Project (if successful)
                        cmdAssociateCicWithProject = new ExecuteCommandAssociateCohortIdentificationConfigurationWithProject(Activator).SetTarget(
                            _project).SetTarget(cohortRequest.CohortIdentificationConfiguration);
                    }

                    var engine = cohortRequest.GetEngine((Pipeline)dd.SelectedItem, new ThrowImmediatelyDataLoadEventListener());
                    engine.ExecutePipeline(new GracefulCancellationToken());
                    _cohortCreated = cohortRequest.CohortCreatedIfAny;
                }

                if (cbDefineCohort.Checked)
                {
                    //associate the configuration with the cohort
                    _configuration.Cohort_ID = _cohortCreated.ID;

                    //set the pipeline to use
                    var pipeline = (Pipeline)ddExtractionPipeline.SelectedItem;
                    if (pipeline != null)
                    {
                        _configuration.DefaultPipeline_ID = pipeline.ID;
                    }

                    _configuration.SaveToDatabase();

                    //User defined cohort if it came from cic then associate the cic with the project
                    if (cmdAssociateCicWithProject != null && !cmdAssociateCicWithProject.IsImpossible)
                    {
                        cmdAssociateCicWithProject.Execute();
                    }
                }

                Cursor = Cursors.Default;

                ExtractionConfigurationCreatedIfAny = _configuration;

                DialogResult = DialogResult.OK;
                MessageBox.Show("Project Created Successfully");
                Close();
            }
            catch (Exception exception)
            {
                ragExecute.Fatal(exception);
            }
            finally
            {
                Cursor = Cursors.Default;
            }
        }
        /// <summary>
        /// Defines a new use case in which the given <see cref="AggregateConfiguration"/> will be turned into an SQL query and used to generate rows
        /// that will be released into the pipeline.  The source is fixed the destination and middle components are open.
        /// </summary>
        /// <param name="aggregateConfiguration">The aggregate query that will be run to generate the rows</param>
        /// <param name="constrainByCohort">Only applies if <see cref="AggregateConfiguration"/> is a patient index table, specifying a cohort will only commit rows
        /// in which the patient id appears in the cohort</param>
        /// <param name="table">The destination table in which to put the matched records.
        /// <para> (table does not have to exist yet, you can use <see cref="DiscoveredDatabase.ExpectTable"/> to obtain a reference to a non existant table)</para></param>
        public CreateTableFromAggregateUseCase(AggregateConfiguration aggregateConfiguration, ExtractableCohort constrainByCohort, DiscoveredTable table)
        {
            if (constrainByCohort == null)
            {
                var src = new AggregateConfigurationTableSource();
                src.PreInitialize(aggregateConfiguration, new ThrowImmediatelyDataLoadEventListener());
                src.TableName  = table.GetRuntimeName();
                ExplicitSource = src;
            }
            else
            {
                AddInitializationObject(constrainByCohort);

                var src = new PatientIndexTableSource();
                src.PreInitialize(aggregateConfiguration, new ThrowImmediatelyDataLoadEventListener());
                src.PreInitialize(constrainByCohort, new ThrowImmediatelyDataLoadEventListener());
                src.TableName  = table.GetRuntimeName();
                ExplicitSource = src;
            }

            AddInitializationObject(aggregateConfiguration);
            AddInitializationObject(aggregateConfiguration.Repository);
            AddInitializationObject(table.Database);

            GenerateContext();
        }
        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);
        }
Esempio n. 22
0
        private ExtractionConfiguration CreateExtractionConfiguration(Project project, ExtractableCohort cohort, string name, bool isReleased, ICheckNotifier notifier, params Catalogue[] catalogues)
        {
            var extractionConfiguration = new ExtractionConfiguration(_repos.DataExportRepository, project);

            extractionConfiguration.Name      = name;
            extractionConfiguration.Cohort_ID = cohort.ID;
            extractionConfiguration.SaveToDatabase();

            foreach (var c in catalogues)
            {
                //Get it's extractableness
                var eds = _repos.DataExportRepository.GetAllObjectsWithParent <ExtractableDataSet>(c).SingleOrDefault()
                          ?? new ExtractableDataSet(_repos.DataExportRepository, c);  //or make it extractable

                extractionConfiguration.AddDatasetToConfiguration(eds);
            }

            var extractionPipeline = _repos.CatalogueRepository.GetAllObjects <Pipeline>().FirstOrDefault(p => p?.Destination?.Class == typeof(ExecuteDatasetExtractionFlatFileDestination).FullName);

            if (isReleased && extractionConfiguration != null)
            {
                var optsExtract = new ExtractionOptions()
                {
                    Pipeline = extractionPipeline.ID,
                    ExtractionConfiguration = extractionConfiguration.ID
                };
                var runnerExtract = new ExtractionRunner(optsExtract);
                try
                {
                    runnerExtract.Run(_repos, new ThrowImmediatelyDataLoadEventListener(), notifier, new GracefulCancellationToken());
                }
                catch (Exception ex)
                {
                    notifier.OnCheckPerformed(new CheckEventArgs("Could not run ExtractionConfiguration (nevermind)", CheckResult.Warning, ex));
                }

                extractionConfiguration.IsReleased = true;
                extractionConfiguration.SaveToDatabase();
            }

            return(extractionConfiguration);
        }
Esempio n. 23
0
        public void CommitCohortExampleTest(DatabaseType dbType, string privateDataType)
        {
            RunBlitzDatabases(RepositoryLocator);

            //find the test server (where we will create the store schema)
            var db = GetCleanedServer(dbType);

            //create the cohort store table
            var wizard              = new CreateNewCohortDatabaseWizard(db, CatalogueRepository, DataExportRepository, false);
            var privateColumn       = new PrivateIdentifierPrototype("chi", privateDataType);
            var externalCohortTable = wizard.CreateDatabase(privateColumn, new ThrowImmediatelyCheckNotifier());

            Assert.AreEqual(dbType, externalCohortTable.DatabaseType);

            //create a project into which we want to import a cohort
            var project = new Project(DataExportRepository, "MyProject");

            project.ProjectNumber = 500;
            project.SaveToDatabase();

            //create a description of the cohort we are importing
            var definition = new CohortDefinition(null, "MyCohort", 1, 500, externalCohortTable);

            //create our cohort (normally this would be read from a file or be the results of cohort identification query)
            var dt = new DataTable();

            dt.Columns.Add("chi");
            dt.Rows.Add("0101010101");
            dt.Rows.Add("0202020202");

            //Create a pipeline (we only need the destination)
            var pipelineDestination = new BasicCohortDestination();

            //choose how to allocate the anonymous release identifiers
            pipelineDestination.ReleaseIdentifierAllocator = typeof(ProjectConsistentGuidReleaseIdentifierAllocator);

            //initialize the destination
            pipelineDestination.PreInitialize(
                new CohortCreationRequest(project, definition, DataExportRepository, "A cohort created in an example unit test"),
                new ThrowImmediatelyDataLoadEventListener());

            //process the cohort data table
            pipelineDestination.ProcessPipelineData(dt, new ThrowImmediatelyDataLoadEventListener(), new GracefulCancellationToken());

            //there should be no cohorts yet
            Assert.IsEmpty(DataExportRepository.GetAllObjects <ExtractableCohort>());

            //dispose of the pipeline
            pipelineDestination.Dispose(new ThrowImmediatelyDataLoadEventListener(), null);

            //now there should be one
            ExtractableCohort cohort = DataExportRepository.GetAllObjects <ExtractableCohort>().Single();

            //make sure we are all on the same page about what the DBMS type is (nothing cached etc)
            Assert.AreEqual(dbType, cohort.ExternalCohortTable.DatabaseType);
            Assert.AreEqual(dbType, cohort.GetQuerySyntaxHelper().DatabaseType);

            Assert.AreEqual(500, cohort.ExternalProjectNumber);
            Assert.AreEqual(2, cohort.CountDistinct);

            var tbl = externalCohortTable.DiscoverCohortTable();

            Assert.AreEqual(2, tbl.GetRowCount());
            var dtInDatabase = tbl.GetDataTable();

            //guid will be something like "6fb23de5-e8eb-46eb-84b5-dd368da21073"
            Assert.AreEqual(36, dtInDatabase.Rows[0]["ReleaseId"].ToString().Length);
            Assert.AreEqual("0101010101", dtInDatabase.Rows[0]["chi"]);
        }
Esempio n. 24
0
 public ViewCohortExtractionUICollection(ExtractableCohort cohort) : this()
 {
     DatabaseObjects.Add(cohort);
 }
        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);
        }