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
8 changes: 7 additions & 1 deletion R/conceptSearchModule.R
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,13 @@ hecateConceptLabel <- function(conceptId) {
return("(invalid concept id)")
}

"(valid concept id)"
concept_name <- concept$conceptName %||% NA_character_
concept_name <- as.character(concept_name)
if (length(concept_name) != 1 || is.na(concept_name) || !nzchar(concept_name)) {
return("(invalid concept id)")
}

return(concept_name)
}

#' @describeIn conceptSearchModule UI for the concept search: a single button that opens the search modal.
Expand Down
1 change: 1 addition & 0 deletions tests/testthat/helper-internals.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ new_cdm_table <- function(type) {

cdm_table_server <- getFromNamespace("cdmTableServer", "PatientGenerator")
normalize_bar_end_update <- getFromNamespace("normalizeBarEndUpdate", "PatientGenerator")
hecate_concept_label <- getFromNamespace("hecateConceptLabel", "PatientGenerator")
48 changes: 48 additions & 0 deletions tests/testthat/test-conceptSearchModule.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
test_that("hecateConceptLabel returns concept names for valid concept ids", {
testthat::local_mocked_bindings(
hecateSearch = function(query, limit = 10) {
data.frame(
conceptId = c(3018251L, 201826L),
conceptName = c("Hemoglobin A1c measurement", "Type 2 diabetes mellitus"),
invalidReason = c(NA_character_, NA_character_)
)
},
.package = "PatientGenerator"
)

expect_equal(
hecate_concept_label("3018251"),
"Hemoglobin A1c measurement"
)
})

test_that("hecateConceptLabel returns invalid concept id for invalid or missing concepts", {
testthat::local_mocked_bindings(
hecateSearch = function(query, limit = 10) {
data.frame(
conceptId = 3018251L,
conceptName = "Hemoglobin A1c measurement",
invalidReason = NA_character_
)
},
.package = "PatientGenerator"
)

expect_equal(hecate_concept_label("abc"), "(invalid concept id)")
expect_equal(hecate_concept_label("9999999"), "(not found)")
})

test_that("hecateConceptLabel returns invalid concept id for invalid vocabulary concepts", {
testthat::local_mocked_bindings(
hecateSearch = function(query, limit = 10) {
data.frame(
conceptId = 123L,
conceptName = "Old concept",
invalidReason = "D"
)
},
.package = "PatientGenerator"
)

expect_equal(hecate_concept_label("123"), "(invalid concept id)")
})
Loading