patternpythonMinor
Doctor/Patient Reservation Scheduling
Viewed 0 times
reservationpatientdoctorscheduling
Problem
I am trying to implement a Doctor/patient scheduling system. It would be great if someone can review my code and suggest how I can improve it further. I would like to know how to have a date-based calendar for this. I also want some idea on how to protect a patient record data from one doctor to another.
One more feature I would like to know is: what kind of exception should I be raising instead of
```
SLOT_1 = '8:00AM'
SLOT_2 = '8:30AM'
SLOT_3 = '9:00AM'
SLOT_4 = '9:30AM'
SLOT_5 = '10:00AM'
SLOT_6 = '10:30AM'
SLOT_7 = '11:00AM'
SLOT_8 = '11:30AM'
SLOT_9 = '1:00PM'
SLOT_10 = '1:30PM'
SLOT_11 = '2:00PM'
SLOT_12 = '2:30PM'
SLOT_13 = '3:00PM'
SLOT_14 = '3:30PM'
SLOT_15 = '4:00PM'
SLOT_16 = '4:30PM'
CLASS_NAME = 'NAME'
CLASS_APPOINTMENT_INFO = 'APPOINTMENT_INFO'
class Patient(object):
CLASS_ID = 'ID'
CLASS_PREV_APPOINTMENTS = 'PREVIOUS_APPOINTMENTS'
def __init__(self, f_name, l_name, ssn):
self.f_name = f_name
self.l_name = l_name
self.ssn = ssn
self.patient_name = self.f_name + " " + self.l_name
self.patient_id = self.f_name[:1] + self.l_name + ssn
self.patient_calendar = {
CLASS_NAME: self.patient_name,
self.CLASS_ID: self.patient_id,
#self.CLASS_PREV_APPOINTMENTS: {},
CLASS_APPOINTMENT_INFO: {}
}
def get_patient_record(self):
patient_record = {
CLASS_NAME : self.patient_name,
self.CLASS_ID : self.patient_id,
}
return patient_record
def print_patient_calendar(self):
print self.patient_calendar
class Doctor(object):
CLASS_SPECIALITY = 'SPECIALITY'
def __init__(self, f_name, l_name, speciality):
self.f_name = f_name
self.l_name = l_name
self.doctor_name = self.f_name + " " + self.l_name
self.speciality = speciality
self.doctor_calendar = {
CLASS_NAME: self.doctor_name,
self.CLASS_SPECIALITY: s
One more feature I would like to know is: what kind of exception should I be raising instead of
True or False?```
SLOT_1 = '8:00AM'
SLOT_2 = '8:30AM'
SLOT_3 = '9:00AM'
SLOT_4 = '9:30AM'
SLOT_5 = '10:00AM'
SLOT_6 = '10:30AM'
SLOT_7 = '11:00AM'
SLOT_8 = '11:30AM'
SLOT_9 = '1:00PM'
SLOT_10 = '1:30PM'
SLOT_11 = '2:00PM'
SLOT_12 = '2:30PM'
SLOT_13 = '3:00PM'
SLOT_14 = '3:30PM'
SLOT_15 = '4:00PM'
SLOT_16 = '4:30PM'
CLASS_NAME = 'NAME'
CLASS_APPOINTMENT_INFO = 'APPOINTMENT_INFO'
class Patient(object):
CLASS_ID = 'ID'
CLASS_PREV_APPOINTMENTS = 'PREVIOUS_APPOINTMENTS'
def __init__(self, f_name, l_name, ssn):
self.f_name = f_name
self.l_name = l_name
self.ssn = ssn
self.patient_name = self.f_name + " " + self.l_name
self.patient_id = self.f_name[:1] + self.l_name + ssn
self.patient_calendar = {
CLASS_NAME: self.patient_name,
self.CLASS_ID: self.patient_id,
#self.CLASS_PREV_APPOINTMENTS: {},
CLASS_APPOINTMENT_INFO: {}
}
def get_patient_record(self):
patient_record = {
CLASS_NAME : self.patient_name,
self.CLASS_ID : self.patient_id,
}
return patient_record
def print_patient_calendar(self):
print self.patient_calendar
class Doctor(object):
CLASS_SPECIALITY = 'SPECIALITY'
def __init__(self, f_name, l_name, speciality):
self.f_name = f_name
self.l_name = l_name
self.doctor_name = self.f_name + " " + self.l_name
self.speciality = speciality
self.doctor_calendar = {
CLASS_NAME: self.doctor_name,
self.CLASS_SPECIALITY: s
Solution
Instead of defining 16 time slots I would recommend you to use datetime module to create a list of time slots. You should also store 'date' along with time. Datetime module provides functions for easy and quick time comparisons.
The following declarations are redundant:
Remove these declarations, and you can directly use these strings instead of the variables:
This makes code smaller and simpler to understand. The keys are self explanatory.
You must implement function which allows storing the patient and doctor information to a file. I recommend pickle module to do this.
You can define a base class PERSON which contains variablea f_name, l_name, full_name and functions which are common to both doctor and patient a. Both Doctor and Patient class extends PERSON class. Instead of get_doctor_record() and get_patient_record() define a function get_record() in PERSON. This will give the code a proper logical structure and remove redundant code.
Remove function isdoctoravailable() and ispatientavailable() from Scheduler and add a function isavailable() in PERSON. So the new schedule function would like:
Because now you have sent all the functions other than schedule inside the Scheduler class to Person class, I don't think defining Scheduler class makes sense. An independent schedule function will look better.
The following code gives a basic idea of how your code will look like after making the above mentioned changes.
The following declarations are redundant:
CLASS_NAME = 'NAME'
CLASS_APPOINTMENT_INFO = 'APPOINTMENT_INFO'
.....
CLASS_ID = 'ID'
CLASS_PREV_APPOINTMENTS = 'PREVIOUS_APPOINTMENTS'Remove these declarations, and you can directly use these strings instead of the variables:
self.patient_calendar = {
'Name': self.patient_name,
'Id' self.patient_id,
'Previous_appointments': {},
'Appointment_info': {}
}This makes code smaller and simpler to understand. The keys are self explanatory.
You must implement function which allows storing the patient and doctor information to a file. I recommend pickle module to do this.
You can define a base class PERSON which contains variablea f_name, l_name, full_name and functions which are common to both doctor and patient a. Both Doctor and Patient class extends PERSON class. Instead of get_doctor_record() and get_patient_record() define a function get_record() in PERSON. This will give the code a proper logical structure and remove redundant code.
Remove function isdoctoravailable() and ispatientavailable() from Scheduler and add a function isavailable() in PERSON. So the new schedule function would like:
def schedule(self,doctor,patient,time):
self.time = time
self.doctor = doctor
self.patient = patient
if self.doctor.isavailable(time) and self.patient.isavailable(time):
self.patient.update_calendar(doctor,time)
self.doctor.update_calendar(patient,time)
print "Appointment Scheduled with Dr. " + doctor.doctor_name + " for patient " + patient.patient_calendar[CLASS_NAME] + "\n"
return TrueBecause now you have sent all the functions other than schedule inside the Scheduler class to Person class, I don't think defining Scheduler class makes sense. An independent schedule function will look better.
The following code gives a basic idea of how your code will look like after making the above mentioned changes.
class Person(object):
def __init__(self, f_name, l_name):
.....
def get_record(self):
....
def print_record(self):
....
def save_record(self):
....
def is_available(self, time):
....
def update_calendar(self, person, time):
....
class Patient(object, Person):
def __init__(self, f_name, l_name, ssn):
super(Patient, self).__init(f_name, l_name)
self.ssn = ssn
class Doctor(object, Person):
def __init__(self, f_name, l_name, speciality):
super(Doctor, self).__init(self, f_name, l_name)
self.speciality = speciality
def schedule(self,doctor,patient,time):
self.time = time
self.doctor = doctor
self.patient = patient
if self.doctor.is_available(time) and self.patient.is_available(time):
self.patient.update_calendar(patient,time)
self.doctor.update_calendar(doctor,time)
print "something"
return True
D1 = Doctor("Ryan", "Giggs", "Dental")
D2 = Doctor("Alex", "Fergusson","General")
P1 = Patient("Wayne", "Rooney", "1234")
P2 = Patient("Wayne", "Bridge", "1214")
schedule(D1,P1,SLOT_11)
schedule(D1,P2,SLOT_1)
P1.print_calendar()
P2.print_calendar()
D1.print_calendar()
D2.print_calendar()Code Snippets
CLASS_NAME = 'NAME'
CLASS_APPOINTMENT_INFO = 'APPOINTMENT_INFO'
.....
CLASS_ID = 'ID'
CLASS_PREV_APPOINTMENTS = 'PREVIOUS_APPOINTMENTS'self.patient_calendar = {
'Name': self.patient_name,
'Id' self.patient_id,
'Previous_appointments': {},
'Appointment_info': {}
}def schedule(self,doctor,patient,time):
self.time = time
self.doctor = doctor
self.patient = patient
if self.doctor.isavailable(time) and self.patient.isavailable(time):
self.patient.update_calendar(doctor,time)
self.doctor.update_calendar(patient,time)
print "Appointment Scheduled with Dr. " + doctor.doctor_name + " for patient " + patient.patient_calendar[CLASS_NAME] + "\n"
return Trueclass Person(object):
def __init__(self, f_name, l_name):
.....
def get_record(self):
....
def print_record(self):
....
def save_record(self):
....
def is_available(self, time):
....
def update_calendar(self, person, time):
....
class Patient(object, Person):
def __init__(self, f_name, l_name, ssn):
super(Patient, self).__init(f_name, l_name)
self.ssn = ssn
class Doctor(object, Person):
def __init__(self, f_name, l_name, speciality):
super(Doctor, self).__init(self, f_name, l_name)
self.speciality = speciality
def schedule(self,doctor,patient,time):
self.time = time
self.doctor = doctor
self.patient = patient
if self.doctor.is_available(time) and self.patient.is_available(time):
self.patient.update_calendar(patient,time)
self.doctor.update_calendar(doctor,time)
print "something"
return True
D1 = Doctor("Ryan", "Giggs", "Dental")
D2 = Doctor("Alex", "Fergusson","General")
P1 = Patient("Wayne", "Rooney", "1234")
P2 = Patient("Wayne", "Bridge", "1214")
schedule(D1,P1,SLOT_11)
schedule(D1,P2,SLOT_1)
P1.print_calendar()
P2.print_calendar()
D1.print_calendar()
D2.print_calendar()Context
StackExchange Code Review Q#49786, answer score: 3
Revisions (0)
No revisions yet.