Last active
October 4, 2018 15:31
-
-
Save gweissman/63a162b64969f56b33ce5f6e0c13f51c to your computer and use it in GitHub Desktop.
Convert a list of icd9 codes associated with poor prognosis cancers to icd10 codes using the 2016 General Equivalency Mappings from CMS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Convert ICD 9 to ICD 10 codes based on the CMS General Equivalency Mappings 2016 | |
# https://www.cms.gov/Medicare/Coding/ICD10/2016-ICD-10-CM-and-GEMs.html | |
library(data.table) | |
library(icd) | |
gem <- fread('~/Desktop/SCIP - Study of Critical Illness Pathways/2018-redo/final_code/2016-General-Equivalence-Mappings/2016_I9gem.txt', | |
colClasses = rep('character',3)) | |
setnames(gem, c('icd9', 'icd10', 'flags_composite')) | |
# these flags defined in the enclosed documentation | |
gem[, flag_approximate := substr(flags_composite, 1, 1) == '1'] # 0/1 | |
gem[, flag_nomap := substr(flags_composite, 2, 2) == '1'] # 0/1 | |
gem[, flag_combination := substr(flags_composite, 3, 3) == '1'] # 0/1 | |
gem[, scenario_code := substr(flags_composite, 4, 4)] # 0-9 | |
gem[, choice_list_code := substr(flags_composite, 5, 5)] # 0-9 | |
# | |
#Combination flag—attribute in a GEM that when turned on indicates that more than one code in the target system is required to satisfy the full equivalent meaning of a code in the source system | |
#Combination entry—an entry in a GEM for which a code in the source system must be linked to more than one code option in the target system to be a valid entry | |
# See Obermeyer Z, Powers BW, Makar M, Keating NL, Cutler DM. Physician characteristics strongly predict patient enrollment in hospice. Health Aff (Millwood). 2015;34(6), Supplemental Table 1: | |
icd9_codes <- c("1500", "1501", "1502", "1503", "1504", "1505", "1508", | |
"1509", "151", "1510", "1511", "1512", "1513", "1514", | |
"1515", "1516", "1518", "1519", "155", "1550", "1551", | |
"1552", "1570", "1571", "1572", "1573", "1574", "1578", | |
"1579", "1580", "1588", "1589", "159", "1590", "1591", | |
"1598", "1599", "1620", "1622", "1623", "1624", "1625", | |
"1628", "1629", "1630", "1631", "1638", "1639", "1641", | |
"1642", "1643", "1648", "1649", "1650", "1658", "1659", | |
"191", "1910", "1911", "1912", "1913", "1914", "1915", | |
"1916", "1917", "1918", "1919", "195", "1951", "1952", | |
"1953", "1958", "1973", "1974", "1975", "1976", "1977", | |
"1978", "1980", "1981", "1982", "1983", "1984", "1985", | |
"1986", "1987", "1988", "19881", "19882", "19889", "1990", | |
"1991", "1992", "20500", "20502", "20520", "20522", "20530", | |
"20532", "20580", "20582", "20590", "20592", "20780", "20800", | |
"20880", "20890", "20892", "2375", "23873", "2391", "2396", | |
"78951") | |
# Run checks: | |
cat('There are', length(icd9_codes), 'codes available for lookup.') | |
cat('There are', sum(icd9_codes %in% gem$icd9), ' codes found in the GEM file.') | |
cat('Of the',sum(icd9_codes %in% gem$icd9),'matches,',gem[icd9 %in% icd9_codes, sum(!flag_nomap),by=icd9][, sum(V1>=1)],'have mappings.') | |
cat('Of the',sum(icd9_codes %in% gem$icd9),'matches,',gem[icd9 %in% icd9_codes, sum(!flag_nomap),by=icd9][, sum(V1>1)],'map to multiple codes.') | |
cat('Of the', sum(icd9_codes %in% gem$icd9), 'matches,', gem[icd9 %in% icd9_codes, sum(flag_combination),by=icd9][,sum(V1>0)],'require a combination of ICD10 codes to match.') | |
# The final mapping to ICD10 includes: | |
final_list_icd10 <- gem[icd9 %in% icd9_codes]$icd10 | |
# and a manual review: | |
knitr::kable(data.table(icd10 = final_list_icd10, | |
description = sapply(final_list_icd10, explain_code))) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment