Fixed a bug in the find patient algorithm