forked from OHDSI/Achilles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
docker-run
executable file
·80 lines (63 loc) · 2.83 KB
/
docker-run
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/usr/bin/Rscript
# Load Achilles and httr.
install.packages("ParallelLogger")
install.packages("DatabaseConnector")
library(ParallelLogger)
library(dplyr)
library(Achilles)
library(httr)
# Get passed environment variables.
env_var_names <- list("ACHILLES_SOURCE", "ACHILLES_DB_URI",
"ACHILLES_CDM_SCHEMA", "ACHILLES_VOCAB_SCHEMA",
"ACHILLES_RES_SCHEMA", "ACHILLES_OUTPUT_BASE",
"ACHILLES_CDM_VERSION")
env_vars <- Sys.getenv(env_var_names, unset=NA)
# Replace unset environement variables with defaults.
default_vars <- list("N/A", "postgresql://localhost/postgres",
"public", "public", "public", "./output", "5")
env_vars[is.na(env_vars)] <- default_vars[is.na(env_vars)]
# Create name to tag results and output path from ACHILLES_SOURCE and timestamp
current_datetime <- strftime(Sys.time(), format="%Y-%m-%dT%H.%M.%S")
output_path <- paste(env_vars$ACHILLES_OUTPUT_BASE, env_vars$ACHILLES_SOURCE,
current_datetime, sep="/")
dir.create(output_path, showWarnings=FALSE, recursive=TRUE, mode="0755")
# Parse DB URI into pieces.
db_conf <- parse_url(env_vars$ACHILLES_DB_URI)
# Some connection packages need the database on the server argument.
server <- paste(db_conf$hostname, db_conf$path, sep="/")
if (db_conf$scheme %in% c("sqlserver", "sql+server", "sql%20server")){
db_conf$scheme <- "sql server"
}
# Create connection details using DatabaseConnector utility.
connectionDetails <- createConnectionDetails(
dbms=db_conf$scheme, user=db_conf$username, password=db_conf$password,
server=server, port=db_conf$port
)
args <- commandArgs(trailingOnly = TRUE)
createIndices <- (db_conf$scheme != "redshift" && db_conf$scheme != "netezza")
if (length(args) == 0 || args[1] != "heel") {
# Run Achilles report and generate data in the results schema.
achillesResults <- achilles(
connectionDetails, cdmDatabaseSchema=env_vars$ACHILLES_CDM_SCHEMA,
resultsDatabaseSchema=env_vars$ACHILLES_RES_SCHEMA,
vocabDatabaseSchema=env_vars$ACHILLES_VOCAB_SCHEMA,
sourceName=env_vars$ACHILLES_SOURCE,
cdmVersion=env_vars$ACHILLES_CDM_VERSION,
createIndices=createIndices
)
} else {
# Run Achilles Heel only
achillesHeel(
connectionDetails,
cdmDatabaseSchema=env_vars$ACHILLES_CDM_SCHEMA,
resultsDatabaseSchema=env_vars$ACHILLES_RES_SCHEMA,
vocabDatabaseSchema=env_vars$ACHILLES_VOCAB_SCHEMA,
cdmVersion=env_vars$ACHILLES_CDM_VERSION)
}
# Export Achilles results to output path in JSON format.
exportToJson(
connectionDetails, cdmDatabaseSchema=env_vars$ACHILLES_CDM_SCHEMA,
resultsDatabaseSchema=env_vars$ACHILLES_RES_SCHEMA,
vocabDatabaseSchema=env_vars$ACHILLES_VOCAB_SCHEMA,
outputPath=output_path, cdmVersion=env_vars$ACHILLES_CDM_VERSION
)