Fixed bugs and added sql for AppointmentRequests.