/
User.py
304 lines (269 loc) · 10.3 KB
/
User.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
from DataBaseUtils import DB
from Entity import Item, Medicine, Message
class User:
def __init__(self,id, name, family, mobile_no, password, email,user_type):
self.id=id
self.name = name
self.family = family
self.mobile_no = mobile_no
self.password = password
self.email = email
self.user_type = user_type
def save(self):
db = DB('localhost', 'root', 'db')
db.sign_up(self)
return
def save_me(self,name,family,mobile_no,email,password):
db = DB('localhost', 'root', 'db')
connection = db.data_base_connection()
try:
sql = "UPDATE `users` SET `name`=%s,`family`=%s,`mobile_no`=%s,`email`=%s,`password`=%s WHERE `email`=%s "
with connection.cursor() as cursor:
cursor.execute(sql,(name,family,mobile_no,email,password,self.email))
connection.commit()
finally:
connection.close()
@staticmethod
def dr_time():
db = DB('localhost', 'root', 'db')
connection = db.data_base_connection()
sql = 'select * from `time`'
try:
with connection.cursor() as cursor:
cursor.execute(sql)
result = cursor.fetchall()
return result
finally:
connection.close()
return result
def send_message(self,message):
m = Message(self.id, message.get('rid'), message.get('title'), message.get('body'))
m.save()
return "done"
def see_messages(self):
db = DB('localhost', 'root', 'db')
connection = db.data_base_connection()
try:
with connection.cursor() as cursor:
sql = 'select * from `mail` where `receive_id` = %s '
cursor.execute(sql,(self.id,))
result = cursor.fetchall()
return result
finally:
connection.close()
class Manager(User): #user_type_id = 1
def add_user(self, user):
db = DB('localhost', 'root', 'db')
connection = db.data_base_connection()
sql = 'INSERT INTO `users` (`name`,`family`,`mobile_no`,`email`, `password`,`user_type`) VALUES (%s,%s,%s,%s,%s,%s)'
try:
with connection.cursor() as cursor:
cursor.execute(sql, (user.name, user.family,user.mobile_no,
user.email,user.password, user.user_type))
connection.commit()
finally:
connection.close()
return # add user to data base
def delete_user(self,id):
db = DB('localhost', 'root', 'db')
db.delete_by_id(id)
return # delete user from data base
def select_all_user(self):
db = DB('localhost', 'root', 'db')
return db.find_all()
class Reception(User): #user_type_id = 2
def delete(self, id):
# check = whether is doctor available
return
@staticmethod
def set_appointment(doctor, patient, weekday, hour):
db = DB('localhost', 'root', 'db')
connection = db.data_base_connection()
sql = 'INSERT INTO `time_table` (`dr_id`,`p_id`,`weekday`,`hour`) VALUES (%s,%s,%s,%s)'
try:
with connection.cursor() as cursor:
cursor.execute(sql, (doctor,patient,weekday,hour))
connection.commit()
finally:
connection.close()
return
@staticmethod
def set_doctors_time_table(doctor,days,hour):
db = DB('localhost', 'root', 'db')
connection = db.data_base_connection()
sql = 'INSERT INTO `time` (`dr_id`,`week_day`,`hours`) VALUES (%s,%s,%s)'
try:
with connection.cursor() as cursor:
cursor.execute(sql, (doctor, days, hour))
connection.commit()
finally:
connection.close()
return
class Accountant(User): #user_type_id = 3
@staticmethod
def set_bill(name, patient, cost):
item =Item(name=name,p=patient,cost=cost)
item.add_item()
return
@staticmethod
def get_bill(p):
return Item.get_all(p)
class Pharmacy(User): #user_type_id = 4
@staticmethod
def get_medicine():
med = Medicine.find_all()
return med
@staticmethod
def get_medicine_filter(time):
med = Medicine.find_all_filter(time)
return med
class Patient(User): #user_type_id = 5
def get_appointment(self,doctor, weekday,hour):
db = DB('localhost', 'root', 'db')
connection = db.data_base_connection()
sql = 'INSERT INTO `time_table` (`dr_id`,`p_id`,`weekday`,`hour`) VALUES (%s,%s,%s,%s)'
try:
with connection.cursor() as cursor:
cursor.execute(sql, (doctor,self.id, weekday, hour))
connection.commit()
finally:
connection.close()
return "done"
def see_my_prescription(self):
db = DB('localhost', 'root', 'db')
connection = db.data_base_connection()
sql = 'select p.p_id,p.dr_id,i.name from `prescription` as p ' \
'inner join `prescription_item` as pi on p.id = pi.pr_id ' \
'inner join `item` as i on i.id = pi.item_id ' \
'WHERE p.p_id = %s'
try:
with connection.cursor() as cursor:
cursor.execute(sql, (self.id,))
result = cursor.fetchall()
return result
finally:
connection.close()
def get_bed(self):
db = DB('localhost', 'root', 'db')
connection = db.data_base_connection()
try:
with connection.cursor() as cursor:
sql = "SELECT * FROM `bed` WHERE `isEmpty`=%s"
cursor.execute(sql, (True,))
result = cursor.fetchone()
sql = 'INSERT INTO `patient_bed` (`patient_id`,`bed_id`) VALUES (%s,%s)'
cursor.execute(sql, (self.id,result['id']))
connection.commit()
sql = 'update `bed` set `isEmpty` = %s where id = %s'
cursor.execute(sql, (False,result['id']))
connection.commit()
finally:
connection.close()
return "done"
def get_bed_data(self):
db = DB('localhost', 'root', 'db')
connection = db.data_base_connection()
try:
with connection.cursor() as cursor:
sql = "select * from `bed` as b " \
"inner join `patient_bed` pb on b.id = pb.bed_id " \
"where pb.patient_id = %s "
cursor.execute(sql, (self.id,))
result = cursor.fetchone()
return result
finally:
connection.close()
class Laboratory(User): #user_type_id = 6
def take_test(self,lab_prescription):
db = DB('localhost', 'root', 'db')
connection = db.data_base_connection()
sql = 'update `lab_prescription` set `isDone` = %s where id = %s'
try:
with connection.cursor() as cursor:
cursor.execute(sql, (True, lab_prescription))
connection.commit()
finally:
connection.close()
return
class Doctor(User): #user_type_id = 7
def visit(self, patient):
return
def see_time_table(self):
db = DB('localhost', 'root', 'db')
connection = db.data_base_connection()
sql = 'select * from `time_table` where `dr_id` = %s '
try:
with connection.cursor() as cursor:
cursor.execute(sql,(self.id,))
result = cursor.fetchall()
return result
finally:
connection.close()
@staticmethod
def see_prescription_history(pid):
db = DB('localhost', 'root', 'db')
connection = db.data_base_connection()
sql = 'select p.p_id,p.dr_id,i.name from `prescription` as p ' \
'inner join `prescription_item` as pi on p.id = pi.pr_id ' \
'inner join `item` as i on i.id = pi.item_id ' \
'WHERE p.p_id = %s'
try:
with connection.cursor() as cursor:
cursor.execute(sql, (pid,))
result = cursor.fetchall()
return result
finally:
connection.close()
def lab_prescription(self,p,name):
db = DB('localhost', 'root', 'db')
connection = db.data_base_connection()
sql = 'INSERT INTO `lab_prescription`(`doctor_id`, `patient_id`, `name`) VALUES (%s,%s,%s)'
try:
with connection.cursor() as cursor:
cursor.execute(sql, (self.id,p,name))
connection.commit()
finally:
connection.close()
def comfirm_time(self,time):
db = DB('localhost', 'root', 'db')
connection = db.data_base_connection()
try:
with connection.cursor() as cursor:
sql = 'update `time_table` set `accepted` = %s where id = %s'
cursor.execute(sql, (True, time))
connection.commit()
finally:
connection.close()
def ignore_time(self, time):
db = DB('localhost', 'root', 'db')
connection = db.data_base_connection()
try:
with connection.cursor() as cursor:
sql = 'update `time_table` set `accepted` = %s where id = %s'
cursor.execute(sql, (False, time))
connection.commit()
finally:
connection.close()
def make_pres(self,pid):
db = DB('localhost', 'root', 'db')
connection = db.data_base_connection()
try:
with connection.cursor() as cursor:
sql = 'insert into `prescription` ( `dr_id`, `p_id`) VALUES (%s,%s) '
cursor.execute(sql, (self.id, pid))
connection.commit()
finally:
connection.close()
return "done"
@staticmethod
def add_item(pres_id, item_id):
db = DB('localhost', 'root', 'db')
connection = db.data_base_connection()
try:
with connection.cursor() as cursor:
sql = 'insert into `prescription_item` ( `pr_id`, `item_id`) VALUES (%s,%s) '
cursor.execute(sql, (pres_id, item_id))
connection.commit()
finally:
connection.close()
return "done"