diff --git a/DESCRIPTION b/DESCRIPTION index f657e21..a40f59c 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -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 = "ernest@guevarra.io", role = c("aut", "cre", "cph"))) + email = "ernest@guevarra.io", 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 @@ -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 diff --git a/NAMESPACE b/NAMESPACE index 6209817..2cc47be 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -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) diff --git a/R/icd_10_get.R b/R/icd_10_get.R new file mode 100644 index 0000000..f8e6465 --- /dev/null +++ b/R/icd_10_get.R @@ -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 +} diff --git a/README.Rmd b/README.Rmd index f1c9c8a..72c010c 100644 --- a/README.Rmd +++ b/README.Rmd @@ -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) diff --git a/README.md b/README.md index 36859a8..3457f6c 100644 --- a/README.md +++ b/README.md @@ -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) diff --git a/data-raw/icd_mapping_tables.R b/data-raw/icd_mapping_tables.R index 95b11f0..b968250 100644 --- a/data-raw/icd_mapping_tables.R +++ b/data-raw/icd_mapping_tables.R @@ -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 +) diff --git a/inst/WORDLIST b/inst/WORDLIST index 6858685..e9c23d1 100644 --- a/inst/WORDLIST +++ b/inst/WORDLIST @@ -1,3 +1,4 @@ +Autocode Autocoding BlockId BrowserLink @@ -18,6 +19,7 @@ IHTM IndexTerm IsLeaf IsResidual +Ituen Lifecycle LinearizationMiniOutput NarrowerTerm @@ -27,6 +29,8 @@ PrimaryLocation SimpleTabulation SupportedClassifications URIs +Udoh +Umanah WIP api autocode diff --git a/man/codigo.Rd b/man/codigo.Rd index f0e7e75..0d1918d 100644 --- a/man/codigo.Rd +++ b/man/codigo.Rd @@ -16,7 +16,8 @@ the ICD API. \seealso{ Useful links: \itemize{ - \item \url{https://oxford-ihtm.io/codigo/,https://github.com/OxfordIHTM/codigo} + \item \url{https://oxford-ihtm.io/codigo/} + \item \url{https://github.com/OxfordIHTM/codigo} \item Report bugs at \url{https://github.com/OxfordIHTM/codigo/issues} } @@ -29,5 +30,12 @@ Authors: \item Anita Makori [copyright holder] } +Other contributors: +\itemize{ + \item Sanjeev Pugazhendhi [thesis advisor, reviewer] + \item Williams Udoh Ituen-Umanah [reviewer] + \item Proochista Ariana [reviewer, copyright holder] +} + } \keyword{internal} diff --git a/man/icd_10_get.Rd b/man/icd_10_get.Rd new file mode 100644 index 0000000..bf0e697 --- /dev/null +++ b/man/icd_10_get.Rd @@ -0,0 +1,86 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/icd_10_get.R +\name{icd_10_get_releases} +\alias{icd_10_get_releases} +\alias{icd_10_get_chapters} +\alias{icd_10_get_release_by_category} +\alias{icd_10_get_info} +\title{Get available ICD-10 releases} +\usage{ +icd_10_get_releases( + api_version = c("v2", "v1"), + base_url = "https://id.who.int", + client = icd_oauth_client(), + scope = "icdapi_access" +) + +icd_10_get_chapters( + release = NULL, + api_version = c("v2", "v1"), + language = "en", + base_url = "https://id.who.int", + client = icd_oauth_client(), + scope = "icdapi_access" +) + +icd_10_get_release_by_category( + category, + api_version = c("v2", "v1"), + base_url = "https://id.who.int", + client = icd_oauth_client(), + scope = "icdapi_access" +) + +icd_10_get_info( + release = NULL, + category, + api_version = c("v2", "v1"), + language = "en", + base_url = "https://id.who.int", + client = icd_oauth_client(), + scope = "icdapi_access" +) +} +\arguments{ +\item{api_version}{Version of the API. Possible values are \code{v1} or \code{v2}. +For example, if you provide value v2, the API will respond in the format of +the version 2 of the API. Default is \code{v2}.} + +\item{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.} + +\item{client}{The OAuth2 client produced through a call to +\code{icd_oauth_client()}.} + +\item{scope}{Scopes to be requested from the resource owner. Default is +\emph{"icdapi_access"} as specified in the ICD API documentation.} + +\item{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 \code{icd_versions}.} + +\item{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 \code{release_id} specified, the available +languages will vary. Default is English ("en"). Note that language support +for ICD-10 is limited to English (\code{en}).} + +\item{category}{ICD-10 category code or for blocks, the code range.} +} +\value{ +A list with information on specified ICD 10 parameters +} +\description{ +Get available ICD-10 releases +} +\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") + +} diff --git a/pkgdown/_pkgdown.yml b/pkgdown/_pkgdown.yml index 478c78c..ff79326 100644 --- a/pkgdown/_pkgdown.yml +++ b/pkgdown/_pkgdown.yml @@ -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