From 1656cb7e2d17bd2fe676671bd357837bb2225dcb Mon Sep 17 00:00:00 2001 From: Ernest Guevarra Date: Wed, 20 Mar 2024 13:46:54 +0000 Subject: [PATCH 1/3] create initials tests for linearization mms search --- .../{test-icd_autocode.R => test-autocode.R} | 0 tests/testthat/test-search.R | 68 ++++++++++++++++--- 2 files changed, 60 insertions(+), 8 deletions(-) rename tests/testthat/{test-icd_autocode.R => test-autocode.R} (100%) diff --git a/tests/testthat/test-icd_autocode.R b/tests/testthat/test-autocode.R similarity index 100% rename from tests/testthat/test-icd_autocode.R rename to tests/testthat/test-autocode.R diff --git a/tests/testthat/test-search.R b/tests/testthat/test-search.R index 80ca8a9..550ace9 100644 --- a/tests/testthat/test-search.R +++ b/tests/testthat/test-search.R @@ -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( @@ -48,3 +50,53 @@ 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") From 542a2157f8eaea95d088aa635167cefc19c39d36 Mon Sep 17 00:00:00 2001 From: Ernest Guevarra Date: Wed, 20 Mar 2024 14:07:01 +0000 Subject: [PATCH 2/3] add more tests for linearization mms search --- R/icd_search.R | 39 ++++++++++++++++++------------------ man/icd_search.Rd | 34 +++++++++++++++---------------- tests/testthat/test-search.R | 11 ++++++++++ 3 files changed, 47 insertions(+), 37 deletions(-) diff --git a/R/icd_search.R b/R/icd_search.R index 776be3e..6242815 100644 --- a/R/icd_search.R +++ b/R/icd_search.R @@ -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 @@ -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 @@ -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 @@ -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`. @@ -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", @@ -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)) { @@ -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 |> diff --git a/man/icd_search.Rd b/man/icd_search.Rd index dac2984..2b960dc 100644 --- a/man/icd_search.Rd +++ b/man/icd_search.Rd @@ -33,7 +33,7 @@ icd_search_mms( flat = TRUE, release = NULL, highlight = FALSE, - medical_coding_mode = TRUE, + medical_mode = TRUE, properties = NULL, api_version = c("v2", "v1"), language = "en", @@ -66,7 +66,7 @@ ICD-11 hierarchy. Otherwise they are listed as flat list of matches.} searched. When set to NULL (default), search is performed on a default set of properties depending on whether foundation or linearization (see section on \code{properties} for more details). Should be set/specified if -\code{medical_coding_mode = FALSE}.} +\code{medical_mode = FALSE}.} \item{release}{A string specifying the release version of the Foundation to search from. If not specified, defaults to the latest release version. See @@ -105,7 +105,7 @@ use foundation descendants (TRUE) or linearization descendants (FALSE)?} \item{keyword}{Logical. Default is FALSE. Should search results show keyword list? See section on \code{keyword} for more details.} -\item{medical_coding_mode}{Logical. Default is FALSE. Should medical coding +\item{medical_mode}{Logical. Default is FALSE. Should medical coding mode be turned on?} } \value{ @@ -114,9 +114,9 @@ A tibble of search results. \description{ Search the foundation component of the ICD-11 } -\section{flexisearch}{ - In the regular search mode (\code{flexisearch = FALSE}), the -function will only give you results that contain all of the words that +\section{On \code{flexisearch}}{ + In the regular search mode (\code{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 @@ -126,7 +126,7 @@ are not matched at all. It is recommended to use flexible search only when regular search does not provide a result. } -\section{keyword}{ +\section{On \code{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 @@ -135,25 +135,25 @@ 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. \emph{titles}, \emph{synonyms}, -\emph{fully specified term}, all terms of other entities that are in the -foundation are aggregated into this entity. By default, \emph{chapters 26}, \emph{V}, -and \emph{X} are not included in the search results. If \code{medical_coding_mode} is +\section{On \code{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. \emph{titles}, +\emph{synonyms}, \emph{fully specified term}, all terms of other entities that are in +the foundation are aggregated into this entity. By default, \emph{chapters 26}, +\emph{V}, and \emph{X} are not included in the search results. If \code{medical_mode} is set to FALSE, then the \code{properties} argument will need to be specified (see next section). } -\section{properties}{ +\section{On \code{properties}}{ In the Foundation search, by default the function searches \emph{"Title"}, \emph{"Synonyms"}, and \emph{"FullySpecifiedName"}. The valid values that could be used for properties are: \emph{"Title"}, \emph{"Synonym"}, \emph{"NarrowerTerm"}, \emph{"FullySpecifiedName"}, \emph{"Definition"}, and \emph{"Exclusion"}. In the MMS search, this argument is only used when -\code{medical_coding_mode = FALSE}. The valid values that could be used are: +\code{medical_mode = FALSE}. The valid values that could be used are: \emph{"Title"}, \emph{"FullySpecifiedName"}, \emph{"Definition"}, \emph{"Exclusion"}, and \emph{"IndexTerm"}. If \emph{"IndexTerm"} is used, the search will be performed on all \emph{"Titles"}, \emph{"Synonyms"}, and \emph{"FullySpecifiedNames"} including the diff --git a/tests/testthat/test-search.R b/tests/testthat/test-search.R index 550ace9..e309fef 100644 --- a/tests/testthat/test-search.R +++ b/tests/testthat/test-search.R @@ -100,3 +100,14 @@ test_search_property <- icd_search_mms( ) 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" +) From ac26e58aa45ed85917de0aa2d572eb8ded32faa8 Mon Sep 17 00:00:00 2001 From: Ernest Guevarra Date: Wed, 20 Mar 2024 14:13:56 +0000 Subject: [PATCH 3/3] add more tests for linearization mms search --- tests/testthat/test-search.R | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/testthat/test-search.R b/tests/testthat/test-search.R index e309fef..0ad9608 100644 --- a/tests/testthat/test-search.R +++ b/tests/testthat/test-search.R @@ -111,3 +111,9 @@ testthat::expect_s3_class( ), "tbl_df" ) + +testthat::expect_error( + icd_search_mms( + q = "cholera", + medical_mode = FALSE) +)