Hakim reported that the Messenger of Allah ﷺ said, "There is no servant whom Allah tests with an affliction in his body except that Allah
says to the angel, 'Record for him the righteous deeds he used to perform.' If Allah heals him, He washes him and purifies him, and if He takes his soul, He forgives him and shows him mercy."
حدثنا حسن حدثنا حماد بن سلمة عن أبي ربيعة
ك أن رسول الله ﷺ قال ما من عبد يبتليه الله عز وجل ببلاء في جسده إلا قال الله عز وجل للملك اكتب له صالح عمله الذي كان يعمله فإن شفاه الله غسله وطهره وإن قبضه غفر له ورحمه