-
Notifications
You must be signed in to change notification settings - Fork 0
/
populate.py
executable file
·53 lines (46 loc) · 1.62 KB
/
populate.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
#!/usr/bin/env python3
from app import db
from app.models import *
from datetime import *
from pprint import pprint as pp
from datetime import datetime
print("* recreating database ...")
db.drop_all()
db.create_all()
patient_data=[
("P1","25","Male"),
("P2","18","Female"),
("P3","40","Personal")
]
for (patient_name,age,gender) in patient_data:
patient = Patient(patient_name=patient_name,age=age,gender=gender)
patient.set_password(patient_name)
db.session.add(patient)
db.session.commit()
print(patient.query.all())
doctor_names = ['D1','D2']
for doctor_name in doctor_names:
doctor = Doctor(doctor_name=doctor_name)
db.session.add(doctor)
db.session.commit()
print(doctor.query.all())
appointment_data=[
("D1","P1","08 03 2018 09:00:00","H"),
("D1","P1","08 04 2018 10:00:00","H"),
("D1","P2","08 03 2018 10:00:00","H"),
("D1","P1","08 04 2018 11:00:00","H"),
("D2","P1","18 03 2018 08:00:00","H"),
("D2","P1","18 04 2018 09:00:00","H"),
("D2","P3","18 03 2018 09:00:00","H"),
("D2","P3","18 04 2018 10:00:00","H")
]
(doctor_name,patient_name,date_string,priority) = appointment_data[0]
for (doctor_name,patient_name,date_string,priority) in appointment_data:
date_time=datetime.strptime(date_string, "%d %m %Y %H:%M:%S")
patient=Patient.query.filter_by(patient_name=patient_name).first()
doctor=Doctor.query.filter_by(doctor_name=doctor_name).first()
appointment=Appointment(patient_id=patient.id,doctor_id=doctor.id,date_time=date_time,priority=priority)
db.session.add(appointment)
db.session.commit()
pp(appointment.query.all())
print("* database populated")