-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathvaccine_reservation_scheduler.py
More file actions
89 lines (77 loc) · 3.68 KB
/
Copy pathvaccine_reservation_scheduler.py
File metadata and controls
89 lines (77 loc) · 3.68 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
import datetime
from enum import IntEnum
import os
import pymssql
import traceback
from sql_connection_manager import SqlConnectionManager
from vaccine_caregiver import VaccineCaregiver
from enums import *
from utils import *
# from covid19_vaccine import COVID19Vaccine as covid
# from vaccine_patient import VaccinePatient as patient
class VaccineReservationScheduler:
def __init__(self):
return
def PutHoldOnAppointmentSlot(self, cursor):
''' Method that reserves a CareGiver appointment slot &
returns the unique scheduling slotid
Should return 0 if no slot is available or -1 if there is a database error'''
# Note to students: this is a stub that needs to replaced with your code
self.slotSchedulingId = 0
self.getAppointmentSQL = "SELECT something..."
try:
cursor.execute(self.getAppointmentSQL)
cursor.connection.commit()
return self.slotSchedulingId
except pymssql.Error as db_err:
print("Database Programming Error in SQL Query processing! ")
print("Exception code: " + str(db_err.args[0]))
if len(db_err.args) > 1:
print("Exception message: " + db_err.args[1])
print("SQL text that resulted in an Error: " + self.getAppointmentSQL)
cursor.connection.rollback()
return -1
def ScheduleAppointmentSlot(self, slotid, cursor):
'''method that marks a slot on Hold with a definite reservation
slotid is the slot that is currently on Hold and whose status will be updated
returns the same slotid when the database update succeeds
returns 0 is there if the database update dails
returns -1 the same slotid when the database command fails
returns 21 if the slotid parm is invalid '''
# Note to students: this is a stub that needs to replaced with your code
if slotid < 1:
return -2
self.slotSchedulingId = slotid
self.getAppointmentSQL = "SELECT something... "
try:
cursor.execute(self.getAppointmentSQL)
return self.slotSchedulingId
except pymssql.Error as db_err:
print("Database Programming Error in SQL Query processing! ")
print("Exception code: " + db_err.args[0])
if len(db_err.args) > 1:
print("Exception message: " + str(db_err.args[1]))
print("SQL text that resulted in an Error: " + self.getAppointmentSQL)
return -1
if __name__ == '__main__':
with SqlConnectionManager(Server=os.getenv("Server"),
DBname=os.getenv("DBName"),
UserId=os.getenv("UserID"),
Password=os.getenv("Password")) as sqlClient:
clear_tables(sqlClient)
vrs = VaccineReservationScheduler()
# get a cursor from the SQL connection
dbcursor = sqlClient.cursor(as_dict=True)
# Iniialize the caregivers, patients & vaccine supply
caregiversList = []
caregiversList.append(VaccineCaregiver('Carrie Nation', dbcursor))
caregiversList.append(VaccineCaregiver('Clare Barton', dbcursor))
caregivers = {}
for cg in caregiversList:
cgid = cg.caregiverId
caregivers[cgid] = cg
# Add a vaccine and Add doses to inventory of the vaccine
# Ass patients
# Schedule the patients
# Test cases done!
clear_tables(sqlClient)