refactored patient search and added automated tests