Commit db60fa60 authored by Petar Horki's avatar Petar Horki

Initial Bitbucket Commit

parents
^data-raw$
^.*\.Rproj$
^\.Rproj\.user$
.Rproj.user
.Rhistory
.RData
.Ruserdata
data-raw
tests/testthat/setup.R
tests/testthat/teardown.R
\ No newline at end of file
Package: omopRds
Type: Package
Title: Transfer Of Data Models From OMOP To DataShield / Opal
Version: 0.1.0
Authors@R: person("Petar", "Horki", email = "phorki@gmail.com",
role = c("aut", "cre"))
Description: The omopRds implements methods facilitating the transfer of data
models from OMOP to DataSHIELD. The OMOP data is accessed through the
OHDSI DatabaseConnector using the SQLRender library and a simple template.
The data is then converted to the JSON format as required by the
DataSHIELD / Opal REST web service. The opalr library is used for
interfacing with the DataSHIELD / Opal server.
Imports:
devtools,
DatabaseConnector,
SqlRender,
jsonlite,
tidyverse,
opalr (>= 1.0.1)
Suggests:
ggvis,
knitr,
rmarkdown,
config,
testthat
Depends: R (>= 3.5.0)
License: LGPL-2.1
NeedsCompilation: no
LazyData: true
VignetteBuilder: knitr
RoxygenNote: 6.1.1
exportPattern("^[[:alpha:]]+")
# omopRds
# .R
#==============================================================================
#' RenderSQLTemplate
#'
#' @description
#' Render SQL template
#'
#' @details
#' Source: https://ohdsi.github.io/SqlRender/articles/UsingSqlRender.html
#'
#' @param sqlTemplateIn The SQL template.
#' @param databaseSchemaIn The database schema.
#' @param databaseTableIn The database table.
#' @param columnsIn The database columns.
#' @param limitIn Limit the number of records returned based on the limitIn value.
#'
#' @export
RenderSQLTemplate <- function(sqlTemplateIn, databaseSchemaIn, tableIn, columnsIn = '*', limitIn = 0) {
# check if the package is available
if (!requireNamespace("SqlRender", quietly = TRUE)) {
stop("Package \"SqlRender\" needed for this function to work. Please install it.",
call. = FALSE)
}
renderedSQL <- SqlRender::render(sqlTemplateIn,
databaseSchema = databaseSchemaIn,
table = tableIn,
columns = columnsIn,
limit = limitIn)
return(renderedSQL)
}
#==============================================================================
#' OpenOmopConnection
#'
#' @description
#' Open an SQL connection
#'
#' @details
#' The SQL connection relies on the OHDSI Database Connector.\cr
#' (https://github.com/OHDSI/DatabaseConnector)\cr
#' For details about arguments see:\cr
#' ?DatabaseConnector::createConnectionDetails()
#'
#' @param dbmsIn The database type.
#' @param serverIn The database server URL.
#' @param userIn The database user.
#' @param passwordIn The database password.
#' @param schemaIn The database schema.
#' @param portIn The database port.
#'
#' @export
OpenOmopConnection <- function(dbmsIn, serverIn, userIn, passwordIn, schemaIn, portIn = 5432) {
# check if the package is available
if (!requireNamespace("DatabaseConnector", quietly = TRUE)) {
stop("Package \"DatabaseConnector\" needed for this function to work. Please install it.",
call. = FALSE)
}
# SQL connection details
myConnectionDetails <- DatabaseConnector::createConnectionDetails(dbms = dbmsIn,
server = serverIn,
user = userIn,
port = portIn,
password = passwordIn,
schema = schemaIn)
# open database connection
myOmopConn <- DatabaseConnector::connect(myConnectionDetails)
return(myOmopConn)
}
#==============================================================================
#' CloseOmopConnection
#'
#' @description
#' Close an SQL connection
#'
#' @details
#' The SQL connection relies on the OHDSI Database Connector.\cr
#' (https://github.com/OHDSI/DatabaseConnector)
#'
#' @param omopConnIn The database connection.
#'
#' @export
CloseOmopConnection <- function(omopConnIn) {
# check if the package is available
if (!requireNamespace("DatabaseConnector", quietly = TRUE)) {
stop("Package \"DatabaseConnector\" needed for this function to work. Please install it.",
call. = FALSE)
}
# close database connection
myReturnValue <- DatabaseConnector::disconnect(omopConnIn)
return(myReturnValue)
}
#==============================================================================
#' ExecuteSQL
#'
#' @description
#' Execute an SQL query
#'
#' @details
#' The SQL connection and query execution rely on the OHDSI Database Connector.\cr
#' (https://github.com/OHDSI/DatabaseConnector)
#'
#' @param omopConnIn The database connection.
#' @param sql The SQL query.
#'
#' @export
ExecuteSQL <- function(omopConnIn, sql) {
# check if the package is available
if (!requireNamespace("DatabaseConnector", quietly = TRUE)) {
stop("Package \"DatabaseConnector\" needed for this function to work. Please install it.",
call. = FALSE)
}
queryResults <- DatabaseConnector::querySql(omopConnIn, sql)
return(queryResults)
}
# omopRds
# .R
#==============================================================================
#' OpenOpalConnection
#'
#' @description
#' Open a connection to Opal server\cr
#' Builds upon the opalr package:\cr
#' https://CRAN.R-project.org/package=opalr
#'
#' @details
#' Open a connection to an Opal server as specified with the given parameters.
#'
#' @param userNameIn Opal username
#' @param passwordIn Opal password
#' @param baseURLIn Opal base URL
#' @export
OpenOpalConnection <- function(userNameIn, passwordIn, baseURLIn) {
# check if the package is available
if (!requireNamespace("opalr", quietly = TRUE)) {
stop("Package \"opalr\" needed for this function to work. Please install it.",
call. = FALSE)
}
myOpalConn <- opalr::opal.login(username = userNameIn,
password = passwordIn,
url = baseURLIn)
return(myOpalConn)
}
#==============================================================================
#' CloseOpalConnection
#'
#' @description
#' Close a connection to Opal server\cr
#' Builds upon the opalr package:\cr
#' https://CRAN.R-project.org/package=opalr
#'
#' @details
#' Close a connection to an Opal server as specified with the given parameters.
#'
#' @param opalConnIn Opal username
#' @export
CloseOpalConnection <- function(opalConnIn) {
# check if the package is available
if (!requireNamespace("opalr", quietly = TRUE)) {
stop("Package \"opalr\" needed for this function to work. Please install it.",
call. = FALSE)
}
returnValue <- opalr::opal.logout(opalConnIn)
return(returnValue)
}
#==============================================================================
#' UploadOpalFile
#'
#' @description
#' Upload a file to Opal server\cr
#' Builds upon the opalr package:\cr
#' https://CRAN.R-project.org/package=opalr
#'
#' @details
#' Upload a local file to a folder in Opal file system
#'
#' @param opalConnIn Opal server connection
#' @param localFilePathIn Local filepath
#' @param remoteDirIn Remote directory path
#' @export
UploadOpalFile <- function(opalConnIn, localFilePathIn, remoteDirIn) {
# check if the package is available
if (!requireNamespace("opalr", quietly = TRUE)) {
stop("Package \"opalr\" needed for this function to work. Please install it.",
call. = FALSE)
}
returnValue <- opalr::opal.file_upload(opalConnIn, source = localFilePathIn, destination = remoteDirIn)
return(returnValue)
}
#==============================================================================
#' CreateOpalTable
#'
#' @description
#' Create Opal table\cr
#' Builds upon the opalr package:\cr
#' https://CRAN.R-project.org/package=opalr
#'
#' @details
#' Create an Opal table from the given parameters.
#'
#' @param opalConnIn Opal server connection
#' @param projectNameIn Project name
#' @param tableSchemaIn Table schema
#' @param contentTypeIn Content-type header(default content-type is JSON)
#' @export
CreateOpalTable <- function(opalConnIn, projectNameIn, tableSchemaIn, contentTypeIn='application/json') {
# check if the package is available
if (!requireNamespace("opalr", quietly = TRUE)) {
stop("Package \"opalr\" needed for this function to work. Please install it.",
call. = FALSE)
}
returnValue <- opalr::opal.post(opalConnIn,
'datasource', projectNameIn,
'tables', body = paste0(tableSchemaIn),
contentType = contentTypeIn)
return(returnValue)
}
#==============================================================================
#' CreateOpalVariable
#'
#' @description
#' Create Opal variable\cr
#' Builds upon the opalr package:\cr
#' https://CRAN.R-project.org/package=opalr
#'
#' @details
#' Create Opal variable from the given parameters.
#'
#' @param opalConnIn Opal server connection
#' @param projectNameIn Project name
#' @param tableNameIn Table name
#' @param variableSchemaIn Variable schema
#' @param contentTypeIn Content-type header(default content-type is JSON)
#' @export
CreateOpalVariable <- function(opalConnIn, projectNameIn, tableNameIn, variableSchemaIn, contentTypeIn='application/json') {
# check if the package is available
if (!requireNamespace("opalr", quietly = TRUE)) {
stop("Package \"opalr\" needed for this function to work. Please install it.",
call. = FALSE)
}
returnValue <- opalr::opal.post(opalConnIn,
'datasource', projectNameIn,
'table', tableNameIn,
'variables', body= paste0(variableSchemaIn),
contentType = contentTypeIn)
return(returnValue)
}
#==============================================================================
#' OpalClientCSVImportCmd
#'
#' @description
#' Generate a command for the Opal command line scripting tool:\cr
#' http://opaldoc.obiba.org/en/latest/python-user-guide/import/import-csv.html
#'
#' @details
#' Import a CSV file, to be found in Opal file system\cr
#' Example:\cr
#' Input: parameters for the opal client\cr
#' baseURLIn = 'https://<SERVER_IP>'\cr
#' userNameIn = '<USER>'\cr
#' passwordIn = '<PASSWORD>'\cr
#' remoteFilePath = '/home/<USER>/Data.csv'\cr
#' destinationIn = 'TestProject'\cr
#' tableIn = 'TestTable'\cr
#' typeIn = 'Participant'\cr
#' Output:\cr
#' /usr/bin/opal import-csv\cr
#' --opal https://<SERVER_IP>\cr
#' --user <USER> --password <PASSWORD> --verbose\cr
#' --path /home/<USER>/Data.csv\cr
#' --destination TestProject\cr
#' --table TestTable\cr
#' --type Participant
#'
#' @param baseURLIn Opal server base URL
#' @param userNameIn User name
#' @param passwordIn Password
#' @param remoteFilePath Remote filepath
#' @param destinationIn Destination datasource name
#' @param tableIn Table(s) to be imported
#' @param typeIn Entity type of the data (e.g. Participant)
#' @export
OpalClientCSVImportCmd <- function(baseURLIn, userNameIn, passwordIn, remoteFilePath, destinationIn, tableIn, typeIn) {
myCmd = paste('/usr/bin/opal import-csv',
'--opal', baseURLIn,
'--user', userNameIn,
'--password', passwordIn,
'--verbose',
'--path', remoteFilePath,
'--destination', destinationIn,
'--table', tableIn,
'--type', typeIn
)
return(myCmd)
}
This diff is collapsed.
#' A small sample of CMS SynPUF data in CDM Version 5.
#'
#' A synthetic dataset containing the gender, ethnicity, and birthdate
#' related attributes of n = 10 persons.
#'
#' @format A data frame with 10 rows and 5 variables:
#' \describe{
#' \item{GENDER_CONCEPT_ID}{The gender of the person.}
#' \item{YEAR_OF_BIRTH}{The year of birth of the person.}
#' \item{MONTH_OF_BIRTH}{The month of birth of the person.}
#' \item{DAY_OF_BIRTH}{The day of birth of the person.}
#' \item{ETHNICITY_CONCEPT_ID}{}
#' }
#' @source \url{http://www.ltscomputingllc.com/downloads/}
"queryResults"
File added
default:
omop:
dbms: 'postgresql'
server: '<SERVER_IP>/<DATABASE>'
user: '<USER>'
port: 5432
password: '<PASSWORD>'
schema: '<SCHEMA>'
opal:
baseURL: 'https://<HOSTNAME>'
userName: 'administrator'
password: '<PASSWORD>'
projectName: 'TestProject'
tableName: 'TestTable'
remoteDir: '/home/administrator/'
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/functions.R
\name{AddAttributes}
\alias{AddAttributes}
\title{AddAttributes}
\usage{
AddAttributes(attributesIn, attributeIn)
}
\arguments{
\item{attributesIn}{Set of attributes to add to.}
\item{attributeIn}{The attribute to add.}
}
\description{
Adds two sets of attributes
}
\details{
Add attribute(s) from attributeIn to attributes from attributesIn
}
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/functions.R
\name{AddVariables}
\alias{AddVariables}
\title{AddVariables}
\usage{
AddVariables(variablesIn, variableIn)
}
\arguments{
\item{variablesIn}{Set of variables to add to.\cr}
\item{variableIn}{The variable to add.}
}
\description{
Adds two sets of variables.
}
\details{
Add variable(s) from variableIn to Variables from variablesIn.
}
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/functions.R
\name{Attribute}
\alias{Attribute}
\title{Attribute}
\usage{
Attribute(valueIn, nameIn, localeIn = "en")
}
\arguments{
\item{valueIn}{The attribute value.}
\item{nameIn}{The attribute name.}
\item{localeIn}{The attribute locale.}
}
\description{
Create an attribute structure, supporting the creation of Opal attributes
}
\details{
Create an attribute with value, name, and locale fields.
}
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/functions.R
\name{AttributeDict}
\alias{AttributeDict}
\title{AttributeDict}
\usage{
AttributeDict()
}
\description{
Construct attributeDict
}
\details{
Construct a dictionary of attributes.
}
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/functions.R
\name{Category}
\alias{Category}
\title{Category}
\usage{
Category(attributesIn, nameIn, isMissingIn = FALSE)
}
\arguments{
\item{nameIn}{The attribute name.}
\item{valueIn}{The attribute value.}
\item{localeIn}{The attribute locale.}
}
\description{
Create a Category structure, supporting the creation of Opal Categories
}
\details{
Create a Category with attributes, isMissing, and name fields.
}
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/functions.R
\name{CategoryDict}
\alias{CategoryDict}
\title{CategoryDict}
\usage{
CategoryDict()
}
\description{
Construct CategoryDict
}
\details{
Construct a dictionary of categories.
}
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/functions.R
\name{CloseOmopConnection}
\alias{CloseOmopConnection}
\title{CloseOmopConnection}
\usage{
CloseOmopConnection(omopConnIn)
}
\arguments{
\item{omopConnIn}{The database connection.}
}
\description{
Close an SQL connection
}
\details{
The SQL connection relies on the OHDSI Database Connector.\cr
(https://github.com/OHDSI/DatabaseConnector)
}
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/functions.R
\name{CloseOpalConnection}
\alias{CloseOpalConnection}
\title{CloseOpalConnection}
\usage{
CloseOpalConnection(opalConnIn)
}
\arguments{
\item{opalConnIn}{Opal username}
}
\description{
Close a connection to Opal server\cr
Builds upon the opalr package:\cr
https://CRAN.R-project.org/package=opalr
}
\details{
Close a connection to an Opal server as specified with the given parameters.
}
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/functions.R
\name{CreateOpalTable}
\alias{CreateOpalTable}
\title{CreateOpalTable}
\usage{
CreateOpalTable(opalConnIn, projectNameIn, tableSchemaIn,
contentTypeIn = "application/json")
}
\arguments{
\item{opalConnIn}{Opal server connection}
\item{projectNameIn}{Project name}
\item{tableSchemaIn}{Table schema}
\item{contentTypeIn}{Content-type header(default content-type is JSON)}
}
\description{
Create Opal table\cr
Builds upon the opalr package:\cr
https://CRAN.R-project.org/package=opalr
}
\details{
Create an Opal table from the given parameters.
}
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/functions.R
\name{CreateOpalVariable}
\alias{CreateOpalVariable}
\title{CreateOpalVariable}
\usage{
CreateOpalVariable(opalConnIn, projectNameIn, tableNameIn,
variableSchemaIn, contentTypeIn = "application/json")
}
\arguments{
\item{opalConnIn}{Opal server connection}
\item{projectNameIn}{Project name}
\item{tableNameIn}{Table name}
\item{variableSchemaIn}{Variable schema}
\item{contentTypeIn}{Content-type header(default content-type is JSON)}
}
\description{
Create Opal variable\cr
Builds upon the opalr package:\cr
https://CRAN.R-project.org/package=opalr
}
\details{
Create Opal variable from the given parameters.
}
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/functions.R
\name{ExecuteSQL}
\alias{ExecuteSQL}
\title{ExecuteSQL}
\usage{
ExecuteSQL(omopConnIn, sql)
}
\arguments{
\item{omopConnIn}{The database connection.}
\item{sql}{The SQL query.}
}
\description{
Execute an SQL query
}
\details{
The SQL connection and query execution rely on the OHDSI Database Connector.\cr
(https://github.com/OHDSI/DatabaseConnector)
}
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/functions.R
\name{FilterCategoryDict}
\alias{FilterCategoryDict}
\title{FilterCategoryDict}
\usage{
FilterCategoryDict(categoryDictIn, domainIn)
}
\arguments{
\item{categoryDictIn}{The category dictionary.}
\item{domainIn}{The domain(s).}
}
\description{
Filter the given categoryDict so that it contains only entries for the given domains.
}
\details{
Assumptions: categoryDictIn has fields domain, attributes, isMissing, and name.
}
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/functions.R
\name{GetAttribute}
\alias{GetAttribute}
\title{GetAttribute}
\usage{
GetAttribute(attributeDictIn, domainIn)
}
\arguments{
\item{attributeDictIn}{The attribute dictionary.}
\item{domainIn}{The domain(s).}
}
\description{
Given the domain(s), get attribute(s) from the provided attributeDict
}
\details{
Assumption: attributeDictIn has fields domain, locale, name, and value.
}
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/functions.R
\name{GetCategories}
\alias{GetCategories}
\title{GetCategories}
\usage{
GetCategories(categoryDictIn, domainIn)
}
\arguments{
\item{categoryDictIn}{The category dictionary.}
\item{domainIn}{The domain(s).}
}
\description{
Extract the category associated with the given domain(s) from the given categoryDict.
}
\details{
Assumptions: categoryDictIn has fields domain, attributes, isMissing, and name.
}
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/functions.R
\name{GetValueTypes}
\alias{GetValueTypes}
\title{GetValueTypes}
\usage{
GetValueTypes(valueTypeDictIn, domainIn)
}
\arguments{
\item{valueTypeDictIn}{The value type dictionary.}
\item{domainIn}{The domain(s).}
}
\description{
Extract the value types associated with the given domain(s) from the given valueTypeDict
}
\details{
Assumptions: valueTypeDictIn has fields domain and valueType
}
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/functions.R
\name{GetVariables}
\alias{GetVariables}
\title{GetVariables}