added table queries for apptid search (still need to link vars in Doctor)