def edit_appointment(appointment_object):
        visitor_id = appointment_object['visitorId']

        visitor_object = {
            'name': appointment_object['visitorName'],
            'address': appointment_object['visitorAddress'],
            'phoneNumber': appointment_object['visitorPhoneNumber']
        }

        VisitorDB.edit_visitor(visitor_id, visitor_object)

        staff_id = appointment_object['staffId']
        subject_of_visit = appointment_object['subject']
        date_time = appointment_object['dateTime']
        status = appointment_object['status']

        appointment_obj = {
            'staffId': staff_id,
            'visitorId': visitor_id,
            'subject': subject_of_visit,
            'dateTime': date_time,
            'status': status
        }

        AppointmentDB.edit_appointment(appointment_object['id'],
                                       appointment_obj)
    def search_all_appointments_visitors_name(visitor_name_keyword):
        try:
            client = MongoClient(Constant.DB_CONNECTION_URL)
            document = client[Constant.DB_NAME][AppointmentDB.COLLECTION_NAME]

            appointments = document.find({})

            appointments_for_staff = []

            for appointment in appointments:
                a = Appointment(str(appointment['_id']),
                                appointment['staffId'],
                                appointment['visitorId'],
                                appointment['subject'],
                                appointment['dateTime'], appointment['status'])

                visitor = VisitorDB.get_visitor_by_id(appointment['visitorId'])
                if visitor_name_keyword.lower() not in visitor.name.lower():
                    continue

                a.set_visitor(visitor)

                staff = StaffDB.get_staff_by_id(appointment['staffId'])
                a.set_staff(staff.serialize)

                appointments_for_staff.append(a)

            client.close()
            return appointments_for_staff

        except Exception as e:
            print('unable to get appointments')
            raise Exception('Could not get appointments')
    def get_appointments_for_staff_in(staff_id, appointment_ids):
        try:
            client = MongoClient(Constant.DB_CONNECTION_URL)
            document = client[Constant.DB_NAME][AppointmentDB.COLLECTION_NAME]

            appointment_ids_obj = [ObjectId(item) for item in appointment_ids]

            appointments = document.find({
                '_id': {
                    '$in': appointment_ids_obj
                },
                'staffId': staff_id
            })

            appointments_for_staff = []

            for appointment in appointments:
                a = Appointment(str(appointment['_id']), staff_id,
                                appointment['visitorId'],
                                appointment['subject'],
                                appointment['dateTime'], appointment['status'])

                visitor = VisitorDB.get_visitor_by_id(appointment['visitorId'])
                a.set_visitor(visitor)

                appointments_for_staff.append(a)

            client.close()
            return appointments_for_staff

        except Exception as e:
            print('unable to get appointments for staff - ' + str(e))
            raise Exception('Could not get appointments for staff')
    def get_appointments_for_staff_and_status_filter_by_date_time(
            staff_id, status, start_time, end_time):
        try:
            client = MongoClient(Constant.DB_CONNECTION_URL)
            document = client[Constant.DB_NAME][AppointmentDB.COLLECTION_NAME]

            appointments = document.find({
                'staffId': staff_id,
                'status': status,
                'dateTime': {
                    '$gte': start_time,
                    '$lte': end_time
                }
            })

            appointments_for_staff = []

            for appointment in appointments:
                a = Appointment(str(appointment['_id']), staff_id,
                                appointment['visitorId'],
                                appointment['subject'],
                                appointment['dateTime'], appointment['status'])

                visitor = VisitorDB.get_visitor_by_id(appointment['visitorId'])
                a.set_visitor(visitor)

                appointments_for_staff.append(a)

            client.close()
            return appointments_for_staff

        except Exception as e:
            print('unable to get appointments for staff')
            raise Exception('Could not get appointments for staff')
    def get_appointments_for_status(status):
        try:
            client = MongoClient(Constant.DB_CONNECTION_URL)
            document = client[Constant.DB_NAME][AppointmentDB.COLLECTION_NAME]

            appointments = document.find({'status': status})

            appointments_for_status = []

            for appointment in appointments:
                a = Appointment(str(appointment['_id']),
                                appointment['staffId'],
                                appointment['visitorId'],
                                appointment['subject'],
                                appointment['dateTime'], status)

                visitor = VisitorDB.get_visitor_by_id(appointment['visitorId'])
                a.set_visitor(visitor)

                staff = StaffDB.get_staff_by_id(appointment['staffId'])
                a.set_staff(staff.serialize)

                appointments_for_status.append(a)

            client.close()
            return appointments_for_status

        except Exception as e:
            print('unable to get appointments for staff')
            raise Exception('Could not get appointments for staff')
    def add_new_appointment(appointment_object):
        staff_id = appointment_object['staffId']
        subject_of_visit = appointment_object['subject']
        date_time = appointment_object['dateTime']

        visitors = appointment_object['visitors']
        for visitor in visitors:
            visitor_id = VisitorDB.new_visitor(visitor)

            appointment_obj = {
                'staffId': staff_id,
                'visitorId': str(visitor_id),
                'subject': subject_of_visit,
                'dateTime': date_time,
            }

            AppointmentDB.new_appointment(appointment_obj)
 def delete_appointment(appointment_id, visitor_id):
     VisitorDB.delete_visitor(visitor_id)
     AppointmentDB.delete_appointment(appointment_id)