From 11223c93b4cd6107c298d5fd5751c445d0ca12fe Mon Sep 17 00:00:00 2001 From: edward-burn <9583964+edward-burn@users.noreply.github.com> Date: Sat, 9 Mar 2024 09:29:42 +0000 Subject: [PATCH] codelist class --- DESCRIPTION | 2 +- R/drugCodes.R | 12 ++++++++++++ R/getICD10StandardCodes.R | 5 +++++ tests/testthat/test-drugCodes.R | 1 + 4 files changed, 19 insertions(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index 1f2bb08..0a50850 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -12,7 +12,7 @@ Description: Generate a candidate code list for the Observational Medical Outcom License: Apache License (>= 2) Encoding: UTF-8 Roxygen: list(markdown = TRUE) -RoxygenNote: 7.2.3 +RoxygenNote: 7.3.1 Depends: R (>= 3.5.0) Imports: diff --git a/R/drugCodes.R b/R/drugCodes.R index efc937b..8d4dc15 100644 --- a/R/drugCodes.R +++ b/R/drugCodes.R @@ -144,6 +144,7 @@ getATCCodes <- function(cdm, dplyr::select("concept_id") %>% dplyr::distinct() %>% dplyr::pull() + } else { atc_descendants[[i]] <- atc_descendants[[i]] %>% dplyr::select(!"ancestor_concept_id") @@ -152,6 +153,11 @@ getATCCodes <- function(cdm, names(atc_descendants)[i] <- workingName } } + + if(isFALSE(withConceptDetails)){ + atc_descendants <- omopgenerics::newCodelist(atc_descendants) + } + return(atc_descendants) } @@ -278,6 +284,7 @@ getDrugIngredientCodes <- function(cdm, dplyr::select("concept_id") %>% dplyr::distinct() %>% dplyr::pull() + } else { ingredientCodes[[i]] <- ingredientCodes[[i]] %>% dplyr::select(!"ancestor_concept_id") @@ -285,6 +292,11 @@ getDrugIngredientCodes <- function(cdm, names(ingredientCodes)[[i]] <- workingName } + + if(isFALSE(withConceptDetails)){ + ingredientCodes <- omopgenerics::newCodelist(ingredientCodes) + } + return(ingredientCodes) } diff --git a/R/getICD10StandardCodes.R b/R/getICD10StandardCodes.R index 11e9f83..6ec139b 100644 --- a/R/getICD10StandardCodes.R +++ b/R/getICD10StandardCodes.R @@ -141,6 +141,11 @@ getICD10StandardCodes <- function(cdm, ) } + + if(isFALSE(withConceptDetails)){ + ICD10StandardCodes <- omopgenerics::newCodelist(ICD10StandardCodes) + } + return(ICD10StandardCodes) } diff --git a/tests/testthat/test-drugCodes.R b/tests/testthat/test-drugCodes.R index 0dc8e81..3b135b7 100644 --- a/tests/testthat/test-drugCodes.R +++ b/tests/testthat/test-drugCodes.R @@ -4,6 +4,7 @@ test_that("getATCCodes working", { for (i in seq_along(backends)) { cdm <- mockVocabRef(backend = backends[i]) atcCodes <- getATCCodes(cdm, level = "ATC 1st") + expect_true("codelist" %in% class(atcCodes)) expect_true(all(atcCodes[[1]] == c(12,13))) expect_true(c("alimentary_tract_and_metabolism") %in% names(atcCodes))