Get started with codigo

This article takes a quick tour of the main features of codigo.

Authenticating with the ICD API

The ICD API uses OAuth2 for authentication. The package has a set of utility functions that support the ICD API authentication specifications leading to the generation of an OAuth2 token. The icd_oauth_client() function is the downstream and user-facing function that creates an ICD OAuth2 client that can be used for token retrieval by future functions that wrap ICD API for entity and linearization information retrieval.

An ICD OAuth2 client can be generated as follows:

icd_oauth_client()

This function uses a built in OAuth2 client created for light use and for purposes of package development and testing.

It is recommended that those intending to use this package for programmatically performing high volume of calls to the ICD API to create their own access keys (client id and client secret) using these instructions.

Then, with your access keys, perform the following commands:

## Create your own OAuth client ----
my_oauth_client <- icd_oauth_client(
  id = "YOUR_CLIENT_ID",
  token_url = "https://icdaccessmanagement.who.int/connect/token",
  secret = "YOUR_CLIENT_SECRET",
  name = "NAME_OF_YOUR_APP"
)

This OAuth2 client can now be used to the various functions in the package that require an OAuth2 client for authentication for making requests to the ICD API.

Autocoding

Autocoding is a focused search that returns results based on the closest match from ICD-11. Autocoding using the ICD Linearization component API endpoint can be done as follows:

icd_autocode("colorectal cancer", client = my_oauth_client)

which gives the following results

#> Release `2024-01` matches a known release for ICD-11.
#> Language `en` is available for the release specified.
#> # A tibble: 1 × 4
#>   searchText        matchLevel matchScore matchType
#>   <chr>                  <int>      <int>     <int>
#> 1 colorectal cancer          3          0         0

Converting ICD-10 codes to ICD-11 and vice versa

If you are working with data that used ICD-10 codes and need these codes to be converted to ICD-11 codes, the icd_map() function assists in performing this. The following code will provide information on what the A00 ICD0-10 code including its ICD-11 counterpart.

icd_map(code = "A00")
#> # A tibble: 1 × 12
#>   icd10_class_kind icd10_depth icd10_code icd10_chapter icd10_title
#>   <chr>            <chr>       <chr>      <chr>         <chr>      
#> 1 category         1           A00        I             Cholera    
#> # ℹ 7 more variables: icd11_class_kind <chr>, icd11_depth <chr>,
#> #   icd11_foundation_uri <chr>, icd11_linearization_uri <chr>,
#> #   icd11_code <chr>, icd11_chapter <chr>, icd11_title <chr>