Mishkat al-Masabih 1560
وَعَنْ أَنَسٍ أَنَّ رَسُولَ اللَّهِ صَلَّى اللَّهُ عَلَيْهِ وَسَلَّمَ قَالَ: إِذَا ابْتُلِيَ الْمُسْلِمُ بِبَلَاءٍ فِي جَسَدِهِ قِيلَ لِلْمَلَكِ: اكْتُبْ لَهُ صَالِحَ عَمَلِهِ الَّذِي كَانَ يَعْمَلُ فَإِنْ شَفَاهُ غَسَّلَهُ وَطَهَّرَهُ وَإِنْ قَبَضَهُ غَفَرَ لَهُ وَرَحِمَهُ . رَوَاهُمَا فِي شرح السّنة
From Anas, that the Messenger of Allah ﷺ said: "When a Muslim is afflicted with a trial in his body, it is said to the angel: 'Write for him the righteous deeds he used to do.' Then if He heals him, He washes him and purifies him; and if He takes him, He forgives him and has mercy on him." He reported both of them in Sharh as-Sunnah.