Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Catalog attempt with docker compose networking example #342

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
7 changes: 5 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ Authors@R:
c(person("Kyle", "Zollo-Venecek", , "[email protected]", role = c("aut", "cre"),
comment = c(ORCID = "0000-0002-1615-590X")),
person("Robert", "Miller", , "[email protected]", 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", , "[email protected]", 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)
Expand All @@ -23,6 +25,7 @@ Imports:
DatabaseConnector,
dplyr,
magrittr,
plumber,
plyr,
rjson,
rpostgis,
Expand Down
2 changes: 2 additions & 0 deletions inst/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.DS_Store
data/
83 changes: 83 additions & 0 deletions inst/repository/R/Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
21 changes: 21 additions & 0 deletions inst/repository/R/R/gaia.R
Original file line number Diff line number Diff line change
@@ -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')
14 changes: 14 additions & 0 deletions inst/repository/R/R/plumber.R
Original file line number Diff line number Diff line change
@@ -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)
}
Binary file added inst/repository/R/dbJars/postgresql-42.2.18.jar
Binary file not shown.
45 changes: 45 additions & 0 deletions inst/repository/R/example.R
Original file line number Diff line number Diff line change
@@ -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))
26 changes: 22 additions & 4 deletions inst/repository/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -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
name: ohdsi-solr-index

networks:
gaiadb:
name: gaiadb_default
external: true