Skip to content

Commit

Permalink
Release v0.3.0
Browse files Browse the repository at this point in the history
Release v0.3.0
  • Loading branch information
anthonysena authored Jan 26, 2024
2 parents 92c64c2 + c95d0c1 commit 67cef19
Show file tree
Hide file tree
Showing 21 changed files with 4,252 additions and 1,115 deletions.
45 changes: 43 additions & 2 deletions .github/workflows/Test_module.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
Test-module:
runs-on: ${{ matrix.config.os }}

name: ${{ matrix.config.os }} (${{ matrix.config.r }})
name: unit-test-${{ matrix.config.os }} (${{ matrix.config.r }})

strategy:
fail-fast: false
Expand All @@ -22,7 +22,7 @@ jobs:
- {os: macOS-latest, r: '4.2.3', rtools: '42', rspm: "https://cloud.r-project.org"}
- {os: ubuntu-20.04, r: '4.2.3', rtools: '42', rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest"}
- {os: windows-latest, r: 'release', rtools: '', rspm: "https://cloud.r-project.org"}
- {os: macOS-latest, r: 'release', rtools: '', rspm: "https://cloud.r-project.org"}
#- {os: macOS-latest, r: 'release', rtools: '', rspm: "https://cloud.r-project.org"}
- {os: ubuntu-20.04, r: 'release', rtools: '', rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest"}

env:
Expand Down Expand Up @@ -64,7 +64,48 @@ jobs:
- uses: r-lib/actions/setup-renv@v2
with:
profile: '"dev"'
cache-version: 4

- name: Run module test script
run: Rscript tests/testScript.R

Test-default-module-restore:
needs: Test-module

name: module-restore-${{ matrix.config.os }} (${{ matrix.config.r }})

strategy:
fail-fast: false
matrix:
config:
- {os: windows-latest, r: '4.2.3', rtools: '42', rspm: "https://cloud.r-project.org"}
- {os: macOS-latest, r: '4.2.3', rtools: '42', rspm: "https://cloud.r-project.org"}
- {os: ubuntu-20.04, r: '4.2.3', rtools: '42', rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest"}
- {os: windows-latest, r: 'release', rtools: '', rspm: "https://cloud.r-project.org"}
#- {os: macOS-latest, r: 'release', rtools: '', rspm: "https://cloud.r-project.org"}
- {os: ubuntu-20.04, r: 'release', rtools: '', rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest"}

runs-on: ${{ matrix.config.os }}

steps:
- uses: actions/checkout@v3

- uses: r-lib/actions/setup-r@v2
with:
r-version: ${{ matrix.config.r }}
rtools-version: ${{ matrix.config.rtools }}

- name: Install system requirements
if: runner.os == 'Linux'
run: |
sudo apt-get install -y make
sudo apt-get install -y default-jdk
sudo apt-get install -y libcurl4-openssl-dev
sudo apt-get install -y libssl-dev
sudo apt-get install -y libglpk-dev
- uses: r-lib/actions/setup-renv@v2
with:
cache-version: 4

41 changes: 40 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,43 @@
.Rproj.user
# History files
.Rhistory
.Rapp.history

# Session Data files
.RData

# User-specific files
.Ruserdata

# Example code in package build process
*-Ex.R

# Output files from R CMD build
/*.tar.gz

# Output files from R CMD check
/*.Rcheck/

# RStudio files
.Rproj.user/

# produced vignettes
vignettes/*.html
vignettes/*.pdf

# OAuth2 token, see https://github.com/hadley/httr/releases/tag/v0.3
.httr-oauth

# knitr and R markdown default cache directories
*_cache/
/cache/

# Temporary files created by R markdown
*.utf8.md
*.knit.md

# R Environment Variables
.Renviron

# Project specific
/extras/test/output
/_targets/
2 changes: 2 additions & 0 deletions .renvignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/extras/
/tests/
136 changes: 72 additions & 64 deletions Main.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2023 Observational Health Data Sciences and Informatics
# Copyright 2024 Observational Health Data Sciences and Informatics
#
# This file is part of CohortGeneratorModule
#
Expand All @@ -14,6 +14,16 @@
# See the License for the specific language governing permissions and
# limitations under the License.

# Adding library references that are required for Strategus
library(CohortGenerator)
library(DatabaseConnector)
library(keyring)
library(ParallelLogger)
library(SqlRender)

# Adding RSQLite so that we can test modules with Eunomia
library(RSQLite)

# Module methods -------------------------
getModuleInfo <- function() {
checkmate::assert_file_exists("MetaData.json")
Expand All @@ -36,8 +46,10 @@ createCohortDefinitionSetFromJobContext <- function(sharedResources, settings) {
if (length(sharedResources) <= 0) {
stop("No shared resources found")
}
cohortDefinitionSharedResource <- getSharedResourceByClassName(sharedResources = sharedResources,
class = "CohortDefinitionSharedResources")
cohortDefinitionSharedResource <- getSharedResourceByClassName(
sharedResources = sharedResources,
class = "CohortDefinitionSharedResources"
)
if (is.null(cohortDefinitionSharedResource)) {
stop("Cohort definition shared resource not found!")
}
Expand All @@ -59,43 +71,39 @@ createCohortDefinitionSetFromJobContext <- function(sharedResources, settings) {
}

setCovariateSchemaTable <- function(
modelDesignList,
modelDesignList,
cohortDatabaseSchema,
cohortTable
){

if(inherits(modelDesignList, 'modelDesign')){
cohortTable) {
if (inherits(modelDesignList, "modelDesign")) {
modelDesignList <- list(modelDesignList)
}
for(i in 1:length(modelDesignList)){

for (i in 1:length(modelDesignList)) {
covariateSettings <- modelDesignList[[i]]$covariateSettings
if(inherits(covariateSettings, 'covariateSettings')){

if (inherits(covariateSettings, "covariateSettings")) {
covariateSettings <- list(covariateSettings)
}

for(j in 1:length(covariateSettings)){

if('cohortDatabaseSchema' %in% names(covariateSettings[[j]])){

for (j in 1:length(covariateSettings)) {
if ("cohortDatabaseSchema" %in% names(covariateSettings[[j]])) {
covariateSettings[[j]]$cohortDatabaseSchema <- cohortDatabaseSchema
}
if('cohortTable' %in% names(covariateSettings[[j]])){
if ("cohortTable" %in% names(covariateSettings[[j]])) {
covariateSettings[[j]]$cohortTable <- cohortTable
}

}

modelDesignList[[i]]$covariateSettings <- covariateSettings
}

return(modelDesignList)
}

# Module methods -------------------------
execute <- function(jobContext) {
rlang::inform("Validating inputs")
inherits(jobContext, 'list')
inherits(jobContext, "list")

if (is.null(jobContext$settings)) {
stop("Analysis settings not found in job context")
Expand All @@ -106,68 +114,66 @@ execute <- function(jobContext) {
if (is.null(jobContext$moduleExecutionSettings)) {
stop("Execution settings not found in job context")
}

workFolder <- jobContext$moduleExecutionSettings$workSubFolder
resultsFolder <- jobContext$moduleExecutionSettings$resultsSubFolder

rlang::inform("Executing PLP")
moduleInfo <- getModuleInfo()

# Creating database details
databaseDetails <- PatientLevelPrediction::createDatabaseDetails(
connectionDetails = jobContext$moduleExecutionSettings$connectionDetails,
connectionDetails = jobContext$moduleExecutionSettings$connectionDetails,
cdmDatabaseSchema = jobContext$moduleExecutionSettings$cdmDatabaseSchema,
cohortDatabaseSchema = jobContext$moduleExecutionSettings$workDatabaseSchema,
cdmDatabaseName = jobContext$moduleExecutionSettings$connectionDetailsReference,
cdmDatabaseId = jobContext$moduleExecutionSettings$databaseId,
#tempEmulationSchema = , is there s temp schema specified anywhere?
cohortTable = jobContext$moduleExecutionSettings$cohortTableNames$cohortTable,
outcomeDatabaseSchema = jobContext$moduleExecutionSettings$workDatabaseSchema,
# tempEmulationSchema = , is there s temp schema specified anywhere?
cohortTable = jobContext$moduleExecutionSettings$cohortTableNames$cohortTable,
outcomeDatabaseSchema = jobContext$moduleExecutionSettings$workDatabaseSchema,
outcomeTable = jobContext$moduleExecutionSettings$cohortTableNames$cohortTable
)

# find where cohortDefinitions are as sharedResources is a list
cohortDefinitionSet <- createCohortDefinitionSetFromJobContext(
sharedResources = jobContext$sharedResources,
settings = jobContext$settings
)
# set the covariate settings schema and tables
)

# set the covariate settings schema and tables
jobContext$settings <- setCovariateSchemaTable(
modelDesignList = jobContext$settings,
modelDesignList = jobContext$settings,
cohortDatabaseSchema = jobContext$moduleExecutionSettings$workDatabaseSchema,
cohortTable = jobContext$moduleExecutionSettings$cohortTableNames$cohortTable
)
)

# run the models
PatientLevelPrediction::runMultiplePlp(
databaseDetails = databaseDetails,
modelDesignList = jobContext$settings,
databaseDetails = databaseDetails,
modelDesignList = jobContext$settings,
cohortDefinitions = cohortDefinitionSet,
saveDirectory = workFolder
)
)

# Export the results
rlang::inform("Export data to csv files")

sqliteConnectionDetails <- DatabaseConnector::createConnectionDetails(
dbms = 'sqlite',
server = file.path(workFolder, "sqlite","databaseFile.sqlite")
dbms = "sqlite",
server = file.path(workFolder, "sqlite", "databaseFile.sqlite")
)

PatientLevelPrediction::extractDatabaseToCsv(
connectionDetails = sqliteConnectionDetails,
connectionDetails = sqliteConnectionDetails,
databaseSchemaSettings = PatientLevelPrediction::createDatabaseSchemaSettings(
resultSchema = 'main', # sqlite settings
tablePrefix = '', # sqlite settings
targetDialect = 'sqlite',
resultSchema = "main", # sqlite settings
tablePrefix = "", # sqlite settings
targetDialect = "sqlite",
tempEmulationSchema = NULL
),
),
csvFolder = file.path(resultsFolder),
fileAppend = NULL
)


}


Expand All @@ -178,38 +184,40 @@ uploadResultsCallback <- function(jobContext) {
schema <- jobContext$moduleExecutionSettings$resultsDatabaseSchema

resultsFolder <- jobContext$moduleExecutionSettings$resultsSubFolder

conn <- DatabaseConnector::connect(connectionDetails)
on.exit(DatabaseConnector::disconnect(conn))

databaseSchemaSettings <- PatientLevelPrediction::createDatabaseSchemaSettings(
resultSchema = schema,
tablePrefix = tablePrefix,
resultSchema = schema,
tablePrefix = tablePrefix,
targetDialect = connectionDetails$dbms
)
)

PatientLevelPrediction::insertCsvToDatabase(
csvFolder = resultsFolder,
conn = conn,
conn = conn,
databaseSchemaSettings = databaseSchemaSettings,
modelSaveLocation = file.path(resultsFolder, 'dbmodels'),
csvTableAppend = ''
modelSaveLocation = file.path(resultsFolder, "dbmodels"),
csvTableAppend = ""
)

}

createDataModelSchema <- function(jobContext) {
connectionDetails <- jobContext$moduleExecutionSettings$resultsConnectionDetails
moduleInfo <- ParallelLogger::loadSettingsFromJson("MetaData.json")
tablePrefix <- moduleInfo$TablePrefix
schema <- jobContext$moduleExecutionSettings$resultsDatabaseSchema


# Workaround for issue https://github.com/tidyverse/vroom/issues/519:
readr::local_edition(1)

PatientLevelPrediction::createPlpResultTables(
connectionDetails = connectionDetails,
targetDialect = connectionDetails$dbms,
resultSchema = schema,
connectionDetails = connectionDetails,
targetDialect = connectionDetails$dbms,
resultSchema = schema,
deleteTables = F,
createTables = T,
createTables = T,
tablePrefix = tablePrefix
)
}
2 changes: 1 addition & 1 deletion MetaData.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"Name": "PatientLevelPredictionModule",
"Version": "0.2.1",
"Version": "0.3.0",
"Dependencies": ["CohortGeneratorModule"],
"TablePrefix": "plp_"
}
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
PatientLevelPredictionModule 0.3.0
=======================
- Using renv project profiles to manage core packages required for module execution vs. those that are needed for development purposes.

PatientLevelPredictionModule 0.2.1
=======================

Expand Down
4 changes: 2 additions & 2 deletions SettingsFunctions.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# This file has been autogenerated in 'extras/ModuleMaintenance.R'. Do not change by hand.
# Copyright 2023 Observational Health Data Sciences and Informatics
# Copyright 2024 Observational Health Data Sciences and Informatics
#
# This file is part of CohortGeneratorModule
#
Expand All @@ -18,7 +18,7 @@
createPatientLevelPredictionModuleSpecifications <- function(modelDesignList) {
specifications <- list(
module = "PatientLevelPredictionModule",
version = "0.2.1",
version = "0.3.0",
remoteRepo = "github.com",
remoteUsername = "ohdsi",
settings = modelDesignList
Expand Down
Loading

0 comments on commit 67cef19

Please sign in to comment.