Skip to content

Commit

Permalink
wrap linearization chapter endpoint; fix #82
Browse files Browse the repository at this point in the history
  • Loading branch information
ernestguevarra committed Mar 20, 2024
1 parent 4205c4b commit 3fd41a4
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 1 deletion.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export(icd_autocode)
export(icd_autocode_foundation)
export(icd_check_language)
export(icd_check_release)
export(icd_get_chapter)
export(icd_get_entities)
export(icd_get_entity)
export(icd_get_foundation)
Expand Down
43 changes: 43 additions & 0 deletions R/icd_get.R
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
#' icd_get_entity(id = "1465325727") ## category; depth 1
#' icd_get_info()
#' icd_get_info("icf")
#' icd_get_chapter()
#' icd_get_chapter("icf")
#'
#' @rdname icd_get
#' @export
Expand Down Expand Up @@ -197,3 +199,44 @@ icd_get_info <- function(linearization = c("mms", "icf"),
#' @rdname icd_get
#' @export
#'
icd_get_chapter <- function(linearization = c("mms", "icf"),
release = NULL,
api_version = c("v2", "v1"),
language = "en",
base_url = "https://id.who.int",
client = icd_oauth_client(),
scope = "icdapi_access") {
## Get linearization to search ----
linearization <- match.arg(linearization)

## Get API version to use ----
api_version <- match.arg(api_version)

## Check release identifier ----
if (!is.null(release))
icd_check_release(release)

Check warning on line 217 in R/icd_get.R

View check run for this annotation

Codecov / codecov/patch

R/icd_get.R#L217

Added line #L217 was not covered by tests
else
release <- icd_get_releases(latest = TRUE) |> dplyr::pull()

## Check language ----
if (!is.null(language))
icd_check_language(release = release, language = language)

## Make base request ----
req <- httr2::request(base_url) |>
httr2::req_url_path("icd/release/11", release, linearization) |>
httr2::req_headers(
Accept = "application/json",
"API-Version" = api_version,
"Accept-Language" = language
)

## Authenticate and perform request ----
resp <- req |>
icd_authenticate(client = client, scope = scope) |>
httr2::req_perform() |>
httr2::resp_body_json()

## Return response ----
resp
}
13 changes: 13 additions & 0 deletions man/icd_get.Rd

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

9 changes: 8 additions & 1 deletion tests/testthat/test-get.R
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@ testthat::expect_true(
all(c("ancestor", "descendant") %in% names(test_get_entity_include))
)

## Test icd_get_release ----
## Test icd_get_info ----

testthat::expect_type(icd_get_info(), "list")

## Test icd_get_chapter ----

testthat::expect_type(icd_get_chapter(), "list")



0 comments on commit 3fd41a4

Please sign in to comment.