R icd package - how to get ICD code explanation for large dataset with repeats

242 Views Asked by At

I have a dataset with ~ 4000 patients and a primary diagnosis given by ICD10 codes. Many of the diagnoses are repeated across patients. I found the "icd" R package.

I'd like it to add a column describing (in words) what the diagnosis is. Note that 2 patients have J12.81.

library(icd)
library(tidyverse)
library(tribble)

mydata <- tribble(
  ~ID, ~ICD10,
  1, "J12.81",
  2, "J44.9",
  3, "J12.81",
  4, "E84.0"
)

desired_output <-tribble(
  ~ID, ~ICD10, ~Description,
  1, "J12.81","Pneumonia due to SARS-associated coronavirus",
  2, "J44.9","Chronic obstructive pulmonary disease, unspecified",
  3, "J12.81","Pneumonia due to SARS-associated coronavirus",
  4, "E84.0","Cystic fibrosis with pulmonary manifestations"
)

I attempted it using this code

desired_output<-mydata %>%
  mutate(description = icd::explain_code(ICD10))

But I get an error description must be size 4 or 1, not 3. Which seems to suggest the explain_code is just getting a list of unique values?

Alternately, is there a way to get an explain_code that outputs the code and description together so I could do a left_join?

1

There are 1 best solutions below

0
On

It's not the explain_code function - it's the explain_table function that will work.

desired_output<-mydata %>%
  mutate(desc = icd::explain_table(ICD10)) %>%
  mutate(description = desc$short_desc) %>%
  select(-desc)