-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
1239 lines (1080 loc) · 55.4 KB
/
Copy pathmain.py
File metadata and controls
1239 lines (1080 loc) · 55.4 KB
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
import sys
import getpass
import cx_Oracle
from PyQt5.QtCore import QDate
from PyQt5.QtWidgets import QApplication, QWidget, QMainWindow
import datetime
from distutils.debug import DEBUG
from SQL_main_app import Ui_MainWindow
from PyQt5 import QtWidgets
from PyQt5 import uic
from PyQt5 import QtCore as qtc
from PyQt5 import QtGui as qtg
cx_Oracle.init_oracle_client(lib_dir=r"C:\instantclient_21_3")
hostname = 'admlab2.cs.put.poznan.pl'
servicename = 'dblab02_students.cs.put.poznan.pl'
# pwd = getpass.getpass('Hasło:\n')
cnxn = cx_Oracle.connect(user='inf145210', password='summazyj123', dsn='%s/%s' % (hostname, servicename))
cnxn.autocommit = True
cursor = cnxn.cursor()
class CardWidget(QWidget):
def __init__(self):
super().__init__()
uic.loadUi('pokaz_karta.ui', self)
class SelectWidget(QWidget):
def __init__(self):
super().__init__()
uic.loadUi('search_window.ui', self)
class SQLappWindow(QMainWindow):
def __init__(self):
super().__init__()
uic.loadUi('SQL_main_app.ui', self)
# self.setupUi(self)
self.dyr_butt.clicked.connect(lambda: self.stackedWidget.setCurrentIndex(1))
self.piel_butt.clicked.connect(lambda: self.stackedWidget.setCurrentIndex(2))
self.lek_butt.clicked.connect(lambda: self.stackedWidget.setCurrentIndex(3))
self.d_backtomain.clicked.connect(lambda: self.stackedWidget.setCurrentIndex(0))
self.p_backtomain.clicked.connect(lambda: self.stackedWidget.setCurrentIndex(0))
self.l_backtomain.clicked.connect(lambda: self.stackedWidget.setCurrentIndex(0))
self.tabWidget.currentChanged.connect(self.deactivate_buttons)
self.tabWidget_2.currentChanged.connect(self.deactivate_buttons)
self.tabWidget_3.currentChanged.connect(self.deactivate_buttons)
# dyrektor
self.d_add.clicked.connect(self.add_as_dyrektor)
self.d_edit.clicked.connect(self.modify_as_dyrektor)
self.d_search.clicked.connect(self.search_as_dyrektor)
self.d_piel_gMod_butt.clicked.connect(self.load_data_dyrektor)
self.d_lek_gMod_butt.clicked.connect(self.load_data_dyrektor)
self.d_sal_gMod_butt.clicked.connect(self.load_data_dyrektor)
# pielegniarka
self.p_add.clicked.connect(self.add_as_piel)
self.p_delete.clicked.connect(self.del_as_piel)
self.p_edit.clicked.connect(self.modify_as_piel)
self.p_search.clicked.connect(self.search_as_piel)
self.p_pac_gMod_butt.clicked.connect(self.load_data_piel)
self.p_bed_gMod_butt.clicked.connect(self.load_data_piel)
self.p_assign_gMod_butt.clicked.connect(self.load_data_piel)
# lekarz
self.l_add.clicked.connect(self.add_as_lek)
self.l_delete.clicked.connect(self.del_as_lekarz)
self.l_edit.clicked.connect(self.modify_as_lekarz)
self.l_search.clicked.connect(self.search_as_lekarz)
self.l_klc_gMod_butt.clicked.connect(self.load_data_lekarz)
self.l_appoin_gMod_butt.clicked.connect(self.load_data_lekarz)
self.l_oper_gMod_butt.clicked.connect(self.load_data_lekarz)
self.l_chor_gMod_butt.clicked.connect(self.load_data_lekarz)
self.d_show_all.clicked.connect(
lambda: self.show_all(self.tabWidget.tabText(self.tabWidget.currentIndex())))
self.p_show_all.clicked.connect(
lambda: self.show_all(self.tabWidget_2.tabText(self.tabWidget_2.currentIndex())))
self.l_show_all.clicked.connect(
lambda: self.show_all(self.tabWidget_3.tabText(self.tabWidget_3.currentIndex())))
self.p_pac_gKLC_butt.clicked.connect(self.show_karta)
self.l_klc_gKLC_butt.clicked.connect(self.show_karta)
def deactivate_buttons(self):
if self.stackedWidget.currentIndex() == 1:
self.d_add.setEnabled(True)
self.d_search.setEnabled(True)
self.d_delete.setEnabled(True)
self.d_edit.setEnabled(True)
if self.tabWidget.currentIndex() == 0:
self.d_delete.setEnabled(False)
elif self.tabWidget.currentIndex() == 1:
self.d_delete.setEnabled(False)
self.d_edit.setEnabled(False)
elif self.tabWidget.currentIndex() == 2:
self.d_add.setEnabled(False)
self.d_search.setEnabled(False)
self.d_delete.setEnabled(False)
elif self.stackedWidget.currentIndex() == 2:
self.p_add.setEnabled(True)
self.p_search.setEnabled(True)
self.p_delete.setEnabled(True)
self.p_edit.setEnabled(True)
if self.tabWidget_2.currentIndex() == 2:
self.p_add.setEnabled(False)
self.p_delete.setEnabled(False)
self.p_search.setEnabled(False)
elif self.tabWidget_2.currentIndex() == 3:
self.p_add.setEnabled(False)
self.p_search.setEnabled(False)
elif self.tabWidget_2.currentIndex() == 1 or self.tabWidget_2.currentIndex() == 0:
self.p_delete.setEnabled(False)
self.p_edit.setEnabled(False)
elif self.tabWidget_2.currentIndex() == 4:
self.p_add.setEnabled(False)
self.p_search.setEnabled(False)
self.p_delete.setEnabled(False)
self.p_edit.setEnabled(False)
elif self.stackedWidget.currentIndex() == 3:
self.l_add.setEnabled(True)
self.l_search.setEnabled(True)
self.l_delete.setEnabled(True)
self.l_edit.setEnabled(True)
if self.tabWidget_3.currentIndex() == 0:
self.l_search.setEnabled(False)
if self.tabWidget_3.currentIndex() == 4:
self.l_add.setEnabled(False)
self.l_delete.setEnabled(False)
elif self.tabWidget_3.currentIndex() == 3:
self.l_add.setEnabled(False)
self.l_delete.setEnabled(False)
self.l_edit.setEnabled(False)
elif self.tabWidget_3.currentIndex() in (1, 2):
self.l_edit.setEnabled(False)
self.l_search.setEnabled(False)
elif self.tabWidget_3.currentIndex() == 5:
self.l_delete.setEnabled(False)
self.l_edit.setEnabled(False)
self.l_search.setEnabled(False)
elif self.tabWidget_3.currentIndex() == 6:
self.l_add.setEnabled(False)
self.l_search.setEnabled(False)
self.l_delete.setEnabled(False)
self.l_edit.setEnabled(False)
def add_as_dyrektor(self):
if self.tabWidget.currentIndex() == 0:
imie = self.d_piel_gM_imie_edit.text().upper()
nazwisko = self.d_piel_gM_nazw_edit.text().upper()
if not imie.isalpha() or not nazwisko.isalpha():
error_dialog = QtWidgets.QErrorMessage()
error_dialog.showMessage('Uzupelnij wszystkie dane poprawnie')
error_dialog.exec_()
return
insert_pracownik = """INSERT INTO pracownik VALUES (DEFAULT, :imie, :nazwisko, :zatrudniony)"""
cursor.prepare(insert_pracownik)
cursor.execute(None,
imie=imie,
nazwisko=nazwisko,
zatrudniony=datetime.datetime.now()
)
insert_pielegniarka = "INSERT INTO pielegniarka VALUES ((SELECT max(id_prac) FROM pracownik), null) "
cursor.execute(insert_pielegniarka)
print("dodałem pielegniarke")
if self.tabWidget.currentIndex() == 1:
imie = self.d_lek_gM_imie_edit.text().upper()
nazwisko = self.d_lek_gM_nazw_edit.text().upper()
specjal = self.d_lek_gM_spec_edit.text().upper()
if not imie.isalpha() or not nazwisko.isalpha() or not specjal.isalpha():
error_dialog = QtWidgets.QErrorMessage()
error_dialog.showMessage('Uzupelnij wszystkie dane poprawnie')
error_dialog.exec_()
return
insert_pracownik = """INSERT INTO pracownik VALUES (DEFAULT, :imie, :nazwisko, :zatrudniony)"""
cursor.prepare(insert_pracownik)
cursor.execute(None,
imie=imie,
nazwisko=nazwisko,
zatrudniony=datetime.datetime.now()
)
insert_lekarz = (
"INSERT INTO lekarz VALUES ((SELECT max(id_prac) FROM pracownik), :SPECJALIZACJA, (SELECT min(id_sali) FROM sala WHERE typ in 'Gabinet lekarski'))")
cursor.execute(insert_lekarz, [specjal])
print("dodałem lekarza")
def load_data_dyrektor(self):
# TODO zrobić funkcje zeby wyswietlalo sie okno o pustym polu
if self.tabWidget.currentIndex() == 0:
found = False
id_prac = self.d_piel_gMod_idpiel_edit.text()
imie = ""
nazwisko = ""
# select po id_prac
# wprowadz otrzymany wynik do imienia i nazwiska
# /błąd jak nie ma takiego rekordu/
cursor.execute(
"SELECT pielegniarka.id_prac, imie, nazwisko, zatrudniony, id_sali FROM pielegniarka join pracownik on pracownik.id_prac = pielegniarka.id_prac")
for item in cursor:
if str(item[0]) == id_prac:
item = tuple(map(str, item))
imie, nazwisko = item[1], item[2]
found = True
break
if not found:
print("nie ma takiego pracownika")
# error messagebox
else:
self.d_piel_gM_imie_edit.setText(imie)
self.d_piel_gM_nazw_edit.setText(nazwisko)
print("laduje piel")
if self.tabWidget.currentIndex() == 2:
found = False
typ = ""
id_sali = self.d_sal_gMod_idsali_edit.text()
# select po id_sali
# wprowadz otrzymany wynik do pól
# /błąd jak nie ma takiego rekordu/
cursor.execute(
"SELECT id_sali, typ FROM sala")
for item in cursor:
if str(item[0]) == id_sali:
item = tuple(map(str, item))
typ = item[1]
found = True
break
if not found:
print("nie ma takiej sali")
else:
self.d_sal_gM_type_combo.setCurrentIndex(self.d_sal_gM_type_combo.findText(typ))
print("laduje sale")
def modify_as_dyrektor(self):
if self.tabWidget.currentIndex() == 0:
id_prac = self.d_piel_gMod_idpiel_edit.text()
imie = self.d_piel_gM_imie_edit.text().upper()
nazwisko = self.d_piel_gM_nazw_edit.text().upper()
# sprawdz czy istnieje
if not id_prac.isnumeric() or not nazwisko.isalpha():
error_dialog = QtWidgets.QErrorMessage()
error_dialog.showMessage('Nazwisko lub id_pracownika jest nieprawidlowe')
error_dialog.exec_()
return
komenda = ('SELECT count(*) from pielegniarka where id_prac = :id_p')
cursor.execute(komenda, [id_prac])
for item in cursor:
if str(item) != '(1,)':
error_dialog = QtWidgets.QErrorMessage()
error_dialog.showMessage('Bledny numer pracownika')
error_dialog.exec_()
return
update_nazwisko = 'UPDATE pracownik SET nazwisko = :naz WHERE id_prac = :id'
cursor.execute(update_nazwisko, [nazwisko, id_prac])
cursor.execute("COMMIT")
print("modify piel")
if self.tabWidget.currentIndex() == 2:
id_sali = self.d_sal_gMod_idsali_edit.text()
typ_sali = self.d_sal_gM_type_combo.currentText()
# sprawdz czy istnieje sala po id_sali
if not id_sali.isnumeric():
error_dialog = QtWidgets.QErrorMessage()
error_dialog.showMessage('id_sali lub typ_sali jest nieprawidlowe')
error_dialog.exec_()
return
komenda = ('SELECT count(*) from sala where id_sali = :id_s')
cursor.execute(komenda, [id_sali])
for item in cursor:
if str(item) != '(1,)':
error_dialog = QtWidgets.QErrorMessage()
error_dialog.showMessage('Bledny numer sali')
error_dialog.exec_()
return
updateSala = ('UPDATE sala SET typ = :typp WHERE id_sali = :id_salii')
cursor.execute(updateSala, [typ_sali, id_sali])
cursor.execute("COMMIT")
print("modify sala")
def search_as_dyrektor(self):
self.window = SelectWidget()
if self.tabWidget.currentIndex() == 0:
imie = self.d_piel_gM_imie_edit.text().upper()
nazwisko = self.d_piel_gM_nazw_edit.text().upper()
# jezeli nic nie ma daj bład
# select * from cos tam where imie = cos nazwisko = cos
self.window.tabela.setColumnCount(5)
self.window.tabela.setRowCount(10)
self.window.tabela.setHorizontalHeaderLabels(["ID prac", "Imie", "Nazwisko", "Zatrudniony", "Nr sali"])
occur = False
cursor.execute(
"SELECT pielegniarka.id_prac, imie, nazwisko, zatrudniony, id_sali FROM pielegniarka join pracownik on pracownik.id_prac = pielegniarka.id_prac")
tablerow = 0
for item in cursor:
item = tuple(map(str, item))
if imie != '':
if imie == item[1]:
occur = True
else:
occur = False
continue
if nazwisko != '':
if nazwisko == item[2]:
occur = True
else:
occur = False
continue
if occur:
for i in range(5):
self.window.tabela.setItem(tablerow, i, QtWidgets.QTableWidgetItem(item[i]))
tablerow += 1
print("search piel")
if self.tabWidget.currentIndex() == 1:
imie = self.d_lek_gM_imie_edit.text().upper()
nazwisko = self.d_lek_gM_nazw_edit.text().upper()
specjal = self.d_lek_gM_spec_edit.text().upper()
self.window.tabela.setColumnCount(5)
self.window.tabela.setRowCount(10)
self.window.tabela.setHorizontalHeaderLabels(
["Imie", "Nazwisko", "Zatrudniony", "Nr sali", "Specjalizacja"])
occur = False
cursor.execute(
"SELECT imie, nazwisko, zatrudniony, id_sali as nr_sali, specjalizacja FROM pracownik join lekarz on pracownik.id_prac = lekarz.id_prac")
tablerow = 0
for item in cursor:
item = tuple(map(str, item))
if imie != '':
if imie == item[0]:
occur = True
else:
occur = False
continue
if nazwisko != '':
if nazwisko == item[1]:
occur = True
else:
occur = False
continue
if specjal != '':
if specjal == item[4]:
occur = True
else:
occur = False
continue
if occur:
for i in range(5):
self.window.tabela.setItem(tablerow, i, QtWidgets.QTableWidgetItem(item[i]))
tablerow += 1
print("search lek")
self.window.show()
def add_as_piel(self):
if self.tabWidget_2.currentIndex() == 0:
imie = self.p_pac_gM_imie_edit.text().upper()
nazwisko = self.p_pac_gM_nazw_edit.text().upper()
pesel = self.p_pac_gM_pesel_edit.text()
data_uro_r = self.p_pac_gM_date_dedit.date().year()
data_uro_m = self.p_pac_gM_date_dedit.date().month()
data_uro_d = self.p_pac_gM_date_dedit.date().day()
# sprawdz czy nie ma o tym samym peselu
if not imie.isalpha() or not nazwisko.isalpha() or not pesel.isnumeric():
error_dialog = QtWidgets.QErrorMessage()
error_dialog.showMessage('Uzupelnij wszystkie dane poprawnie')
error_dialog.exec_()
return
insert_pacjent = """INSERT INTO pacjent VALUES (:pesel, :imie, :nazwisko, :data_ur)"""
cursor.prepare(insert_pacjent)
cursor.execute(None,
pesel=pesel,
imie=imie,
nazwisko=nazwisko,
data_ur=datetime.date(data_uro_r, data_uro_m, data_uro_d)
)
print("dodaj pacjent")
if self.tabWidget_2.currentIndex() == 1:
imie_o = self.p_odw_gM_imie_edit.text().upper()
nazwisko_o = self.p_odw_gM_nazw_edit.text().upper()
pesel_o = self.p_odw_gM_peselO_edit.text()
pesel = self.p_odw_gM_pesel_edit.text()
st_pok = self.p_odw_gM_pokr_combo.currentText()
if not imie_o.isalpha() or not nazwisko_o.isalpha() or not pesel_o.isnumeric() or not pesel.isnumeric() or not st_pok.isalpha():
error_dialog = QtWidgets.QErrorMessage()
error_dialog.showMessage('Uzupelnij wszystkie dane poprawnie')
error_dialog.exec_()
return
insert_pracownik = """INSERT INTO odwiedziny VALUES (:data_odw, :pesel_odw, :pesel, :imie_odw, :nazwisko_odw, :st_pokr)"""
cursor.prepare(insert_pracownik)
cursor.execute(None,
data_odw=datetime.datetime.now(),
pesel=pesel,
pesel_odw=pesel_o,
imie_odw=imie_o,
nazwisko_odw=nazwisko_o,
st_pokr=st_pok
)
print("dodaj odwiedziny")
def del_as_piel(self):
if self.tabWidget_2.currentIndex() == 3:
id_prac = self.p_assign_gU_idpiel_edit.text()
# jezeli puste info
# jezeli istenieje ok jezeli nie to powiadom
update_pielegniarka = 'UPDATE pielegniarka SET id_sali = :id_salii WHERE id_prac = :id'
cursor.execute(update_pielegniarka, ["", id_prac])
cursor.execute("COMMIT")
print("usun przypisanie do sali")
def load_data_piel(self):
if self.tabWidget_2.currentIndex() == 2:
found = False
id_sali, pesel, usytuowanie, respirator = "", "", "", ""
id_lozka = self.p_bed_gMod_idbed_edit.text()
# jezeli puste notyfikacja
# select po unikat
cursor.execute(
"SELECT id_lozka, id_sali, pesel, usytuowanie, respirator FROM lozko")
for item in cursor:
if str(item[0]) == id_lozka:
item = tuple(map(str, item))
id_sali, pesel, usytuowanie, respirator = item[1], item[2], item[3], item[4]
found = True
break
if not found:
print("nie ma takiego pracownika")
# error messagebox
else:
self.p_bed_gM_plc_combo.setCurrentIndex(self.p_bed_gM_plc_combo.findText(usytuowanie))
self.p_bed_gM_res_combo.setCurrentIndex(self.p_bed_gM_res_combo.findText(respirator))
self.p_bed_gM_idsali_edit.setText(id_sali)
self.p_bed_gM_pesel_edit.setText(pesel)
print("zaladuj lozko")
if self.tabWidget_2.currentIndex() == 3:
found = False
id_sali = ""
id_prac = self.p_assign_gMod_idpiel_edit.text()
# jezeli puste notify
# select po unikat
cursor.execute(
"SELECT pielegniarka.id_prac, id_sali FROM pielegniarka join pracownik on pracownik.id_prac = pielegniarka.id_prac")
for item in cursor:
if str(item[0]) == id_prac:
item = tuple(map(str, item))
id_sali = item[1]
found = True
break
if not found:
print("nie ma takiego pracownika")
# error messagebox
else:
self.p_assign_gM_idsali_edit.setText(id_sali)
print("zaladuj przypis")
def modify_as_piel(self):
if self.tabWidget_2.currentIndex() == 2:
id_lozka = self.p_bed_gMod_idbed_edit.text()
# jezeli puste notyfikacja
# select po unikat
polozenie = self.p_bed_gM_plc_combo.currentText()
resp = self.p_bed_gM_res_combo.currentText()
id_sali = self.p_bed_gM_idsali_edit.text()
pesel = self.p_bed_gM_pesel_edit.text()
# update
if not pesel.isnumeric() or not id_lozka.isnumeric():
error_dialog = QtWidgets.QErrorMessage()
error_dialog.showMessage('id_lozka lub pesel jest nieprawidlowe')
error_dialog.exec_()
return
komenda = ('SELECT count(*) from lozko where id_lozka = :id_l')
cursor.execute(komenda, [id_lozka])
for item in cursor:
if str(item) != '(1,)':
error_dialog = QtWidgets.QErrorMessage()
error_dialog.showMessage('Bledny numer lozka')
error_dialog.exec_()
return
komenda2 = ('SELECT count(*) from pacjent where pesel = :id_p')
cursor.execute(komenda2, [pesel])
for item in cursor:
if str(item) != '(1,)':
error_dialog = QtWidgets.QErrorMessage()
error_dialog.showMessage('Bledny pesel')
error_dialog.exec_()
return
update_wstepny = ('UPDATE lozko SET pesel = NULL WHERE pesel in :psssl')
cursor.execute(update_wstepny, [pesel])
update_lozko = ('UPDATE lozko SET pesel = :psl WHERE id_lozka = :id')
cursor.execute(update_lozko, [pesel, id_lozka])
cursor.execute("COMMIT")
print("update lozko")
if self.tabWidget_2.currentIndex() == 3:
id_prac = self.p_assign_gMod_idpiel_edit.text()
# jezeli puste notify
# select po unikat
id_sali = self.p_assign_gM_idsali_edit.text()
# sprawdz czy sala istnieje jak nie error message
update_pielegniarka = 'UPDATE pielegniarka SET id_sali = :id_salii WHERE id_prac = :id'
cursor.execute(update_pielegniarka, [id_sali, id_prac])
cursor.execute("COMMIT")
print("update przypis")
def search_as_piel(self):
if self.tabWidget_2.currentIndex() == 0:
# jezeli puste notyfikacja
imie = self.p_pac_gM_imie_edit.text().upper()
nazwisko = self.p_pac_gM_nazw_edit.text().upper()
pesel = self.p_pac_gM_pesel_edit.text().upper()
data = self.p_pac_gM_date_dedit.date().toString("yyyy-MM-dd")
# select po tym co nie jest null
self.window = SelectWidget()
self.window.tabela.setColumnCount(4)
self.window.tabela.setRowCount(10)
self.window.tabela.setHorizontalHeaderLabels(["PESEL", "Imie", "Nazwisko", "Data urodzenia"])
occur = False
cursor.execute(
"SELECT p.* FROM pacjent p")
tablerow = 0
for item in cursor:
item = tuple(map(str, item))
if pesel != '':
if pesel == item[0]:
occur = True
else:
occur = False
continue
if imie != '':
if imie == item[1]:
occur = True
else:
occur = False
continue
if nazwisko != '':
if nazwisko == item[2]:
occur = True
else:
occur = False
continue
if occur:
for i in range(4):
self.window.tabela.setItem(tablerow, i, QtWidgets.QTableWidgetItem(item[i]))
tablerow += 1
print("szukaj pacjent")
if self.tabWidget_2.currentIndex() == 1:
imie_o = self.p_odw_gM_imie_edit.text().upper()
nazwisko_o = self.p_odw_gM_nazw_edit.text().upper()
pesel_o = self.p_odw_gM_peselO_edit.text()
pesel = self.p_odw_gM_pesel_edit.text()
st_pok = self.p_odw_gM_pokr_combo.currentText()
# select po tym co nie jest null
self.window = SelectWidget()
self.window.tabela.setColumnCount(6)
self.window.tabela.setRowCount(50)
self.window.tabela.setHorizontalHeaderLabels(
["Imie", "Nazwisko", "Imie odwiedzajacego", "Nazwisko odwiedzajacego", "Stopien pokrewienstwa",
"Data odwiedzin"])
occur = False
cursor.execute(
"SELECT imie, nazwisko, imie_odw, nazwisko_odw, st_pokrewienstwa, data_odw FROM odwiedziny o join pacjent p on p.pesel = o.pesel")
tablerow = 0
for item in cursor:
item = tuple(map(str, item))
if imie_o != '':
if imie_o == item[2]:
occur = True
else:
occur = False
continue
if nazwisko_o != '':
if nazwisko_o == item[3]:
occur = True
else:
occur = False
continue
if st_pok != '':
if st_pok == item[4]:
occur = True
else:
occur = False
continue
if occur:
for i in range(6):
self.window.tabela.setItem(tablerow, i, QtWidgets.QTableWidgetItem(item[i]))
tablerow += 1
print("szukaj odwiedz")
self.window.show()
def add_as_lek(self):
if self.tabWidget_3.currentIndex() == 0:
pesel = self.l_klc_gM_pesel_edit.text()
nazwa_chor = self.l_klc_gM_idchor_edit.text().upper()
nazwa_leku = self.l_klc_gM_idlek_edit.text().upper()
stan = self.l_klc_gM_stan_txt_edit.toPlainText()
# insert
if not nazwa_chor.isalpha() or not nazwa_leku.isalpha() or not pesel.isnumeric():
error_dialog = QtWidgets.QErrorMessage()
error_dialog.showMessage('Uzupelnij wszystkie dane poprawnie')
error_dialog.exec_()
return
insert_KARTA = """INSERT INTO karta_lecz_chor VALUES (DEFAULT, :pesel, (SELECT id_choroby from choroba WHERE nazwa in :nazwa_c), :d_zdiag, (SELECT id_leku from leki WHERE nazwa in :nazwa_l), :data_wpisu, :stan)"""
cursor.prepare(insert_KARTA)
cursor.execute(None,
pesel=pesel,
nazwa_c=nazwa_chor,
d_zdiag=datetime.date.today(),
nazwa_l=nazwa_leku,
data_wpisu=datetime.date.today(),
stan=stan
)
print("dodaje karte")
if self.tabWidget_3.currentIndex() == 1:
imie_l = self.l_appoin_gM_imielek_edit.text().upper()
nazwisko_l = self.l_appoin_gM_nazwlek_edit.text().upper()
pesel = self.l_appoin_gM_pesel_edit.text()
data_wizyt_r = self.l_appoin_gM_dateofappoin_dedit.date().year()
data_wizyt_m = self.l_appoin_gM_dateofappoin_dedit.date().month()
data_wizyt_d = self.l_appoin_gM_dateofappoin_dedit.date().day()
if not imie_l.isalpha() or not nazwisko_l.isalpha() or not pesel.isnumeric():
error_dialog = QtWidgets.QErrorMessage()
error_dialog.showMessage('Uzupelnij wszystkie dane poprawnie')
error_dialog.exec_()
return
insert_pracownik = """INSERT INTO wizyta VALUES (DEFAULT, :data_wizyty, (SELECT id_prac FROM pracownik WHERE imie in :imie_l and nazwisko in :nazwisko_l), :pesel)"""
cursor.prepare(insert_pracownik)
cursor.execute(None,
data_wizyty=datetime.date(data_wizyt_r, data_wizyt_m, data_wizyt_d),
imie_l=imie_l,
nazwisko_l=nazwisko_l,
pesel=pesel
)
print("dodaje wizyte")
if self.tabWidget_3.currentIndex() == 2: # operacja
nazwa_oper = self.l_oper_gM_nazwa_edit.text().upper()
pesel_p = self.l_oper_gM_pesel_edit.text()
imie_lek = self.l_oper_gM_imielek_edit.text().upper()
nazwisko_lek = self.l_oper_gM_nazwilek_edit.text().upper()
nazwa_chor = self.l_oper_gM_idchor_edit.text().upper()
id_sali = self.l_oper_gM_idsali_edit.text()
data_oper = self.l_oper_gM_date_dedit.date().toString("yyyy-MM-dd")
czas = self.l_oper_gM_time_spinbox.value()
# id choroby = nazwa?
# insert
if not nazwa_oper.isalpha() or not imie_lek.isalpha() or not pesel_p.isnumeric() or not nazwisko_lek.isnumeric() or not nazwa_chor.isalpha():
error_dialog = QtWidgets.QErrorMessage()
error_dialog.showMessage('Uzupelnij wszystkie dane poprawnie')
error_dialog.exec_()
return
insert_pracownik = """INSERT INTO operacja VALUES (DEFAULT, :data_op, :nazwa_op, :dl_trwania, :pesel, (SELECT id_choroby FROM choroba WHERE nazwa in :nazwa_c), (SELECT id_prac FROM pracownik WHERE imie in :imie_l and nazwisko in :nazwisko_l), :id_sali )"""
cursor.prepare(insert_pracownik)
cursor.execute(None,
data_op=datetime.datetime.now(),
nazwa_op=nazwa_oper,
dl_trwania=czas,
pesel=pesel_p,
nazwa_c=nazwa_chor,
imie_l=imie_lek,
nazwisko_l=nazwisko_lek,
id_sali=id_sali
)
print("dodaje operacje")
if self.tabWidget_3.currentIndex() == 5:
imie = self.p_pac_gM_imie_edit_3.text().upper()
nazwisko = self.p_pac_gM_nazw_edit_3.text().upper()
pesel = self.p_pac_gM_pesel_edit_3.text()
data_uro_r = self.p_pac_gM_date_dedit.date().year()
data_uro_m = self.p_pac_gM_date_dedit.date().month()
data_uro_d = self.p_pac_gM_date_dedit.date().day()
# sprawdz czy nie ma o tym samym peselu
if not imie.isalpha() or not nazwisko.isalpha() or not pesel.isnumeric():
error_dialog = QtWidgets.QErrorMessage()
error_dialog.showMessage('Uzupelnij wszystkie dane poprawnie')
error_dialog.exec_()
return
insert_pacjent = """INSERT INTO pacjent VALUES (:pesel, :imie, :nazwisko, :data_ur)"""
cursor.prepare(insert_pacjent)
cursor.execute(None,
pesel=pesel,
imie=imie,
nazwisko=nazwisko,
data_ur=datetime.date(data_uro_r, data_uro_m, data_uro_d)
)
print("dodaje pacjent")
def del_as_lekarz(self):
if self.tabWidget_3.currentIndex() == 0:
nr_karty = self.l_klc_gU_nrkart_edit.text()
# sprawdz czy istnieje
# delete
delete_karta = 'DELETE FROM karta_lecz_chor WHERE nr_karty in :karta'
cursor.execute(delete_karta, [nr_karty])
cursor.execute("COMMIT")
print("usun karte")
if self.tabWidget_3.currentIndex() == 1:
id_wizyty = self.l_appoin_gU_idlek_edit.text()
# jak jedno puste błąd
# sprawdz czy istnieje
# delete
delete_wizyta = 'DELETE FROM wizyta where id_wizyty in :id_w'
cursor.execute(delete_wizyta, [id_wizyty])
cursor.execute("COMMIT")
print("usun wizyte")
if self.tabWidget_3.currentIndex() == 2:
id_operacji = self.l_oper_gU_idoper_edit.text()
# sprawdz czy istnieje
# delete
delete_operacja = 'DELETE FROM operacja where id_operacji in :id_op'
cursor.execute(delete_operacja, [id_operacji])
cursor.execute("COMMIT")
print("usun operacje")
def load_data_lekarz(self):
if self.tabWidget_3.currentIndex() == 0:
# select jezeli jest
found = False
pesel, nazwa_c, nazwa_l, stan = "", "", "", ""
nr_karty = self.l_klc_gMod_nrkart_edit.text()
cursor.execute(
"SELECT nr_karty, k.pesel, c.nazwa, stan, l.nazwa FROM choroba c join karta_lecz_chor k on c.id_choroby = k.id_choroby join leki l on k.id_leku = l.id_leku")
for item in cursor:
if str(item[0]) == nr_karty:
item = tuple(map(str, item))
pesel, nazwa_c, stan, nazwa_l = item[1], item[2], item[3], item[4]
found = True
break
if not found:
print("nie ma takiej karty")
# error messagebox
else:
self.l_klc_gM_pesel_edit.setText(pesel)
self.l_klc_gM_idchor_edit.setText(nazwa_c)
self.l_klc_gM_idlek_edit.setText(nazwa_l)
self.l_klc_gM_stan_txt_edit.setPlainText(stan)
print("ładuj karte")
if self.tabWidget_3.currentIndex() == 4:
found = False
nazwa_c, uleczal = "", ""
id_choroby = self.l_chor_gMod_idchor_edit.text()
cursor.execute("SELECT id_choroby, nazwa, uleczalnosc FROM choroba")
for item in cursor:
if str(item[0]) == id_choroby:
item = tuple(map(str, item))
nazwa_c, uleczal = item[1], item[2]
found = True
break
if not found:
print("nie ma takiego pracownika")
# error messagebox
else:
self.l_chor_gM_nazwa_edit.setText(nazwa_c)
self.l_chor_gM_ulecz_combo.setCurrentIndex(self.l_chor_gM_ulecz_combo.findText(uleczal))
print("ładuj choroba")
def modify_as_lekarz(self):
if self.tabWidget_3.currentIndex() == 0:
nr_karty = self.l_klc_gMod_nrkart_edit.text()
pesel = self.l_klc_gM_pesel_edit.text()
id_choroby = self.l_klc_gM_idchor_edit.text()
id_leku = self.l_klc_gM_idlek_edit.text()
stan = self.l_klc_gM_stan_txt_edit.toPlainText()
# update
if not stan.isalpha() or not nr_karty.isnumeric():
error_dialog = QtWidgets.QErrorMessage()
error_dialog.showMessage('stan lub nr_karty jest nieprawidlowe')
error_dialog.exec_()
return
komenda = ('SELECT count(*) from karta_lecz_chor where nr_karty = :id_k')
cursor.execute(komenda, [nr_karty])
for item in cursor:
if str(item) != '(1,)':
error_dialog = QtWidgets.QErrorMessage()
error_dialog.showMessage('Bledny numer karty')
error_dialog.exec_()
return
update_karta = 'UPDATE karta_lecz_chor SET stan = :stann where nr_karty in :karta'
cursor.execute(update_karta, [stan, nr_karty])
cursor.execute("COMMIT")
print("edytuj karte")
if self.tabWidget_3.currentIndex() == 4:
id_choroby = self.l_chor_gMod_idchor_edit.text()
uleczal = self.l_chor_gM_ulecz_combo.currentText()
update_choroba = ('UPDATE choroba SET uleczalnosc = :ulecz WHERE id_choroby = :id')
cursor.execute(update_choroba, [uleczal, id_choroby])
cursor.execute("COMMIT")
print("edytuj choroba")
def search_as_lekarz(self):
self.window = SelectWidget()
if self.tabWidget_3.currentIndex() == 0:
pesel = self.l_klc_gM_pesel_edit.text()
id_choroby = self.l_klc_gM_idchor_edit.text()
id_leku = self.l_klc_gM_idlek_edit.text()
# select
print("szukam karte")
if self.tabWidget_3.currentIndex() == 1:
id_lekarz = self.l_appoin_gM_idlek_edit.text()
pesel = self.l_appoin_gM_pesel_edit.text()
data_wizyt = self.l_appoin_gM_dateofappoin_dedit.date().toString("yyyy-MM-dd")
# select
print("szukam wizyte")
if self.tabWidget_3.currentIndex() == 2:
nazwa_oper = self.l_oper_gM_nazwa_edit.text()
pesel_p = self.l_oper_gM_pesel_edit.text()
id_lekarz = self.l_oper_gM_idlek_edit.text()
id_choroby = self.l_oper_gM_idchor_edit.text()
id_sali = self.l_oper_gM_idsali_edit.text()
data_oper = self.l_oper_gM_date_dedit.date().toString("yyyy-MM-dd")
czas = self.l_oper_gM_time_spinbox.value()
# select
print("szukam operacje")
if self.tabWidget_3.currentIndex() == 3:
nazwa_lek = self.l_leki_gM_nazwa_edit.text().upper()
na_rec = self.l_leki_gM_rec_combo.currentText()
# select
self.window.tabela.setColumnCount(3)
self.window.tabela.setRowCount(10)
self.window.tabela.setHorizontalHeaderLabels(["Id leku", "Nazwa", "Na recepte"])
occur = False
cursor.execute(
"SELECT * FROM leki")
tablerow = 0
for item in cursor:
item = tuple(map(str, item))
if nazwa_lek != '':
if nazwa_lek == item[1]:
occur = True
else:
occur = False
continue
if na_rec != '':
if na_rec == item[2]:
occur = True
else:
occur = False
continue
if occur:
for i in range(3):
self.window.tabela.setItem(tablerow, i, QtWidgets.QTableWidgetItem(item[i]))
tablerow += 1
print("szukam leki")
if self.tabWidget_3.currentIndex() == 4:
nazwa_chor = self.l_chor_gM_nazwa_edit.text().upper()
ulecz = self.l_chor_gM_ulecz_combo.currentText()
# select
self.window.tabela.setColumnCount(3)
self.window.tabela.setRowCount(10)
self.window.tabela.setHorizontalHeaderLabels(["Id choroby", "Nazwa choroby", "Uleczalność"])
occur = False
cursor.execute("SELECT * FROM choroba")
tablerow = 0
for item in cursor:
item = tuple(map(str, item))
if nazwa_chor != '':
if nazwa_chor == item[1]:
occur = True
else:
occur = False
continue
if ulecz != '':
if ulecz == item[2]:
occur = True
else:
occur = False
continue
if occur:
for i in range(3):
self.window.tabela.setItem(tablerow, i, QtWidgets.QTableWidgetItem(item[i]))
tablerow += 1
print("szukam choroba")
if self.tabWidget_3.currentIndex() == 5:
imie = self.p_pac_gM_imie_edit_3.text()
nazwisko = self.p_pac_gM_nazw_edit_3.text()
pesel = self.p_pac_gM_pesel_edit_3.text()
data = self.p_pac_gM_date_dedit_3.date().toString("yyyy-MM-dd")
# select po tym co nie jest null
print("szukam pacjent")
self.window.show()
def show_all(self, name):
self.window = SelectWidget()
self.window.wynik_label.setText(name)
if self.stackedWidget.currentIndex() == 1:
if self.tabWidget.currentIndex() == 0:
self.window.tabela.setColumnCount(5)
self.window.tabela.setRowCount(50)
self.window.tabela.setHorizontalHeaderLabels(["Id prac", "Imie", "Nazwisko", "Zatrudniony", "Nr sali"])
cursor.execute(
"SELECT pielegniarka.id_prac, imie, nazwisko, zatrudniony, id_sali FROM pielegniarka join pracownik on pracownik.id_prac = pielegniarka.id_prac")
tablerow = 0
for item in cursor:
print(item)
item = tuple(map(str, item))
for i in range(5):
self.window.tabela.setItem(tablerow, i, QtWidgets.QTableWidgetItem(item[i]))
tablerow += 1
if self.tabWidget.currentIndex() == 1:
self.window.tabela.setColumnCount(6)
self.window.tabela.setRowCount(50)
self.window.tabela.setHorizontalHeaderLabels(
["Id prac", "Imie", "Nazwisko", "Zatrudniony", "Nr sali", "Specjalizacja"])
cursor.execute(
"SELECT lekarz.id_prac, imie, nazwisko, zatrudniony, id_sali as nr_sali, specjalizacja FROM pracownik join lekarz on pracownik.id_prac = lekarz.id_prac")
tablerow = 0
for item in cursor:
item = tuple(map(str, item))
for i in range(6):
self.window.tabela.setItem(tablerow, i, QtWidgets.QTableWidgetItem(item[i]))
tablerow += 1
if self.tabWidget.currentIndex() == 2:
self.window.tabela.setColumnCount(3)
self.window.tabela.setRowCount(50)
self.window.tabela.setHorizontalHeaderLabels(["Nr sali", "Typ sali", "Liczba lozek"])