Skip to content

Commit

Permalink
Merge pull request #13 from OHDSI/develop
Browse files Browse the repository at this point in the history
update to v0.0.4
  • Loading branch information
mdlavallee92 authored Jan 28, 2024
2 parents cb807fa + a742b8a commit 72963e7
Show file tree
Hide file tree
Showing 132 changed files with 5,423 additions and 1,220 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: Ulysses
Title: Automate OHDSI Study Setup
Version: 0.0.3
Version: 0.0.4
Authors@R:
person("Martin", "Lavallee", , "[email protected]", role = c("aut", "cre"))
Description: Automates setup of OHDSI study and provides functions to assist on improving organization
Expand Down
29 changes: 23 additions & 6 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,54 @@

export("%>%")
export(addConfig)
export(addDataSources)
export(addLinks)
export(addStudyMember)
export(addTags)
export(buildStudyHub)
export(checkConfig)
export(checkDatabaseCredential)
export(cohortManifest)
export(defaultCredentials)
export(importCredentialsToConfig)
export(importImages)
export(initConfig)
export(isOhdsiStudy)
export(makeAnalysisPlan)
export(makeAnalysisScript)
export(makeCaprScript)
export(makeCohortDetails)
export(makeConfig)
export(makeContributionGuidelines)
export(makeHowToRun)
export(makeInternals)
export(makeKeyringSetup)
export(makeMeetingMinutes)
export(makeMigrationScript)
export(makeNews)
export(makeOhdsiProtocol)
export(makeReadMe)
export(makeResultsReport)
export(makeStudySettings)
export(makeTechSpecs)
export(makeWebApiScript)
export(moduleTable)
export(newOhdsiStudy)
export(previewStudyHub)
export(publishStudyToRepository)
export(requestStudyRepository)
export(retrieveStudySettings)
export(setCredential)
export(setMultipleCredentials)
export(setStudyAuthors)
export(setStudyDescription)
export(setStudyInfo)
export(setStudyKeyring)
export(setStudyLinks)
export(setStudyTags)
export(setStudyTimeline)
export(updateDeveloperInfo)
export(updateLeadInfo)
export(updateStudyDescription)
export(updateStudyEndDate)
export(updateStudyStatus)
export(updateStudyTitle)
export(updateStudyVersion)
export(updateTherapeuticArea)
export(zipResults)
import(fs)
import(rlang)
Expand Down
12 changes: 12 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
Ulysses 0.0.4
=============
* Finalize Directory
* Finalize meta fields for _study.yml
* Reconfigure `newOhdsiStudy()` with better meta inputs
* Add functions to interface with _study.yml
* Reroute makeFiles to directory and meta fields
* Add `makeMigrationsScript()` template
* Update study hub website format
* Update vignette


Ulysses 0.0.3
=============

Expand Down
144 changes: 143 additions & 1 deletion R/config.R
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ checkConfig <- function() {
bullet = "warning", bullet_col = "yellow")

txt <- glue::glue(
"`Ulysses::makeConfig(block = '[block_name]', database = '[database_name]')` "
"`Ulysses::initConfig()` "
)
cli::cat_line("To create config.yml edit and run function:\n\n ", crayon::red(txt), "\n")
cli::cat_line()
Expand All @@ -40,6 +40,148 @@ checkConfig <- function() {

}

#TODO keep this list up to date
knownDataSourceTable <- function() {

dt <- tibble::tibble(
databaseName = c("Optum Clinformatics", "Optum Market Clarity", "Merative MarketScan",
"German DA", "CPRD Gold", "CPRD Aurum", "THIN Belgium", "JMDC", "MDV"),
blockId = c("optumClaims", "optumEHR", "mktscan", "da", "gold", "aurum", "thin", "jmdc", "mdv")
)
return(dt)
}



config_block_text <- function(block, database, title, dbms, user,
password, connectionString, cdmDatabaseSchema, resultsDatabaseSchema,
workDatabaseSchema, tempEmulationSchema, cohortTable) {

txt <- glue::glue(
"\n\n# {title} Credentials\n
{block}:
databaseName: {database}
dbms: {dbms}
user: {user}
password: {password}
connectionString: {connectionString}
cdmDatabaseSchema: {cdmDatabaseSchema}
resultsDatabaseSchema: {resultsDatabaseSchema}
vocabDatabaseSchema: {cdmDatabaseSchema}
workDatabaseSchema: {workDatabaseSchema}
tempEmulationSchema: {tempEmulationSchema}
cohortTable: {cohortTable}
\n\n")
return(txt)
}
#' Function to import credentials in stored csv to study config.yml
#' @param credFile a credential.csv file stored in a secure location
#' @param projectPath the path to the project
#' @param open toggle on whether the file should be opened
#' @export
importCredentialsToConfig <- function(credFile, projectPath = here::here(), open = TRUE) {

# import credentials
creds <- readr::read_csv(file = credFile, show_col_types = FALSE)

# check _study.yml for loaded databases
studyMeta <- retrieveStudySettings(projectPath)$study
dataSources <- studyMeta$about$`data-sources`

# subset creds with loaded Data Sources
dt <- creds %>%
dplyr::filter(
db_title %in% dataSources
)
# make cred text for config file
config_txt <- purrr::pmap_chr(
dt,
~config_block_text(
block = ..1,
database = ..2,
title = ..3,
dbms = ..4,
user = ..9,
password = ..10,
connectionString = ..5,
cdmDatabaseSchema = ..6,
resultsDatabaseSchema = ..8,
workDatabaseSchema = ..7,
tempEmulationSchema = ..7,
cohortTable = paste0("cohort_", ..1)
)
)

header <- glue::glue(" # Config File for {studyMeta$title}\n
default:
projectName: {studyMeta$id}
")

full_txt <- c(header, config_txt)
readr::write_lines(full_txt, file = fs::path(projectPath, "config.yml"))

cli::cat_bullet("Initializing config.yml using imported credentials",
bullet = "tick", bullet_col = "green")


if (open) {

cli::cat_bullet("Check config.yml",
bullet = "bullet", bullet_col = "red")

rstudioapi::navigateToFile(file = fs::path(projectPath, "config.yml"))
}

invisible(full_txt)

}


#' Function to create a config.yml file
#' @param block the name of the config block, defaults to BlockName
#' @param database the name of the database for the block, default to DatabaseName
#' @param withKeyring should the config file use keyring, default FALSE
#' @param projectPath the path to the project
#' @param open toggle on whether the file should be opened
#' @export
initConfig <- function(block = "BlockName",
database = "DatabaseName",
withKeyring = FALSE,
projectPath = here::here(),
open = TRUE) {

# retrieve study meta
studyMeta <- retrieveStudySettings(projectPath = projectPath)$study


data <- rlang::list2(
'Title' = studyMeta$title,
'ID' = studyMeta$id,
'Cohort' = paste(studyMeta$id, database, sep = "_"),
'Block' = block,
'Database' = database
)

if (withKeyring) {
template_file <- "config_keyring.yml"
} else {
template_file <- "config_raw.yml"
}

usethis::use_template(
template = template_file,
save_as = fs::path("config.yml"),
data = data,
open = open,
package = "Ulysses")

usethis::use_git_ignore(ignores = "config.yml")

invisible(data)
}



#' Add a line to the config file
#' @param block the name of the config block
#' @param database the name of the database for the block, default to block name
Expand Down
Loading

0 comments on commit 72963e7

Please sign in to comment.