Ranges of ICD-9 codes

These internal functions generate ranges of valid ICD-9 codes, without including parent codes when the range limit would subset the parent. These were primarily designed to accurately reflect definitions for comorbidity maps. For example, the published article defining Quan’s version of the Elixhauser comorbidities includes the following expression as part of the definition of the arrythmia comorbidity: 746.3 – 746.6.

The functions can be used by running devtools::load_all() from the icd source tree available from github, or by using the

Using icd, we can use this shortcut to expand decimal ICD-9 codes to all possible child codes:

"746.3" %i9da% "746.6"
# equivalent to:
identical("746.3" %i9da% "746.6",
  icd:::expand_range("746.3", "746.6", defined = FALSE))

This includes all possible codes, not just the ones that have been explicitly defined: this is important in correctly assigning new or slightly incorrect ICD codes in the right comorbidity). In contrast, the same expression using just defined codes gives:

If a country adds more detail, e.g., a new code 746.60, we want to capture this as an arrythmia comorbidity, even though the USA or WHO schemes do not include it. For this reason, icd expands out all the possible codes for each ICD-9 comorbidity in the included maps. (ICD-10 codes cannot be expanded this way in the maps due to the very large number of permutations, but the equivalent is done during the computation of comorbidities.)

Ranges spanning higher-level codes

Another problem is whether to include broader parent codes when a range does not include all the children: e.g., "100.99" %i9da% "101.01" does not include 100 or 100.0, both of which imply larger subsets than requested by the range command (i.e., every code from 100.00 to 100.99). The shorter forms %i9s% and %i9d% return only real codes (i.e., listed in the CMS definitions as either three-digit codes or diagnoses), whereas %i9sa% and %i9da% return all possible syntactically valid ICD-9 codes:

This is used internally to interpret ranges of ICD-9 codes specified in the literature. Sometimes it is not clear exactly what an ICD-9 range presented in a paper means, but at least we can explicitly decide what should be included in our interpretation, and the ranges can be reused even when the underlying codes may be different, as codes are added and removed from time-to-time, and although the original papers would have been based on their ICD-9 ranges resolving to a specific set of codes, they are likely to be valid for new diagnoses in the given subgroups. Ultimately, this needs detailed attention, but the strategy in is to give a good best guess, given these limitations.

Finding codes in hierarchy

It is easy to find the children of a higher-level ICD-9 code:

By adding defined = TRUE, all syntactically valid ICD-9 codes are returned, even if not defined by CMS as diagnoses. This is relevant because of minor coding errors, or coding in a different year to the master list. A planned feature is to allow testing of an ICD-9 code against the valid codes for the year it was entered, but at present only the 2014 master list is used. This means that some older valid codes may no longer be on the list. However, there have been very few changes to ICD-9-CM in the last five years with ICD-10-CM in the wings.

condense is the reverse operation to children. You need to specify whether you want to consider all possible children or just defined codes.