Learn R Programming

icd (version 4.0.6)

is_valid: Check whether ICD-9 codes are syntactically valid

Description

These functions check whether the given ICD codes look correct, but do not check whether they have actual definitions in any particular ICD scheme. For that, see is_defined.

Usage

is_valid(x, ...)

# S3 method for icd10 is_valid(x, short_code = guess_short(x), whitespace_ok = TRUE, re_short = re_icd10_short, re_decimal = re_icd10_decimal, ...)

# S3 method for icd10fr is_valid(x, short_code = guess_short(x), whitespace_ok = TRUE, ...)

# S3 method for icd9 is_valid(x, short_code = guess_short(x), whitespace_ok = TRUE, ...)

# S3 method for comorbidity_map is_valid(x, short_code, ...)

Arguments

x

An ICD-9 or 10 code. If the class is set to 'icd9', 'icd10', 'icd10cm' etc then perform appropriate validation.

...

arguments passed on to other functions

whitespace_ok

Single logical, if TRUE, the default, matches for ICD codes will accept leading and trailing white space.

major

character vector of 'major' part of ICD-9 codes, i.e. that part which falls before the decimal point, in decimal notation. (In five digit notation, the 'major' part is be the first three characters (with leading zeroes), and includes V or E prefix.

Value

logical vector with TRUE or FALSE for each ICD code provided according to its validity

Methods (by class)

  • icd10: Test whether generic ICD-10 code is valid

  • icd10fr: Test whether generic ICD-10-FR code is valid

  • icd9: Test whether generic ICD-10 code is valid

  • comorbidity_map: Validate a mapping of ICD codes to comorbidities.

Three-digit validation

icd9_is_valid_major validates just the 'major' three-digit part of an ICD-9 code. This can in fact be provided as a numeric, since there is no ambiguity. Numeric-only codes should be one to three digits, V codes are followed by one or two digits, and E codes always by three digits between 800 and 999.

<code>NA</code> values

Currently, there is a limitation on NA values. Calling with NA (which is a logical vector of length one by default) fails, because it is not a string. This is rarely of significance in real life, since the NA will be part of a character vector of codes, and will therefore be cast already to NA_character

Class

S3 class of on object in R is just a vector. Attributes are lost with manipulation, with the exception of class: therefore, elements of the class vector are used to describe features of the data. If these are not present, the user may specify (e.g. decimal vs short_code type, ICD-9 vs ICD-10 WHO), but if they are, the correct functions are called without any guess work. There is overlap between sets with combinations of short_code or decimal_code, and ICD-9 or ICD-10 codes, so guessing is never going to be perfect.

Details

Leading zeroes in the decimal form are not ambiguous. Although integer ICD-9 codes could be intended by the user, there is a difference between 100, 100.0, 100.00. Therefore a warning is given if a numeric value is provided.

See Also

http://www.stata.com/users/wgould/icd9/icd9.hlp http://www.sascommunity.org/wiki/Validate_the_format_of_ICD-9_codes

Examples

Run this code
# NOT RUN {
is_valid(as.icd9(c(
  "", "1", "22", "333", "4444", "123.45", "V",
  "V2", "V34", "V567", "E", "E1", "E70", "E"
)))
# internal function:
icd:::is_valid_major(c(
  "", "1", "22", "333", "4444", "123.45", "V",
  "V2", "V34", "V567", "E", "E1", "E70", "E"
))
# }

Run the code above in your browser using DataLab