The messenger of Allah (may the peace and blessings of Allah be upon him) said: Whoever sees an afflicted person and says:
الحَمْدُ لِلَّهِ الَّذِي عَافَانِي مِمَّا ابْتَلَاكَ بِهِ، وَفَضَّلَنِي عَلَى كَثِيرٍ مِمَّنْ خَلَقَ تَفْضِيلًا
Alhamdu lillaahil-lathee ‘aafaanee mimmab-talaaka bihi wa fadhdhalanee ‘alaa katheerin mimman khalaqa tafdheela.
“Praise be to Allah who had saved me from what He had afflicted you with, and for honouring me over many of his creations.”
….He (or she) will never be afflicted by it (this particular affliction).
Reference: At-Tirmithi 5/493,4. See also Al-Albani, Sahih At-Tirmithi 3/153