Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: ROMOPAPI
Title: ROMOPAPI
Version: 2.1.1
Version: 2.2.0
Authors@R:
person("Javier", "Gracia-Tabuenca", , "javier.graciatabuenca@tuni.fi", role = c("aut", "cre"),
comment = c(ORCID = "YOUR-ORCID-ID"))
Expand Down
8 changes: 4 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,18 @@ RUN apt-get update && apt-get install -y openjdk-8-jdk liblzma-dev libbz2-dev li

# Install renv and restore packages
ARG ROMOPAPI_BRANCH=main
ARG BUILD_CACHE_BUSTER=3
ARG BUILD_CACHE_BUSTER=5

# Install renv and restore packages
RUN --mount=type=secret,id=build_github_pat \
cp /usr/local/lib/R/etc/Renviron /tmp/Renviron \
&& echo "GITHUB_PAT=$(cat /run/secrets/build_github_pat)" >> /usr/local/lib/R/etc/Renviron \
&& Rscript -e 'install.packages("remotes")' \
&& Rscript -e 'remotes::install_github("FINNGEN/ROMOPAPI")' \
&& Rscript -e 'remotes::install_github("FINNGEN/ROMOPAPI@'$ROMOPAPI_BRANCH'")' \
&& cp /tmp/Renviron /usr/local/lib/R/etc/Renviron;

# Expose the port that the API will run on
EXPOSE 8585
EXPOSE 8564

# Run the API server
CMD ["Rscript", "-e", "ROMOPAPI::runApiServer(host = '0.0.0.0', port = 8585)"]
CMD ["Rscript", "-e", "ROMOPAPI::runApiServer(host = '0.0.0.0', port = 8564)"]
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# ROMOPAPI
- Added number_of_descendants to concepts with code counts
- Added conceptId 21600744 to testing data

# ROMOPAPI 2.1.1
- Added caching concepts with code counts at startup

Expand Down
3 changes: 2 additions & 1 deletion R/getCodeCounts.R
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,8 @@ getCodeCounts <- function(
dplyr::rename(node_record_counts = record_counts, node_descendant_record_counts = descendant_record_counts)

# - Get concept details
conceptsWithCodeCounts <- getConceptsWithCodeCounts_memoise(CDMdbHandler, codeCountsTable = codeCountsTable)
conceptsWithCodeCounts <- getConceptsWithCodeCounts_memoise(CDMdbHandler, codeCountsTable = codeCountsTable) |>
dplyr::select(-number_of_descendants)
concepts <- familyTreeWithMappings |>
dplyr::distinct(child_concept_id) |>
dplyr::rename(concept_id = child_concept_id) |>
Expand Down
2 changes: 1 addition & 1 deletion R/getConceptsWithCodeCounts.R
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ getConceptsWithCodeCounts <- function(
SELECT DISTINCT
c.concept_id,
c.concept_name, c.domain_id, c.vocabulary_id, c.concept_class_id, c.standard_concept, c.concept_code,
cc.record_counts, cc.descendant_record_counts
cc.record_counts, cc.descendant_record_counts, cc.number_of_descendants
FROM @vocabularyDatabaseSchema.concept c
INNER JOIN @resultsDatabaseSchema.@codeCountsTable cc
ON c.concept_id = cc.concept_id;"
Expand Down
4 changes: 2 additions & 2 deletions R/runApiServer.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#' @param cohortTableHandlerConfig Configuration for connecting to the OMOP CDM database.
#' If NULL, uses test Eunomia database
#' @param host Host address to run the API server on. Defaults to "127.0.0.1"
#' @param port Port number to run the API server on. Defaults to 8585
#' @param port Port number to run the API server on. Defaults to 8564
#' @param buildCountsTable Logical indicating whether to build code counts tables. Defaults to FALSE
#' @param ... Additional arguments passed to plumber::pr_run()
#'
Expand All @@ -33,7 +33,7 @@
runApiServer <- function(
cohortTableHandlerConfig = NULL,
host = "127.0.0.1",
port = 8585,
port = 8564,
buildCountsTable = FALSE,
...) {
#
Expand Down
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,19 @@ library(ROMOPAPI)
runApiServer()
```

This will start the API server on port 8585.
This will start the API server on port 8564.

#### Testing endpoints

The main endpoint for testing is: http://127.0.0.1:8585/report?conceptId=<concept_id>
The main endpoint for testing is: http://127.0.0.1:8564/report?conceptId=<concept_id>

For example, http://127.0.0.1:8585/report?conceptId=317009
For example, http://127.0.0.1:8564/report?conceptId=317009

This will return an HTML report for the concept id 317009.

#### Production endpoints

The main endpoint for production is: http://127.0.0.1:8585/getCodeCounts?conceptId=<concept_id>
The main endpoint for production is: http://127.0.0.1:8564/getCodeCounts?conceptId=<concept_id>

This will return the code counts for the concept ids 317009.

Expand All @@ -49,7 +49,7 @@ Separated in 3 tables:
- `stratified_code_counts`: patient counts by conceptId stratified by gender, year, and age decile


See the API documentation for more details: http://127.0.0.1:8585/__docs__/
See the API documentation for more details: http://127.0.0.1:8564/__docs__/

### Running the API Server with a custom database

Expand Down Expand Up @@ -143,7 +143,7 @@ Based on the example output, getCodeCounts returns a list with 3 components:
Existing docker image is available at: https://hub.docker.com/repository/docker/javiergrata/romopapi/

```
docker run -p 8585:8585 javiergrata/romopapi
docker run -p 8564:8564 javiergrata/romopapi
```

## Build the docker image
Expand All @@ -163,7 +163,7 @@ docker build --secret id=build_github_pat,src=GITHUBPAT.txt --build-arg ROMOPAPI
## Run the docker container

```
docker run -p 8585:8585 romopapi
docker run -p 8564:8564 romopapi
```


2 changes: 1 addition & 1 deletion inst/plumber/plumber.R
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ function() {
function() {
concepts <- getConceptsWithCodeCounts_memoise(CDMdbHandler = CDMdbHandler)
concepts <- concepts |>
dplyr::select(concept_id, concept_name, vocabulary_id, concept_code)
dplyr::select(concept_id, concept_name, vocabulary_id, concept_code, number_of_descendants)
return(concepts)
}

Expand Down
9 changes: 6 additions & 3 deletions inst/sql/sql_server/createCodeCountsTable.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ DROP TABLE IF EXISTS @resultsDatabaseSchema.@codeCountsTable;
CREATE TABLE @resultsDatabaseSchema.@codeCountsTable (
concept_id int,
record_counts int,
descendant_record_counts int
descendant_record_counts int,
number_of_descendants int
);

INSERT INTO @resultsDatabaseSchema.@codeCountsTable
Expand Down Expand Up @@ -57,7 +58,8 @@ descendant_counts AS (
SELECT
ca.ancestor_concept_id AS concept_id,
COALESCE(cc.record_counts, 0) AS record_counts,
SUM(COALESCE(cctosum.record_counts, 0)) AS descendant_record_counts
SUM(COALESCE(cctosum.record_counts, 0)) AS descendant_record_counts,
COUNT(*) AS number_of_descendants
FROM
temp_concept_ancestor ca
INNER JOIN
Expand All @@ -77,6 +79,7 @@ descendant_counts AS (
SELECT
CAST(ccd.concept_id AS BIGINT) AS concept_id,
CAST(ccd.record_counts AS BIGINT) AS record_counts,
CAST(ccd.descendant_record_counts AS BIGINT) AS descendant_record_counts
CAST(ccd.descendant_record_counts AS BIGINT) AS descendant_record_counts,
CAST(ccd.number_of_descendants AS BIGINT) AS number_of_descendants
FROM
descendant_counts ccd;
Binary file modified inst/testdata/data/FinnGenR13_countsOnly.sqlite
Binary file not shown.
5 changes: 4 additions & 1 deletion inst/testdata/data/createTestingData.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,13 @@ conceptIds <- c(
45596282, # ICD10: Asthma
21601855, # ATC level 4: C10AA (Statins)
320136, # Big graph, parent of Asthma snomed concept (Disorders of the respiratory system)
4024567# biger
4024567,# biger
21600744 # bug in plot
)

CDMdbHandler <- HadesExtras_createCDMdbHandlerFromList(test_cohortTableHandlerConfig, loadConnectionChecksLevel = "basicChecks")
# uncomment to create code counts tables
createCodeCountsTables(CDMdbHandler)
helper_createSqliteDatabaseFromDatabase(
CDMdbHandler,
conceptIds = conceptIds,
Expand Down
4 changes: 2 additions & 2 deletions man/runApiServer.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tests/testmanual/manualtest-runApiServer.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ ROMOPAPI::runApiServer(
buildCountsTable = FALSE
)

# http://127.0.0.1:8585/__docs__/
# http://127.0.0.1:8564/__docs__/
26 changes: 25 additions & 1 deletion tests/testthat/test-createCodeCountsTable.R
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@ test_that("createCodeCountsTables works", {
expect_equal(c(
"concept_id",
"record_counts",
"descendant_record_counts"
"descendant_record_counts",
"number_of_descendants"
))

# check that descendant_record_counts is greater than or equal to record_counts
Expand All @@ -129,4 +130,27 @@ test_that("createCodeCountsTables works", {
dplyr::count() |>
dplyr::pull(n) |>
expect_equal(code_counts |> dplyr::count() |> dplyr::pull(n))

# check that number_of_descendants is greater than or equal to 1
code_counts |>
dplyr::filter(number_of_descendants < 1) |>
dplyr::count() |>
dplyr::pull(n) |>
expect_equal(0)

# check that all with record_counts = descendant_record_counts have number_of_descendants = 1
code_counts |>
dplyr::filter(record_counts == descendant_record_counts) |>
dplyr::filter(number_of_descendants != 1) |>
dplyr::count() |>
dplyr::pull(n) |>
expect_equal(0)

# check that all with number_of_descendants > 1 have record_counts > descendant_record_counts
code_counts |>
dplyr::filter(number_of_descendants > 1) |>
dplyr::filter(record_counts > descendant_record_counts) |>
dplyr::count() |>
dplyr::pull(n) |>
expect_equal(0)
})
2 changes: 1 addition & 1 deletion tests/testthat/test-getConceptsWithCodeCounts.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ test_that("getConceptsWithCodeCounts works", {
# Check column names match expected structure
expected_columns <- c("concept_id", "concept_name", "domain_id", "vocabulary_id",
"concept_class_id", "standard_concept", "concept_code",
"record_counts", "descendant_record_counts")
"record_counts", "descendant_record_counts", "number_of_descendants")

result |>
colnames() |>
Expand Down