-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainWindow.py
1098 lines (932 loc) · 38.5 KB
/
MainWindow.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
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
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# 使用UTF-8标准编码避免中文乱码
# -*- coding: UTF-8 -*-
from PyQt5.QtWidgets import QApplication, QMainWindow, QTableView, QAbstractItemView, QMessageBox, QTreeWidgetItem, \
QPushButton, QComboBox, QVBoxLayout, QWidget, QFrame, QLabel
from PyQt5.QtGui import QStandardItemModel, QStandardItem, QPixmap
from PyQt5.QtCore import Qt, pyqtSlot
# 导入UI
from UI.Ui_MainWindow import Ui_MainWindow
# 导入各种类【功能函数】
#~~~系统管理~~~
from ShowDatabase import ShowDatabase
#~~~样本管理~~~
from CreateSample import CreateSample #添加样本
from RecycleBinDialog import RecycleBinDialog #查看回收站样本
from EnterToday import EnterToday #查看今日入库
from SearchWindow import SearchWindow #查询样本
from SampleClass import SampleClass #分析样本类别
from UseRatio import UseRatio #分析容器使用率
from InsertResult import InsertExam #插入检查结果
from SampleCalendar import SampleCalendar #按天入库样本数
#~~~病人管理~~~
from PatientStatis import PatientStatis
from ExamSta import ExamStatis #检验结果统计
from AddPatient import AddPatient#添加病人
from PatientSearch import PatientSearch#查询病人信息
from PatientCalender import PatientCalendar #按天入库样本数
from PredictDisease import PredictDisease#疾病预测
from AddHistory import AddHistory
from ManDiagnosis import ManDiag
#~~~~~检验管理~~~
from ExamPatient import ExamPatient
from ExamDiagnosis import ExamDiagnosis
from DataChange import DataChange
from CorAnalysis import CorExam
from ClusterShow import ClusterSHow
#~~~结果管理~~~
from DiseaseTree import DiseaseTree #疾病树
from DiseaseClass import DiseaseClass
from DiagPatient import DiagPatient
from DiagExam import DiagExam
from TestData import TestExam
from Diagnosis_timeline import DiagTime
# 相关配置
from Util.Common import get_sql_connection, get_logger, show_error_message, show_successful_message
# 其他必须
import sys
import datetime
# 主题
import qdarkstyle
from qt_material import apply_stylesheet
# 主窗口
class MainWindow(QMainWindow):
# 初始化函数
def __init__(self):
# 继承QMainWindow基本功能
super(MainWindow, self).__init__()
# self.setStyleSheet("background-color: white;") #设置背景颜色
# 创建下拉列表
self.frame = QFrame(self)
self.frame.resize(500, 600)
self.frame.setStyleSheet(
'border-image: url("./start.png"); background-repeat: no-repeat;')
self.frame.move(450, 100)
self.cb = QComboBox(self) # 下拉列表
self.cb.addItems(["出凝血科室", "尿液检验", "其他科室"]) # 科室名称(继续添加)
self.cb.move(650, 750)
self.cb.adjustSize() # 根据长度自动调节宽度
self.btn = QPushButton("确定", self) # 确定按钮
self.btn.move(750, 750)
self.btn.clicked.connect(self.cao) # 绑定槽函数,确定后,显示后续所有ui
def cao(self):
if self.cb.currentText() == '出凝血科室':
self.__UI = Ui_MainWindow()
self.__UI.setupUi(self)
self.setCentralWidget(self.__UI.tabWidget)
# self.showMaximized()
# self.setGeometry(200, 200, 1100, 800)
self.desktop = QApplication.desktop()
self.screenRect = self.desktop.screenGeometry()
self.height = self.screenRect.height()
self.width = self.screenRect.width()
self.setGeometry(0, 0, self.width, self.height)
# 设置右侧tab的宽度
self.set_tableview(
self.__UI.tableView_show,
horsize=130,
versize=50)
self.set_tableview_patient(
self.__UI.tableView_patient,
horsize=130,
versize=50)
self.set_tableview_exam(
self.__UI.tableView_result,
horsize=130,
versize=50)
self.set_tableview_result(
self.__UI.tableView_result,
horsize=130,
versize=50)
# 设置model
self.data_model = self.get_model()
self.set_model()
# 病人信息
self.data_model_patient = self.get_model_patient()
self.set_model_patient()
#检验
self.data_model_exam = self.get_model_exam()
self.set_model_exam()
#诊断结果
self.data_model_diagnosis = self.get_model_diagnosis()
self.set_model_diagnosis()
# 自己设置的
self.location = ""
# 样本id
self.sample_id = ""
# 病人id
self.patient_id = ""
self.patient_id_fromP = ""
# 设置为不可见
self.btn.setVisible(False)
self.cb.setVisible(False)
self.frame.setVisible(False)
# 删除控件
self.btn.deleteLater()
self.cb.deleteLater()
self.frame.deleteLater()
# 其他科室的
else:
print("还没做呢")
## ============================== 自动连接槽函数区 ==============================#
#~~~系统管理~~~
#点击【数据库】
@pyqtSlot()
def on_db_show_clicked(self):
db_dialog = ShowDatabase(self)
db_dialog.setAttribute(Qt.WA_DeleteOnClose)
db_dialog.show()
# 点击【查询样本】
@pyqtSlot()
def on_search_sample_clicked(self):
search_dialog = SearchWindow(self)
search_dialog.setAttribute(Qt.WA_DeleteOnClose)
search_dialog.show()
# 点击【新增样本】
@pyqtSlot()
def on_add_sample_clicked(self):
creation_dialog = CreateSample(self, self.location)
creation_dialog.setAttribute(Qt.WA_DeleteOnClose)
creation_dialog.data_update_signal.connect(self.do_receive_data)
creation_dialog.show()
# 点击【删除样本】
@pyqtSlot()
def on_delete_sample_clicked(self):
self.on_act_delete_triggered()
# 点击【查看回收站样本】
@pyqtSlot()
def on_trash_clicked(self):
recycle_dialog = RecycleBinDialog(self)
recycle_dialog.setAttribute(Qt.WA_DeleteOnClose)
recycle_dialog.show()
# 点击【当日入库】
@pyqtSlot()
def on_enter_today_clicked(self):
today_dialog = EnterToday(self)
today_dialog.setAttribute(Qt.WA_DeleteOnClose)
today_dialog.show()
# 点击【样本类别】
@pyqtSlot()
def on_sample_class_clicked(self):
sample_class_widget = SampleClass(self)
sample_class_widget.setAttribute(Qt.WA_DeleteOnClose)
sample_class_widget.show()
# 点击【容器使用率】
@pyqtSlot()
def on_use_ratio_clicked(self):
ratio_dialog = UseRatio(self)
ratio_dialog.setAttribute(Qt.WA_DeleteOnClose)
ratio_dialog.show()
# 点击【日期热图】
@pyqtSlot()
def on_calendar_clicked(self):
calender_dialog = SampleCalendar(self)
calender_dialog.setAttribute(Qt.WA_DeleteOnClose)
calender_dialog.show()
# 点击【添加检验结果】
@pyqtSlot()
def on_add_exam_clicked(self):
add_dialog = InsertExam(self, self.sample_id, self.patient_id) # 示例化
add_dialog.setAttribute(Qt.WA_DeleteOnClose)
add_dialog.show()
#~~~病人管理~~~~
#点击统计
@pyqtSlot()
def on_patient_sta_clicked(self):
patient_widget = PatientStatis(self)
patient_widget.setAttribute(Qt.WA_DeleteOnClose)
patient_widget.show()
#点击【添加病人】
@pyqtSlot()
def on_add_patient_clicked(self):
add_patient_dialog = AddPatient(self)
add_patient_dialog.setAttribute(Qt.WA_DeleteOnClose)
# 连接槽函数
# add_patient_dialog.data_update_signal.connect(self.do_receive_data)
add_patient_dialog.show()
# 点击【病人信息】
@pyqtSlot()
def on_patient_info_clicked(self):
psearch_dialog = PatientSearch(self)
psearch_dialog.setAttribute(Qt.WA_DeleteOnClose)
psearch_dialog.show()
# 点击【删除样本】
@pyqtSlot()
def on_delete_patient_clicked(self):
self.on_delete_patient_triggered()
@pyqtSlot()
def on_patient_time_clicked(self):
pcalender_dialog = PatientCalendar(self)
pcalender_dialog.setAttribute(Qt.WA_DeleteOnClose)
pcalender_dialog.show()
# 点击【自动诊断】
@pyqtSlot()
def on_auto_diag_clicked(self):
print("自动诊断")
try: # 执行sql语句
sql1 = """UPDATE Diagnosis_table INNER JOIN Exam_table ON Diagnosis_table.patient_ID=Exam_table.patient_ID SET Diagnosis_table.auto_result = '出血病' WHERE (Exam_table.APTT >= 38) """
sql2 = """UPDATE Diagnosis_table INNER JOIN Exam_table ON Diagnosis_table.patient_ID=Exam_table.patient_ID SET Diagnosis_table.auto_result = '血栓病' WHERE (Exam_table.APTT <= 15) """
#是否有诊断结果
sql3 = """ UPDATE Patient_table INNER JOIN Diagnosis_table Diagnosis_table.patient_ID=Patient_table.patient_ID
SET Patient_table.result = '有' WHERE Diagnosis_table.result IS NOT NULL"""
sql = """UPDATE t_sample INNER JOIN Exam_table ON t_sample.ID=Exam_table.sample_ID
SET t_sample.result = '有检验结果' WHERE Exam_table.exam_ID IS NOT NULL"""
connection_auto = get_sql_connection()
cursor_auto = connection_auto.cursor()
cursor_auto.execute(sql1)
cursor_auto.execute(sql2)
connection_auto.commit()#需要提交
show_successful_message(self, "自动标注成功")
except Exception as e:
print(e)
show_error_message(self, "错误,请检查")
#点击【疾病预测】
@pyqtSlot()
def on_predict_disease_clicked(self):
predict_dialog = PredictDisease(self,self.patient_id_fromP)
predict_dialog.setAttribute(Qt.WA_DeleteOnClose)
predict_dialog.show()
#点击【人工诊断】
@pyqtSlot()
def on_man_diag_clicked(self):
man_dialog = ManDiag(self,self.patient_id_fromP)
man_dialog.setAttribute(Qt.WA_DeleteOnClose)
man_dialog.show()
# ~~~~~~~~~【检验管理】~~~~~~~~~~~~
# 检验数据统计
@pyqtSlot()
def on_exam_statis_clicked(self):
exam_sta_widget = ExamStatis(self)
exam_sta_widget.setAttribute(Qt.WA_DeleteOnClose)
exam_sta_widget.show()
@pyqtSlot()
def on_exam_patient_clicked(self):
examp_widget = ExamPatient(self)
examp_widget.setAttribute(Qt.WA_DeleteOnClose)
examp_widget.show()
@pyqtSlot()
def on_exam_diagnosis_clicked(self):
examd_widget = ExamDiagnosis(self)
examd_widget.setAttribute(Qt.WA_DeleteOnClose)
examd_widget.show()
@pyqtSlot()
def on_data_change_clicked(self):
change_widget = DataChange(self)
change_widget.setAttribute(Qt.WA_DeleteOnClose)
change_widget.show()
@pyqtSlot()
def on_cor_analysis_clicked(self):
print("点了呢")
cor_widget = CorExam(self)
cor_widget.setAttribute(Qt.WA_DeleteOnClose)
cor_widget.show()
#~~~~~~~~~【诊断管理】~~~~~~~~~~~~
# 点击【疾病介绍】
@pyqtSlot()
def on_disease_tree_clicked(self):
disease_widget = DiseaseTree(self)
disease_widget.setAttribute(Qt.WA_DeleteOnClose)
disease_widget.show()
#点击【疾病类型】
@pyqtSlot()
def on_diag_class_clicked(self):
disease_class_diag = DiseaseClass(self)
disease_class_diag.setAttribute(Qt.WA_DeleteOnClose)
disease_class_diag.show()
#点击按病人统计
@pyqtSlot()
def on_analysis_patient_clicked(self):
diat_patient_dialog = DiagPatient(self)
diat_patient_dialog.setAttribute(Qt.WA_DeleteOnClose)
diat_patient_dialog.show()
# 点击按病人统计
@pyqtSlot()
def on_analysis_exam_clicked(self):
diag_exam_dialog = DiagExam(self)
diag_exam_dialog.setAttribute(Qt.WA_DeleteOnClose)
diag_exam_dialog.show()
#显著性分析
@pyqtSlot()
def on_diag_test_clicked(self):
test_dialog = TestExam(self)
test_dialog.setAttribute(Qt.WA_DeleteOnClose)
test_dialog.show()
@pyqtSlot()
def on_cluster_analysis_clicked(self):
cluster_dialog = ClusterSHow(self)
cluster_dialog.setAttribute(Qt.WA_DeleteOnClose)
cluster_dialog.show()
def on_diag_timeline_clicked(self):
change_widget = DiagTime(self)
change_widget.setAttribute(Qt.WA_DeleteOnClose)
change_widget.show()
## ============================== 槽函数区 ==============================#
# 槽函数(为了删除样本)
#槽函数选择是在Qt Designer中定义的
def talbe_choose(self):
row = (self.__UI.tableView_show.currentIndex().row())
col = (self.__UI.tableView_show.currentIndex().column())
id_data = (self.data_model.itemData(self.data_model.index(row, 0)))
p_data = (self.data_model.itemData(self.data_model.index(row, 1)))
self.sample_id = (id_data[0])
self.patient_id = (p_data[0])
def table_patient_choose(self):
row = (self.__UI.tableView_patient.currentIndex().row())
p_data = (self.data_model_patient.itemData(self.data_model_patient.index(row, 0)))
self.patient_id_fromP = (p_data[0])
## ============================== 点击不同的层级 ==============================#
# ~~~~~【样本管理】~~~~~~
@pyqtSlot(QTreeWidgetItem, QTreeWidgetItem)
# 目录树节点变化
def on_treeWidget_show_currentItemChanged(
self, current: QTreeWidgetItem, previous: QTreeWidgetItem):
flg = False
# 表示已经到最后一级了
if current.childCount() == 0:
flg = True
# 是当前选中的widget
first_name = current.text(0)
# 递归地找到路径
while current.parent() is not None:
current = current.parent()
first_name = current.text(0) + '-' + first_name
self.data_model = self.get_raw_model(
labels=[
'样本编号',
'病人编号',
'样本类型',
'样本量',
'添加日期',
'更新时间',
'状态',
'归属',
'位置',
'是否有检查结果'],
colCount=10)
# 连接到数据库
connection = get_sql_connection()
# 创建游标
cursor = connection.cursor()
# 已经到最后一级
if flg:
sql = """select * from t_sample where t_sample.sample_belong = '%s' """ % first_name
else:
sql = """select * from t_sample where t_sample.sample_belong like '""" + \
first_name + """%'"""
# 执行查询结果
cursor.execute(sql)
if self.__UI.tableView_show.model() is not None:
self.__UI.tableView_show.model().clear()
if cursor.rowcount != 0:
self.data_model = self.add_model_data(
self.data_model, list(cursor.fetchall()))
self.set_model()
# 传入的参数
self.location = first_name
# ~~~~~【病人管理】~~~~~~
@pyqtSlot(QTreeWidgetItem, QTreeWidgetItem)
# 目录树节点变化
def on_treeWidget_patient_currentItemChanged(
self, current: QTreeWidgetItem, previous: QTreeWidgetItem):
flg = False
# 表示已经到最后一级了
if current.childCount() == 0:
flg = True
# 是当前选中的widget
first_name = []
first_name.append(current.text(0))
# 递归地找到路径
while current.parent() is not None:
current = current.parent()
first_name.append(current.text(0))
self.data_model_patient = self.get_raw_model(
labels=[
'病人编号',
'病人姓名',
'年龄',
'性别',
'联系方式',
'是否有诊断结果',
'是否吸烟',
'是否饮酒',
'是否有输血史',
'是否有手术史',
'是否有传染疾病史',
'是否过敏史',
],
colCount=12)
# 连接到数据库
connection = get_sql_connection()
cursor = connection.cursor()
# 已经到最后一级
if flg:
types = first_name[0]
if types == '女性':
target = '女'
sql = """select * from Patient_table where gender = '%s' """ % target
if types == '男性':
target = '男'
sql = """select * from Patient_table where gender = '%s' """ % target
if types == '18以下':
target = 18
sql = """select * from Patient_table where Age < 18 """
if types == '18-35':
sql = """select * from Patient_table where Age >= 18 and Age <= 35 """
if types == '36-60':
sql = """select * from Patient_table where Age >= 36 and Age <= 60 """
if types == '60以上':
sql = """select * from Patient_table where Age >60"""
if types == '有':
sql = """select * from Patient_table where result='有'"""
if types == '无':
sql = """select * from Patient_table where result='无'"""
else:
sql = """select * from Patient_table"""
# 执行查询结果
cursor.execute(sql)
if self.__UI.tableView_patient.model() is not None:
self.__UI.tableView_patient.model().clear()
if cursor.rowcount != 0:
self.data_model_patient = self.add_model_data(
self.data_model_patient, list(cursor.fetchall()))
self.set_model_patient()
#~~~~~【检验管理】~~~~~
@pyqtSlot(QTreeWidgetItem, QTreeWidgetItem)
# 目录树节点变化
def on_treeWidget_exam_currentItemChanged(
self, current: QTreeWidgetItem, previous: QTreeWidgetItem):
flg = False
# 表示已经到最后一级了
if current.childCount() == 0:
flg = True
# 是当前选中的widget
first_name = []
first_name.append(current.text(0))
# 递归地找到路径
while current.parent() is not None:
current = current.parent()
first_name.append(current.text(0))
self.data_model_exam = self.get_raw_model(
labels=[
'检验编号',
'样本编号',
'病人编号',
'突变类型',
'核酸改变',
'氨基酸改变',
'Domain',
'基因型',
'APTT',
'Ag',
'全血凝固时间',
'血浆蛋白',
'凝血因子活性',
'结合胆红素',
'PP',
'血型',
'血糖',
'乳酸',
'中性粒细胞',
'血红蛋白',
'尿素',
'二聚体',
'血红素',
'呼吸频率',
'舒张压',
'收缩压',
'血氧饱和度',
'血小板',
'添加日期'
],
colCount=29)
connection = get_sql_connection()
cursor = connection.cursor()
types = first_name[0]
if types == 'A':
sql = """select * from Exam_table where Blood_type = 'A' """
elif types == 'B':
sql = """select * from Exam_table where Blood_type = 'B' """
elif types == 'O':
sql = """select * from Exam_table where Blood_type = 'O' """
elif types == 'AB':
sql = """select * from Exam_table where Blood_type = 'AB' """
elif types == '连锁':
sql = """select * from Exam_table where genotype LIKE '%连锁%' """
elif types == 'Het':
sql = """select * from Exam_table where genotype LIKE '%Het%' """
elif types == 'Homologous':
sql = """select * from Exam_table where genotype LIKE '%Homologous%' """
else:
sql = """select * from Exam_table """
# 执行查询结果
cursor.execute(sql)
if self.__UI.tableView_exam.model() is not None:
self.__UI.tableView_exam.model().clear()
if cursor.rowcount != 0:
self.data_model_exam = self.add_model_data(
self.data_model_exam, list(cursor.fetchall()))
self.set_model_exam()
#~~~~~【诊断管理】~~~~~~
@pyqtSlot(QTreeWidgetItem, QTreeWidgetItem)
# 目录树节点变化
def on_treeWidget_result_currentItemChanged(
self, current: QTreeWidgetItem, previous: QTreeWidgetItem):
flg = False
# 表示已经到最后一级了
if current.childCount() == 0:
flg = True
# 是当前选中的widget
first_name = []
first_name.append(current.text(0))
# 递归地找到路径
while current.parent() is not None:
current = current.parent()
first_name.append(current.text(0))
self.data_model_diagnosis = self.get_raw_model(
labels=[
'病人编号',
'自动诊断结果',
'结果',
'疾病类型',
'血友病类型',
'描述',
'诊断日期',
'VWD类型'],
colCount=8)
# 连接到数据库
connection = get_sql_connection()
# 创建游标
cursor = connection.cursor()
# 已经到最后一级
types = first_name[0]
print(types)
if types == '出血病':
sql = """select * from Diagnosis_table where binary_type = '%s' """ % ("出血病")
if types == '血栓病':
sql = """select * from Diagnosis_table where binary_type = '%s'""" % ("血栓病")
if types == '血友病':
sql = """SELECT * FROM Diagnosis_table WHERE result LIKE '%血友%'"""
#todo:
#这里会崩掉有点奇怪
if types == '血友病B':
sql = """SELECT * FROM Diagnosis_table WHERE result LIKE '%血友病B%'"""
if types == '血友病A':
sql = """SELECT * FROM Diagnosis_table WHERE result LIKE '%血友病A%'"""
if types == '血管性血友病':
sql = """select * from Diagnosis_table where result = '%s'""" % ("血管性血友病")
if types == '1':
sql = """select * from Diagnosis_table where vwd_type='%s'"""%('1')
if types == '3':
sql = """select * from Diagnosis_table where vwd_type='%s'"""%('3')
if types == '2A':
sql = """select * from Diagnosis_table where vwd_type='%s'"""%('2A')
if types == '2B':
sql = """select * from Diagnosis_table where vwd_type='%s'"""%('2B')
if types == '2M':
sql = """select * from Diagnosis_table where vwd_type='%s'"""%('2M')
if types == '2N':
sql = """select * from Diagnosis_table where vwd_type='%s'"""%('2N')
if types == '白色血栓':
sql = """select * from Diagnosis_table where result LIKE '%白色%'"""
if types == '红色血栓':
sql = """select * from Diagnosis_table where result LIKE '%红色%'"""
if types == '混合血栓':
sql = """select * from Diagnosis_table where result LIKE '%混合%'"""
if types == '透明血栓':
sql = """select * from Diagnosis_table where result LIKE '%透明%'"""
# 执行查询结果
cursor.execute(sql)
if self.__UI.tableView_result.model() is not None:
self.__UI.tableView_result.model().clear()
if cursor.rowcount != 0:
self.data_model_diagnosis = self.add_model_data(
self.data_model_diagnosis, list(cursor.fetchall()))
self.set_model_diagnosis()
## ============================== 槽函数区 ==============================#
# 点击【删除】槽函数
def on_act_delete_triggered(self):
try:
sample_id = str(self.sample_id)
sql_find = """select * from t_sample where ID='%s' """ % (sample_id)
connection_find = get_sql_connection() # 建立链接
cursor_find = connection_find.cursor() # 建立游标
cursor_find.execute(sql_find) # 执行查询
data_find = cursor_find.fetchone()
print(data_find)
# 得到数据
ID = data_find[0]
patient_id = data_find[1]
type = data_find[2]
sample_size = data_find[3]
creation_date = data_find[4]
modification_date = data_find[5]
sample_status = '回收站'
sample_belong = data_find[7]
box_loc = data_find[8]
# 插入到回收站数据库中
sql_insert = """insert into recycle_sample(ID,patinent_ID,type,sample_size,creation_date, modification_date,sample_status, sample_belong,box)
values('%s','%s','%s',%f,'%s','%s','%s', '%s','%s')""" % (ID, patient_id, type, sample_size, creation_date,
modification_date, sample_status, sample_belong, box_loc)
# 删除
sql = """delete from t_sample where ID='%s' """ % (sample_id)
connection_insert = get_sql_connection()
cursor_insert = connection_insert.cursor()
cursor_insert.execute(sql_insert)
connection_insert.commit()
connection_delete = get_sql_connection()
cursor_delete = connection_delete.cursor()
cursor_delete.execute(sql)
connection_delete.commit()
show_successful_message(self, "删除成功")
except Exception as e:
show_error_message(self, "删除错误,请检查")
def on_delete_patient_triggered(self):
print("传过来了")
try:
patient_id = str(self.patient_id_fromP)
# 删除
sql = """delete from Patient_table where patient_ID='%s' """ % (patient_id)
connection_delete = get_sql_connection()
cursor_delete = connection_delete.cursor()
cursor_delete.execute(sql)
connection_delete.commit()
show_successful_message(self, "删除成功")
except Exception as e:
show_error_message(self, "删除错误,请检查")
## ============================== 自定义槽函数区 ==============================#
@pyqtSlot(list)
def do_receive_data(self, data_list: list):
self.data_model = self.add_model_data(self.data_model, data_list)
## ===============================【数据模型】==========================================================#
# 获取数据模型
def get_model(self):
raw_model = self.get_raw_model(
labels=[
'样本编号',
'病人编号',
'样本类型',
'样本量',
'添加日期',
'更新时间',
'状态',
'归属',
'位置',
'是否有检查结果'],
colCount=10)
# 从数据库中得到所有的数据
data_list = self.read_sql_data()
if len(data_list) > 0:
return self.add_model_data(raw_model, data_list)
#病人数据
def get_model_patient(self):
raw_model = self.get_raw_model(
labels=[
'病人编号',
'病人姓名',
'年龄',
'性别',
'联系方式',
'是否有诊断结果',
'是否吸烟',
'是否饮酒',
'是否有输血史',
'是否有手术史',
'是否有传染疾病史',
'是否过敏史',
],
colCount=12)
# 从数据库中得到所有的数据
data_list = self.read_sql_data_patient()
if len(data_list) > 0:
return self.add_model_data(raw_model, data_list)
def get_model_exam(self):
raw_model = self.get_raw_model(
labels=[
'检验编号',
'样本编号',
'病人编号',
'突变类型',
'核酸改变',
'氨基酸改变',
'Domain',
'基因型',
'APTT',
'Ag',
'全血凝固时间',
'血浆蛋白',
'凝血因子活性',
'结合胆红素',
'PP',
'血型',
'血糖',
'乳酸',
'中性粒细胞',
'血红蛋白',
'尿素',
'二聚体',
'血红素',
'呼吸频率',
'舒张压',
'收缩压',
'血氧饱和度',
'血小板',
'添加日期'
],
colCount=29)
# 从数据库中得到所有的数据
data_list = self.read_sql_data_exam()
if len(data_list) > 0:
return self.add_model_data(raw_model, data_list)
#诊断数据
def get_model_diagnosis(self):
raw_model = self.get_raw_model(
labels=[
'病人编号',
'自动诊断结果',
'结果',
'疾病类型',
'血友病类型',
'描述',
'诊断日期',
'VWD类型',
],
colCount=8)
# 从数据库中得到所有的数据
data_list = self.read_sql_data_diagnosis()
if len(data_list) > 0:
return self.add_model_data(raw_model, data_list)
#------------------------------------------
# 获取无数据的数据模型
def get_raw_model(
self,
labels: list,
colCount: int = 2) -> QStandardItemModel:
'''
获取无数据的数据模型
:param colCount:要设置的列数
:return:无数据的数据模型
'''
raw_model = QStandardItemModel(0, colCount)
raw_model.setHorizontalHeaderLabels(labels)
return raw_model
#--------------------------------------------------------------------------
# 读取数据库数据
def read_sql_data(self) -> list:
# 获取数据库的连接
connection = get_sql_connection()
# 建立游标
cursor = connection.cursor()
# 执行sql语句
cursor.execute('select * from t_sample;')
# 返回全部内容
return cursor.fetchall()
# 读病人数据库
def read_sql_data_patient(self) -> list:
# 获取数据库的连接
connection = get_sql_connection()
# 建立游标
cursor = connection.cursor()
# 执行sql语句
cursor.execute('select * from Patient_table;')
# 返回全部内容
return cursor.fetchall()
# 读疾病数据库
def read_sql_data_exam(self) -> list:
connection = get_sql_connection()
cursor = connection.cursor()
cursor.execute('select * from Exam_table;')
return cursor.fetchall()
#读疾病数据库
def read_sql_data_diagnosis(self) -> list:
# 获取数据库的连接
connection = get_sql_connection()
# 建立游标
cursor = connection.cursor()
# 执行sql语句
cursor.execute('select * from Diagnosis_table;')
# 返回全部内容
return cursor.fetchall()
# --------------------------------------------------------------------------
# 向模型添加数据
def add_model_data(self, model: QStandardItemModel,
data_list: list) -> QStandardItemModel:
fun = self.choose_add_function(data_list)
if fun is None:
show_error_message(self, "数据类型错误,请检查")
return
final_model = fun(model, data_list)
return final_model
# 生产者函数:选择添加模式
def choose_add_function(self, data_list: list):
method = None
if isinstance(data_list[0], tuple):
method = self.add_multiple_data
else:
method = self.add_single_data
return method
# 添加单条记录
def add_single_data(self, model: QStandardItemModel,
record: list) -> QStandardItemModel:
return model.appendRow(
[QStandardItem(self.process_data(item)) for item in record])
# 添加多条信息
def add_multiple_data(
self,
model: QStandardItemModel,
data_list: list) -> QStandardItemModel:
for record in data_list:
row = []
for item in record:
item = self.process_data(item)
row.append(QStandardItem(item))
model.appendRow(row)
return model
# 处理数据
def process_data(self, data: any) -> any:
if isinstance(data, str):
pass
elif isinstance(data, datetime.datetime):