Skip to content

Commit

Permalink
Merge pull request #98 from OxfordIHTM/dev
Browse files Browse the repository at this point in the history
create wrappers for icd-10 api endpoints
  • Loading branch information
ernestguevarra authored Apr 23, 2024
2 parents 99217ed + 4b02ce0 commit 24317ca
Show file tree
Hide file tree
Showing 10 changed files with 309 additions and 7 deletions.
10 changes: 6 additions & 4 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ Type: Package
Title: Interface to the International Classification of Diseases (ICD) API
Version: 0.0.0.9000
Authors@R: c(
person("Anita", "Makori", email = "",
role = c("aut", "cph")),
person("Anita", "Makori", role = c("aut", "cph")),
person("Ernest", "Guevarra",
comment = c(ORCID = "0000-0002-4887-4415"),
email = "[email protected]", role = c("aut", "cre", "cph")))
email = "[email protected]", role = c("aut", "cre", "cph")),
person("Sanjeev", "Pugazhendhi", role = c("ths", "rev")),
person("Williams", "Udoh Ituen-Umanah", role = "rev"),
person("Proochista", "Ariana", role = c("rev", "cph")))
Description: The International Classification of Diseases (ICD) serves a broad
range of uses globally and provides critical knowledge on the extent, causes
and consequences of human disease and death worldwide via data that is
Expand All @@ -34,7 +36,7 @@ LazyData: true
Language: en-GB
RoxygenNote: 7.3.1
Roxygen: list(markdown = TRUE)
URL: https://oxford-ihtm.io/codigo/,https://github.com/OxfordIHTM/codigo
URL: https://oxford-ihtm.io/codigo/, https://github.com/OxfordIHTM/codigo
BugReports: https://github.com/OxfordIHTM/codigo/issues
Config/testthat/edition: 3
VignetteBuilder: knitr
4 changes: 4 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Generated by roxygen2: do not edit by hand

export(icd_10_get_chapters)
export(icd_10_get_info)
export(icd_10_get_release_by_category)
export(icd_10_get_releases)
export(icd_authenticate)
export(icd_autocode)
export(icd_autocode_foundation)
Expand Down
186 changes: 186 additions & 0 deletions R/icd_10_get.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
#'
#' Get available ICD-10 releases
#'
#' @param release A string specifying the release version of ICD-10 to search
#' from. If not specified, defaults to the latest release version. See
#' the available versions with `icd_versions`.
#' @param api_version Version of the API. Possible values are `v1` or `v2`.
#' For example, if you provide value v2, the API will respond in the format of
#' the version 2 of the API. Default is `v2`.
#' @param language ICD-API is multi-lingual. By changing this header, you may
#' make the API respond in different languages. Languages will be available as
#' the translations of ICD-11 completes. The values are language codes such as
#' en, es, zh, etc. Depending on the `release_id` specified, the available
#' languages will vary. Default is English ("en"). Note that language support
#' for ICD-10 is limited to English (`en`).
#' @param category ICD-10 category code or for blocks, the code range.
#' @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 scope Scopes to be requested from the resource owner. Default is
#' *"icdapi_access"* as specified in the ICD API documentation.
#'
#' @returns A list with information on specified ICD 10 parameters
#'
#' @examples
#' icd_10_get_releases()
#' icd_10_get_chapters()
#' icd_10_get_release_by_category(category = "A00")
#' icd_10_get_release_by_category(category = "A00-A09")
#' icd_10_get_info(category = "A00")
#' icd_10_get_info(category = "A00-A09")
#'
#' @rdname icd_10_get
#' @export
#'
#'

icd_10_get_releases <- function(api_version = c("v2", "v1"),
base_url = "https://id.who.int",
client = icd_oauth_client(),
scope = "icdapi_access") {
## Get API version to use ----
api_version <- match.arg(api_version)

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

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

## Return response ----
resp
}


#'
#' @rdname icd_10_get
#' @export
#'

icd_10_get_chapters <- function(release = NULL,
api_version = c("v2", "v1"),
language = "en",
base_url = "https://id.who.int",
client = icd_oauth_client(),
scope = "icdapi_access") {
## Get API version to use ----
api_version <- match.arg(api_version)

## Check release identifier ----
if (!is.null(release))
icd_check_release(release)
else
release <- icd_get_releases(icd = "icd10", 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/10", release) |>
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
}


#'
#' @rdname icd_10_get
#' @export
#'

icd_10_get_release_by_category <- function(category,
api_version = c("v2", "v1"),
base_url = "https://id.who.int",
client = icd_oauth_client(),
scope = "icdapi_access") {
## Get API version to use ----
api_version <- match.arg(api_version)

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

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

## Return response ----
resp
}


#'
#' @rdname icd_10_get
#' @export
#'

icd_10_get_info <- function(release = NULL,
category,
api_version = c("v2", "v1"),
language = "en",
base_url = "https://id.who.int",
client = icd_oauth_client(),
scope = "icdapi_access") {
## Get API version to use ----
api_version <- match.arg(api_version)

## Check release identifier ----
if (!is.null(release))
icd_check_release(release)
else
release <- icd_get_releases(icd = "icd10", 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/10", release, category) |>
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
}
2 changes: 1 addition & 1 deletion README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ knitr::opts_chunk$set(
[![Project Status: WIP – Initial development is in progress, but there has not yet been a stable, usable release suitable for the public.](https://www.repostatus.org/badges/latest/wip.svg)](https://www.repostatus.org/#wip)
[![Lifecycle: experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://lifecycle.r-lib.org/articles/stages.html#experimental)
[![R-CMD-check](https://github.com/OxfordIHTM/icd/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/OxfordIHTM/icd/actions/workflows/R-CMD-check.yaml)
[![Codecov test coverage](https://codecov.io/gh/OxfordIHTM/codigo/branch/main/graph/badge.svg)](https://app.codecov.io/gh/OxfordIHTM/codigo?branch=main)
[![test-coverage](https://github.com/OxfordIHTM/icd/actions/workflows/test-coverage.yaml/badge.svg)](https://github.com/OxfordIHTM/icd/actions/workflows/test-coverage.yaml)
[![Codecov test coverage](https://codecov.io/gh/OxfordIHTM/codigo/branch/main/graph/badge.svg)](https://app.codecov.io/gh/OxfordIHTM/codigo?branch=main)
[![CodeFactor](https://www.codefactor.io/repository/github/oxfordihtm/codigo/badge)](https://www.codefactor.io/repository/github/oxfordihtm/codigo)
<!-- badges: end -->

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ public.](https://www.repostatus.org/badges/latest/wip.svg)](https://www.repostat
[![Lifecycle:
experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://lifecycle.r-lib.org/articles/stages.html#experimental)
[![R-CMD-check](https://github.com/OxfordIHTM/icd/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/OxfordIHTM/icd/actions/workflows/R-CMD-check.yaml)
[![test-coverage](https://github.com/OxfordIHTM/icd/actions/workflows/test-coverage.yaml/badge.svg)](https://github.com/OxfordIHTM/icd/actions/workflows/test-coverage.yaml)
[![Codecov test
coverage](https://codecov.io/gh/OxfordIHTM/codigo/branch/main/graph/badge.svg)](https://app.codecov.io/gh/OxfordIHTM/codigo?branch=main)
[![test-coverage](https://github.com/OxfordIHTM/icd/actions/workflows/test-coverage.yaml/badge.svg)](https://github.com/OxfordIHTM/icd/actions/workflows/test-coverage.yaml)
[![CodeFactor](https://www.codefactor.io/repository/github/oxfordihtm/codigo/badge)](https://www.codefactor.io/repository/github/oxfordihtm/codigo)
<!-- badges: end -->

Expand Down
5 changes: 5 additions & 0 deletions data-raw/icd_mapping_tables.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,8 @@ unzip(
overwrite = TRUE,
exdir = "data-raw/icd-mapping"
)


map_to_multiple <- read_xlsx(
file = "data-raw/icd-mapping/10To11MapToMultipleCategories.xlsx", sheeet = 1
)
4 changes: 4 additions & 0 deletions inst/WORDLIST
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
Autocode
Autocoding
BlockId
BrowserLink
Expand All @@ -18,6 +19,7 @@ IHTM
IndexTerm
IsLeaf
IsResidual
Ituen
Lifecycle
LinearizationMiniOutput
NarrowerTerm
Expand All @@ -27,6 +29,8 @@ PrimaryLocation
SimpleTabulation
SupportedClassifications
URIs
Udoh
Umanah
WIP
api
autocode
Expand Down
10 changes: 9 additions & 1 deletion man/codigo.Rd

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

86 changes: 86 additions & 0 deletions man/icd_10_get.Rd

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

7 changes: 7 additions & 0 deletions pkgdown/_pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,13 @@ reference:
- icd_get_entity
- icd_get_info

- title: Get ICD-10
contents:
- icd_10_get_releases
- icd_10_get_chapters
- icd_10_get_release_by_category
- icd_10_get_info

- title: Structure
contents:
- icd_structure_foundation
Expand Down

0 comments on commit 24317ca

Please sign in to comment.