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.0.0
Version: 2.1.0
Authors@R:
person("Javier", "Gracia-Tabuenca", , "javier.graciatabuenca@tuni.fi", role = c("aut", "cre"),
comment = c(ORCID = "YOUR-ORCID-ID"))
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ 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=1
ARG BUILD_CACHE_BUSTER=2

# Install renv and restore packages
RUN --mount=type=secret,id=build_github_pat \
Expand Down
2 changes: 1 addition & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export(createReport)
export(createStratifiedCodeCountsTable)
export(create_api)
export(fct_setUpLogger)
export(getCDMSource)
export(getAPIInfo)
export(getCodeCounts)
export(getCodeCounts_memoise)
export(getConceptsWithCodeCounts)
Expand Down
5 changes: 5 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# ROMOPAPI 2.1.0
- Added getAPIInfo endpoint to API
- Updated db with large tree
- Fixed error in getCodeCounts when conceptId was the root of the tree

# ROMOPAPI 2.0.0
- Updated to use DatabaseConnector v7

Expand Down
20 changes: 13 additions & 7 deletions R/getCDMSource.R → R/getAPIInfo.R
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@

#' Get the CDM source information
#' Get the API information
#'
#' @description
#' Retrieves the CDM source information from the vocabulary schema of an OMOP CDM database.
#' This includes metadata about the database source, version, and other administrative details.
#'
#' Retrieves the API information from the vocabulary schema of an OMOP CDM database.
#' This includes metadata about the API, version, and other administrative details.
#' @param CDMdbHandler A CDMdbHandler object that contains database connection details
#'
#' @return A tibble containing the CDM source information with columns from the cdm_source table
Expand All @@ -16,9 +15,9 @@
#'
#' @export
#'
getCDMSource <- function(
getAPIInfo <- function(
CDMdbHandler) {
ParallelLogger::logInfo("getCDMSource: Getting CDM source information")
ParallelLogger::logInfo("getAPIInfo: Getting API information")
#
# VALIDATE
#
Expand All @@ -39,5 +38,12 @@ getCDMSource <- function(
vocabularyDatabaseSchema = vocabularyDatabaseSchema
) |> tibble::as_tibble()

return(cdm_source)
info <- list(
cdm_source_name = cdm_source$cdm_source_name,
cdm_source_abbreviation = cdm_source$cdm_source_abbreviation,
vocabulary_version = cdm_source$vocabulary_version,
romop_api_version = as.character(utils::packageVersion("ROMOPAPI"))
)

return(info)
}
12 changes: 9 additions & 3 deletions R/getCodeCounts.R
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,9 @@ getCodeCounts <- function(
)
-- take only parents who are someones children, or are the parents of the concept id
SELECT * FROM temp_tree tt
WHERE parent_concept_id IN (SELECT DISTINCT child_concept_id FROM temp_tree ) OR child_concept_id IN (@conceptId)
WHERE parent_concept_id IN (SELECT DISTINCT child_concept_id FROM temp_tree ) OR
child_concept_id IN (@conceptId) OR
parent_concept_id IN (@conceptId) -- when concept is top in tree
"

# Gets tree of descendants and the code counts for each descendant
Expand Down Expand Up @@ -173,7 +175,9 @@ getCodeCounts <- function(
dplyr::distinct(concept_id, maps_to_concept_id) |>
dplyr::rename(maps_to_concept_id = concept_id, concept_id = maps_to_concept_id) |>
dplyr::mutate(levels = "Maps to")
)
) |>
# If concept maps to itself, bcs concept in concept and source concept columns, dont take it
dplyr::filter(concept_id != maps_to_concept_id)

familyTreeWithMappings <- dplyr::bind_rows(
familyTreeWithInfo,
Expand All @@ -194,7 +198,9 @@ getCodeCounts <- function(
codeCounts |> dplyr::select(-maps_to_concept_id) |>
dplyr::group_by(concept_id, calendar_year, gender_concept_id, age_decile) |>
dplyr::summarise(record_counts = sum(record_counts), .groups = "drop")
)
) |>
# If concept maps to itself, bcs concept in concept and source concept columns, dont take it
dplyr::distinct()

familyTreeDescendants <- familyTreeWithMappings |>
dplyr::filter(!levels %in% c("Mapped from", "Maps to", "-1", "0")) |>
Expand Down
17 changes: 17 additions & 0 deletions R/helper.R
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,23 @@ helper_createSqliteDatabaseFromDatabase <- function(
tempTable = FALSE,
)

# get CDMsource
sql <- "SELECT DISTINCT c.* FROM @vocabularyDatabaseSchema.cdm_source c"
cdmSource <- DatabaseConnector::renderTranslateQuerySql(
connection = sourceConnection,
sql = sql,
vocabularyDatabaseSchema = sourceVocabularyDatabaseSchema
) |>
tibble::as_tibble()

targetConnection |> DatabaseConnector::insertTable(
tableName = "cdm_source",
data = cdmSource,
dropTableIfExists = TRUE,
createTable = TRUE,
tempTable = FALSE,
)

# disconnect
targetConnection |> DatabaseConnector::disconnect()
sourceConnection |> DatabaseConnector::disconnect()
Expand Down
6 changes: 3 additions & 3 deletions inst/plumber/plumber.R
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ function(res, conceptId=0L) {
}


#* Get the CDM source information
#* @get /getCDMSource
#* Get the API information
#* @get /getAPIInfo
function() {
getCDMSource(
getAPIInfo(
CDMdbHandler = CDMdbHandler
)
}
Expand Down
Binary file modified inst/testdata/data/FinnGenR13_countsOnly.sqlite
Binary file not shown.
11 changes: 8 additions & 3 deletions inst/testdata/data/createTestingData.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ conceptIds <- c(
317009, # Snomed: Asthma
45596282, # ICD10: Asthma
21601855, # ATC level 4: C10AA (Statins)
#2010001615, # test endpoint
320136 # Big graph, parent of Asthma snomed concept (Disorders of the respiratory system)
320136, # Big graph, parent of Asthma snomed concept (Disorders of the respiratory system)
4024567# biger
)

CDMdbHandler <- HadesExtras_createCDMdbHandlerFromList(test_cohortTableHandlerConfig, loadConnectionChecksLevel = "basicChecks")
Expand All @@ -25,7 +25,7 @@ connection <- DatabaseConnector::connect(DatabaseConnector::createConnectionDet

DatabaseConnector::dbListTables(connection) |>
sort() |>
expect_equal(c("code_counts", "concept", "concept_ancestor", "stratified_code_counts"))
expect_equal(c("cdm_source", "code_counts", "concept", "concept_ancestor", "stratified_code_counts"))

dplyr::tbl(connection, "concept") |>
dplyr::count() |>
Expand All @@ -47,3 +47,8 @@ dplyr::tbl(connection, "stratified_code_counts") |>
dplyr::pull(n) |>
expect_gt(0)

dplyr::tbl(connection, "cdm_source") |>
dplyr::count() |>
dplyr::pull(n) |>
expect_gt(0)

13 changes: 7 additions & 6 deletions man/getCDMSource.Rd → man/getAPIInfo.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-timeplotview.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ conceptId <- 782748

conceptId <- 21602735

conceptId <- 2010001615 # test endpoint
conceptId <- 2010001618 # test endpoint


results <- getCodeCounts(
Expand Down
20 changes: 20 additions & 0 deletions tests/testthat/test-getAPIInfo.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# create test for getCDMSource

test_that("getAPIInfo works", {
# only works in a full CDM databas

CDMdbHandler <- HadesExtras_createCDMdbHandlerFromList(test_cohortTableHandlerConfig, loadConnectionChecksLevel = "basicChecks")
withr::defer({
CDMdbHandler <- NULL
gc()
})

api_info <- getAPIInfo(CDMdbHandler)

# Check column names
api_info |> names() |>
expect_equal(c("cdm_source_name", "cdm_source_abbreviation", "vocabulary_version", "romop_api_version"))
api_info$romop_api_version |>
expect_equal(as.character(utils::packageVersion("ROMOPAPI")))

})
20 changes: 0 additions & 20 deletions tests/testthat/test-getCDMSource.R

This file was deleted.