コード例 #1
0
        /// <summary>
        /// Creates new databases on the given server for RDMP platform databases
        /// </summary>
        /// <param name="options"></param>
        public void CreatePlatformDatabases(PlatformDatabaseCreationOptions options)
        {
            DiscoveredServerHelper.CreateDatabaseTimeoutInSeconds = options.CreateDatabaseTimeout;

            Create(DefaultCatalogueDatabaseName, new CataloguePatcher(), options);
            Create(DefaultDataExportDatabaseName, new DataExportPatcher(), options);

            var dqe     = Create(DefaultDQEDatabaseName, new DataQualityEnginePatcher(), options);
            var logging = Create(DefaultLoggingDatabaseName, new LoggingDatabasePatcher(), options);

            CatalogueRepository.SuppressHelpLoading = true;

            var repo = new PlatformDatabaseCreationRepositoryFinder(options);

            if (!options.SkipPipelines)
            {
                var creator = new CataloguePipelinesAndReferencesCreation(repo, logging, dqe);
                creator.Create();
            }

            if (options.ExampleDatasets)
            {
                var examples = new ExampleDatasetsCreation(new ThrowImmediatelyActivator(repo, null), repo);
                var server   = new DiscoveredServer(options.GetBuilder("ExampleData"));

                examples.Create(server.GetCurrentDatabase(), new ThrowImmediatelyCheckNotifier()
                {
                    WriteToConsole = true
                }, options);
            }
        }
コード例 #2
0
        public PlatformDatabaseCreationRepositoryFinder(PlatformDatabaseCreationOptions options)
        {
            var cata   = options.GetBuilder(PlatformDatabaseCreation.DefaultCatalogueDatabaseName);
            var export = options.GetBuilder(PlatformDatabaseCreation.DefaultDataExportDatabaseName);

            _linkedRepositoryProvider = new LinkedRepositoryProvider(cata.ConnectionString, export.ConnectionString);
        }
コード例 #3
0
        internal void Create(DiscoveredDatabase db, ICheckNotifier notifier, PlatformDatabaseCreationOptions options)
        {
            if (db.Exists())
            {
                if (options.DropDatabases)
                {
                    db.Drop();
                }
                else
                {
                    throw new Exception("Database " + db.GetRuntimeName() + " already exists and allowDrop option was not specified");
                }
            }

            notifier.OnCheckPerformed(new CheckEventArgs("About to create " + db.GetRuntimeName(), CheckResult.Success));
            //create a new database for the datasets
            db.Create();

            notifier.OnCheckPerformed(new CheckEventArgs("Succesfully created " + db.GetRuntimeName(), CheckResult.Success));

            //fixed seed so everyone gets the same datasets
            var r = new Random(options.Seed);

            notifier.OnCheckPerformed(new CheckEventArgs("Generating people", CheckResult.Success));
            //people
            var people = new PersonCollection();

            people.GeneratePeople(options.NumberOfPeople, r);

            //datasets
            var biochem     = ImportCatalogue(Create <Biochemistry>(db, people, r, notifier, options.NumberOfRowsPerDataset, "chi", "Healthboard", "SampleDate", "TestCode"));
            var demography  = ImportCatalogue(Create <Demography>(db, people, r, notifier, options.NumberOfRowsPerDataset, "chi", "dtCreated", "hb_extract"));
            var prescribing = ImportCatalogue(Create <Prescribing>(db, people, r, notifier, options.NumberOfRowsPerDataset, "chi", "PrescribedDate", "Name")); //<- this is slooo!
            var admissions  = ImportCatalogue(Create <HospitalAdmissions>(db, people, r, notifier, options.NumberOfRowsPerDataset, "chi", "AdmissionDate"));
            var carotid     = Create <CarotidArteryScan>(db, people, r, notifier, options.NumberOfRowsPerDataset, "RECORD_NUMBER");

            //the following should not be extractable
            ForExtractionInformations(demography,
                                      e => e.DeleteInDatabase(),
                                      "chi_num_of_curr_record",
                                      "surname",
                                      "forename",
                                      "current_address_L1",
                                      "current_address_L2",
                                      "current_address_L3",
                                      "current_address_L4",
                                      "birth_surname",
                                      "previous_surname",
                                      "midname",
                                      "alt_forename",
                                      "other_initials",
                                      "previous_address_L1",
                                      "previous_address_L2",
                                      "previous_address_L3",
                                      "previous_address_L4",
                                      "previous_postcode",
                                      "date_address_changed",
                                      "adr",
                                      "previous_gp_accept_date",
                                      "hic_dataLoadRunID");

            //the following should be special approval only
            ForExtractionInformations(demography,
                                      e => {
                e.ExtractionCategory = ExtractionCategory.SpecialApprovalRequired;
                e.SaveToDatabase();
            },
                                      "current_postcode",
                                      "current_gp",
                                      "previous_gp",
                                      "date_of_birth");


            CreateAdmissionsViews(db);
            var vConditions = ImportCatalogue(db.ExpectTable("vConditions"));
            var vOperations = ImportCatalogue(db.ExpectTable("vOperations"));

            CreateGraph(biochem, "Test Codes", "TestCode", false, null);
            CreateGraph(biochem, "Test Codes By Date", "SampleDate", true, "TestCode");

            CreateFilter(biochem, "Creatinine", "TestCode", "TestCode like '%CRE%'", @"Serum creatinine is a blood measurement.  It is an indicator of renal health.");
            CreateFilter(biochem, "Test Code", "TestCode", "TestCode like @code", "Filters any test code set");

            CreateExtractionInformation(demography, "Age", "date_of_birth", "FLOOR(DATEDIFF(DAY, date_of_birth, GETDATE()) / 365.25) As Age");
            var fAge = CreateFilter(demography, "Older at least x years", "Age", "FLOOR(DATEDIFF(DAY, date_of_birth, GETDATE()) / 365.25) >= @age", "Patients age is greater than or equal to the provided @age");

            SetParameter(fAge, "@age", "int", "16");

            CreateGraph(demography, "Patient Ages", "Age", false, null);

            CreateGraph(prescribing, "Approved Name", "ApprovedName", false, null);
            CreateGraph(prescribing, "Approved Name Over Time", "PrescribedDate", true, "ApprovedName");

            CreateGraph(prescribing, "Bnf", "FormattedBnfCode", false, null);
            CreateGraph(prescribing, "Bnf Over Time", "PrescribedDate", true, "FormattedBnfCode");

            CreateFilter(
                CreateGraph(vConditions, "Conditions frequency", "Field", false, "Condition"),
                "Common Conditions Only",
                @"(Condition in 
(select top 40 Condition from vConditions c
 WHERE Condition <> 'NULL' AND Condition <> 'Nul' 
 group by Condition order by count(*) desc))");

            CreateFilter(
                CreateGraph(vOperations, "Operation frequency", "Field", false, "Operation"),
                "Common Operation Only",
                @"(Operation in 
(select top 40 Operation from vOperations c
 WHERE Operation <> 'NULL' AND Operation <> 'Nul' 
 group by Operation order by count(*) desc))");

            //group these all into the same folder
            admissions.Folder = new CatalogueFolder(admissions, @"\admissions");
            admissions.SaveToDatabase();
            vConditions.Folder = new CatalogueFolder(vConditions, @"\admissions");
            vConditions.SaveToDatabase();
            vOperations.Folder = new CatalogueFolder(vOperations, @"\admissions");
            vOperations.SaveToDatabase();


            //Create cohort store database
            var wizard = new CreateNewCohortDatabaseWizard(db, _repos.CatalogueRepository, _repos.DataExportRepository, false);
            var externalCohortTable = wizard.CreateDatabase(new PrivateIdentifierPrototype("chi", "varchar(10)"), new ThrowImmediatelyCheckNotifier());

            //Find the pipeline for committing cohorts
            var cohortCreationPipeline = _repos.CatalogueRepository.GetAllObjects <Pipeline>().FirstOrDefault(p => p?.Source?.Class == typeof(CohortIdentificationConfigurationSource).FullName);

            if (cohortCreationPipeline == null)
            {
                throw new Exception("Could not find a cohort committing pipeline");
            }

            //A cohort creation query
            var f = CreateFilter(vConditions, "Lung Cancer Condition", "Condition", "Condition like 'C349'", "ICD-10-CM Diagnosis Code C34.9 Malignant neoplasm of unspecified part of bronchus or lung");

            var cic = CreateCohortIdentificationConfiguration((ExtractionFilter)f);

            var cohort = CommitCohortToNewProject(cic, externalCohortTable, cohortCreationPipeline, "Lung Cancer Project", "P1 Lung Cancer Patients", 123, out Project project);

            var cohortTable = cohort.ExternalCohortTable.DiscoverCohortTable();

            using (var con = cohortTable.Database.Server.GetConnection())
            {
                con.Open();
                //delete half the records (so we can simulate cohort refresh)
                var cmd = cohortTable.Database.Server.GetCommand(string.Format("DELETE TOP (10) PERCENT from {0}", cohortTable.GetFullyQualifiedName()), con);
                cmd.ExecuteNonQuery();
            }

            var ec1 = CreateExtractionConfiguration(project, cohort, "First Extraction (2016 - project 123)", true, notifier, biochem, prescribing, demography);
            var ec2 = CreateExtractionConfiguration(project, cohort, "Project 123 - 2017 Refresh", true, notifier, biochem, prescribing, demography, admissions);
            var ec3 = CreateExtractionConfiguration(project, cohort, "Project 123 - 2018 Refresh", true, notifier, biochem, prescribing, demography, admissions);

            ReleaseAllConfigurations(notifier, ec1, ec2, ec3);
        }
コード例 #4
0
        private SqlConnectionStringBuilder Create(string databaseName, IPatcher patcher, PlatformDatabaseCreationOptions options)
        {
            SqlConnection.ClearAllPools();

            var builder = options.GetBuilder(databaseName);

            DiscoveredDatabase db = new DiscoveredServer(builder).ExpectDatabase(builder.InitialCatalog);

            if (options.DropDatabases && db.Exists())
            {
                Console.WriteLine("Dropping Database:" + builder.InitialCatalog);
                db.Drop();
            }

            MasterDatabaseScriptExecutor executor = new MasterDatabaseScriptExecutor(db);

            executor.BinaryCollation = options.BinaryCollation;
            executor.CreateAndPatchDatabase(patcher, new AcceptAllCheckNotifier());
            Console.WriteLine("Created " + builder.InitialCatalog + " on server " + builder.DataSource);

            return(builder);
        }