Reformat and fix patient Id cache logic