### SQLite Migration Example Source: https://github.com/ohdsi/cohortdiagnostics/blob/main/inst/sql/sql_server/migrations/README.md Illustrates a platform-specific migration strategy for SQLite, which does not support renaming columns. This example shows recreating a table and copying data. ```sql inst/sql/sqlite/migrations/Migration_2-v3_1_0_ir_person_years.sql ``` -------------------------------- ### Install and Restore Packages with renv Source: https://github.com/ohdsi/cohortdiagnostics/blob/main/inst/shiny/DiagnosticsExplorer/README.md Installs the renv package and restores project dependencies to create an isolated environment for the Shiny app. ```R install.packages("renv") renv::restore() ``` -------------------------------- ### Get Eunomia Test Database Connection Details Source: https://github.com/ohdsi/cohortdiagnostics/blob/main/docs/articles/RunningCohortDiagnostics.html Use the Eunomia package to obtain connection details for a local SQLite database, suitable for testing and examples. ```r connectionDetails <- Eunomia::getEunomiaConnectionDetails() cdmDatabaseSchema <- "main" tempEmulationSchema <- NULL cohortDatabaseSchema <- "main" cohortTable <- "cohort" ``` -------------------------------- ### Launch the Shiny Application Source: https://github.com/ohdsi/cohortdiagnostics/blob/main/inst/shiny/DiagnosticsExplorer/README.md Launches the Diagnostics Explorer Shiny application after dependencies have been installed. ```R shiny::runApp() ``` -------------------------------- ### Install Required Packages Source: https://github.com/ohdsi/cohortdiagnostics/blob/main/docs/articles/RunningCohortDiagnostics.html Install the CohortDiagnostics package and optionally ROhdsiWebApi for downloading cohort definitions from ATLAS. ```r remotes::install_github("OHDSI/Eunomia") remotes::install_github("OHDSI/ROhdsiWebApi") ``` -------------------------------- ### Valid Migration File Names Source: https://github.com/ohdsi/cohortdiagnostics/blob/main/inst/sql/sql_server/migrations/README.md Examples of correctly formatted file names for SQL Server migrations. The pattern requires 'Migration_-' followed by a descriptive name. ```text Migration_2-MyMigration.sql Migration_2-v3.2whaterver.sql Migration_4-TEST.sql Migration_4-2018922-vAAAA.sql ``` -------------------------------- ### Install CohortDiagnostics Package Source: https://github.com/ohdsi/cohortdiagnostics/blob/main/README.md Use these R commands to download and install the CohortDiagnostics package. Ensure your R environment is configured, including Java, by following the instructions provided. ```r remotes::install_github("OHDSI/CohortDiagnostics") ``` -------------------------------- ### Example config.yml for remote databases Source: https://github.com/ohdsi/cohortdiagnostics/blob/main/docs/articles/DatabaseModeInDiagnosticsExplorer.html This YAML configuration is used for connecting to remote PostgreSQL databases. It specifies connection details such as database type, server address, user credentials, port, and schema information. It also includes options for secure key storage, table prefixes, and enabling/disabling annotations and authorization. ```yaml # Alter these configuration settings for usage with remote databases connectionDetails: dbms: "postgresql" server: "my-database-server.com/myDatabaseName" user: "postrgres" password: "secret_password" port: 5432 # Store connection details as a json string in keyring # Store with keyring::key_set_with_value("KEYNAME", jsonlite::toJSON(myConnectionDetails)) connectionDetailsSecureKey: ~ # If you used a table prefix to store the results (e.g. cd_) tablePrefix: "" # Results schema being used resultsDatabaseSchema: "cohort_diagnostics" # Vocabulary schemas. Should include the reuslts schema and optional custom vocabularies vocabularyDatabaseSchemas: ["cohort_diagnostics"] # Custom table name for cohorts and cdm databases (probably not needed, ignores table prefix) cohortTableName: "cohort" databaseTableName: "database" # If you wish to enable annotation - not currently reccomended in multi-user environments enableAnnotation: FALSE enableAuthorization: FALSE ``` -------------------------------- ### Inserting Migration Record Source: https://github.com/ohdsi/cohortdiagnostics/blob/main/inst/sql/sql_server/migrations/README.md Example of how to add a record to the migrations table to track completed migrations. The `migration_completed` field must exactly match the migration file name. ```sql INSERT INTO @results_schema.@table_prexif@migration (migration_completed, migration_order) VALUES ('Migration_1-v3_1_0_time_id.sql', 1); ``` -------------------------------- ### Install Latest Hydra Version Source: https://github.com/ohdsi/cohortdiagnostics/blob/main/docs/articles/CreatingAStudyPackage.html Ensure you have the latest version of Hydra, as CohortDiagnostics support is in the develop branch. This command installs the develop branch. ```r # please ensure you have the latest version of Hydra. As of 08/13/2021 - CohortDiagnostics support for Hydra is still in develop branch. # please check hydra release notes and update hydra remotes::install_github("OHDSI/Hydra", ref = "develop") ``` -------------------------------- ### Invalid Migration File Names Source: https://github.com/ohdsi/cohortdiagnostics/blob/main/inst/sql/sql_server/migrations/README.md Examples of incorrectly formatted file names for SQL Server migrations. These violate the required naming pattern. ```text MyMigration.sql # Does not include Migration_1 Migration_2v3.2whaterver.sql # missing - -TEST_Migration_1.sql # Wrong order Migraton_4-a.sql # Migration spelt wrong ``` -------------------------------- ### Get Cohorts JSON and SQL Source: https://github.com/ohdsi/cohortdiagnostics/blob/main/NEWS.md This refactored function retrieves the JSON and parameterized OHDSI SQL for cohorts requiring diagnostics. It enhances error handling by using the checkmate R-package. ```r getCohortsJsonAndSql ``` -------------------------------- ### Get CDM Data Source Information Source: https://github.com/ohdsi/cohortdiagnostics/blob/main/docs/reference/getCdmDataSourceInformation.html Retrieves metadata about the CDM source, including its name, description, release dates, and version information. This function requires either connection details or an active connection to the database and the CDM schema name. ```r getCdmDataSourceInformation( connectionDetails = connectionDetails, cdmDatabaseSchema = "cdm_data.dbo" ) ``` -------------------------------- ### Set Up Secure Connection Details with keyring Source: https://github.com/ohdsi/cohortdiagnostics/blob/main/inst/shiny/DiagnosticsExplorer/README.md Demonstrates how to create a list of connection details and save them securely using the keyring package. This avoids storing sensitive credentials in plain text. ```R myConnectionDetails <- list( user = "myusername", password = "someSecretPassword", server = "my-server-address.com/cohort_diagnostics", dbms = "postgresql", port = 5432 ) keyring::key_set_with_value("KEYNAME", jsonlite::toJSON(myConnectionDetails)) ``` -------------------------------- ### Prepare Shiny App for Publishing Source: https://github.com/ohdsi/cohortdiagnostics/blob/main/docs/articles/ViewingResultsUsingDiagnosticsExplorer.html Launches the Diagnostics Explorer Shiny application with options to make it publishable. This involves specifying the SQLite database path, setting 'makePublishable' to TRUE, defining the output directory for publishable files, and optionally overwriting the directory if it already exists. ```r launchDiagnosticsExplorer( sqliteDbPath = "MyCohortDiagnosticsResulst.sqlite", makePublishable = TRUE, publishDir = file.path(getwd(), "MyStudyDiagnosticsExplorer"), overwritePublishDir = TRUE ) ``` -------------------------------- ### Setting up and Fetching Cohort Definitions Source: https://github.com/ohdsi/cohortdiagnostics/blob/main/docs/articles/CreatingAStudyPackage.html This R code snippet initializes variables, sets up the ROhsiWebApi connection, and retrieves metadata for specified cohort IDs. ```r organizationName <- "OHDSI" description <- "Cohort diagnostics on Thrombosis With Thrombocytopenia Syndrome cohorts." library(magrittr) # Set up baseUrl <- Sys.getenv("baseUrl") # if you have security enabled, please authorize the use - example below # ROhsiWebApi::authorizeWebApi(baseUrl, 'windows') cohortIds <- c( 22040, 22042, 22041, 22039, 22038, 22037, 22036, 22035, 22034, 22033, 22031, 22032, 22030, 22028, 22029 ) ################# end of user input ############## webApiCohorts <- ROhsiWebApi::getCohortDefinitionsMetaData(baseUrl = baseUrl) studyCohorts <- webApiCohorts %>% dplyr::filter(.data$id %in% cohortIds) ``` -------------------------------- ### SqlRender Parameters in Migrations Source: https://github.com/ohdsi/cohortdiagnostics/blob/main/inst/sql/sql_server/migrations/README.md Demonstrates how to define and use SqlRender parameters for table names and schemas within migration scripts. The `@table_prefix` parameter is crucial for table referencing. ```sql @results_schema @table_prefix ``` -------------------------------- ### Launching Diagnostics Explorer with publishing options Source: https://github.com/ohdsi/cohortdiagnostics/blob/main/docs/articles/DatabaseModeInDiagnosticsExplorer.html This R code demonstrates how to launch the Diagnostics Explorer Shiny application with specific configuration for publishing. It allows you to specify a configuration file path, make the output publishable, define a directory for the published output, and choose whether to overwrite an existing directory. ```r launchDiagnosticsExplorer( shinyConfigPath = "path/to/config.yml", makePublishable = TRUE, publishDir = file.path(getwd(), "MyStudyDiagnosticsExplorer"), overwritePublishDir = TRUE ) ``` -------------------------------- ### Create Diagnostics Explorer Shiny App Folder Source: https://github.com/ohdsi/cohortdiagnostics/blob/main/docs/articles/ViewingResultsUsingDiagnosticsExplorer.html Creates a Shiny app folder in your R working directory, overwriting existing ones and copying the SQLite file. The app will then load and display a publish button. ```r createMyStudyShinyApp("MyStudyDiagnosticsExplorer", "MyCohortDiagnosticsResults.sqlite") ``` -------------------------------- ### Get Results Data Model Specifications Source: https://github.com/ohdsi/cohortdiagnostics/blob/main/docs/reference/getResultsDataModelSpecifications.html Call this function to retrieve the specifications for the Cohort Diagnostics results data model. The function returns a tibble data frame. ```R getResultsDataModelSpecifications() ``` -------------------------------- ### Get Default Covariate Settings Source: https://github.com/ohdsi/cohortdiagnostics/blob/main/docs/reference/getDefaultCovariateSettings.html Call this function to retrieve the default covariate settings. Note that certain time windows are mandatory for other diagnostics and will be included regardless of user specifications. ```r getDefaultCovariateSettings() ``` -------------------------------- ### Study Package Configuration Variables Source: https://github.com/ohdsi/cohortdiagnostics/blob/main/docs/articles/CreatingAStudyPackage.html Define key variables for your study package, including output folder, version, name, package name, skeleton version, and creator/modifier details. ```r outputFolder <- "d:/temp/output" # location where you study package will be created ########## Please populate the information below ##################### version <- "v0.1.0" name <- "Thrombosis With Thrombocytopenia Syndrome cohorts - an OHDSI network study" packageName <- "ThrombosisWithThrombocytopeniaSyndrome" skeletonVersion <- "v0.0.1" createdBy <- "rao@ohdsi.org" createdDate <- Sys.Date() # default modifiedBy <- "rao@ohdsi.org" modifiedDate <- Sys.Date() ``` -------------------------------- ### Instantiate Cohort Tables using CohortGenerator Source: https://github.com/ohdsi/cohortdiagnostics/blob/main/docs/articles/RunningCohortDiagnostics.html Creates necessary cohort tables in the database and generates the cohort set. Note that this will delete existing tables unless incremental mode is enabled. ```r cohortTableNames <- CohortGenerator::getCohortTableNames(cohortTable = cohortTable) # Next create the tables on the database CohortGenerator::createCohortTables( connectionDetails = connectionDetails, cohortTableNames = cohortTableNames, cohortDatabaseSchema = "main", incremental = FALSE ) # Generate the cohort set CohortGenerator::generateCohortSet( connectionDetails = connectionDetails, cdmDatabaseSchema = cdmDatabaseSchema, cohortDatabaseSchema = cohortDatabaseSchema, cohortTableNames = cohortTableNames, cohortDefinitionSet = cohortDefinitionSet, incremental = FALSE ) ``` -------------------------------- ### Launch Diagnostics Explorer with SQLite Source: https://github.com/ohdsi/cohortdiagnostics/blob/main/docs/articles/ViewingResultsUsingDiagnosticsExplorer.html Launches the Diagnostics Explorer Shiny application using a pre-existing SQLite database file. Ensure the SQLite file is accessible, typically in a 'data' folder if running from RStudio. ```r launchDiagnosticsExplorer(sqliteDbPath = "MyCohortDiagnosticsResulst.sqlite") ``` -------------------------------- ### Launch Diagnostics Explorer Over Network Source: https://github.com/ohdsi/cohortdiagnostics/blob/main/docs/articles/ViewingResultsUsingDiagnosticsExplorer.html Launches the Diagnostics Explorer Shiny application, making it accessible over your network within the firewall by setting the `runOverNetwork` parameter to TRUE. ```r launchDiagnosticsExplorer(runOverNetwork = TRUE) ``` -------------------------------- ### Execute Cohort Diagnostics Source: https://github.com/ohdsi/cohortdiagnostics/blob/main/docs/reference/executeDiagnostics.html Runs cohort diagnostics on instantiated cohorts. Assumes cohorts are already instantiated using the CohortGenerator package. Specify the export folder, database ID, and schema details. ```r executeDiagnostics( cohortDefinitionSet = cohortDefinitionSet, exportFolder = "C:/output", databaseId = "MyDatabase", cohortDatabaseSchema = "my_cohort_schema", cdmDatabaseSchema = "my_cdm_schema", runInclusionStatistics = TRUE, runIncludedSourceConcepts = TRUE, runOrphanConcepts = TRUE, runTimeSeries = FALSE, runVisitContext = TRUE, runBreakdownIndexEvents = TRUE, runIncidenceRate = TRUE, runCohortRelationship = TRUE, runTemporalCohortCharacterization = TRUE, temporalCovariateSettings = FeatureExtraction::createTemporalCovariateSettings( useDemographics = TRUE, useTimeId = TRUE, useEventId = TRUE ) ) ``` -------------------------------- ### Create PostgreSQL Connection Details Source: https://github.com/ohdsi/cohortdiagnostics/blob/main/docs/articles/RunningCohortDiagnostics.html Configure R to connect to a PostgreSQL database using the DatabaseConnector package. Refer to the package documentation for DBMS-specific settings. ```r library(CohortDiagnostics) connectionDetails <- createConnectionDetails( dbms = "postgresql", server = "localhost/ohdsi", user = "joe", password = "supersecret" ) ``` -------------------------------- ### Create Publishable Shiny Zip Source: https://github.com/ohdsi/cohortdiagnostics/blob/main/docs/reference/createDiagnosticsExplorerZip.html This utility creates a zip file containing the Shiny app code and an SQLite database, suitable for publishing on servers. It takes the Shiny code from an R project and adds an SQLite file to the archive. ```r createDiagnosticsExplorerZip( outputZipfile = file.path(getwd(), "DiagnosticsExplorer.zip"), sqliteDbPath = "MergedCohortDiagnosticsData.sqlite", shinyDirectory = system.file(file.path("shiny", "DiagnosticsExplorer"), package = "CohortDiagnostics"), overwrite = FALSE ) ``` -------------------------------- ### Execute Cohort Diagnostics Source: https://github.com/ohdsi/cohortdiagnostics/blob/main/docs/articles/RunningCohortDiagnostics.html Executes the cohort diagnostics using the provided cohort definition set and connection details. Results are exported to a specified folder. ```r exportFolder <- "export" executeDiagnostics(cohortDefinitionSet, connectionDetails = connectionDetails, cohortTable = cohortTable, cohortDatabaseSchema = cohortDatabaseSchema, cdmDatabaseSchema = cdmDatabaseSchema, exportFolder = exportFolder, databaseId = "MyCdm", minCellCount = 5 ) ``` -------------------------------- ### Building the Study Package with Hydra Source: https://github.com/ohdsi/cohortdiagnostics/blob/main/docs/articles/CreatingAStudyPackage.html This R code loads the generated JSON specifications and uses the Hydra package to build the study package in the specified output folder. ```r #### Code that uses the ExampleCohortDiagnosticsSpecs in Hydra to build package hydraSpecificationFromFile <- Hydra::loadSpecifications(fileName = jsonFileName) unlink(x = outputFolder, recursive = TRUE) dir.create(path = outputFolder, showWarnings = FALSE, recursive = TRUE) Hydra::hydrate( specifications = hydraSpecificationFromFile, outputFolder = outputFolder ) ``` -------------------------------- ### Upload Results to Database Source: https://github.com/ohdsi/cohortdiagnostics/blob/main/docs/reference/uploadResults.html Use this function to upload study results to a database server. Ensure the results data model tables are created beforehand. For optimal performance, set the POSTGRES_PATH environmental variable to the location of the psql executable. ```r uploadResults( connectionDetails, schema, zipFileName, forceOverWriteOfSpecifications = FALSE, purgeSiteDataBeforeUploading = TRUE, tempFolder = tempdir(), tablePrefix = "", ... ) ``` -------------------------------- ### Execute Diagnostics with CohortGenerator Source: https://github.com/ohdsi/cohortdiagnostics/blob/main/docs/reference/executeDiagnostics.html Run diagnostics using cohorts defined via CohortGenerator. Ensure connection details and schemas are correctly specified. ```r if (FALSE) { # Load cohorts (assumes that they have already been instantiated) cohortTableNames <- CohortGenerator::getCohortTableNames(cohortTable = "cohort") cohorts <- CohortGenerator::getCohortDefinitionSet(packageName = "MyGreatPackage") connectionDetails <- createConnectionDetails( dbms = "postgresql", server = "ohdsi.com", port = 5432, user = "me", password = "secure" ) executeDiagnostics( cohorts = cohorts, exportFolder = "export", cohortTableNames = cohortTableNames, cohortDatabaseSchema = "results", cdmDatabaseSchema = "cdm", databaseId = "mySpecialCdm", connectionDetails = connectionDetails ) } ``` -------------------------------- ### deployPositConnectApp Source: https://github.com/ohdsi/cohortdiagnostics/blob/main/docs/reference/deployPositConnectApp.html Deploys your application to a Posit Connect platform or shinyapps.io server. This function allows you to publish your Cohort Diagnostics results as a web application. ```APIDOC ## deployPositConnectApp ### Description Deploy your application to an posit connect platform or shinyapps.io server. ### Usage ```R deployPositConnectApp( appName, appDir = tempfile(), sqliteDbPath = "MergedCohortDiagnosticsData.sqlite", shinyDirectory = system.file(file.path("shiny", "DiagnosticsExplorer"), package = "CohortDiagnostics"), connectionDetails = NULL, shinyConfigPath = NULL, resultsDatabaseSchema = NULL, vocabularyDatabaseSchemas = resultsDatabaseSchema, tablePrefix = "", cohortTableName = "cohort", databaseTableName = "database", port = 80, useRenvironFile = FALSE, ... ) ``` ### Arguments #### `appName` * **string** - name to call app - should be unique on posit connect server #### `appDir` * **string** - optional - directory to use to copy files for deployment. If you use a consistent dir other internal options can change. #### `sqliteDbPath` * **string** - Path to merged sqlite file. See `createMergedResultsFile` to create file. #### `shinyDirectory` * **string** - (optional) Directyory shiny app code lives. Use this if you wish to modify the explorer #### `connectionDetails` * **connectionDetails object** - An object of type `connectionDetails` as created using the `createConnectionDetails` function in the DatabaseConnector package, specifying how to connect to the server where the CohortDiagnostics results have been uploaded using the `uploadResults` function. #### `shinyConfigPath` * **string** - Path to shiny yml configuration file (use instead of sqliteDbPath or connectionDetails object) #### `resultsDatabaseSchema` * **string** - The schema on the database server where the CohortDiagnostics results have been uploaded. #### `vocabularyDatabaseSchemas` * **list of strings** - (optional) A list of one or more schemas on the database server where the vocabulary tables are located. The default value is the value of the resultsDatabaseSchema. We can provide a list of vocabulary schema that might represent different versions of the OMOP vocabulary tables. The default value is the value of the resultsDatabaseSchema. We can provide a list of vocabulary schema that might represent different versions of the OMOP vocabulary tables. It allows us to compare the impact of vocabulary changes on Diagnostics. Not supported with an sqlite database. #### `tablePrefix` * **string** - (Optional) string to insert before table names (e.g. "cd_") for database table names #### `cohortTableName` * **string** - (Optional) if cohort table name differs from the standard - cohort (ignores prefix if set) #### `databaseTableName` * **string** - (Optional) if database table name differs from the standard - database (ignores prefix if set) #### `port` * **integer** - (optional) Only used if `runOverNetwork` = TRUE. #### `useRenvironFile` * **logical** - not recommended, store db credentials in .Renviron file #### `...` * **any** - other parameters passed to rsconnect::deployApp ``` -------------------------------- ### Create Diagnostics Explorer Zip Archive Source: https://github.com/ohdsi/cohortdiagnostics/blob/main/docs/articles/ViewingResultsUsingDiagnosticsExplorer.html Automatically creates a zip archive of the Diagnostics Explorer Shiny application for deployment on shared environments. This includes the application and its dependencies. ```r createDiagnosticsExplorerZip(outputZipfile = "MyCdProject.zip", sqliteDbPath = "MyCohortDiagnosticsResulst.sqlite") ``` -------------------------------- ### Load Cohort Definition Set from Package Source: https://github.com/ohdsi/cohortdiagnostics/blob/main/docs/articles/RunningCohortDiagnostics.html Load cohort definitions from a study package using CohortGenerator. This ensures reproducibility by using a snapshot of cohort definitions. ```r library(CohortDiagnostics) covariateSettings <- CohortGenerator::getCohortDefinitionSet( settingsFileName = "Cohorts.csv", jsonFolder = "cohorts", sqlFolder = "sql/sql_server", packageName = "CohortDiagnostics" ) ``` -------------------------------- ### launchDiagnosticsExplorer Source: https://github.com/ohdsi/cohortdiagnostics/blob/main/docs/reference/launchDiagnosticsExplorer.html Launches the Diagnostics Explorer Shiny app, allowing users to explore cohort diagnostics results. The app can connect to data via an SQLite database file or directly to a database server using connection details. ```APIDOC ## launchDiagnosticsExplorer ### Description Launches a Shiny app that allows the user to explore the diagnostics. This function can be used to visualize results stored in an SQLite file or directly from a database. ### Usage ```r launchDiagnosticsExplorer( sqliteDbPath = "MergedCohortDiagnosticsData.sqlite", connectionDetails = NULL, shinyConfigPath = NULL, resultsDatabaseSchema = NULL, vocabularyDatabaseSchema = NULL, vocabularyDatabaseSchemas = resultsDatabaseSchema, tablePrefix = "", cohortTableName = "cohort", databaseTableName = "database", aboutText = NULL, runOverNetwork = FALSE, port = 80, makePublishable = FALSE, publishDir = file.path(getwd(), "DiagnosticsExplorer"), overwritePublishDir = FALSE, launch.browser = FALSE ) ``` ### Arguments * **sqliteDbPath** (character) - Path to merged sqlite file. See `createMergedResultsFile` to create file. * **connectionDetails** (object) - An object of type `connectionDetails` as created using the `createConnectionDetails` function in the DatabaseConnector package, specifying how to connect to the server where the CohortDiagnostics results have been uploaded using the `uploadResults` function. * **shinyConfigPath** (character) - Path to shiny yml configuration file (use instead of sqliteDbPath or connectionDetails object) * **resultsDatabaseSchema** (character) - The schema on the database server where the CohortDiagnostics results have been uploaded. * **vocabularyDatabaseSchema** (character) - (Deprecated) Please use vocabularyDatabaseSchemas. * **vocabularyDatabaseSchemas** (list) - (optional) A list of one or more schemas on the database server where the vocabulary tables are located. The default value is the value of the resultsDatabaseSchema. We can provide a list of vocabulary schema that might represent different versions of the OMOP vocabulary tables. It allows us to compare the impact of vocabulary changes on Diagnostics. Not supported with an sqlite database. * **tablePrefix** (character) - (Optional) string to insert before table names (e.g. "cd_") for database table names * **cohortTableName** (character) - (Optional) if cohort table name differs from the standard - cohort (ignores prefix if set) * **databaseTableName** (character) - (Optional) if database table name differs from the standard - database (ignores prefix if set) * **aboutText** (character) - Text (using HTML markup) that will be displayed in an About tab in the Shiny app. If not provided, no About tab will be shown. * **runOverNetwork** (logical) - (optional) Do you want the app to run over your network? * **port** (numeric) - (optional) Only used if `runOverNetwork` = TRUE. * **makePublishable** (logical) - (Optional) copy data files to make app publishable to posit connect/shinyapp.io * **publishDir** (character) - If make publishable is true - the directory that the shiny app is copied to * **overwritePublishDir** (logical) - (Optional) If make publishable is true - overwrite the directory for publishing * **launch.browser** (logical) - Should the app be launched in your default browser, or in a Shiny window. Note: copying to clipboard will not work in a Shiny window. ### Details Launches a Shiny app that allows the user to explore the diagnostics. ### Developed By Jamie Gilbert, Gowtham Rao, Martijn Schuemie, Patrick Ryan, James Weaver. ``` -------------------------------- ### Create Results Data Model Tables Source: https://github.com/ohdsi/cohortdiagnostics/blob/main/docs/reference/createResultsDataModel.html Use this function to create the Cohort Diagnostics results data model tables on a PostgreSQL database server. Ensure you have a DatabaseConnector connectionDetails instance configured. ```r createResultsDataModel( connectionDetails = connectionDetails, databaseSchema = "your_schema", tablePrefix = "cd_" ) ``` -------------------------------- ### createResultsDataModel Source: https://github.com/ohdsi/cohortdiagnostics/blob/main/docs/reference/createResultsDataModel.html Creates the results data model tables on a database server. Currently, only PostgreSQL is supported. An optional table prefix can be provided. ```APIDOC ## createResultsDataModel ### Description Creates the results data model tables on a database server. Currently, only PostgreSQL is supported. An optional table prefix can be provided. ### Usage ```R createResultsDataModel(connectionDetails = NULL, databaseSchema, tablePrefix = "") ``` ### Arguments * **connectionDetails** (object) - DatabaseConnector connectionDetails instance. See `DatabaseConnector::createConnectionDetails`. * **databaseSchema** (string) - The schema on the PostgreSQL server where the tables will be created. * **tablePrefix** (string) - Optional string to insert before table names (e.g. "cd_") for database table names. ### Details Only PostgreSQL servers are supported. ``` -------------------------------- ### Load Cohort References from WebApi Source: https://github.com/ohdsi/cohortdiagnostics/blob/main/docs/articles/RunningCohortDiagnostics.html Loads cohort definitions from a WebApi instance into a data frame for use with cohort diagnostics. Ensure 'generateStats' is TRUE to include inclusion rule statistics. ```r # Set up url baseUrl <- "https://atlas.hosting.com/WebAPI" # list of cohort ids cohortIds <- c(18345, 18346) covariateSet <- ROhdsiWebApi::exportCohortDefinitionSet( baseUrl = baseUrl, cohortIds = cohortIds, generateStats = TRUE ) ``` -------------------------------- ### getCdmDataSourceInformation Source: https://github.com/ohdsi/cohortdiagnostics/blob/main/docs/reference/getCdmDataSourceInformation.html Retrieves information from the CDM source table, such as source name, description, release date, CDM release date, version, and vocabulary version, if available. ```APIDOC ## getCdmDataSourceInformation ### Description Returns information from the CDM source table. This function retrieves details like the CDM source name, description, release date, CDM release date, version, and vocabulary version where available. ### Method Not Applicable (R function) ### Parameters #### Arguments - **connectionDetails** (object of type `connectionDetails`) - An object of type `connectionDetails` as created using the `createConnectionDetails` function in the DatabaseConnector package. Can be left NULL if `connection` is provided. - **connection** (object of type `connection`) - An object of type `connection` as created using the `connect` function in the DatabaseConnector package. Can be left NULL if `connectionDetails` is provided, in which case a new connection will be opened at the start of the function, and closed when the function finishes. - **cdmDatabaseSchema** (string) - Schema name where your patient-level data in OMOP CDM format resides. Note that for SQL Server, this should include both the database and schema name, for example 'cdm_data.dbo'. ### Value Returns a data frame containing information from the CDM Data source. ``` -------------------------------- ### Create Merged Results File Source: https://github.com/ohdsi/cohortdiagnostics/blob/main/docs/articles/ViewingResultsUsingDiagnosticsExplorer.html Converts CSV files from Cohort Diagnostics output into an SQLite database for faster loading of the Shiny application. Specify the directory containing the CSV files and the desired path for the SQLite database. ```r createMergedResultsFile("C:/temp/allZipFiles", sqliteDbPath = "MyCohortDiagnosticsResulst.sqlite") ``` -------------------------------- ### executeDiagnostics Source: https://github.com/ohdsi/cohortdiagnostics/blob/main/docs/reference/executeDiagnostics.html Runs the cohort diagnostics on all (or a subset of) the cohorts instantiated using the CohortGenerator package. Assumes the cohorts have already been instantiated. ```APIDOC ## executeDiagnostics ### Description Runs the cohort diagnostics on all (or a subset of) the cohorts instantiated using the CohortGenerator package. Assumes the cohorts have already been instantiated. ### Usage ```r executeDiagnostics( cohortDefinitionSet, exportFolder, databaseId, cohortDatabaseSchema, databaseName = NULL, databaseDescription = NULL, connectionDetails = NULL, connection = NULL, cdmDatabaseSchema, tempEmulationSchema = getOption("sqlRenderTempEmulationSchema"), cohortTable = "cohort", cohortTableNames = CohortGenerator::getCohortTableNames(cohortTable = cohortTable), vocabularyDatabaseSchema = cdmDatabaseSchema, cohortIds = NULL, cdmVersion = 5, runInclusionStatistics = TRUE, runIncludedSourceConcepts = TRUE, runOrphanConcepts = TRUE, runTimeSeries = FALSE, runVisitContext = TRUE, runBreakdownIndexEvents = TRUE, runIncidenceRate = TRUE, runCohortRelationship = TRUE, runTemporalCohortCharacterization = TRUE, temporalCovariateSettings = getDefaultCovariateSettings(), minCellCount = 5, minCharacterizationMean = 0.01, irWashoutPeriod = 0, incremental = FALSE, incrementalFolder = file.path(exportFolder, "incremental"), runFeatureExtractionOnSample = FALSE, sampleN = 1000, seed = 64374, seedArgs = NULL ) ``` ### Arguments * **cohortDefinitionSet** - Data.frame of cohorts must include columns cohortId, cohortName, json, sql * **exportFolder** - The folder where the output will be exported to. If this folder does not exist it will be created. * **databaseId** - A short string for identifying the database (e.g. 'Synpuf'). * **cohortDatabaseSchema** - Schema name where your cohort table resides. Note that for SQL Server, this should include both the database and schema name, for example 'scratch.dbo'. * **databaseName** - The full name of the database. If NULL, defaults to value in cdm_source table * **databaseDescription** - A short description (several sentences) of the database. If NULL, defaults to value in cdm_source table * **connectionDetails** - An object of type `connectionDetails` as created using the `createConnectionDetails` function in the DatabaseConnector package. Can be left NULL if `connection` is provided. * **connection** - An object of type `connection` as created using the `connect` function in the DatabaseConnector package. Can be left NULL if `connectionDetails` is provided, in which case a new connection will be opened at the start of the function, and closed when the function finishes. * **cdmDatabaseSchema** - Schema name where your patient-level data in OMOP CDM format resides. Note that for SQL Server, this should include both the database and schema name, for example 'cdm_data.dbo'. * **tempEmulationSchema** - Some database platforms like Oracle and Impala do not truly support temp tables. To emulate temp tables, provide a schema with write privileges where temp tables can be created. * **cohortTable** - Name of the cohort table. * **cohortTableNames** - Cohort Table names used by CohortGenerator package * **vocabularyDatabaseSchema** - Schema name where the vocabulary tables reside. Defaults to `cdmDatabaseSchema`. ``` -------------------------------- ### Execute Diagnostics with Custom Cohort Data Frame Source: https://github.com/ohdsi/cohortdiagnostics/blob/main/docs/reference/executeDiagnostics.html Run diagnostics using a custom data frame of cohorts. This method allows for direct SQL or JSON definitions. ```r # Use a custom set of cohorts defined in a data.frame cohorts <- data.frame( cohortId = c(100), cohortName = c("Cohort Name"), logicDescription = c("My Cohort"), sql = c(readLines("path_to.sql")), json = c(readLines("path_to.json")) ) executeDiagnostics( cohorts = cohorts, exportFolder = "export", cohortTable = "cohort", cohortDatabaseSchema = "results", cdmDatabaseSchema = "cdm", databaseId = "mySpecialCdm", connectionDetails = connectionDetails ) } ``` -------------------------------- ### getDefaultCovariateSettings Source: https://github.com/ohdsi/cohortdiagnostics/blob/main/docs/reference/getDefaultCovariateSettings.html Retrieves the default covariate settings for cohort diagnostics execution. Certain time windows are required by other diagnostics and will always be included. ```APIDOC ## getDefaultCovariateSettings ### Description Retrieves the default covariate settings for cohort diagnostics execution. Certain time windows are required by other diagnostics and will always be included. ### Usage ```R defaultCovariateSettings <- getDefaultCovariateSettings() ``` ### Details Overriding the default behavior is possible, however, certain time windows are a requirement of other diagnostics. The following time windows will be included regardless of user specifications: * (-365, 0) * (-30, 0) * (-365, -31) * (-30, -1) * (0, 0) * (1, 30) * (31, 365) * (-9999, 9999) ### Returns A list of default covariate settings. ``` -------------------------------- ### Extract Concept Set SQL from Cohort SQL Source: https://github.com/ohdsi/cohortdiagnostics/blob/main/NEWS.md Use this function to extract concept set SQL from cohort definition SQL. This aids in understanding or modifying the SQL generated for concept sets. ```r extractConceptSetsSqlFromCohortSql ```