forked from Bhanu9650/OpenEHR-Project
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_db.py
359 lines (249 loc) · 11.7 KB
/
test_db.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
import pytest
from flaskapp.models import userdata, patient, doctor, prescription
from flaskapp.models import doseDirection, orderDetails, pastHistoryIllness
from flaskapp.models import allergyIntolerance, problemList
from flaskapp import app, db
import datetime
from datetime import datetime
def test_userdata1(test_client, init_db):
user1 = userdata.query.filter_by(user_id=1).first()
assert user1.user_id == 1
assert user1.role == "doctor"
assert user1.email == "dinesh@gmail.com"
assert user1.password == "123"
def test_userdata1_invalid_role(test_client, init_db):
user1 = userdata.query.filter_by(user_id=1).first()
assert user1.user_id == 1
assert not user1.role == "patient"
assert user1.email == "dinesh@gmail.com"
assert user1.password == "123"
def test_userdata1_invalid_email(test_client, init_db):
user1 = userdata.query.filter_by(user_id=1).first()
assert user1.user_id == 1
assert user1.role == "doctor"
assert not user1.email == "prabh@gmail.com"
assert user1.password == "123"
def test_userdata2(test_client, init_db):
user2 = userdata.query.filter_by(user_id=2).first()
assert user2.user_id == 2
assert user2.role == "patient"
assert not user2.email == "dinesh@gmail.com"
assert user2.password == "123"
def test_userdata2_invalid_role(test_client, init_db):
user2 = userdata.query.filter_by(user_id=2).first()
assert user2.user_id == 2
assert not user2.role == "doctor"
assert user2.email == "prabh@gmail.com"
assert user2.password == "123"
def test_userdata2_invalid_email(test_client, init_db):
user2 = userdata.query.filter_by(user_id=2).first()
assert user2.user_id == 2
assert user2.role == "patient"
assert not user2.email == "dk@gmail.com"
assert user2.password == "123"
def test_patient_model(test_client, init_db):
patient1 = patient.query.filter_by(patient_id=2).first()
assert patient1.patient_id == 2
assert patient1.patient_name == "Prabhpreet Singh"
assert patient1.address == "Prabhpreet Singh Address"
assert patient1.age == 25
assert patient1.gender == "Male"
assert patient1.phone == "9876543210"
def test_patient_model_invalid(test_client, init_db):
patient1 = patient.query.filter_by(patient_id=2).first()
assert patient1.patient_id == 2
assert not patient1.patient_name == "Dinesh Kumar"
assert patient1.address == "Prabhpreet Singh Address"
assert patient1.age == 25
assert patient1.gender == "Male"
assert patient1.phone == "9876543210"
def test_patient_model_invalid(test_client, init_db):
patient1 = patient.query.filter_by(patient_id=2).first()
assert patient1.patient_id == 2
assert patient1.patient_name == "Prabhpreet Singh"
assert patient1.address == "Prabhpreet Singh Address"
assert patient1.age == 25
assert patient1.gender == "Male"
assert not patient1.phone == "654987123"
def test_doctor_model(test_client, init_db):
doctor1 = doctor.query.filter_by(doctor_id=1).first()
assert doctor1.doctor_id == 1
assert doctor1.doctor_name == "Dinesh Kumar"
assert doctor1.year_exp == 10
assert doctor1.speciality == "Cardiologist"
assert doctor1.phone == "7894561230"
assert doctor1.description == "Dinesh Kumar Description"
assert doctor1.address == "Dinesh Kumar Address"
def test_doctor_model_invalid_name(test_client, init_db):
doctor1 = doctor.query.filter_by(doctor_id=1).first()
assert doctor1.doctor_id == 1
assert not doctor1.doctor_name == "Prabhpreet Singh"
assert doctor1.year_exp == 10
assert doctor1.speciality == "Cardiologist"
assert doctor1.phone == "7894561230"
assert doctor1.description == "Dinesh Kumar Description"
assert doctor1.address == "Dinesh Kumar Address"
def test_doctor_model_invalid_phone(test_client, init_db):
doctor1 = doctor.query.filter_by(doctor_id=1).first()
assert doctor1.doctor_id == 1
assert doctor1.doctor_name == "Dinesh Kumar"
assert doctor1.year_exp == 10
assert doctor1.speciality == "Cardiologist"
assert not doctor1.phone == "9876543210"
assert doctor1.description == "Dinesh Kumar Description"
assert doctor1.address == "Dinesh Kumar Address"
def test_prescription_model(test_client, init_db):
presc = prescription.query.filter_by(prescription_id=1).first()
assert presc.prescription_id == 1
assert presc.patient_id == 2
assert presc.doctor_id == 1
def test_prescription_model_invalid_prescription_id(test_client, init_db):
presc = prescription.query.filter_by(prescription_id=1).first()
assert not presc.prescription_id == 2
assert presc.patient_id == 2
assert presc.doctor_id == 1
def test_prescription_model_invalid_patient_id(test_client, init_db):
presc = prescription.query.filter_by(prescription_id=1).first()
assert presc.prescription_id == 1
assert not presc.patient_id == 1
assert presc.doctor_id == 1
def test_prescription_model_invalid_doctor_id(test_client, init_db):
presc = prescription.query.filter_by(prescription_id=1).first()
assert presc.prescription_id == 1
assert presc.patient_id == 2
assert not presc.doctor_id == 2
def test_doseDirection_model(test_client, init_db):
dose = doseDirection.query.filter_by(prescription_id=1).first()
assert dose.dose_id == 1
assert dose.prescription_id == 1
assert dose.dose == 2.5
assert dose.dose_unit == "mg"
assert dose.frequency_per_day == "3/d"
def test_doseDirection_model_invalid_dose_id(test_client, init_db):
dose = doseDirection.query.filter_by(prescription_id=1).first()
assert not dose.dose_id == 2
assert dose.prescription_id == 1
assert dose.dose == 2.5
assert dose.dose_unit == "mg"
assert dose.frequency_per_day == "3/d"
def test_doseDirection_model_invalid_presc_id(test_client, init_db):
dose = doseDirection.query.filter_by(prescription_id=1).first()
assert dose.dose_id == 1
assert not dose.prescription_id == 2
assert dose.dose == 2.5
assert dose.dose_unit == "mg"
assert dose.frequency_per_day == "3/d"
def test_doseDirection_model_invalid_dose_amt(test_client, init_db):
dose = doseDirection.query.filter_by(prescription_id=1).first()
assert dose.dose_id == 1
assert dose.prescription_id == 1
assert not dose.dose == 5.5
assert dose.dose_unit == "mg"
assert dose.frequency_per_day == "3/d"
def test_doseDirection_model_invalid_units(test_client, init_db):
dose = doseDirection.query.filter_by(prescription_id=1).first()
assert dose.dose_id == 1
assert dose.prescription_id == 1
assert dose.dose == 2.5
assert not dose.dose_unit == "kg"
assert dose.frequency_per_day == "3/d"
def test_orderDetails_model(test_client, init_db):
order = orderDetails.query.filter_by(prescription_id=1).first()
assert order.orderdetails_id == 1
assert order.prescription_id == 1
assert order.status == "active"
def test_orderDetails_model_invalid_(test_client, init_db):
order = orderDetails.query.filter_by(prescription_id=1).first()
assert not order.orderdetails_id == 2
assert order.prescription_id == 1
assert order.status == "active"
def test_orderDetails_model_invalid_presc_id(test_client, init_db):
order = orderDetails.query.filter_by(prescription_id=1).first()
assert order.orderdetails_id == 1
assert not order.prescription_id == 2
assert order.status == "active"
def test_orderDetails_model_invalid_status(test_client, init_db):
order = orderDetails.query.filter_by(prescription_id=1).first()
assert order.orderdetails_id == 1
assert order.prescription_id == 1
assert not order.status == "inactive"
def test_pastHistory_model(test_client, init_db):
past_history = pastHistoryIllness.query.filter_by(patient_id=2).first()
assert past_history.illness_id == 1
assert past_history.patient_id == 2
assert past_history.problem_name == "Problem 1"
assert past_history.body_site == "Arm"
assert past_history.datetime_onset == datetime(2020, 11, 10, 10, 0, 0)
def test_pastHistory_model_invalid_illness_id(test_client, init_db):
past_history = pastHistoryIllness.query.filter_by(patient_id=2).first()
assert not past_history.illness_id == 2
assert past_history.patient_id == 2
assert past_history.problem_name == "Problem 1"
assert past_history.body_site == "Arm"
assert past_history.datetime_onset == datetime(2020, 11, 10, 10, 0, 0)
def test_pastHistory_model_invalid_patient_id(test_client, init_db):
past_history = pastHistoryIllness.query.filter_by(patient_id=2).first()
assert past_history.illness_id == 1
assert not past_history.patient_id == 1
assert past_history.problem_name == "Problem 1"
assert past_history.body_site == "Arm"
assert past_history.datetime_onset == datetime(2020, 11, 10, 10, 0, 0)
def test_pastHistory_model_invalid_problem_name(test_client, init_db):
past_history = pastHistoryIllness.query.filter_by(patient_id=2).first()
assert past_history.illness_id == 1
assert past_history.patient_id == 2
assert not past_history.problem_name == "Another Problem"
assert past_history.body_site == "Arm"
assert past_history.datetime_onset == datetime(2020, 11, 10, 10, 0, 0)
def test_allergyIntolerance_model(test_client, init_db):
allergy = allergyIntolerance.query.filter_by(patient_id=2).first()
assert allergy.allergy_id == 1
assert allergy.patient_id == 2
assert allergy.substance == "Lactose"
assert allergy.verification_status == "Approved"
assert allergy.allergy_intol_type == "allergy"
def test_allergyIntolerance_model_invalid_allergy_id(test_client, init_db):
allergy = allergyIntolerance.query.filter_by(patient_id=2).first()
assert not allergy.allergy_id == 2
assert allergy.patient_id == 2
assert allergy.substance == "Lactose"
assert allergy.verification_status == "Approved"
assert allergy.allergy_intol_type == "allergy"
def test_allergyIntolerance_model_invalid_patient_id(test_client, init_db):
allergy = allergyIntolerance.query.filter_by(patient_id=2).first()
assert allergy.allergy_id == 1
assert not allergy.patient_id == 1
assert allergy.substance == "Lactose"
assert allergy.verification_status == "Approved"
assert allergy.allergy_intol_type == "allergy"
def test_allergyIntolerance_model_invalid_verfi(test_client, init_db):
allergy = allergyIntolerance.query.filter_by(patient_id=2).first()
assert allergy.allergy_id == 1
assert allergy.patient_id == 2
assert allergy.substance == "Lactose"
assert not allergy.verification_status == "rejected"
assert allergy.allergy_intol_type == "allergy"
def test_problemList_model(test_client, init_db):
problem = problemList.query.filter_by(patient_id=2).first()
assert problem.problem_id == 1
assert problem.patient_id == 2
assert problem.problem_diag_name == "Fever"
assert problem.body_site == "Stomach"
def test_problemList_model_invalid_problem_id(test_client, init_db):
problem = problemList.query.filter_by(patient_id=2).first()
assert not problem.problem_id == 2
assert problem.patient_id == 2
assert problem.problem_diag_name == "Fever"
assert problem.body_site == "Stomach"
def test_problemList_model_invalid_patient_id(test_client, init_db):
problem = problemList.query.filter_by(patient_id=2).first()
assert problem.problem_id == 1
assert not problem.patient_id == 1
assert problem.problem_diag_name == "Fever"
assert problem.body_site == "Stomach"
def test_problemList_model_invalid_body_site(test_client, init_db):
problem = problemList.query.filter_by(patient_id=2).first()
assert problem.problem_id == 1
assert problem.patient_id == 2
assert problem.problem_diag_name == "Fever"
assert not problem.body_site == "arm"