-
Notifications
You must be signed in to change notification settings - Fork 0
/
touch_icd10.py
314 lines (297 loc) · 9 KB
/
touch_icd10.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
import pickle
import re
# function reading in dictionaries generated
def dicts_icd10():
inFile = "icd10_dictionaries.txt"
try:
fhand = open(inFile)
dictNames = [a.strip() for a in fhand.readlines()]
except:
print("Error: failed to open/find", inFile)
exit()
# read in generated dictionaries
for oneDict in dictNames:
try:
with open(oneDict, 'rb') as handle:
tmp = pickle.load(handle)
dictIn = re.sub("dict/icd10_|\.pickle", "", oneDict)
exec("dicts_icd10." + dictIn + " = tmp")
del tmp
except:
print("Error: failed to open/find", oneDict)
exit()
# other constant variables
com1 = [0] * 30
com2 = ["chf", "valve", "pulmcirc", "perivasc", "htn", "htncx", "para",
"neuro", "chrnlung", "dm", "dmcx", "hypothy", "renlfail", "liver",
"ulcer", "aids", "lymph", "mets", "tumor", "arth", "coag", "obese",
"wghtloss", "lytes", "bldloss", "anemdef", "alcohol", "drug",
"psych", "depress"]
como = {}
for i in range(30):
como[com2[i]] = com1[i]
dicts_icd10.como = como
com2.append("htn_c")
com2.remove("htn")
com2.remove("htncx")
dicts_icd10.colNames = com2
# function generating comorbodity measures from icd10 code
def icd10(admission, drg_idx, dx_idx, dicts):
como = dicts.como.copy()
htnpreg_ = 0
htnwochf_ = 0
htnwchf_ = 0
hrenworf_ = 0
hrenwrf_ = 0
hhrwohrf_ = 0
hhrwchf_ = 0
hhrwrf_ = 0
hhrwhrf_ = 0
ohtnpreg_ = 0
for i in dx_idx[1:]:
if admission[i] == "na" or len(admission[i]) == 0:
continue
else:
dx_value = dicts.rcomfmt.get(admission[i], "others")
if dx_value != "others":
como[dx_value] = 1
# detailed hypertension flags
if dx_value == "htnpreg":
htnpreg_ = 1
if dx_value == "htnwochf":
htnwochf_ = 1
if dx_value == "htnwchf":
htnwchf_ = 1
if dx_value == "hrenworf":
hrenworf_ = 1
if dx_value == "hrenwrf":
hrenwrf_ = 1
if dx_value == "hhrwohrf":
hhrwohrf_ = 1
if dx_value == "hhrwchf":
hhrwchf_ = 1
if dx_value == "hhrwrf":
hhrwrf_ = 1
if dx_value == "hhrwhrf":
hhrwhrf_ = 1
if dx_value == "ohtnpreg":
ohtnpreg_ = 1
# Initialize Hypertension, CHF, and Renal Comorbidity flags to 1 using the
# detail hypertension flags.
if htnpreg_ or htnwochf_ or hrenworf_ or hhrwohrf_ or ohtnpreg_:
como["htncx"] = 1
if htnwchf_:
como["htncx"] = 1
como["chf"] = 1
if hrenwrf_ or hhrwrf_:
como["htncx"] = 1
como["renlfail"] = 1
if hhrwchf_:
como["htncx"] = 1
como["chf"] = 1
if hhrwhrf_:
como["htncx"] = 1
como["chf"] = 1
como["renlfail"] = 1
# Set up code to only count the more severe comorbidity
if como["htncx"]:
como["htn"] = 0
if como["mets"]:
como["tumor"] = 0
if como["dmcx"]:
como["dm"] = 0
# Examine DRG and set flags to identify a particular DRG group
drg = admission[drg_idx]
cardflg = 0
periflg = 0
cereflg = 0
nervflg = 0
pulmflg = 0
diabflg = 0
hypoflg = 0
renalflg = 0
renfflg = 0
liverflg = 0
ulceflg = 0
hivflg = 0
leukflg = 0
cancflg = 0
arthflg = 0
nutrflg = 0
anemflg = 0
alcflg = 0
htncxflg = 0
htnflg = 0
coagflg = 0
psyflg = 0
obeseflg = 0
deprsflg = 0
if dicts.carddrg.get(drg, "no") == 'yes':
cardflg = 1
if dicts.peridrg.get(drg, "no") == 'yes':
periflg = 1
if dicts.ceredrg.get(drg, "no") == 'yes':
cereflg = 1
if dicts.nervdrg.get(drg, "no") == 'yes':
nervflg = 1
if dicts.pulmdrg.get(drg, "no") == 'yes':
pulmflg = 1
if dicts.diabdrg.get(drg, "no") == 'yes':
diabflg = 1
if dicts.hypodrg.get(drg, "no") == 'yes':
hypoflg = 1
if dicts.renaldrg.get(drg, "no") == 'yes':
renalflg = 1
if dicts.renfdrg.get(drg, "no") == 'yes':
renfflg = 1
if dicts.liverdrg.get(drg, "no") == 'yes':
liverflg = 1
if dicts.ulcedrg.get(drg, "no") == 'yes':
ulceflg = 1
if dicts.hivdrg.get(drg, "no") == 'yes':
hivflg = 1
if dicts.leukdrg.get(drg, "no") == 'yes':
leukflg = 1
if dicts.cancdrg.get(drg, "no") == 'yes':
cancflg = 1
if dicts.arthdrg.get(drg, "no") == 'yes':
arthflg = 1
if dicts.nutrdrg.get(drg, "no") == 'yes':
nutrflg = 1
if dicts.anemdrg.get(drg, "no") == 'yes':
anemflg = 1
if dicts.alcdrg.get(drg, "no") == 'yes':
alcflg = 1
if dicts.htncxdrg.get(drg, "no") == 'yes':
htncxflg = 1
if dicts.htndrg.get(drg, "no") == 'yes':
htnflg = 1
if dicts.coagdrg.get(drg, "no") == 'yes':
coagflg = 1
if dicts.psydrg.get(drg, "no") == 'yes':
psyflg = 1
if dicts.obesedrg.get(drg, "no") == 'yes':
obeseflg = 1
if dicts.deprsdrg.get(drg, "no") == 'yes':
deprsflg = 1
# Redefining comorbidities by eliminating the DRG directly related to
# comorbidity, thus limiting the screens to principal diagnoses not
# directly related to comorbidity in question
if como["chf"] and cardflg:
como["chf"] = 0
if como["valve"] and cardflg:
como["valve"] = 0
if como["pulmcirc"] and (cardflg or pulmflg):
como["pulmcirc"] = 0
if como["perivasc"] and periflg:
como["perivasc"] = 0
if como["htn"] and htnflg:
como["htn"] = 0
# Apply DRG Exclusions to Hypertension Complicated, Congestive Heart
# Failure, and Renal Failure comorbidities using the detailed hypertension
# flags created above.
if como["htncx"] and htncxflg:
como["htncx"] = 0
if htnpreg_ and htncxflg:
como["htncx"] = 0
if htnwochf_ and (htncxflg or cardflg):
como["htncx"] = 0
if htnwchf_:
if htncxflg:
como["htncx"] = 0
if cardflg:
como["htncx"] = 0
como["chf"] = 0
if hrenworf_ and (htncxflg or renalflg):
como["htncx"] = 0
if hrenwrf_:
if htncxflg:
como["htncx"] = 0
if renalflg:
como["htncx"] = 0
como["renlfail"] = 0
if hhrwohrf_ and (htncxflg or cardflg or renalflg):
como["htncx"] = 0
if hhrwchf_:
if htncxflg:
como["htncx"] = 0
if cardflg:
como["htncx"] = 0
como["chf"] = 0
if renalflg:
como["htncx"] = 0
if hhrwrf_:
if htncxflg or cardflg:
como["htncx"] = 0
if renalflg:
como["htncx"] = 0
como["renlfail"] = 0
if hhrwhrf_:
if htncxflg:
como["htncx"] = 0
if cardflg:
como["htncx"] = 0
como["chf"] = 0
if renalflg:
como["htncx"] = 0
como["renlfail"] = 0
if ohtnpreg_ and (htncxflg or cardflg or renalflg):
como["htncx"] = 0
if como["neuro"] and nervflg:
como["neuro"] = 0
if como["chrnlung"] and pulmflg:
como["chrnlung"] = 0
if como["dm"] and diabflg:
como["dm"] = 0
if como["dmcx"] and diabflg:
como["dmcx"] = 0
if como["hypothy"] and hypoflg:
como["hypothy"] = 0
if como["renlfail"] and renfflg:
como["renlfail"] = 0
if como["liver"] and liverflg:
como["liver"] = 0
if como["ulcer"] and ulceflg:
como["ulcer"] = 0
if como["aids"] and hivflg:
como["aids"] = 0
if como["lymph"] and leukflg:
como["lymph"] = 0
if como["mets"] and cancflg:
como["mets"] = 0
if como["tumor"] and cancflg:
como["tumor"] = 0
if como["arth"] and arthflg:
como["arth"] = 0
if como["coag"] and coagflg:
como["coag"] = 0
if como["obese"] and (nutrflg or obeseflg):
como["obese"] = 0
if como["wghtloss"] and nutrflg:
como["wghtloss"] = 0
if como["lytes"] and nutrflg:
como["lytes"] = 0
if como["bldloss"] and anemflg:
como["bldloss"] = 0
if como["anemdef"] and anemflg:
como["anemdef"] = 0
if como["alcohol"] and alcflg:
como["alcohol"] = 0
if como["drug"] and alcflg:
como["drug"] = 0
if como["psych"] and psyflg:
como["psych"] = 0
if como["depress"] and deprsflg:
como["depress"] = 0
if como["para"] and cereflg:
como["para"] = 0
# Combine HTN and HTNCX into HTN_C
if como["htn"] or como["htncx"]:
como["htn_c"] = 1
else:
como["htn_c"] = 0
# remove htn and htncx
como.pop("htn", None)
como.pop("htncx", None)
out = [como[key] for key in dicts.colNames]
return out