Skip to content

Commit

Permalink
Merge pull request #77 from OxfordIHTM/dev
Browse files Browse the repository at this point in the history
create initials tests for linearization mms search
  • Loading branch information
ernestguevarra authored Mar 20, 2024
2 parents 100def8 + ac26e58 commit 4bd56ba
Show file tree
Hide file tree
Showing 4 changed files with 113 additions and 45 deletions.
39 changes: 19 additions & 20 deletions R/icd_search.R
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#'
#' Search the foundation component of the ICD-11
#'
#' @section flexisearch: In the regular search mode (`flexisearch = FALSE`), the
#' function will only give you results that contain all of the words that
#' @section On `flexisearch`: In the regular search mode (`flexisearch = FALSE`),
#' the function will only give you results that contain all of the words that
#' you've used in your search. It accepts different variants or synonyms of
#' the words but essentially it searches for a result that contains all
#' components of your search. Whereas in flexible search mode, the results do
Expand All @@ -11,29 +11,29 @@
#' are not matched at all. It is recommended to use flexible search only when
#' regular search does not provide a result.
#'
#' @section keyword: If set to true, the search result will also include
#' @section On `keyword`: If set to true, the search result will also include
#' keyword list. If the last word provided is incomplete, keyword list
#' includes all words that start with the incomplete word
#' (word completion mode). If the last word is complete, the keyword list
#' will provide suggested additional words that could be added to the search
#' query (word suggestion mode).
#'
#' @section medical_coding_mode: When searching the classification for medical
#' coding purposes, this should be set to TRUE (default). In this mode, the
#' search gives results only from the entities that have a code. The system
#' will search all index terms of an entity. i.e. *titles*, *synonyms*,
#' *fully specified term*, all terms of other entities that are in the
#' foundation are aggregated into this entity. By default, *chapters 26*, *V*,
#' and *X* are not included in the search results. If `medical_coding_mode` is
#' @section On `medical_mode`: When searching the classification for
#' medical coding purposes, this should be set to TRUE (default). In this
#' mode, the search gives results only from the entities that have a code.
#' The system will search all index terms of an entity. i.e. *titles*,
#' *synonyms*, *fully specified term*, all terms of other entities that are in
#' the foundation are aggregated into this entity. By default, *chapters 26*,
#' *V*, and *X* are not included in the search results. If `medical_mode` is
#' set to FALSE, then the `properties` argument will need to be specified
#' (see next section).
#'
#' @section properties: In the Foundation search, by default the function
#' @section On `properties`: In the Foundation search, by default the function
#' searches *"Title"*, *"Synonyms"*, and *"FullySpecifiedName"*. The valid
#' values that could be used for properties are: *"Title"*, *"Synonym"*,
#' *"NarrowerTerm"*, *"FullySpecifiedName"*, *"Definition"*, and
#' *"Exclusion"*. In the MMS search, this argument is only used when
#' `medical_coding_mode = FALSE`. The valid values that could be used are:
#' `medical_mode = FALSE`. The valid values that could be used are:
#' *"Title"*, *"FullySpecifiedName"*, *"Definition"*, *"Exclusion"*, and
#' *"IndexTerm"*. If *"IndexTerm"* is used, the search will be performed on
#' all *"Titles"*, *"Synonyms"*, and *"FullySpecifiedNames"* including the
Expand All @@ -47,9 +47,6 @@
#' 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 subtree A string or vector of strings of URIs. If provided, the
Expand All @@ -66,13 +63,13 @@
#' ICD-11 hierarchy. Otherwise they are listed as flat list of matches.
#' @param keyword Logical. Default is FALSE. Should search results show keyword
#' list? See section on `keyword` for more details.
#' @param medical_coding_mode Logical. Default is FALSE. Should medical coding
#' @param medical_mode Logical. Default is FALSE. Should medical coding
#' mode be turned on?
#' @param properties A string or a vector of strings for the properties to be
#' searched. When set to NULL (default), search is performed on a default
#' set of properties depending on whether foundation or linearization (see
#' section on `properties` for more details). Should be set/specified if
#' `medical_coding_mode = FALSE`.
#' `medical_mode = FALSE`.
#' @param release A string specifying the release version of the Foundation to
#' search from. If not specified, defaults to the latest release version. See
#' the available versions with `icd_versions`.
Expand Down Expand Up @@ -210,7 +207,7 @@ icd_search_mms <- function(q,
flat = TRUE,
release = NULL,
highlight = FALSE,
medical_coding_mode = TRUE,
medical_mode = TRUE,
properties = NULL,
api_version = c("v2", "v1"),
language = "en",
Expand Down Expand Up @@ -265,7 +262,7 @@ icd_search_mms <- function(q,
)

### Medical coding mode and Properties ----
if (!medical_coding_mode) {
if (!medical_mode) {
req <- req |>
httr2::req_url_query(medicalCodingMode = "false")
if (!is.null(properties)) {
Expand All @@ -274,7 +271,9 @@ icd_search_mms <- function(q,
propertiesToBeSearched = paste(properties, collapse = ",")
)
} else {
stop("The `properties` argument needs to be specified if `medical_coding_mode = FALSE`")
stop(
"The `properties` argument needs to be specified if `medical_mode = FALSE`"
)
}
} else {
req <- req |>
Expand Down
34 changes: 17 additions & 17 deletions man/icd_search.Rd

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

File renamed without changes.
85 changes: 77 additions & 8 deletions tests/testthat/test-search.R
Original file line number Diff line number Diff line change
@@ -1,43 +1,45 @@
# Test search function/s -------------------------------------------------------

## Foundation ----

test_search_default <- icd_search_foundation(q = "cholera")

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

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

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

testthat::expect_type(test_search_list, "list")

## Test release specification ----
### Test release specification ----
test_search_release <- icd_search_foundation(q = "cholera", release = "2024-01")
testthat::expect_message(icd_search_foundation(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_foundation(q = "cholera", release = "2025-01"))

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

## Test subtrees query ----
### Test subtrees query ----
test_search_subtree <- icd_search_foundation(q = "cholera", subtree = "http://id.who.int/icd/entity/1435254666")
testthat::expect_message(icd_search_foundation(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 chapter query ----
test_search_chapter <- icd_search_foundation(q = "cholera", chapter = "01")
testthat::expect_message(icd_search_foundation(q = "cholera", chapter = "01"))
testthat::expect_s3_class(test_search_chapter, "tbl_df")
testthat::expect_type(test_search_chapter, "list")

## Test properties query ----
### Test properties query ----
test_search_property <- icd_search_foundation(
q = "cholera",
properties = c(
Expand All @@ -48,3 +50,70 @@ test_search_property <- icd_search_foundation(
testthat::expect_s3_class(test_search_property, "tbl_df")
testthat::expect_type(test_search_property, "list")


## Linearization - MMS ----

test_search_default <- icd_search_mms(q = "cholera")

### Test message ----
testthat::expect_message(icd_search_mms(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))

### Test list output ----
test_search_list <- icd_search_mms(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"))
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"))

### Test language specification ----
testthat::expect_warning(icd_search_mms(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"))
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"))
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(
q = "cholera",
properties = c(
"Title","Synonym", "NarrowerTerm", "FullySpecifiedName",
"Definition", "Exclusion"
)
)
testthat::expect_s3_class(test_search_property, "tbl_df")
testthat::expect_type(test_search_property, "list")

### Test medical_mode ----

testthat::expect_s3_class(
icd_search_mms(
q = "cholera",
medical_mode = FALSE,
properties = c("Title","Definition", "IndexTerm")
),
"tbl_df"
)

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

0 comments on commit 4bd56ba

Please sign in to comment.