diff --git a/DESCRIPTION b/DESCRIPTION index f1549dd8..04faf129 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -5,8 +5,10 @@ Authors@R: c(person("Kyle", "Zollo-Venecek", , "kzollovenecek@tuftsmedicalcenter.org", role = c("aut", "cre"), comment = c(ORCID = "0000-0002-1615-590X")), person("Robert", "Miller", , "rmiller@minderoo.org", role = c("aut"), - comment = c(ORCID = "0000-0002-1787-2855"))) -Description: What the package does (one paragraph). + comment = c(ORCID = "0000-0002-1787-2855")), + person("Timothy", "Norris", , "tibben@ocf.berkeley.edu", role = c("aut"), + comment = c(ORCID = "0000-0002-0898-3027"))) +Description: GIS integration into the OHDSI assemblage of tools for EHR analysis. License: Apache License (>= 2) Encoding: UTF-8 Roxygen: list(markdown = TRUE) @@ -23,6 +25,7 @@ Imports: DatabaseConnector, dplyr, magrittr, + plumber, plyr, rjson, rpostgis, diff --git a/inst/.gitignore b/inst/.gitignore new file mode 100644 index 00000000..5c774c53 --- /dev/null +++ b/inst/.gitignore @@ -0,0 +1,2 @@ +.DS_Store +data/ \ No newline at end of file diff --git a/inst/repository/R/Dockerfile b/inst/repository/R/Dockerfile new file mode 100644 index 00000000..a0995cb0 --- /dev/null +++ b/inst/repository/R/Dockerfile @@ -0,0 +1,83 @@ +FROM ubuntu:latest + +# get necessary system utilties +RUN apt-get update && \ + apt-get install -y \ + software-properties-common \ + default-jre \ + default-jdk + +# add needed repository for GIS tools +RUN add-apt-repository ppa:ubuntugis/ppa +RUN apt update && apt upgrade -y + +# get libraries for GIS tools +ENV DEBIAN_FRONTEND noninteractive +RUN apt-get install -y \ + libgdal-dev gdal-bin \ + libproj22 \ + libproj-dev \ + libfontconfig1-dev \ + libharfbuzz-dev \ + libfribidi-dev \ + libudunits2-dev \ + libsodium-dev \ + r-base + +# install all known dependencies for gaiaCore +RUN R -e "install.packages(c( \ + 'devtools', \ + 'bit', \ + 'bit64', \ + 'blob', \ + 'checkmate', \ + 'class', \ + 'classInt', \ + 'DatabaseConnector', \ + 'DBI', \ + 'dbplyr', \ + 'dplyr', \ + 'e1071', \ + 'generics', \ + 'hms', \ + 'KernSmooth', \ + 'lattice', \ + 'MASS', \ + 'plyr', \ + 'plumber', \ + 'progress', \ + 'proxy', \ + 'raster', \ + 'readr', \ + 'rgeos', \ + 'rJava', \ + 'rjson', \ + 'rpostgis', \ + 'RPostgreSQL', \ + 'sf', \ + 'sp', \ + 'SqlRender', \ + 'terra', \ + 'tidyr', \ + 'tidyselect', \ + 'triebeard', \ + 'tzdb', \ + 'units', \ + 'urltools', \ + 'usethis', \ + 'vroom' \ + ))" + +# install gaiaCore +RUN R -e "library('devtools'); devtools::install_github('OHDSI/GIS')" + +# copy DatabaseConnector jar file for postgres +RUN mkdir /ohdsi-gis && mkdir /ohdsi-gis/dbJars +COPY ./dbJars /ohdsi-gis/dbJars +ENV DATABASECONNECTOR_JAR_FOLDER /ohdsi-gis/dbJars + +# copy api app for gaiaCore +COPY ./R /ohdsi-gis +WORKDIR /ohdsi-gis + +CMD ["sh", "-c", "Rscript gaia.R"] \ No newline at end of file diff --git a/inst/repository/R/R/gaia.R b/inst/repository/R/R/gaia.R new file mode 100644 index 00000000..c567dff2 --- /dev/null +++ b/inst/repository/R/R/gaia.R @@ -0,0 +1,21 @@ +# plumber.R + +library(gaiaCore) +library(DatabaseConnector) +library(plumber) + +# set database connection +# from R docker container to gaiaDB docker container - network gaiadb_default +connectionDetails <- DatabaseConnector::createConnectionDetails( + dbms = "postgresql", + server = "gis_postgis/gaiaDB", + port = 5432, + user="postgres", + password = "mysecretpassword") + +# initialize DB connection +gaiaCore::initializeDatabase(connectionDetails) + +# configure and run endpoint +root <- pr("plumber.R") +root %>% pr_run(port=8000,host='0.0.0.0') \ No newline at end of file diff --git a/inst/repository/R/R/plumber.R b/inst/repository/R/R/plumber.R new file mode 100644 index 00000000..6445e362 --- /dev/null +++ b/inst/repository/R/R/plumber.R @@ -0,0 +1,14 @@ +#* Load the variable from the variable_source +#* @param variable_id The variable to load +#* @get /load +function(variable_id=-1){ + if (variable_id > 0) { + res <- capture.output( + gaiaCore::loadVariable(connectionDetails,variable_id), + type='message' + ) + } else { + res <- 'You must pass a variable_id' + } + list(res) +} \ No newline at end of file diff --git a/inst/repository/R/dbJars/postgresql-42.2.18.jar b/inst/repository/R/dbJars/postgresql-42.2.18.jar new file mode 100644 index 00000000..7a851472 Binary files /dev/null and b/inst/repository/R/dbJars/postgresql-42.2.18.jar differ diff --git a/inst/repository/R/example.R b/inst/repository/R/example.R new file mode 100644 index 00000000..0b571299 --- /dev/null +++ b/inst/repository/R/example.R @@ -0,0 +1,45 @@ +# install.packages("devtools") +# install.packages("roxygen2") +library(devtools) +library(roxygen2) +library(DatabaseConnector) +setwd("d:/Sync/gitRepos/projects/ohdsi-gis/") +load_all(".") +# devtools::install_github("OHDSI/GIS") +library(gaiaCore) + +# must download driver first, see: https://ohdsi.github.io/DatabaseConnectorJars/ +Sys.setenv("DATABASECONNECTOR_JAR_FOLDER" = "d:/Sync/gitRepos/GIS/dbJars") + +# set database connection +connectionDetails <- DatabaseConnector::createConnectionDetails( + dbms = "postgresql", + server = "localhost/gaiaDB", + port = 5433, + user="postgres", + password = "mysecretpassword") + +# initialize DB connection +gaiaCore::initializeDatabase(connectionDetails) + +# create index tables +gaiaCore::createIndices(connectionDetails) + +conn <- DatabaseConnector::connect(connectionDetails) +on.exit(DatabaseConnector::disconnect(conn)) +backboneExists <- DatabaseConnector::querySql(conn, sql = "SELECT schema_name FROM information_schema.schemata WHERE schema_name = 'backbone';") +backboneExists + +gaiaCore::loadVariable(connectionDetails,33) + +dataSourceTable <- gaiaCore::getDataSourceTable(connectionDetails = connectionDetails) +print(names(dataSourceTable)) +uuids <- dataSourceTable$DATA_SOURCE_UUID +print(uuids) + +conn <- DatabaseConnector::connect(connectionDetails) +on.exit(DatabaseConnector::disconnect(conn)) +attrIndex <- DatabaseConnector::dbReadTable(conn, "backbone.attr_index", check.names = FALSE) +print(names(attrIndex)) +names(attrIndex) <- tolower(names(attrIndex)) +print(names(attrIndex)) diff --git a/inst/repository/docker-compose.yml b/inst/repository/docker-compose.yml index 76e23bdf..c2632637 100644 --- a/inst/repository/docker-compose.yml +++ b/inst/repository/docker-compose.yml @@ -1,21 +1,39 @@ version: "3.9" services: - ohdsi: - container_name: gis_repo + gaia_r: + container_name: gaia-r + build: ./R/ + image: gaia_r + ports: + - "8000:8000" + networks: + - gaiadb + gis_repo: + container_name: gis-repo build: ./searchApp/ - image: ohdsi_repo + image: gis_repo ports: - "5000:5000" + networks: + - gaiadb links: - "solr:index" + - "gaia_r:gaiaCore" solr: container_name: solr image: solr + networks: + - gaiadb volumes: - ./collections:/collections - solr-data:/var/solr volumes: solr-data: - name: ohdsi-solr-index \ No newline at end of file + name: ohdsi-solr-index + +networks: + gaiadb: + name: gaiadb_default + external: true