Refactoring the code to delete thread.sleep and use better ways to ensure presence of encounters in patient dashboard.