/// <summary> /// For refreshing the current extraction configuration CohortIdentificationConfiguration ONLY. The ExtractionConfiguration must have a cic and a refresh pipeline configured on it. /// </summary> /// <param name="configuration"></param> public CohortCreationRequest(ExtractionConfiguration configuration) { _repository = (DataExportRepository)configuration.Repository; if (configuration.CohortIdentificationConfiguration_ID == null) { throw new NotSupportedException("Configuration '" + configuration + "' does not have an associated CohortIdentificationConfiguration for cohort refreshing"); } var origCohort = configuration.Cohort; var origCohortData = origCohort.GetExternalData(); CohortIdentificationConfiguration = configuration.CohortIdentificationConfiguration; Project = configuration.Project; if (Project.ProjectNumber == null) { throw new ProjectNumberException("Project '" + Project + "' does not have a ProjectNumber"); } var definition = new CohortDefinition(null, origCohortData.ExternalDescription, origCohortData.ExternalVersion + 1, (int)Project.ProjectNumber, origCohort.ExternalCohortTable); definition.CohortReplacedIfAny = origCohort; NewCohortDefinition = definition; DescriptionForAuditLog = "Cohort Refresh"; AddInitializationObject(Project); AddInitializationObject(CohortIdentificationConfiguration); AddInitializationObject(FileToLoad); AddInitializationObject(ExtractionIdentifierColumn); AddInitializationObject(this); GenerateContext(); }
public CohortCreationRequest(Project project, CohortDefinition newCohortDefinition, IDataExportRepository repository, string descriptionForAuditLog) { _repository = repository; Project = project; NewCohortDefinition = newCohortDefinition; DescriptionForAuditLog = descriptionForAuditLog; AddInitializationObject(Project); AddInitializationObject(this); GenerateContext(); }
public void DeprecateOldCohort(bool deprecate) { var proj = new Project(DataExportRepository, projName); proj.ProjectNumber = 999; proj.SaveToDatabase(); // we are replacing this imaginary cohort var definition998 = new CohortDefinition(null, "CommittingNewCohorts", 1, 999, _externalCohortTable); // with this one (v2) var definition999 = new CohortDefinition(null, "CommittingNewCohorts", 2, 999, _externalCohortTable); // Create a basic cohort first CohortCreationRequest request1 = new CohortCreationRequest(proj, definition998, (DataExportRepository)DataExportRepository, "fish"); request1.Check(new ThrowImmediatelyCheckNotifier()); using var con = _cohortDatabase.Server.GetManagedConnection(); request1.PushToServer(con); request1.ImportAsExtractableCohort(deprecate, false); // the definition was imported and should now be a saved ExtractableCohort var cohort998 = request1.CohortCreatedIfAny; Assert.IsNotNull(cohort998); Assert.IsFalse(cohort998.IsDeprecated); // define that the new definition attempts to replace the old one definition999.CohortReplacedIfAny = cohort998; CohortCreationRequest request2 = new CohortCreationRequest(proj, definition999, (DataExportRepository)DataExportRepository, "fish"); request2.Check(new ThrowImmediatelyCheckNotifier()); request2.PushToServer(con); request2.ImportAsExtractableCohort(deprecate, false); // after committing the new cohort the old one should be deprecated? cohort998.RevertToDatabaseState(); Assert.AreEqual(deprecate, cohort998.IsDeprecated); }
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; } }
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"]); }
public void MigrateUsages(bool migrate) { var proj = new Project(DataExportRepository, projName); proj.ProjectNumber = 999; proj.SaveToDatabase(); // we are replacing this imaginary cohort var definition998 = new CohortDefinition(null, "CommittingNewCohorts", 1, 999, _externalCohortTable); // with this one (v2) var definition999 = new CohortDefinition(null, "CommittingNewCohorts", 2, 999, _externalCohortTable); // Create a basic cohort first CohortCreationRequest request1 = new CohortCreationRequest(proj, definition998, (DataExportRepository)DataExportRepository, "fish"); request1.Check(new ThrowImmediatelyCheckNotifier()); using var con = _cohortDatabase.Server.GetManagedConnection(); request1.PushToServer(con); request1.ImportAsExtractableCohort(true, migrate); // the definition was imported and should now be a saved ExtractableCohort var cohort998 = request1.CohortCreatedIfAny; Assert.IsNotNull(cohort998); Assert.IsFalse(cohort998.IsDeprecated); // legit user 1 var ec1 = new ExtractionConfiguration(DataExportRepository, proj) { IsReleased = false, Cohort_ID = cohort998.ID }; ec1.SaveToDatabase(); // legit user 2 var ec2 = new ExtractionConfiguration(DataExportRepository, proj) { IsReleased = false, Cohort_ID = cohort998.ID }; ec2.SaveToDatabase(); // has no cohort yet defined so should not be migrated var ec3 = new ExtractionConfiguration(DataExportRepository, proj); // is frozen so should not be migrated var ec4 = new ExtractionConfiguration(DataExportRepository, proj) { IsReleased = true, Cohort_ID = cohort998.ID }; ec4.SaveToDatabase(); // define that the new definition attempts to replace the old one definition999.CohortReplacedIfAny = cohort998; CohortCreationRequest request2 = new CohortCreationRequest(proj, definition999, (DataExportRepository)DataExportRepository, "fish"); request2.Check(new ThrowImmediatelyCheckNotifier()); request2.PushToServer(con); request2.ImportAsExtractableCohort(true, migrate); // the definition was imported and should now be a saved ExtractableCohort var cohort999 = request2.CohortCreatedIfAny; Assert.IsNotNull(cohort999); // after committing the new cohort who should be migrated? ec1.RevertToDatabaseState(); ec2.RevertToDatabaseState(); ec3.RevertToDatabaseState(); ec4.RevertToDatabaseState(); // should have been updated to use the new cohort Assert.AreEqual(ec1.Cohort_ID, migrate ? cohort999.ID : cohort998.ID); Assert.AreEqual(ec2.Cohort_ID, migrate ? cohort999.ID: cohort998.ID); // should not have magically gotten a cohort Assert.IsNull(ec3.Cohort_ID); // is frozen so should not have been changed to the new cohort (and therefore still use cohort998) Assert.AreEqual(ec4.Cohort_ID, cohort998.ID); }