-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmedicalCard.py
230 lines (200 loc) · 9.88 KB
/
medicalCard.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
import main_window
from PyQt5.QtWidgets import QMainWindow
from PyQt5.QtGui import QIcon
from data.all_models import *
from PyQt5 import uic
from utitlities import *
from data.config import *
from accept import Accept
from error import Error
import datetime
class MedicalCard(QMainWindow):
def __init__(self, name, date, time, doctor):
super().__init__()
uic.loadUi(MEDICAL_CARD_UI, self)
self.setWindowTitle('Медицинская Карта')
self.setWindowIcon(QIcon(ICON))
self.name = name
self.doctor = doctor
member = Patient.get(Patient.current_name == self.name)
self.update_list_of_notes(member)
self.name_label.setText(f'{member.last_name} {member.first_name} {member.middle_name}')
self.date_label.setText(member.date)
self.address_label.setText(member.address)
self.number_label.setText(str(member.number))
self.preparations = self.get_preparations()
self.services = self.get_services()
self.date = date
self.time = time
self.serv = True
self.services_push_button.setStyleSheet("QPushButton"
"{"
"background-color : lightgrey;"
"}")
self.preparations_push_button.setStyleSheet("QPushButton"
"{"
"background-color : white;"
"}"
)
self.set_services()
self.services_push_button.clicked.connect(self.set_services)
self.preparations_push_button.clicked.connect(self.set_preparations)
self.add_push_button.clicked.connect(self.add_service)
self.cost = 0
self.list_of_services = {}
self.save_push_button.clicked.connect(self.check_note)
self.accept_widget = Accept('')
self.accept_widget.accept_push_button.clicked.connect(self.ok)
self.accept_widget.not_accept_push_button.clicked.connect(self.not_ok)
self.error_widget = Error('')
self.error_widget.accept_push_button.clicked.connect(self.error)
self.delete_push_button.clicked.connect(self.delete_service)
s = get_without_failing(History, (History.datetime == f'{self.date} {self.time}'))
print(s)
if s:
self.save_push_button.setText('Изменить')
history_note = History.get(History.datetime == f'{self.date} {self.time}')
self.cost = history_note.amount
print(history_note.list_of_services)
self.cost_line_edit.setText(str(history_note.amount))
for i in history_note.list_of_services.split('\n'):
name, count, price = i.split()
name = name[:-1]
if name not in self.list_of_services:
self.list_of_services[name] = [0, 0]
self.list_of_services[name][0] += int(count)
self.list_of_services[name][1] += int(price)
self.update_price_list()
self.appeal_text_edit.setPlainText(str(history_note.name))
self.note_text_edit.setPlainText(str(history_note.note))
self.get_prices()
def get_history(self):
pass
def get_prices(self):
self.list_of_amounts.clear()
patient = Patient.get(Patient.current_name == self.name)
notes = get_without_failing(History, History.Patient_id == patient.id)
price = 0
if not notes:
return
for i in notes:
self.list_of_amounts.addItem(f'{i.datetime} {i.amount}')
price += i.amount
self.amount_label.setText(str(price))
def delete_service(self):
name = self.price_list.currentItem().text().split()[0][:-1]
count = self.list_of_services[name][0]
price = self.list_of_services[name][1] // count
self.list_of_services[name] = [count - 1, (count - 1) * price]
self.cost -= price
print(self.list_of_services)
self.update_price_list()
def add_service(self):
if self.services_combo_box.currentText() in self.list_of_services:
self.list_of_services[self.services_combo_box.currentText()][0] += self.count_spin_box.value()
else:
self.list_of_services[self.services_combo_box.currentText()] = [self.count_spin_box.value(), 0]
print(self.services_combo_box.currentText())
if self.serv:
article = Services.get(Services.name == self.services_combo_box.currentText()).article
else:
article = Preparations.get(Preparations.name == self.services_combo_box.currentText()).article
price = Price.get(Price.article == article).price
self.list_of_services[self.services_combo_box.currentText()][1] = \
self.list_of_services[self.services_combo_box.currentText()][0] * price
self.cost += price * self.count_spin_box.value()
self.update_price_list()
self.count_spin_box.setValue(0)
def set_services(self):
self.services_push_button.setStyleSheet("QPushButton"
"{"
"background-color : lightgrey;"
"}")
self.preparations_push_button.setStyleSheet("QPushButton"
"{"
"background-color : white;"
"}"
)
self.services_combo_box.clear()
self.services_combo_box.addItems(self.services)
self.serv = True
def set_preparations(self):
self.services_push_button.setStyleSheet("QPushButton"
"{"
"background-color : white;"
"}"
)
self.preparations_push_button.setStyleSheet("QPushButton"
"{"
"background-color : lightgrey;"
"}")
self.services_combo_box.clear()
self.services_combo_box.addItems(self.preparations)
self.serv = False
def get_preparations(self):
prep = get_without_failing(Preparations, Preparations.id >= 0)
list_of_names = [i.name for i in prep]
return list_of_names
def get_services(self):
serv = get_without_failing(Services, Services.id >= 0)
list_of_names = [i.name for i in serv]
return list_of_names
def update_price_list(self):
self.price_list.clear()
for i in self.list_of_services.keys():
if self.list_of_services[i][0] > 0:
self.price_list.addItem(
f'{str(i).capitalize()}: {self.list_of_services[i][0]} {self.list_of_services[i][1]}')
self.cost_line_edit.setText(str(self.cost))
items = [self.price_list.item(x).text() for x in range(self.price_list.count())]
print(items)
def check_note(self):
if len(self.appeal_text_edit.toPlainText()) == 0 or len(self.note_text_edit.toPlainText()) == 0:
self.check(self.error_widget, self.pass_func, 'Проверьте правильность введенных данных')
return
self.check(self.accept_widget, self.save_note, 'Подтвердить введеную информацию')
def save_note(self):
member = Patient.get(Patient.current_name == self.name)
print(self.doctor)
doctor = Doctor.get(Doctor.current_name == self.doctor)
print(self.date, self.time, member.id, doctor.id, ' '.join(self.list_of_services), self.cost,
self.note_text_edit.toPlainText())
s = get_without_failing(History, History.datetime == f'{self.date} {self.time}')
items = [self.price_list.item(x).text() for x in range(self.price_list.count())]
if not s:
history_note = History.create(name=str(self.appeal_text_edit.toPlainText()),
datetime=f'{self.date} {self.time}',
Patient_id=member.id, Doctor_id=doctor.id, list_of_services='\n'.join(items),
amount=self.cost, note=self.note_text_edit.toPlainText())
else:
self.save_push_button.setText('Изменить')
history_note = History.get(History.datetime == f'{self.date} {self.time}')
history_note.list_of_services = ' '.join(items)
history_note.amount = self.cost
history_note.note = self.note_text_edit.toPlainText()
history_note.save()
self.update_list_of_notes(member)
self.get_prices()
def check(self, main_func, func, text):
main_func.accept_push_button.clicked.connect(func)
main_func.label.setText(text)
main_func.show()
self.setEnabled(False)
def ok(self):
self.accept_widget.hide()
self.setEnabled(True)
def not_ok(self):
self.accept_widget.hide()
self.setEnabled(True)
def pass_func(self):
return
def error(self):
self.error_widget.hide()
self.setEnabled(True)
def update_list_of_notes(self, member):
s = get_without_failing(History, History.Patient_id == member.id)
if s:
for n, i in enumerate(s):
doctor = Doctor.get(Doctor.id == i.Doctor_id)
self.list_of_notes.addItem(
f'{n + 1} | {doctor.current_name} | {i.datetime} | {i.name} | {i.note}')