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
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
##
import os
import re
os.environ['TF_XLA_FLAGS'] = '--tf_xla_enable_xla_devices'
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3'
import splittxt
import tools
import predict
import tensorflow
##
class Oral:
def __init__(self, ImagingFindings, ImagingConclusion, verbose = True):
self.verbose = verbose
self._Conclusion = ''
self._Finding = ''
if '送检淋巴结' in ImagingConclusion:
self._Conclusion = ImagingConclusion
self._Finding = ImagingFindings
else:
self._Conclusion = ImagingFindings
self._Finding = ImagingConclusion
self._Conclusion = self._Conclusion.strip('"').strip() \
.replace("大于", ">").replace("小于", "<").replace("大于等于", "≥").replace("小于等于", "≤").replace(">", ">").replace(
"<", "<")
self._Finding = self._Finding.strip('"').strip() \
.replace("大于", ">").replace("小于", "<").replace("大于等于", "≥").replace("小于等于", "≤").replace(">", ">").replace(
"<", "<")
self.ImmunohistochemistryContent = ''
self.MolecularResultsContent = ''
self.Degree = ''
self.CuttingEdgePathologyOther = ''
self.CuttingEdgePathology = ''
_, CuttingEdge1, _, MolecularResults1, Immunohistochemistry1 = splittxt.splittxt(
self._Conclusion)
_, CuttingEdge2, _, MolecularResults2, Immunohistochemistry2 = splittxt.splittxt(
self._Finding)
self.ConclusionCuttingEdge = CuttingEdge1 + CuttingEdge2
self.ConclusionMolecularResults = MolecularResults1 + MolecularResults2
if Immunohistochemistry1 != Immunohistochemistry2:
self.ConclusionImmunohistochemistry = Immunohistochemistry1 + Immunohistochemistry2
else:
self.ConclusionImmunohistochemistry = Immunohistochemistry1
# self.ConclusionFrist, self.ConclusionCuttingEdge, self.ConclusionMolecularResults, self.ConclusionImmunohistochemistry = splittxt.splittxt(
# self._Conclusion + self._Finding)
# self.FindingFrist, self.FindingCuttingEdge, self.FindingMolecularResults, self.FindingImmunohistochemistry = splittxt.splittxt(
# self._Finding + self._Conclusion)
if self.ConclusionCuttingEdge != "":
self.CuttingEdgePathology = tools.CuttingEdgePathology(self.ConclusionCuttingEdge) # 术后病理切缘
self.CuttingEdgePathologyOther = ""
if self.CuttingEdgePathology == "其他情况":
CuttingEdgeID = tools.FindChar(self.ConclusionCuttingEdge)[0] + 1
self.CuttingEdgePathologyOther = self.ConclusionCuttingEdge[CuttingEdgeID:] # 其他术后病理切缘情况
self.Degree = tools.findDegree(self.ConclusionCuttingEdge) # 黏膜上皮异常增生程度
# print(self.Degree)
self.Degree = self.getDegree(self.Degree)
if self.CuttingEdgePathologyOther == '':
self.CuttingEdgePathologyOther = '无'
# 分子结果
if self.ConclusionMolecularResults != "":
MolecularResultsID = tools.FindChar(self.ConclusionMolecularResults)[0]
self.MolecularResultsContent = self.ConclusionMolecularResults[MolecularResultsID:] # 分子结果
if self.MolecularResultsContent == "":
self.MolecularResultsContent = "无"
# 免疫组化
# print(self.ConclusionImmunohistochemistry)
if self.ConclusionImmunohistochemistry != "":
self.Immunohistochemistryisornot = "有" # 免疫组化有无
# print(self.Immunohistochemistryisornot)
# ImmunohistochemistryID = tools.FindChar(self.ConclusionImmunohistochemistry)[0]
# print(tools.FindChar(self.ConclusionImmunohistochemistry))
# print(self.ConclusionImmunohistochemistry)
# print(self.ConclusionImmunohistochemistry[ImmunohistochemistryID:])
# self.ImmunohistochemistryContent = self.ConclusionImmunohistochemistry[ImmunohistochemistryID:] # 免疫组化结果
self.ImmunohistochemistryContent = self.ConclusionImmunohistochemistry # 免疫组化结果
else:
self.Immunohistochemistryisornot = "无" # 免疫组化有无
# self.print_original_data()
self.ConclusionFrist, _, self.ConclusionCuttingLymph, _, _ = splittxt.splittxt(
self._Conclusion)
self.FindingFrist, _, self.FindingCuttingLymph, _, _ = splittxt.splittxt(
self._Finding)
self.ConclusionFrist = self.ConclusionFrist.replace('肿物', '肿块').replace('\n', '。')
tensorflow.keras.backend.clear_session()
if self.verbose:
print(self.ConclusionFrist + self.ConclusionCuttingLymph)
ans, y_pre = predict.predict(self.ConclusionFrist + self.ConclusionCuttingLymph)
self._y_pre = predict.output(self.ConclusionFrist + self.ConclusionCuttingLymph, y_pre)
if self.verbose:
self.print_list_item(ans)
self.FindingFrist = self.FindingFrist.replace('肿物', '肿块').replace('\n', '。')
tensorflow.keras.backend.clear_session()
if self.verbose:
print(self.FindingFrist + self.FindingCuttingLymph)
ans_o, y_pre_o = predict.predict(self.FindingFrist + self.FindingCuttingLymph)
self._y_pre_o = predict.output(self.FindingFrist + self.FindingCuttingLymph, y_pre_o)
if self.verbose:
self.print_list_item(ans_o)
tensorflow.keras.backend.clear_session()
if self.verbose:
print(self.ConclusionCuttingLymph)
ans_lymph, y_pre_lymph = predict.predict(self.ConclusionCuttingLymph)
self._y_pre_lymph = predict.output(self.ConclusionCuttingLymph, y_pre_lymph)
# if self.verbose:
# self.print_list_item(ans_lymph)
def _get_entity_with_O(self, y_pre, with_o):
all = []
if with_o:
for i in range(len(y_pre)):
if i == 0:
# print('O', ImagingConclusionFrist[0:y_pre[i][2]].replace('\n', ' '), str(0), str(y_pre[i][2]))
# print(y_pre[i][0], y_pre[i][1], y_pre[i][2], y_pre[i][3])
all.append({'tag': 'O', 'words': self.FindingFrist[0:y_pre[i][2]].replace('\n', ' '), 'h': 0,
'r': y_pre[i][2]})
all.append({'tag': y_pre[i][0], 'words': y_pre[i][1], 'h': y_pre[i][2], 'r': y_pre[i][3]})
else:
O_h = y_pre[i - 1][3] + 1
O_r = y_pre[i][2]
# print('O', ImagingConclusionFrist[O_h:O_r].replace('\n', ' '), str(y_pre[i - 1][3] + 1), str(y_pre[i][2]))
# print(y_pre[i][0], y_pre[i][1], y_pre[i][2], y_pre[i][3])
all.append({'tag': 'O', 'words': self.FindingFrist[O_h:O_r].replace('\n', ' '),
'h': y_pre[i - 1][3] + 1, 'r': y_pre[i][2]})
all.append({'tag': y_pre[i][0], 'words': y_pre[i][1], 'h': y_pre[i][2], 'r': y_pre[i][3]})
else:
for i in range(len(y_pre)):
if i == 0:
# print('O', ImagingConclusionFrist[0:y_pre[i][2]].replace('\n', ' '), str(0), str(y_pre[i][2]))
# print(y_pre[i][0], y_pre[i][1], y_pre[i][2], y_pre[i][3])
all.append({'tag': 'O', 'words': self.ConclusionFrist[0:y_pre[i][2]].replace('\n', ' '), 'h': 0,
'r': y_pre[i][2]})
all.append({'tag': y_pre[i][0], 'words': y_pre[i][1], 'h': y_pre[i][2], 'r': y_pre[i][3]})
else:
O_h = y_pre[i - 1][3] + 1
O_r = y_pre[i][2]
# print('O', ImagingConclusionFrist[O_h:O_r].replace('\n', ' '), str(y_pre[i - 1][3] + 1), str(y_pre[i][2]))
# print(y_pre[i][0], y_pre[i][1], y_pre[i][2], y_pre[i][3])
all.append({'tag': 'O', 'words': self.ConclusionFrist[O_h:O_r].replace('\n', ' '),
'h': y_pre[i - 1][3] + 1, 'r': y_pre[i][2]})
all.append({'tag': y_pre[i][0], 'words': y_pre[i][1], 'h': y_pre[i][2], 'r': y_pre[i][3]})
return all
def max_size(self, type):
haveSIZE = False
for i in self._get_entity_with_O(self._y_pre, False):
if i['tag'] == 'SIZE':
haveSIZE = True
all = []
if not haveSIZE:
all = self._get_entity_with_O(self._y_pre_o, True)
else:
all = self._get_entity_with_O(self._y_pre, False)
# for i in all:
# print(i)
max = 0
max_i = 0
numbers = []
types = []
for i in range(0, len(all)):
if type in all[i]['words']:
types.append(all[i]['words'])
if all[i]['tag'] == 'SIZE' and len(types) != 0:
numbers.append(tools.exactNumber(all[i]['words']))
types = []
if len(numbers) == 0:
return ""
for arr_i in range(0, len(numbers)):
for num in numbers[arr_i]:
if (re.match("^\d+?\.\d+?$", str(num)) or num.isdigit()) and (
re.match("^\d+?\.\d+?$", str(max)) or num.isdigit()):
if float(num) > float(max):
max = num
max_i = arr_i
s = ''
for num in numbers[max_i]:
s += str(num) + '*'
return s.strip("*").strip("cm")
def get_DOI(self):
haveDOI = False
for i in self._get_entity_with_O(self._y_pre_o, True):
if i['tag'] == 'DOI':
haveDOI = True
all = []
if not haveDOI:
all = self._get_entity_with_O(self._y_pre, False)
else:
all = self._get_entity_with_O(self._y_pre_o, True)
DOI_txt = ''
# all = self._get_entity_with_O(self._y_pre, False)
# for i in all:
# print(i)
for i in all:
if i['tag'] == 'DOI':
DOI_txt += i['words'] + '\n'
return DOI_txt
def get_pT(self):
pT_txt = ''
haveDOI = False
for i in self._get_entity_with_O(self._y_pre_o, True):
if i['tag'] == 'DOI':
haveDOI = True
all = []
if not haveDOI:
all = self._get_entity_with_O(self._y_pre, False)
else:
all = self._get_entity_with_O(self._y_pre_o, True)
for i in all:
if i['tag'] == 'DOI':
pT_txt += tools.pT(i['words']) + '\n'
return pT_txt
def get_differentiation(self):
differentiation_txt = ''
differentiations = []
all = self._get_entity_with_O(self._y_pre, False)
# print('self._y_pre:')
for i in all:
# print(i)
if i['tag'] == 'LEVEL':
_, ans = tools.differentiation(i['words'])
differentiations.append(ans)
# differentiation_txt += ans + '\n'
all = self._get_entity_with_O(self._y_pre_o, True)
# print('self._y_pre_o:')
for i in all:
# print(i)
if i['tag'] == 'LEVEL':
_, ans = tools.differentiation(i['words'])
differentiations.append(ans.strip())
if ('中-低分化' in (self.ConclusionFrist + self.ConclusionCuttingLymph)) or (
'中-低分化' in (self.FindingFrist + self.FindingCuttingLymph)):
differentiations.append("Ⅱ级中分化")
differentiations.append("Ⅲ级低分化")
differentiations = set(differentiations)
for i in differentiations:
differentiation_txt += i + '\n'
return differentiation_txt
def get_invasion(self, type):
all = self._get_entity_with_O(self._y_pre, False)
for i in all:
if i['tag'] == 'INVASION':
if type in i['words']:
return '是'
return '否'
def getENE(self):
all = self._get_entity_with_O(self._y_pre, False)
for i in all:
if i['tag'] == 'ENE':
return '有'
return '无'
def getDegree(self, dgr):
if '-' in dgr:
dgr_list = dgr.split('-')
for i in range(len(dgr_list)):
if "度" not in dgr_list[i]:
dgr_list[i] += "度"
rt_dgr = ""
for i in dgr_list:
rt_dgr += i
rt_dgr += '\n'
rt_dgr.strip('\n')
return rt_dgr
else:
return dgr
def getANATOMY(self):
all = self._get_entity_with_O(self._y_pre, False)
have_anatomy = False
for i in all:
if i['tag'] == 'ANATOMY':
have_anatomy = True
if not have_anatomy:
all = self._get_entity_with_O(self._y_pre_o, True)
count_i = 0
count_o = 0
anatomy_list_init = []
for i in all:
if i['tag'] == 'ANATOMY':
if ('I' in i['words'] or 'V' in i['words'] or i['words'] == '左' or i['words'] == '右') and (
'DOI' not in i['words'] and 'b' not in i['words'] and 'a' not in i['words'] and 'A' not in i[
'words'] and 'B' not in i['words']):
count_i += 1
anatomy_list_init.append(i['words'])
# if i['words'] == '右' or i['words'] == '左':
# rt_txt += i['words']
# else:
# rt_txt += i['words'] + '、'
else:
count_o += 1
# print(anatomy_list_init)
anatomy_list_rt = []
l_or_r = ''
for i in range(len(anatomy_list_init)):
if anatomy_list_init[i] == '左' or anatomy_list_init[i] == '右':
l_or_r = anatomy_list_init[i]
elif ('左' not in anatomy_list_init[i] and '右' not in anatomy_list_init[i]) and (
'I' in anatomy_list_init[i] or 'V' in anatomy_list_init[i]):
if l_or_r != '':
anatomy_list_rt.append(l_or_r + anatomy_list_init[i].strip('区').strip('淋巴结') + '区')
else:
count_o += 1
elif '左' in anatomy_list_init[i] or '右' in anatomy_list_init[i]:
anatomy_list_rt.append(anatomy_list_init[i].strip('区').strip('淋巴结') + '区')
anatomy_set_rt = set(anatomy_list_rt)
# print(anatomy_set_rt)
rt_txt = ''
for i in anatomy_set_rt:
rt_txt += (i + '、')
if count_o != 0:
if count_i == 0:
rt_txt = (rt_txt.strip('、') + '其他')
else:
rt_txt = (rt_txt.strip('、') + '、其他')
return rt_txt.strip('、')
def getANATOMY_o(self):
all = self._get_entity_with_O(self._y_pre, False)
have_anatomy = False
for i in all:
if i['tag'] == 'ANATOMY':
have_anatomy = True
if not have_anatomy:
all = self._get_entity_with_O(self._y_pre_o, True)
rt_txt = ''
anatomy_o_list = []
anatomy_list = []
for i in all:
if i['tag'] == 'ANATOMY':
if ('I' in i['words'] or 'V' in i['words'] or i['words'] == '左' or i['words'] == '右') and (
'DOI' not in i['words'] and 'b' not in i['words'] and 'a' not in i['words'] and 'A' not in i[
'words'] and 'B' not in i['words']):
anatomy_list.append(i['words'])
continue
else:
anatomy_o_list.append(i['words'])
l_or_r = ''
for i in range(len(anatomy_list)):
if anatomy_list[i] == '左' or anatomy_list[i] == '右':
l_or_r = anatomy_list[i]
elif ('左' not in anatomy_list[i] and '右' not in anatomy_list[i]) and (
'I' in anatomy_list[i] or 'V' in anatomy_list[i]):
if l_or_r == '':
anatomy_o_list.append(anatomy_list[i])
elif '左' in anatomy_list[i] or '右' in anatomy_list[i]:
continue
# print(anatomy_o_list)
if len(anatomy_o_list) == 0:
return '无'
anatomy_o_list = set(anatomy_o_list)
for i in anatomy_o_list:
if ('I' in i or 'V' in i) and ('区' not in i):
rt_txt += i + '区、'
else:
rt_txt += i + '、'
return rt_txt.strip('、')
def get_histological_type(self):
all = self._get_entity_with_O(self._y_pre, False)
# print(all)
count_s = 0
count_o = 0
rt_txt = ''
for i in all:
if i['tag'] == 'SQUAMOUS':
count_s += 1
if i['tag'] == 'OTHER':
if ('恶性' in i['words'] or '癌' in i['words'] or '肉瘤' in i['words'] or '异常增生' in i[
'words']) and ('鳞状细胞' not in i['words']):
count_o += 1
all = self._get_entity_with_O(self._y_pre_o, True)
# print(all)
for i in all:
if i['tag'] == 'SQUAMOUS':
count_s += 1
if i['tag'] == 'OTHER':
if ('恶性' in i['words'] or '癌' in i['words'] or '肉瘤' in i['words'] or '异常增生' in i[
'words']) and ('鳞状细胞' not in i['words']):
# print(i['words'])
count_o += 1
if '鳞状细胞癌' in self._Conclusion or '鳞状细胞癌' in self._Finding:
count_s += 1
if count_s > 0:
rt_txt += '鳞状细胞癌\n'
if count_o > 0:
rt_txt += '其他'
if count_o == 0 and count_s == 0:
rt_txt = '无'
return rt_txt.strip('、')
def get_other_type(self):
all = self._get_entity_with_O(self._y_pre, False)
# for i in all:
# print(i)
rt_txt = ''
count = 0
entity = []
for i in all:
if i['tag'] == 'OTHER':
count += 1
if ('恶性' in i['words'] or '癌' in i['words'] or '肉瘤' in i['words'] or '异常增生' in i[
'words']) and ('鳞状细胞' not in i['words']):
entity.append(i['words'])
all = self._get_entity_with_O(self._y_pre_o, True)
for i in all:
if i['tag'] == 'OTHER':
count += 1
if ('恶性' in i['words'] or '癌' in i['words'] or '肉瘤' in i['words'] or '异常增生' in i[
'words']) and ('鳞状细胞' not in i['words']):
entity.append(i['words'])
entity = set(entity)
for i in entity:
rt_txt += i + '\n'
return '无' if count == 0 else rt_txt
def get_number(self):
# all = get_entity_with_O(y_pre)
count = 0
# for i in self._y_pre:
# print(i)
for i in range(1, len(self._y_pre)):
if self._y_pre[i][0] == 'NUMBER' and self._y_pre[i - 1][0] == 'ANATOMY':
# print(y_pre[i][1])
if '各' in self._y_pre[i][1]:
# print(self._y_pre[i][1])
count_a = 0
for j in range(1, len(self._y_pre)):
if self._y_pre[j][0] == 'ANATOMY':
count_a += 1
# print(self._y_pre[i][1].replace(' ', '').strip('').strip('只').strip('块').strip('组织').strip(
# '枚').strip('各'))
count = float(self._y_pre[i][1].replace(' ', '').strip('').strip('只').strip('块').strip('组织').strip(
'枚').strip('各')) * count_a
return count
n = self._y_pre[i][1].replace(' ', '').strip('').strip('只').strip('块').strip('组织').strip('枚').strip('各')
if '/' in n:
count += float(n.split('/')[1]) if (len(tools.exactNumber(
str(n.split('/')[1]))) != 0) and n.split('/')[1] != '' and ((re.match(
"^\d+?\.\d+?$", str(n.split('/')[1]))) or str(n.split('/')[1]).isdigit()) \
else float(0)
else:
count += float(n) if (len(tools.exactNumber(str(n)))) and (
re.match("^\d+?\.\d+?$", str(n)) or str(n).isdigit()) != 0 else float(0)
return count
def get_p_number(self):
count = 0
num_list = []
for item in self._y_pre_lymph:
if item[0] == "NUMBER":
num_list.append(item)
if item[0] == "PN":
if item[1] == '阳性(+)' or item[1] == '阳性(+)' or item[1] == '阳性' or item[1] == '(+)' or item[
1] == '(+)' or item[1] == '+':
# print(num_list)
if len(num_list) == 0:
pass
else:
# self.print_y_pred()
for p_item in num_list:
n_str = p_item[1].replace(' ', '').strip('').strip('只').strip('块').strip('组织').strip(
'枚').strip('各')
# print(n_str)
if '/' in n_str:
# print(n_str.split('/')[0])
# if len(tools.exactNumber(str(n_str.split('/')[0]))) != 0:
# print("*")
# if n_str.split('/')[0] != '':
# print("**")
# if (re.match("^\d+?\.\d+?$", str(n_str.split('/')[0]))) or str(n_str.split('/')[0]).isdigit():
# print("***")
count += float(n_str.split('/')[0]) if (len(tools.exactNumber(
str(n_str.split('/')[0]))) != 0) and n_str.split('/')[0] != '' and ((re.match(
"^\d+?\.\d+?$", str(n_str.split('/')[0]))) or str(n_str.split('/')[0]).isdigit()) \
else float(0)
else:
count += float(n_str) if (len(tools.exactNumber(str(n_str))) != 0) and (
(re.match("^\d+?\.\d+?$", str(n_str))) or str(n_str).isdigit()) else float(0)
elif item[1] == '阴性(-)' or item[1] == '阴性(-)' or item[1] == '阴性' or item[1] == '(-)' or item[
1] == '(-)' or item[1] == '-':
num_list = []
return count
def get_p_max(self):
p_list = []
p_list_tmp = []
size_list = []
size_list_tmp = []
# print('----------')
for item in self._y_pre_lymph:
if item[0] == "ANATOMY":
p_list_tmp.append(item)
if item[0] == "SIZE":
size_list_tmp.append(item)
if item[0] == "NUMBER" and '/' in item[1]:
if len(p_list_tmp) == 0:
pass
else:
for p_item in p_list_tmp:
p_list.append(p_item)
for size_item in size_list_tmp:
size_list.append(size_item[1])
p_list_tmp = []
size_list_tmp = []
if item[0] == "PN":
if item[1] == '阳性(+)' or item[1] == '阳性(+)' or item[1] == '阳性' or item[1] == '(+)' or item[
1] == '(+)' or item[1] == '+':
if len(p_list_tmp) == 0:
pass
else:
for p_item in p_list_tmp:
p_list.append(p_item)
for size_item in size_list_tmp:
size_list.append(size_item[1])
p_list_tmp = []
size_list_tmp = []
else:
p_list_tmp = []
size_list_tmp = []
# print(p_list)
# print(size_list)
if len(p_list) != 0:
contains_single_left = False
contains_single_right = False
for i in p_list:
if i[1] == '左':
contains_single_left = True
if i[1] == '右':
contains_single_right = True
if contains_single_left or contains_single_right == True:
p_list = self._handle_single(p_list)
# for i in p_list:
# print(i)
# print('-------------')
# self.print_y_pred_o()
p_anatomy = ''
for i in range(len(self._y_pre_o)):
if self._y_pre_o[i][0] == 'ANATOMY':
p_anatomy = self._y_pre_o[i][1].strip().strip('区')
if self._y_pre_o[i][0] == 'SIZE':
# print(y_pre_o[i][1])
if p_anatomy != '':
for j in range(0, len(p_list)):
# print(p_list[j][1].strip().strip('区'))
if p_list[j][1].strip().strip('区')[0] == '左' or p_list[j][1].strip().strip('区')[0] == '右':
if p_anatomy[0] != p_list[j][1].strip().strip('区')[0]:
p_anatomy = p_list[j][1].strip().strip('区')[0] + p_anatomy
# print(p_anatomy)
# print(p_list[j][1].strip().strip('区'))
# print(p_anatomy)
if p_list[j][1].strip().strip('区') == p_anatomy:
size_list.append(self._y_pre_o[i][1])
p_anatomy = ''
all_size = []
# print(size_list)
for i in size_list:
for j in tools.exactNumber(i):
all_size.append(j)
for i in range(len(all_size)):
if re.match("^\d+?\.\d+?$", all_size[i]) or all_size[i].isdigit():
all_size[i] = float(all_size[i])
# print(all_size)
if len(all_size) != 0:
return max(all_size)
return 0
# print(len(size_list))
def _handle_single(self, p_list):
rt_list = []
lr = ''
for i in p_list:
if i[1] == '左' or i[1] == '右':
lr = i[1]
else:
rt_list += [[i[0], lr + i[1], i[2], i[3]]]
return rt_list
def get_pN(self):
# if type(self.get_p_max())== int or type(self.get_p_max())== float:
# print(self.get_p_max())
return tools.pN(self.get_p_number(), float(self.get_p_max()), self.getENE())
def findSJ(self):
if '送检淋巴结' in self._Conclusion:
return '是'
else:
return '否'
def get_Info(self):
print("术后病理切缘:")
print(str(self.CuttingEdgePathology).strip())
print("其他术后病理切缘情况:")
print(str(self.CuttingEdgePathologyOther).strip())
print("黏膜上皮异常增生程度:")
print(str(self.Degree).strip())
print("分子结果:")
print(str(self.MolecularResultsContent).strip())
print("免疫组化:")
print(str(self.Immunohistochemistryisornot).strip())
print("免疫组化结果:")
print(str(self.ImmunohistochemistryContent).strip())
print("送检组织大小cm:")
print(str(self.max_size("组织")).strip())
print("肿块大小:")
print(str(self.max_size("肿块")).strip())
print("浸润深度(DOI)mm:")
print(str(self.get_DOI()).strip())
print("pT:")
print(str(self.get_pT()).strip())
print("分化程度")
print(str(self.get_differentiation()).strip())
print("神经侵犯:")
print(str(self.get_invasion('神经')).strip())
print("血管侵犯:")
print(str(self.get_invasion('血管')).strip())
print("淋巴结包膜外ENE(+):")
print(str(self.getENE()).strip())
print("送检淋巴结部位:")
print(str(self.getANATOMY().strip('、')).strip())
print("其他送检淋巴结部位:")
print(str(self.getANATOMY_o().strip('、')).strip())
print("组织学类型:")
print(str(self.get_histological_type()).strip())
print("其他组织学类型:")
print(str(self.get_other_type()).strip())
if self.findSJ() == '是':
print('送检淋巴结数目:')
print(str(self.get_number()).strip())
print("阳性淋巴结数量:")
print(str(self.get_p_number()).strip())
print("阳性淋巴结最大直径cm:")
print(str(self.get_p_max()).strip())
print("pN:")
print(str(self.get_pN()).strip())
def print_original_data(self):
print(self._Finding)
print(self._Conclusion)
def print_y_pred(self):
for i in self._y_pre:
print(i)
def print_y_pred_o(self):
for i in self._y_pre_o:
print(i)
def print_list_item(self, l):
for i in l:
print(i)
def get_json(self):
if self.verbose:
self.print_y_pred()
print("-----------------")
self.print_y_pred_o()
print("-----------------")
self.get_Info()
return {
"送检组织大小cm": str(self.max_size("组织")).strip(),
"肿块大小": str(self.max_size("肿块")).strip(),
"组织学类型": str(self.get_histological_type()).strip(),
"其他组织学类型": str(self.get_other_type()).strip(),
"分化程度": str(self.get_differentiation()).strip(),
"浸润深度(DOI)mm": str(self.get_DOI()).strip(),
"pT": str(self.get_pT()).strip(),
"神经侵犯": str(self.get_invasion('神经')).strip(),
"血管侵犯": str(self.get_invasion('血管')).strip(),
"术后病理切缘": str(self.CuttingEdgePathology).strip(),
"其他术后病理切缘情况": str(self.CuttingEdgePathologyOther).strip(),
"黏膜上皮异常增生程度": str(self.Degree).strip(),
"免疫组化": str(self.Immunohistochemistryisornot).strip(),
"免疫组化结果": str(self.ImmunohistochemistryContent).strip(),
"分子结果": str(self.MolecularResultsContent).strip(),
"是否送检淋巴结": str(self.findSJ()).strip(),
"送检淋巴结部位": str(self.getANATOMY()).strip() if str(self.findSJ()).strip() == '是' else '',
"其他送检淋巴结部位": str(self.getANATOMY_o().strip('、')).strip() if str(self.findSJ()).strip() == '是' else '',
"送检淋巴结数目": str(self.get_number()).strip() if str(self.findSJ()).strip() == '是' else '',
"阳性淋巴结数目": str(self.get_p_number()).strip() if str(self.findSJ()).strip() == '是' else '',
"阳性淋巴结最大直径cm": str(self.get_p_max()).strip() if str(self.findSJ()).strip() == '是' else '',
"淋巴结包膜外ENE(+)": str(self.getENE()).strip() if str(self.findSJ()).strip() == '是' else '',
"pN": str(self.get_pN()).strip() if str(self.findSJ()).strip() == '是' else '',
}
##
if __name__ == '__main__':
Finding = """
" 左颈大块:6*5*4cm,一侧见一腺体3*3*2cm,灰黄分叶,余为脂肪血管。
左I区: 3只直径0.2-1.2cm。
左II区: 3只直径0.5-1.2cm。
左III区: 3只直径0.5-1cm。
左IV区: 3只直径0.5-0.8cm。
右I区:3只直径1-2cm。
右II区: 3只直径1cm。
右III区: 3只直径0.5-0.8cm。
右IV区: 3只直径0.5-0.6cm。
右颈淋巴:7*7*6cm,內见一腺体3*3*2cm,灰黄分叶,余为脂肪血管。"
"""
Conclusion = """
"“左颌下腺”慢性涎腺炎
“右颌下腺”慢性涎腺炎
送检淋巴结:“左”“I区”1/3只、“II区”1/3只、“III区”1/3只(肿瘤位于软组织内)及“右”“I区”2/3只(其中1只肿瘤侵犯至包膜外)、“II区”2/3只(肿瘤侵犯至包膜外)有肿瘤转移(+),余及“左IV区”3只、“右”“III区”3只、“IV区”3只均阴性(-)"
"""
oral = Oral(Finding, Conclusion)
oral.print_y_pred()
print("-----------------")
oral.print_y_pred_o()
print("-----------------")
oral.get_Info()
print(oral.get_json())