Changed get prev visit and next visit query