fixing bugs in appointment queries

fixing bugs in appointment queries