-
Notifications
You must be signed in to change notification settings - Fork 72
/
createPrunedTables.r
46 lines (40 loc) · 1.77 KB
/
createPrunedTables.r
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
#' @title Create pruned CDM and Vocab tables.
#'
#' @description This function creates the pruned cdm and vocab tables by keeping only those rows from
#' the original tables for given concept_ids. (Eunomia support)
#'
#' @param connectionDetails An R object of type\cr\code{connectionDetails} created using the
#' function \code{createConnectionDetails} in the
#' \code{DatabaseConnector} package.
#'
#' @param cdmSchema The name of the database schema that contains the CDM.
#' Requires read and write permissions to this database. On SQL
#' Server, this should specify both the database and the schema,
#' so for example 'cdm_instance.dbo'.
#' @param eventConceptId A vector of concept_ids returned from \code{getEventConceptId}.
#' @param cdmVersion The version of your CDM. Currently "5.3.1" and "5.4.0".
#'
#'@export
createPrunedTables <-
function(connectionDetails,
cdmSchema,
eventConceptId,
cdmVersion)
{
if (cdmVersion == "5.3.1")
sqlFilePath <- "cdm_version/v531"
else if (cdmVersion == "5.4.0")
sqlFilePath <- "cdm_version/v540"
else
stop("Unsupported CDM specified. Supported CDM versions are \"5.3.1\" and \"5.4.0\"")
sql <- SqlRender::loadRenderTranslateSql(
sqlFileName = paste0(sqlFilePath, "/create_pruned_tables.sql"),
packageName = "ETLSyntheaBuilder",
dbms = connectionDetails$dbms,
cdm_schema = cdmSchema,
event_concept_id = eventConceptId
)
conn <- DatabaseConnector::connect(connectionDetails)
DatabaseConnector::executeSql(conn, sql)
on.exit(DatabaseConnector::disconnect(conn))
}