def run(): #--------------------------------SETUP---------------------------------- conn = services.getConnection() empName = "booking test person 1" services.deleteStaff(conn,empName) testEmp = model.staff.StaffMember(empName, 1, True) testEmp.flush(conn) #--------------------------------INSERT TEST------------------------------- bookingTest = model.booking.Booking(empName, "2010-12-30 13:00:00", "2010-12-30 15:00:00", model.LOC1) bookingTest.flush(conn) #-------------------------------UPDATE TEST--------------------------------- #--------------------------------DELETE TEST-------------------------------- #--------------------------------CLEAN UP---------------------------------- services.deleteStaff(conn, empName) conn.close()
def availableStaff(timestamp, roleId): """ Returns a json list of names of available staff """ conn = services.getConnection() def getName( staff ): return staff.name return json.dumps(map(getName, services.getAvailableStaff(conn, timestamp, int(roleId))))
def display(date, tab): """ Displays the calendar page """ standardSlots = ["08:00AM", "08:15AM", "08:30AM", "08:45AM", "09:00AM", "09:15AM", "09:30AM", "09:45AM", "10:00AM", "10:15AM", "10:30AM", "10:45AM", "11:00AM", "11:15AM", "11:30AM", "11:45AM", "12:00PM", "12:15PM", "12:30PM", "12:45PM", "01:00PM", "01:15PM", "01:30PM", "01:45PM", "02:00PM", "02:15PM", "02:30PM", "02:45PM", "03:00PM", "03:15PM", "03:30PM", "03:45PM", "04:00PM", "04:15PM", "04:30PM", "04:45PM", "05:00PM", "05:15PM", "05:30PM", "05:45PM", "06:00PM", "06:15PM", "06:30PM", "06:45PM", "07:00PM"] schedule = [] #list of dicts of lists, days -> timeslot -> appointment list locations = None roles = None for day in range(util.DAYS_IN_WEEK): schedule.append({}) #the beginning of the week - the week is either given or the current week is used startDate = util.startOfWeek(util.toDatetime(date) if date else util.today()) tab = int(tab) #build a list of maps of time to appointments with some default values #prepopulated so they are always displayed for day in schedule: for timeslot in standardSlots: day[timeslot] = [] #get a database connection conn = services.getConnection() #get all the locations and roles locations = services.getLocations(conn) roles = sorted(services.getRoles(conn)) #get all the appointments for the week and add them to the schedule for appointment in services.getAppointments(conn, startDate): time = appointment.getFTime() weekday = appointment.time.weekday() #if the appointment is not scheduled for one of the standard times #then add that time slot if time not in schedule[weekday]: schedule[weekday][time] = [] schedule[weekday][time].append(appointment) conn.close() #format and return the page return build(locations, roles, schedule, startDate, tab)
def supportAppExists(timestamp, location, roleId): """ Checks if a supporting (support or medical person) appointment exists at the time slot """ conn = services.getConnection() #check for appointments apps = services.getAppsAtTime(conn, timestamp, location=location, roleId=int(roleId)) if len(apps): return json.dumps(True) else: return json.dumps(False)
def isNameConflict(name): """ Returns an html snipit saying whether or not there is a staff member with the same name """ result = "" connection = services.getConnection() #look for any conflict staff = services.getStaff(connection, name) #if there is a conflict return an error message if staff: result = "There is already a staff member named %s" % name return result
def delete(name): """ Deletes the staff member identified by their name """ results = process.ERROR_PAGE connection = services.getConnection() name = util.strip(name) #if the name exsits then delete it if services.nameExists(connection, name): services.deleteStaff(connection, name) results = REDIRECT return results
def display(): """ Displays a list of all the staff members """ connection = services.getConnection() roleMap = {} #build role map for role in services.getRoles(connection): roleMap[role.roleId] = role.name #get all the staff staffList = services.getAllStaff(connection) connection.close() return _render(staffList, roleMap)
def run(): dbConn = services.getConnection() # clear outs existing employees services.deleteStaff(dbConn, "test1") services.deleteStaff(dbConn, "test2") # create a new employee first = model.staff.StaffMember("test1", 1, True, "street", "city", "OR", "zip", "phone") first.flush(dbConn) # check if it is created firstCheck = services.getStaff(dbConn, "test1") print "created", first print "found ", firstCheck print "created and found ", first == firstCheck # update employee first.name = "test2" first.roleId = 2 first.isActive = False first.street = "newStreet" first.city = "newCity" first.state = "WA" first.zip = "newZip" first.phone = "newPhone" first.flush(dbConn, "test1") secondCheck = services.getStaff(dbConn, "test2") print "updated", first print "found ", secondCheck print "updated and found ", first == secondCheck # delete employee services.deleteStaff(dbConn, "test2") thirdCheck = services.getStaff(dbConn, "test2") print "deleted and gone ", thirdCheck == None dbConn.close()
def delete( name, timestamp ): """ deletes the appointment identified by given timestamp and name """ results = process.ERROR_PAGE datetime = util.toDatetime(timestamp) connection = services.getConnection() #if the data is valid then delete the appointment and redirect to the #main page if services.nameExists(connection, name) and datetime: services.deleteAppointment(connection, datetime, name) results = REDIRECT % (util.toDateStr(datetime), datetime.weekday()) connection.close() return results
def display(startDateStr, location): """ Displays a detailed list of the days appointments """ startOfWeek = util.toDatetime( startDateStr ) connection = services.getConnection() appointments = [] #make the appointment list nested - a list for each day of the week for day in range(util.DAYS_IN_WEEK): appointments.append( [] ) #add all the appointments to the list for appointment in services.getAppointments(connection, startOfWeek, location): weekday = appointment.time.weekday() appointments[weekday].append(appointment) return build( appointments, startOfWeek, location )
def add(name, roleId, phone, street, city, state, zipCode, isActive=False, oldName=None): """ Adds or updates a staff member with the information given """ results = process.ERROR_PAGE connection = services.getConnection() try: roleId = int(roleId) except: validData = False isActive = isActive == "on" phone = phone.replace("(", "").replace(")","").replace("-","").replace(" ","") name = util.strip(name) street = util.strip(street) state = util.strip(state).upper() zipCode = util.strip(zipCode) validData = (len(zipCode) == 0 or len(zipCode) == 5) and (len(state) == 0 or len(state) == 2) if oldName: oldName = util.strip(oldName) validData = validData and services.nameExists(connection, oldName) #if the data is valid then flush it to the database if validData: staff = model.staff.StaffMember(name, roleId, isActive, street, city, state, zipCode, phone) staff.flush(connection, oldName) results = REDIRECT connection.close() return results
def isAppointmentConflict(name, timestamp): """ Returns an html snipit saying whether or not there is a conflict with another appointment """ appointment = None result = "" datetime = util.toDatetime(timestamp); connection = services.getConnection() #lookup an appointment for that time for that person, if we have the whole #timestamp if datetime: appointment = services.getAppointment(connection, datetime, name) #if an appointment was found generate an error string if appointment: result = "There is already an appointment for %s on %s at %s" %( appointment.staffName, appointment.getFDate(), appointment.getFTime() ) connection.close() return result
def add( date, time, staff, location, desc, addToSupport=False, addToMedical=False, \ oldName=None, oldTime=None, oldDate=None, **kwargs): """ Checks the given data and if it looks valid then add/update the appointment date - the date of the appointment time - the time of the appointment location - the location desc - generic text about the appt oldName - the previous person the appt was for oldTime - the previous time of the appt oldDate - the previous date of the appt addToSupport - copy all the information to the support appointment at the same time and place addToMedical - copy all the information to the medical appointment at the same time and place kwargs - a collection of optional data (the names of the form field match the names of the appointment fields """ result = None oldTimestamp = None date = util.strip(date) name = util.strip(staff) location = util.strip(location) supportAppts = None medicalAppts = None #set all the optional parameters to None if they are an empty string for key,value in kwargs.items(): if value == "": kwargs[key] = None conn = services.getConnection() datetime = util.toDatetime(date, time) #check the required data for errors validData = services.locationExists(conn, location) \ and datetime != None and services.nameExists(conn, name) \ and checkDate(kwargs["lastPeriod"]) \ and checkDate(kwargs["dateConfirmed"]) #check the old name of the appointment if one was given if oldName: oldName= util.strip(oldName) validData = validData and services.nameExists(conn, oldName) #assemble the old timestamp for the appointment if all the information was given if oldTime and oldDate: oldTimestamp = util.toDatetime(util.strip(oldDate), util.strip(oldTime)) validData = validData and oldTimestamp != None #if we are not performing an update then check to see if the new appointment #time and person are not already taken if not (oldTimestamp == datetime and oldName == staff): validData= validData and not services.getAppointment(conn, datetime, staff) if addToSupport: supportAppts = services.getAppsAtTime(conn, datetime, location, model.role.SUPPORT) validData = validData and len(supportAppts) if addToMedical: medicalAppts = services.getAppsAtTime(conn, datetime, location, model.role.MEDICAL) validData = validData and len(medicalAppts) #if the data was valid than save it to the database if validData: otherAppts = [] #create the appointment object appointment = Appointment(datetime, name, location, None, desc, **kwargs) #flush the appointment object to the database appointment.flush(conn, oldTimestamp, oldName) if addToSupport: otherAppts += supportAppts if addToMedical: otherAppts += medicalAppts #add the one extra field that needs to be updated as well kwargs["description"] = desc #update all the other appointments for appt in otherAppts: model.updateAll(appt, kwargs) appt.flush(conn, appt.time, appt.staffName) #set the redirect for the brower result = REDIRECT % (date, datetime.weekday()) #else show an error page else: result = process.ERROR_PAGE conn.close() return result
def run(): #YYYY-MM-DD HH:MM:SS #--------------------------SETUP------------------------------------------ conn = services.getConnection() staff = [ model.staff.StaffMember("test1", 1, False), model.staff.StaffMember("test2", 1, True), model.staff.StaffMember("test3", 2, True) ] apps = [ model.appointment.Appointment("2010-12-25 11:00:00", "test1", "Albany"), model.appointment.Appointment("2010-12-23 00:00:00", "test1", "Corvallis"), model.appointment.Appointment("2010-12-21 00:00:00", "test2", "Albany"), model.appointment.Appointment(util.toDatetime("2010-12-25 00:00:00"), "test3", "Albany"), model.appointment.Appointment("2010-12-24 00:00:00", "test3", "Corvallis"), model.appointment.Appointment("2010-11-24 00:00:00", "test3", "Corvallis") ] objs = [] for a in apps: services.deleteAppointment(conn, a.time, a.staffName) for s in staff: services.deleteStaff(conn, s.name) for s in staff: objs.append(s) for a in apps: objs.append(a) for o in objs: o.flush(conn) #-----------------------------ALL STAFF----------------------------------- #all staff results = filterList( services.getAllStaff(conn), staff ) print "all staff", len(results) == 3 #only role 1 results = filterList( services.getAllStaff(conn, roleId = 1), staff ) print "role 1 staff", len(results) == 2 #only active results = filterList( services.getAllStaff(conn, active=True), staff ) print "active staff", len(results) == 2 #only inactive, role 1 results = filterList( services.getAllStaff(conn, active=False, roleId = 1), staff ) print "inactive, role 1 staff", len(results) == 1 #------------------------------ALL APPOINTMENTS--------------------------- #all appointments results = filterList( services.getAppointments(conn, util.startOfWeek(util.toDatetime("2010-12-25 00:00:00"))), apps ) print "all appointments", len(results) == 5 #only role 1 results = filterList( services.getAppointments(conn, util.startOfWeek(util.toDatetime("2010-12-25 00:00:00")), roleId = 1), apps ) print "role 1 appointments", len(results) == 3 #only Albany results = filterList( services.getAppointments(conn, util.startOfWeek(util.toDatetime("2010-12-25 00:00:00")), location = "Albany"), apps ) print "Albany appointments", len(results) == 3 #only Corvallis role 2 results = filterList( services.getAppointments(conn, util.startOfWeek(util.toDatetime("2010-12-25 00:00:00")), location = "Corvallis", roleId = 2), apps ) print "role 2 corvallis appointments", len(results) == 1 #---------------------------------ROLES------------------------------------- print "3 Roles found", len( services.getRoles(conn) ) == 3 #---------------------------CLEAN UP-------------------------------------- for a in apps: services.deleteAppointment(conn, a.time, a.staffName) for s in staff: services.deleteStaff(conn, s.name)