Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nameStyle argument for drug ingredients #227

Merged
merged 2 commits into from
Oct 14, 2024
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: CodelistGenerator
Title: Identify Relevant Clinical Codes and Evaluate Their Use
Version: 3.2.0
Version: 3.2.0.900
Authors@R: c(
person("Edward", "Burn", email = "[email protected]",
role = c("aut", "cre"),
Expand Down
15 changes: 11 additions & 4 deletions R/drugCodes.R
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,8 @@ getATCCodes <- function(cdm,
#' @param name Names of ingredients of interest. For example, c("acetaminophen",
#' "codeine"), would result in a list of length two with the descendant
#' concepts for these two particular drug ingredients.
#' @param nameStyle Name style to apply to returned list. Can be one of
#' "{concept_code}_{concept_name}", "{concept_code}", or "{concept_name}".
#' @param doseForm Only descendants codes with the specified dose form
#' will be returned. If NULL, descendant codes will be returned regardless
#' of dose form.
Expand All @@ -214,11 +216,13 @@ getATCCodes <- function(cdm,
#' @examples
#' \dontrun{
#' cdm <- mockVocabRef()
#' getDrugIngredientCodes(cdm = cdm, name = "Adalimumab")
#' getDrugIngredientCodes(cdm = cdm, name = "Adalimumab",
#' nameStyle = "{concept_name}")
#' CDMConnector::cdmDisconnect(cdm)
#'}
getDrugIngredientCodes <- function(cdm,
name = NULL,
nameStyle = "{concept_code}_{concept_name}",
doseForm = NULL,
doseUnit = NULL,
routeCategory = NULL,
Expand All @@ -236,6 +240,10 @@ getDrugIngredientCodes <- function(cdm,
add = errorMessage,
null.ok = TRUE
)
checkmate::assert_choice(x = nameStyle,
choices = c("{concept_code}_{concept_name}",
"{concept_code}",
"{concept_name}"))
checkmate::assertCharacter(type, len = 1)
checkmate::reportAssertions(collection = errorMessage)

Expand Down Expand Up @@ -303,14 +311,13 @@ getDrugIngredientCodes <- function(cdm,
f = as.factor(ingredientCodes$ancestor_concept_id),
drop = TRUE
)

names(ingredientCodes) <- dplyr::tibble(concept_id = names(ingredientCodes)) |>
dplyr::mutate(seq = dplyr::row_number()) |>
dplyr::left_join(ingredientConcepts |>
dplyr::mutate(concept_id = as.character(.data$concept_id)),
by= "concept_id") |>
dplyr::mutate(new_name = paste0(.data$concept_code, "_",
omopgenerics::toSnakeCase(.data$concept_name))) |>
dplyr::mutate(concept_name = paste0(omopgenerics::toSnakeCase(.data$concept_name)),
new_name = glue::glue(nameStyle)) |>
dplyr::arrange(seq) |>
dplyr::pull("new_name")

Expand Down
7 changes: 6 additions & 1 deletion man/getDrugIngredientCodes.Rd

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

16 changes: 15 additions & 1 deletion tests/testthat/test-dbms.R
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,22 @@ test_that("redshift", {
expect_true(nrow(asthma) > 0)

# drug ingredients
expect_no_error(metformin <- getDrugIngredientCodes(cdm, "metformin"))
expect_no_error(metformin <- getDrugIngredientCodes(cdm, "metformin",
nameStyle = "{concept_name}"))
expect_true(inherits(metformin, "codelist"))
expect_true("metformin" %in% names(metformin))

expect_no_error(metformin_2 <- getDrugIngredientCodes(cdm, "metformin",
nameStyle = "{concept_code}"))
expect_true("6809" %in% names(metformin_2))

expect_no_error(metformin_3 <- getDrugIngredientCodes(cdm, "metformin",
nameStyle = "{concept_code}_{concept_name}"))
expect_true("6809_metformin" %in% names(metformin_3))

expect_error(getDrugIngredientCodes(cdm, "metformin",
nameStyle = "something else"))


# achilles
cdm$achilles_results <- cdm$condition_occurrence %>%
Expand Down
8 changes: 8 additions & 0 deletions tests/testthat/test-drugCodes.R
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,14 @@ test_that("no duplicate names example 1",{
overwrite = TRUE)
attr(cdm, "write_schema") <- "main"

expect_error(getDrugIngredientCodes(
cdm = cdm, name = "Adalimumab", nameStyle = "{concept_name}"
))

expect_no_error(getDrugIngredientCodes(
cdm = cdm, name = "Adalimumab", nameStyle = "{concept_code}"
))

ingredient_list <- getDrugIngredientCodes(
cdm = cdm, name = "Adalimumab"
)
Expand Down
Loading