suppressWarnings({ suppressPackageStartupMessages({ loadNamespace("knitr") # for opts_chunk only library("icd") library("magrittr") library("utils") }) }) knitr::opts_chunk$set( collapse = TRUE, comment = "#>" )
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:
"746.3" %i9d% "746.6"
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.)
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:
# get all possible codes head("003" %i9sa% "0033", n = 9) # show first 9 of 111 values # just get the ones which correspond to diagnoses (keeping the 3-digit chapters) "494" %i9s% "4941" "10099" %i9sa% "10101" "V10" %i9da% "V10.02" "E987" %i9da% "E988.1" # can't range between different types: "V10" %i9s% "E800" # should throw an error
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 \code{icd9} is to give a good best guess, given these limitations.
Another way of specifying ranges are to use function calls. These are exactly equivalent to the %i9s%
and %i9d%
range operators. This example shows the result when the user specifies a range which would include parents but not all their children:
icd:::expand_range("4820", "4823") # default, equivalent to %i9s% icd:::expand_range("4820", "4823", defined = FALSE) # see the first few differences (which are by definition not 'real' codes): head( setdiff(icd:::expand_range("4820", "4823", defined = FALSE), icd:::expand_range("4820", "4823")))
It is easy to find the children of a higher-level ICD-9 code:
children("391") # mid-level code children("0032") # leaf node has no children, so returns itself children("00320") # pneumococcal pneumonia is a three-digit ICD-9 code with no descendants children("481")
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.
# first ten possible ICD-9 child codes from 391 children("391", defined = FALSE)[1:10]
condense
is the reverse operation to children
. You need to specify whether you want to consider all possible children or just defined codes.
icd::condense(children("0032"), defined = TRUE) codes <- children("0032", defined = FALSE) codes icd::condense(codes, defined = FALSE)
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.