Skip to contents

To interact with ICD-11 you should first get your token:

library(WHOicd)

#Substitute CLIENT_ID and CLIENT_SECRET by your credentials
token <- get_token(CLIENT_ID, CLIENT_SECRET)

Autocoding text diagnosis

The function for automatically assigning an ICD-11 code from a diagnostic text is icd11_autocode():

#Auto code a diagnostic text such as `cerebrovascular accident`
code_results <- icd11_autocode(token, "Patient with cerebrovascular accident")

Code results is a list with multiple entries. In particular, theCode will give you the ICD-11 code identified:

#Recover the code that matched
code_results |> retrieve("theCode")
#> [1] "8B20"

The matchScore gives you a number between 0 and 1 specifying how good the match is. A perfect match is 1 while no-match would be 0.

#Recover the code that matched
code_results |> retrieve("matchScore")
#> [1] 0.7573679

Information on a code

Once you have the matched code such as 8B20 from the previous section you can look for it with icd11_codeinfo.

#Recover the code that matched
code_info <- icd11_codeinfo(token, code = "8B20")

A lot of information is retrieved from the code:

names(code_info)
#>  [1] "@context"                         "@id"                             
#>  [3] "parent"                           "browserUrl"                      
#>  [5] "code"                             "source"                          
#>  [7] "classKind"                        "postcoordinationScale"           
#>  [9] "title"                            "definition"                      
#> [11] "exclusion"                        "relatedEntitiesInMaternalChapter"
#> [13] "indexTerm"

In particular: * parent gives information of the chapter/section/block this code belongs to, * @id returns the URI which is the main indexing for the code in the online system, * title which is the name of the code, * exclusion which are the conditions not included, * definition provides a medical description of what it means, * browseUrl a link to the online website to search for it * relatedEntitiesInMaternalChapter are related codes in the chapter of maternal disease

You can use the retrieve function or access the elements from the list directly:

code_info |> retrieve("title")
#> [1] "en"                                           
#> [2] "Stroke not known if ischaemic or haemorrhagic"

Searching for codes

The icd11_search() function allows you to search for text and retrieve codes that contain that text. As an example, we can search for all codes containing or related to malaria:

abortion_codes <- icd11_search(token, text = "malaria")

Which you can retrieve() the codes and titles of:

tibble::tibble(
  code = abortion_codes |> retrieve("theCode"),
  title = abortion_codes |> retrieve("title")
)
#> # A tibble: 36 × 2
#>    code   title                                                               
#>    <chr>  <chr>                                                               
#>  1 1F45   Malaria without parasitological confirmation                        
#>  2 1F4Z   Malaria, unspecified                                                
#>  3 1F42.Z Plasmodium malariae malaria without complication                    
#>  4 1F44   Other parasitologically confirmed malaria                           
#>  5 KA64.Y Other specified parasitic diseases in the fetus or newborn          
#>  6 1F40.Z Malaria due to Plasmodium falciparum, unspecified                   
#>  7 1F43   Malaria due to Plasmodium ovale                                     
#>  8 1F41.Z Plasmodium vivax malaria without complication                       
#>  9 QC42.Y Other specified personal history of infectious or parasitic diseases
#> 10 KA64.1 Congenital falciparum malaria                                       
#> # ℹ 26 more rows