Skip to contents

The function icd_expand takes a data.frame containing ICD codes and optional metadata as input. It returns a data.frame containing all ICD codes at or below the specified level of the hierarchy (e.g. the specification "E11" is expanded to include all three, four and five-digit codes beginning with E11).

Usage

icd_expand(
  icd_in,
  year,
  col_icd = "ICD",
  col_meta = NULL,
  type = "strict",
  ignore_icd_errors = FALSE
)

Arguments

icd_in

Data frame defining ICD codes of interest

year

ICD 10 version

col_icd

Column of icd_in containing ICD codes (Default: ICD)

col_meta

(Optional) Columns containing meta information to retain (e.g. Grouper, age or other criteria for later use). If left NULL, only col_icd is retained.

type

A character string determining how strictly matching should be performed, passed to icd_parse. This must be one of "strict" (str contains a ICD code with no extraneous characters), bounded (str contains an ICD code with a word boundary on both sides) or weak (ICD codes are extracted even if they are contained within a word, e.g. "E10Diabetes" would return "E10"). Default: strict.

ignore_icd_errors

logical. Whether to ignore incorrectly specified input (potentially leading to incomplete output) or stop if any ICD specification does not correspond to a valid ICD code. Default: FALSE, stop on error.

Value

data.frame with columns YEAR, ICD_CODE, ICD_COMPRESSED, ICD_LABEL and, if specified, columns specified by col_meta

See also

icd_history() to historize the output

Examples

# Incomplete or non-terminal codes expand to the right.
# This is useful to specified code blocks in a compact manner
icd_meta <- data.frame(ICD = "R1")
icd_expand(icd_meta, year = 2019)
#> # A tibble: 33 × 7
#>    icd_spec  year icd3  icd_code icd_normcode icd_sub label                     
#>    <chr>    <int> <chr> <chr>    <chr>        <chr>   <chr>                     
#>  1 R1        2019 R10   R10.-    R10          R10     Bauch- und Beckenschmerzen
#>  2 R1        2019 R10   R10.0    R10.0        R100    Akutes Abdomen            
#>  3 R1        2019 R10   R10.1    R10.1        R101    Schmerzen im Bereich des …
#>  4 R1        2019 R10   R10.2    R10.2        R102    Schmerzen im Becken und a…
#>  5 R1        2019 R10   R10.3    R10.3        R103    Schmerzen mit Lokalisatio…
#>  6 R1        2019 R10   R10.4    R10.4        R104    Sonstige und nicht näher …
#>  7 R1        2019 R11   R11      R11          R11     Übelkeit und Erbrechen    
#>  8 R1        2019 R12   R12      R12          R12     Sodbrennen                
#>  9 R1        2019 R13   R13.-    R13          R13     Dysphagie                 
#> 10 R1        2019 R13   R13.0    R13.0        R130    Dysphagie mit Beaufsichti…
#> # … with 23 more rows

# Optional metadata columns can be carried
# through with the specification
icd_meta <- data.frame(ICD = "M54", icd_label = "Back pain")
icd_expand(icd_meta, year = 2019, col_meta = "icd_label")
#> # A tibble: 50 × 8
#>    icd_spec icd_label  year icd3  icd_code icd_normcode icd_sub label           
#>    <chr>    <chr>     <int> <chr> <chr>    <chr>        <chr>   <chr>           
#>  1 M54      Back pain  2019 M54   M54.-    M54          M54     Rückenschmerzen 
#>  2 M54      Back pain  2019 M54   M54.0-   M54.0        M540    Pannikulitis in…
#>  3 M54      Back pain  2019 M54   M54.00   M54.00       M5400   Pannikulitis in…
#>  4 M54      Back pain  2019 M54   M54.01   M54.01       M5401   Pannikulitis in…
#>  5 M54      Back pain  2019 M54   M54.02   M54.02       M5402   Pannikulitis in…
#>  6 M54      Back pain  2019 M54   M54.03   M54.03       M5403   Pannikulitis in…
#>  7 M54      Back pain  2019 M54   M54.04   M54.04       M5404   Pannikulitis in…
#>  8 M54      Back pain  2019 M54   M54.05   M54.05       M5405   Pannikulitis in…
#>  9 M54      Back pain  2019 M54   M54.06   M54.06       M5406   Pannikulitis in…
#> 10 M54      Back pain  2019 M54   M54.07   M54.07       M5407   Pannikulitis in…
#> # … with 40 more rows