Sayyiduna Anas bin Malik (may Allah be pleased with him) narrates that the Prophet (peace and blessings be upon him) said: "When Allah Almighty tests a Muslim servant with a trial (that is, an illness) in his body, Allah Almighty says to the angel: 'Keep recording for him the righteous deeds he used to do before.' If Allah Almighty grants him a cure, He washes him (of sins) and purifies him, and if He takes his soul, He forgives him and has mercy on him."
Abu Ya'la and Ahmad recorded it, and its narrators are thiqat (trustworthy).
Hadith Referenceمجمع الزوائد ومنبع الفوائد / كتاب الجنائز / 3812