Skip to content

Commit

Permalink
re-factor icd_search
Browse files Browse the repository at this point in the history
  • Loading branch information
ernestguevarra committed Mar 20, 2024
1 parent 33f9d10 commit 3b13b21
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 26 deletions.
2 changes: 1 addition & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ export(icd_get_languages)
export(icd_get_mms_release)
export(icd_get_releases)
export(icd_oauth_client)
export(icd_search)
export(icd_search_foundation)
export(icd_search_mms)
export(icd_structure_autocode)
export(icd_structure_foundation)
export(icd_structure_search)
Expand Down
17 changes: 9 additions & 8 deletions R/icd_search.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#'
#' Search the foundation component of the ICD-11
#' Search the foundation component or linearizations of the ICD-11
#'
#' @section On `flexisearch`: In the regular search mode (`flexisearch = FALSE`),
#' the function will only give you results that contain all of the words that
Expand Down Expand Up @@ -47,11 +47,10 @@
#' codes such as en, es, zh, etc. Depending on the `release` specified, the
#' available languages will vary.
#'
#' @param q String. Text to be searched. Having the character `%` at the end will
#' be regarded as a wild card for that word.
#' @param q String. Text to be searched. Having the character `%` at the end
#' will be regarded as a wild card for that word.
#' @param linearization A character value for which linearization to search.
#' Currently, the only possible value for this is *"mms"*. See section on
#' `linearization` for more details.
#' Currently, the possible values for this are *"mms"* and *"icf"*.
#' @param subtree A string or vector of strings of URIs. If provided, the
#' search will be performed on the entities provided and their descendants.
#' @param use_foundation Logical. Default is FALSE. Should subtree filter
Expand Down Expand Up @@ -92,15 +91,17 @@
#' @param base_url The base URL of the API. Default uses the WHO API server at
#' https://id.who.int. If you are using a locally deployed server or hosting
#' your own ICD API server, you should specify the URL of your instance here.
#' @param client The OAuth2 client produced through a call to `icd_oauth_client()`.
#' @param client The OAuth2 client produced through a call to
#' `icd_oauth_client()`.
#' @param scope Scopes to be requested from the resource owner. Default is
#' *"icdapi_access"* as specified in the ICD API documentation.
#'
#' @return A tibble of search results.
#'
#' @examples
#' icd_search_foundation("colorectal cancer")
#' icd_search_mms("colorectal cancer")
#' icd_search("colorectal cancer")
#' icd_search("impairment", linearization = "icf")
#'
#' @rdname icd_search
#' @export
Expand Down Expand Up @@ -202,7 +203,7 @@ icd_search_foundation <- function(q,
#' @export
#'
icd_search <- function(q,
linearization = "mms",
linearization = c("mms", "icf"),
subtree = NULL,
use_foundation = FALSE,
keyword = FALSE,
Expand Down
9 changes: 7 additions & 2 deletions man/icd_search.Rd

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

69 changes: 54 additions & 15 deletions tests/testthat/test-search.R
Original file line number Diff line number Diff line change
Expand Up @@ -53,45 +53,45 @@ testthat::expect_type(test_search_property, "list")

## Linearization - MMS ----

test_search_default <- icd_search_mms(q = "cholera")
test_search_default <- icd_search(q = "cholera")

### Test message ----
testthat::expect_message(icd_search_mms(q = "cholera"))
testthat::expect_message(icd_search(q = "cholera"))
testthat::expect_s3_class(test_search_default, "tbl_df")
testthat::expect_type(test_search_default, "list")

### Test no message ----
testthat::expect_no_message(icd_search_mms(q = "cholera", verbose = FALSE))
testthat::expect_no_message(icd_search(q = "cholera", verbose = FALSE))

### Test list output ----
test_search_list <- icd_search_mms(q = "cholera", tabular = FALSE)
test_search_list <- icd_search(q = "cholera", tabular = FALSE)

testthat::expect_type(test_search_list, "list")

### Test release specification ----
test_search_release <- icd_search_mms(q = "cholera", release = "2024-01")
testthat::expect_message(icd_search_mms(q = "cholera", release = "2024-01"))
test_search_release <- icd_search(q = "cholera", release = "2024-01")
testthat::expect_message(icd_search(q = "cholera", release = "2024-01"))
testthat::expect_s3_class(test_search_release, "tbl_df")
testthat::expect_type(test_search_release, "list")
testthat::expect_error(icd_search_mms(q = "cholera", release = "2025-01"))
testthat::expect_error(icd_search(q = "cholera", release = "2025-01"))

### Test language specification ----
testthat::expect_warning(icd_search_mms(q = "cholera", language = "pp"))
testthat::expect_warning(icd_search(q = "cholera", language = "pp"))

### Test subtrees query ----
test_search_subtree <- icd_search_mms(q = "cholera", subtree = "http://id.who.int/icd/entity/1435254666")
testthat::expect_message(icd_search_mms(q = "cholera", subtree = "http://id.who.int/icd/entity/1435254666"))
test_search_subtree <- icd_search(q = "cholera", subtree = "http://id.who.int/icd/entity/1435254666")
testthat::expect_message(icd_search(q = "cholera", subtree = "http://id.who.int/icd/entity/1435254666"))
testthat::expect_s3_class(test_search_subtree, "tbl_df")
testthat::expect_type(test_search_subtree, "list")

### Test chapter query ----
test_search_chapter <- icd_search_mms(q = "cholera", chapter = "01")
testthat::expect_message(icd_search_mms(q = "cholera", chapter = "01"))
test_search_chapter <- icd_search(q = "cholera", chapter = "01")
testthat::expect_message(icd_search(q = "cholera", chapter = "01"))
testthat::expect_s3_class(test_search_chapter, "tbl_df")
testthat::expect_type(test_search_chapter, "list")

### Test properties query ----
test_search_property <- icd_search_mms(
test_search_property <- icd_search(
q = "cholera",
properties = c(
"Title","Synonym", "NarrowerTerm", "FullySpecifiedName",
Expand All @@ -104,7 +104,7 @@ testthat::expect_type(test_search_property, "list")
### Test medical_mode ----

testthat::expect_s3_class(
icd_search_mms(
icd_search(
q = "cholera",
medical_mode = FALSE,
properties = c("Title","Definition", "IndexTerm")
Expand All @@ -113,7 +113,46 @@ testthat::expect_s3_class(
)

testthat::expect_error(
icd_search_mms(
icd_search(
q = "cholera",
medical_mode = FALSE)
)


## Linearization - ICF ----

test_search_default <- icd_search(q = "cholera", linearization = "icf")

### Test message ----
testthat::expect_message(icd_search(q = "cholera", linearization = "icf"))
testthat::expect_s3_class(test_search_default, "tbl_df")
testthat::expect_type(test_search_default, "list")

### Test no message ----
testthat::expect_no_message(
icd_search(q = "cholera", linearization = "icf", verbose = FALSE)
)

### Test list output ----
test_search_list <- icd_search(
q = "cholera",
linearization = "icf",
tabular = FALSE
)

testthat::expect_type(test_search_list, "list")

### Test release specification ----
test_search_release <- icd_search(
q = "cholera", linearization = "icf", release = "2024-01"
)
testthat::expect_message(
icd_search(
q = "cholera", linearization = "icf", release = "2024-01"
)
)
testthat::expect_s3_class(test_search_release, "tbl_df")
testthat::expect_type(test_search_release, "list")
testthat::expect_error(
icd_search(q = "cholera", linearization = "icf", release = "2025-01")
)

0 comments on commit 3b13b21

Please sign in to comment.