-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #363 from onc-healthit/rest_api
REST API
- Loading branch information
Showing
19 changed files
with
2,713 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
FROM rstudio/plumber | ||
|
||
ARG cert_dir | ||
ARG LANTERN_DBNAME | ||
ARG LANTERN_DBPORT | ||
ARG LANTERN_DBHOST | ||
ARG LANTERN_DBUSER | ||
ARG LANTERN_DBPASSWORD | ||
ARG LANTERN_DBSSLMODE | ||
|
||
COPY ${cert_dir}/ /usr/local/share/ca-certificates | ||
RUN update-ca-certificates | ||
|
||
# list all the needed packages here in the same fashion | ||
RUN R -e "install.packages('broom')" | ||
RUN R -e "install.packages('RPostgres')" | ||
RUN R -e "install.packages('dbplyr')" | ||
RUN R -e "install.packages('tidyverse')" | ||
RUN R -e "install.packages('here')" | ||
RUN R -e "install.packages('cachem')" | ||
|
||
RUN apt update -qq \ | ||
&& apt install --yes --no-install-recommends \ | ||
r-cran-rpostgresql libpq-dev | ||
|
||
WORKDIR /home/plumber | ||
|
||
ENV RENV_VERSION 0.13.2 | ||
RUN R -e "install.packages('remotes', repos = c(CRAN = 'https://cloud.r-project.org'))" | ||
RUN R -e "remotes::install_github('rstudio/renv@${RENV_VERSION}')" | ||
|
||
ADD /download/plumber.R /home/plumber/plumber.R | ||
ADD /download/restendpoints.R /home/plumber/download/restendpoints.R | ||
ADD /download/downloadsmodule.R /home/plumber/download/downloadsmodule.R | ||
ADD /common/db_connection.R /home/plumber/common/db_connection.R | ||
ADD /common/endpoints.R /home/plumber/common/endpoints.R | ||
ADD /common/http_codes.csv /home/plumber/download/http_codes.csv | ||
|
||
# Environment variables are passed to R via .Renviron file the container | ||
RUN env | grep LANTERN > /home/plumber/.Renviron | ||
|
||
# to launch your docker container | ||
CMD ["/home/plumber/plumber.R"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
# Capability Querier | ||
|
||
The capability querier is a service that queries endpoints for their capability statements, and sends those capability statements along with any additional relevant information to a queue. | ||
|
||
## Configuration | ||
The capability querier reads the following environment variables: | ||
|
||
**These variables can use the default values *in development*. These should be set on the production system.** | ||
|
||
* **LANTERN_QHOST**: The hostname where the queue is hosted. | ||
|
||
Default value: localhost | ||
|
||
* **LANTERN_QPORT**: The port where the queue is hosted. | ||
|
||
Default value: 5672 | ||
|
||
* **LANTERN_QUSER**: The user that the application will use to read and write from the queue. | ||
|
||
Default value: capabilityquerier | ||
|
||
* **LANTERN_QPASSWORD**: The password for accessing the database as user LANTERN_QUSER. | ||
|
||
Default value: capabilityquerier | ||
|
||
* **LANTERN_QUERY_NUMWORKERS**: The number of workers to use to parallelize processing of the capability statements and version responses. | ||
|
||
Default value: 10 | ||
|
||
* **LANTERN_DBHOST**: The hostname where the database is hosted. | ||
|
||
Default value: localhost | ||
|
||
* **LANTERN_DBPORT**: The port where the database is hosted. | ||
|
||
Default value: 5432 | ||
|
||
* **LANTERN_DBUSER**: The database user that the application will use to read and write from the database. | ||
|
||
Default value: lantern | ||
|
||
* **LANTERN_DBPASSWORD**: The password for accessing the database as user LANTERN_DBUSER. | ||
|
||
Default value: postgrespassword | ||
|
||
* **LANTERN_DBNAME**: The name of the database being accessed. | ||
|
||
Default value: lantern | ||
|
||
* **LANTERN_DBSSLMODE**: The level of SSL certificate verification that is performed. For a production system, this should be set to 'verify-full'. | ||
|
||
Default value: disable | ||
|
||
### Test Configuration | ||
|
||
When testing, the capability querier uses the following environment variables: | ||
|
||
* **LANTERN_TEST_QUSER** instead of LANTERN_QUSER: The user that the application will use to read and write from the queue. | ||
|
||
Default value: capabilityquerier | ||
|
||
* **LANTERN_TEST_QPASSWORD** instead of LANTERN_QPASSWORD: The password for accessing the database as user LANTERN_QUSER. | ||
|
||
Default value: capabilityquerier | ||
|
||
* **LANTERN_TEST_DBUSER** instead of LANTERN_DBUSER: The database user that the application will use to read and write from the database. | ||
|
||
Default value: lantern | ||
|
||
* **LANTERN_TEST_DBPASSWORD** instead of LANTERN_DBPASSWORD: The password for accessing the database as user LANTERN_TEST_DBUSER. | ||
|
||
Default value: postgrespassword | ||
|
||
* **LANTERN_TEST_DBNAME** instead of LANTERN_DBNAME: The name of the database being accessed. | ||
|
||
Default value: lantern_test | ||
|
||
## Building and Running | ||
|
||
The capability querier currently connects to the lantern message queue (RabbbitMQ). All log messages are written to stdout. | ||
|
||
### Using Docker-Compose | ||
|
||
The capability querier has been added to the application docker-compose file. See the [top-level README](../README.md) for how to run docker-compose. | ||
|
||
### Using the Individual Docker Container | ||
|
||
At this time, it's not recommended to start this as an individual container because of the dependence on the endpointlist file which is in another go project. This is challenging to manage for starting a single instance and not worth pursuing given that starting this container with all the other containers or running alone should be sufficient. | ||
|
||
### Running alone | ||
|
||
The instructions below assume that you are in `capabilityquerier/`. | ||
|
||
The capability querier has not yet been dockerized. To run, perform the following commands: | ||
|
||
```bash | ||
go get ./... # You may have to set environment variable GO111MODULE=on | ||
go mod download | ||
go run cmd/main.go | ||
``` | ||
|
||
## Scaling | ||
|
||
To scale out the capability querier service edit the docker-compose.yml and docker-compose.override.yml file to include additional capability querier services. | ||
``` | ||
capability_querier_2: | ||
... | ||
``` | ||
|
||
Each instance of the capability querier will query endpoints from the same endpoints-to-capability queue in a round robin style. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
# Database connection functions | ||
library(DBI) | ||
library(dplyr) | ||
library(tidyverse) | ||
library(here) | ||
library(memoise) | ||
library(readr) | ||
|
||
# Read database connection information from .Renviron file | ||
# If doing local development: you can readRenviron("../.env") | ||
# and set the db_config$host = "localhost" | ||
|
||
db_config <- list("dbname" = Sys.getenv("LANTERN_DBNAME"), | ||
"host" = Sys.getenv("LANTERN_DBHOST"), | ||
"port" = Sys.getenv("LANTERN_DBPORT"), | ||
"user" = Sys.getenv("LANTERN_DBUSER"), | ||
"password" = Sys.getenv("LANTERN_DBPASSWORD") | ||
) | ||
|
||
# db_config$host <- ifelse(Sys.getenv("HOME") == "/home/shiny", db_config$host, "localhost") | ||
|
||
# Connect to the Lantern database | ||
db_connection <- | ||
dbConnect( | ||
RPostgres::Postgres(), | ||
dbname = db_config$dbname, | ||
host = db_config$host, # i.e. 'ec2-54-83-201-96.compute-1.amazonaws.com' | ||
port = db_config$port, | ||
user = db_config$user, | ||
password = db_config$password | ||
) | ||
|
||
# Make connections to the various lantern tables | ||
db_tables <- list( | ||
fhir_endpoints = tbl(db_connection, "fhir_endpoints"), | ||
fhir_endpoints_info = tbl(db_connection, "fhir_endpoints_info"), | ||
fhir_endpoints_metadata = tbl(db_connection, "fhir_endpoints_metadata"), | ||
fhir_endpoints_info_history = tbl(db_connection, "fhir_endpoints_info_history"), | ||
end_org = tbl(db_connection, "endpoint_organization"), | ||
hit_prod = tbl(db_connection, "healthit_products"), | ||
npi_organizations = tbl(db_connection, "npi_organizations"), | ||
endpoint_export = tbl(db_connection, "endpoint_export"), | ||
organization_location = tbl(db_connection, "organization_location"), | ||
vendors = tbl(db_connection, "vendors") | ||
) | ||
|
||
valid_fhir_versions <- c("No Cap Stat", "0.4.0", "0.5.0", "1.0.0", "1.0.1", "1.0.2", "1.1.0", "1.2.0", "1.4.0", "1.6.0", "1.8.0", "3.0.0", "3.0.1", "3.0.2", "3.2.0", "3.3.0", "3.5.0", "3.5a.0", "4.0.0", "4.0.1") | ||
|
||
# Cache the result of load_http_codes_internal function | ||
#load_http_codes <- memoise(load_http_codes_internal()) | ||
|
||
# Function to retrieve HTTP codes | ||
http_response_code_tbl <- function() { | ||
http_codes <- read_csv("/home/plumber/download/http_codes.csv", col_types = cols(code = "i")) %>% | ||
mutate(code_chr = as.character(code)) | ||
http_codes | ||
} |
Oops, something went wrong.