From a8e86ac347fc142905c1ce67675d00e60fde025b Mon Sep 17 00:00:00 2001 From: javier-gracia-tabuenca-tuni Date: Mon, 29 Sep 2025 14:31:04 +0300 Subject: [PATCH 1/5] added DRUG_STRENGTH --- R/databasesFromAndToCSV.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/databasesFromAndToCSV.R b/R/databasesFromAndToCSV.R index 86bbd9e..781cff9 100644 --- a/R/databasesFromAndToCSV.R +++ b/R/databasesFromAndToCSV.R @@ -24,7 +24,7 @@ omopVocabularyCSVsToDuckDB <- function( "CONCEPT_RELATIONSHIP", "CONCEPT_SYNONYM", "DOMAIN", - # "DRUG_STRENGTH", TEMP: loading makes error, leave out at the moment + "DRUG_STRENGTH", "RELATIONSHIP", "VOCABULARY" ) From deadbe76cfd5161ea25b937c46f3be9e0ff2f8cc Mon Sep 17 00:00:00 2001 From: javier-gracia-tabuenca-tuni Date: Mon, 29 Sep 2025 15:24:19 +0300 Subject: [PATCH 2/5] changed DBI::dbListTables with DatabaseConnector::getTableNames --- R/appendUsagiFileToSTCMtable.R | 2 +- R/databasesFromAndToCSV.R | 2 +- R/updateUsagiFile.R | 2 +- R/validateCDMtablesWithDQD.R | 2 +- R/validateUsagiFile.R | 2 +- tests/testthat/test-appendUsagiFileToSTCMTable.R | 14 +++++++------- 6 files changed, 12 insertions(+), 12 deletions(-) diff --git a/R/appendUsagiFileToSTCMtable.R b/R/appendUsagiFileToSTCMtable.R index 2318b1b..8b2aacb 100644 --- a/R/appendUsagiFileToSTCMtable.R +++ b/R/appendUsagiFileToSTCMtable.R @@ -67,7 +67,7 @@ appendUsagiFileToSTCMtable <- function( # # check if the sourceToConceptMapTable exists - listTables <- DBI::dbListTables(connection, vocabularyDatabaseSchema) + listTables <- DatabaseConnector::getTableNames(connection, vocabularyDatabaseSchema) if (!sourceToConceptMapTable %in% listTables) { stop(paste0("The sourceToConceptMapTable ", sourceToConceptMapTable, " does not exist in the vocabularyDatabaseSchema ", vocabularyDatabaseSchema)) } diff --git a/R/databasesFromAndToCSV.R b/R/databasesFromAndToCSV.R index 781cff9..217bf76 100644 --- a/R/databasesFromAndToCSV.R +++ b/R/databasesFromAndToCSV.R @@ -113,7 +113,7 @@ duckdbToOMOPVocabularyCSVs <- function( OMOPVocabularyTableNames |> stringr::str_to_lower() |> checkmate::assertSubset( - DatabaseConnector::dbListTables(connection) + DatabaseConnector::getTableNames(connection) ) pathToOMOPVocabularyCSVsFolder |> checkmate::assertDirectoryExists() diff --git a/R/updateUsagiFile.R b/R/updateUsagiFile.R index 2fd1bde..03fe78f 100644 --- a/R/updateUsagiFile.R +++ b/R/updateUsagiFile.R @@ -51,7 +51,7 @@ updateUsagiFile <- function( # Check if required tables exist # tables <- DatabaseConnector::getTableNames(condlnection, vocabularyDatabaseSchema) # TEMP untill solved https://github.com/OHDSI/DatabaseConnector/issues/299 - tableNames <- DatabaseConnector::dbListTables(connection, vocabularyDatabaseSchema) + tableNames <- DatabaseConnector::getTableNames(connection, vocabularyDatabaseSchema) c("concept", "concept_relationship", "domain") |> checkmate::assertSubset(tableNames) diff --git a/R/validateCDMtablesWithDQD.R b/R/validateCDMtablesWithDQD.R index 0ce3086..dfe9c13 100644 --- a/R/validateCDMtablesWithDQD.R +++ b/R/validateCDMtablesWithDQD.R @@ -20,7 +20,7 @@ validateCDMtablesWithDQD <- function(connectionDetails, vocabularyDatabaseSchema validationResultsFolder |> checkmate::assertDirectory() connection <- DatabaseConnector::connect(connectionDetails) - tableNames <- DatabaseConnector::dbListTables(connection, vocabularyDatabaseSchema) + tableNames <- DatabaseConnector::getTableNames(connection, vocabularyDatabaseSchema) DatabaseConnector::disconnect(connection) OMOPVocabularyTableNames <- c( diff --git a/R/validateUsagiFile.R b/R/validateUsagiFile.R index 4b2e3b1..eee9cb8 100644 --- a/R/validateUsagiFile.R +++ b/R/validateUsagiFile.R @@ -41,7 +41,7 @@ validateUsagiFile <- function( # Check if required tables exist # tables <- DatabaseConnector::getTableNames(condlnection, vocabularyDatabaseSchema) # TEMP untill solved https://github.com/OHDSI/DatabaseConnector/issues/299 - tableNames <- DatabaseConnector::dbListTables(connection, vocabularyDatabaseSchema) + tableNames <- DatabaseConnector::getTableNames(connection, vocabularyDatabaseSchema) c("concept", "concept_relationship", "domain") |> checkmate::assertSubset(tableNames) diff --git a/tests/testthat/test-appendUsagiFileToSTCMTable.R b/tests/testthat/test-appendUsagiFileToSTCMTable.R index e1894aa..6749c9c 100644 --- a/tests/testthat/test-appendUsagiFileToSTCMTable.R +++ b/tests/testthat/test-appendUsagiFileToSTCMTable.R @@ -28,7 +28,7 @@ test_that("test appendUsagiFileToSTCMTable appends the usagi file to the sourceT expect_equal(nrowUsagiFile) stcmTable |> - dplyr::filter(TARGET_CONCEPT_ID != 0L) |> + dplyr::filter(target_concept_id != 0L) |> dplyr::count() |> dplyr::pull(n) |> expect_equal(nrowUsagiFileMapped) @@ -71,7 +71,7 @@ test_that("test appendUsagiFileToSTCMTable appends the usagi file to the sourceT expect_equal(nrowUsagiFile) stcmTable |> - dplyr::filter(TARGET_CONCEPT_ID != 0L) |> + dplyr::filter(target_concept_id != 0L) |> dplyr::count() |> dplyr::pull(n) |> expect_equal(nrowUsagiFileMapped) @@ -84,7 +84,7 @@ test_that("test appendUsagiFileToSTCMTable appends the usagi file to the sourceT "source_domain", "source_parents_concept_ids")) stcmTable |> - dplyr::filter(is.na(SOURCE_PARENTS_CONCEPT_IDS)) |> + dplyr::filter(is.na(source_parents_concept_ids)) |> nrow() |> expect_equal(0) @@ -119,14 +119,14 @@ test_that("test appendUsagiFileToSTCMTable appends the ICD10fi usagi file to the # For source code C18.62 the parent concept IDs should be ICD10 code C18.6 with concept_id 45552246 stcmTable |> - dplyr::filter(SOURCE_CODE == "C18.62") |> - dplyr::pull(SOURCE_PARENTS_CONCEPT_IDS) |> + dplyr::filter(source_code == "C18.62") |> + dplyr::pull(source_parents_concept_ids) |> expect_equal("45552246") # For source code Y94.1 the parent concept IDs should be ICD10fi code Y94 with concept_id 2000503727 stcmTable |> - dplyr::filter(SOURCE_CODE == "Y94.1") |> - dplyr::pull(SOURCE_PARENTS_CONCEPT_IDS) |> + dplyr::filter(source_code == "Y94.1") |> + dplyr::pull(source_parents_concept_ids) |> expect_equal("2000503725") }) From afbf486b0e5ba2298b29de510e73d477f89f15c7 Mon Sep 17 00:00:00 2001 From: javier-gracia-tabuenca-tuni Date: Mon, 29 Sep 2025 15:34:56 +0300 Subject: [PATCH 3/5] Updated NEWS.md to fix warning --- inst/testdata/VOCABULARIES/ICD10fi/NEWS.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/inst/testdata/VOCABULARIES/ICD10fi/NEWS.md b/inst/testdata/VOCABULARIES/ICD10fi/NEWS.md index a20328b..c1a6df8 100644 --- a/inst/testdata/VOCABULARIES/ICD10fi/NEWS.md +++ b/inst/testdata/VOCABULARIES/ICD10fi/NEWS.md @@ -16,4 +16,4 @@ # ICD10fi v1.0.0 - Brought from old FinOMOP "Tietoriihi" GitLab with some minor fixes. -- Mappings of 12 of the codes fixed in 2023-03. \ No newline at end of file +- Mappings of 12 of the codes fixed in 2023-03. From 46136b0ce437924c68d35e3a2cca83f90f67ca30 Mon Sep 17 00:00:00 2001 From: javier-gracia-tabuenca-tuni Date: Tue, 30 Sep 2025 10:48:12 +0300 Subject: [PATCH 4/5] Refactored CONCEPT_RELATIONSHIPToANCESTOR SQL query to aggregate ancestor and descendant concept IDs, ensuring unique relationships. Added tests to verify uniqueness of ancestor_concept_id and descendant_concept_id. --- inst/sql/sql_server/CONCEPT_RELATIONSHIPToANCESTOR.sql | 9 +++++++-- .../testthat/test-conceptRelationshipToAncestorTables.R | 8 ++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/inst/sql/sql_server/CONCEPT_RELATIONSHIPToANCESTOR.sql b/inst/sql/sql_server/CONCEPT_RELATIONSHIPToANCESTOR.sql index 2813717..dabde08 100644 --- a/inst/sql/sql_server/CONCEPT_RELATIONSHIPToANCESTOR.sql +++ b/inst/sql/sql_server/CONCEPT_RELATIONSHIPToANCESTOR.sql @@ -76,8 +76,13 @@ WITH RECURSIVE ancestor_cte AS ( FROM #relationships ) AS r ) -SELECT DISTINCT * -FROM ancestor_cte_self_reference; +SELECT + ancestor_concept_id, + descendant_concept_id, + MIN(min_levels_of_separation) as min_levels_of_separation, + MAX(max_levels_of_separation) as max_levels_of_separation +FROM ancestor_cte_self_reference +GROUP BY ancestor_concept_id, descendant_concept_id; -- 4- Remove the temporary table diff --git a/tests/testthat/test-conceptRelationshipToAncestorTables.R b/tests/testthat/test-conceptRelationshipToAncestorTables.R index d692664..22646a8 100644 --- a/tests/testthat/test-conceptRelationshipToAncestorTables.R +++ b/tests/testthat/test-conceptRelationshipToAncestorTables.R @@ -42,4 +42,12 @@ test_that("conceptRelationshipToAncestorTables creates CONCEPT_ANCESTOR table fr dplyr::pull(n) |> expect_equal(c(1,8,16)) + + # check ancestor_concept_id and descendant_concept_id are unique + ancestor |> + dplyr::distinct(ancestor_concept_id, descendant_concept_id) |> + nrow() |> + expect_equal(ancestor |> nrow()) + + }) From 6721a650432a2986e0e75aed3085a7f7bd2abeb1 Mon Sep 17 00:00:00 2001 From: javier-gracia-tabuenca-tuni Date: Tue, 30 Sep 2025 11:13:47 +0300 Subject: [PATCH 5/5] v2.1.0 --- DESCRIPTION | 2 +- NEWS.md | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index 135fe48..04c3a9a 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: ROMOPMappingTools Title: Tools for Working with OMOP CDM Mappings -Version: 2.0.4 +Version: 2.1.0 Authors@R: person("Javier", "Gracia-Tabuenca", , "javier.graciatabuenca@tuni.fi", role = c("aut", "cre"), comment = c(ORCID = "0000-0002-2455-0598")) diff --git a/NEWS.md b/NEWS.md index 2cb5980..b983f61 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,9 @@ +# ROMOPMappingTools 2.1.0 + +- Fixed concept_ancestor table generation. ICD10fi hierarchy was not correct, and duplicated rows were present in the table. +- Added DRUG_STRENGTH table generation. This was missing, and created warnings in the DQD validation. +- Fixed errors due to DatabaseConnector v7.0.0. + # ROMOPMappingTools 2.0.5 - Fixed a bug in Usagi to STCM table conversion with respect to source parents