Musnad Ahmad 841
It was narrated that `Ali bin Abi Talib (رضي الله عنه) said:
I fell sick and the Messenger of Allah (ﷺ) passed by me when I was saying O Allah, if my time has come then grant me relief; if it has not yet come then raise me in status; and if this is a trial then grant me patience. The Messenger of Allah    (ﷺ)  said: “What did you say?” He repeated to him what he had said, and he nudged him with his foot and said: `O Allah, grant him well being` or “O Allah, heal him.” - Shu`bah was not certain. He [‘Ali] said: And I never suffered that sickness again after that.
حَدَّثَنَا مُحَمَّدُ بْنُ جَعْفَرٍ، حَدَّثَنَا شُعْبَةُ، عَنْ عَمْرِو بْنِ مُرَّةَ، عَنْ عَبْدِ اللَّهِ بْنِ سَلَمَةَ، عَنْ عَلِيِّ بْنِ أَبِي طَالِبٍ، رَضِيَ اللَّهُ عَنْهُ قَالَ كُنْتُ شَاكِيًا فَمَرَّ بِي رَسُولُ اللَّهِ صَلَّى اللَّهُ عَلَيْهِ وَسَلَّمَ وَأَنَا أَقُولُ اللَّهُمَّ إِنْ كَانَ أَجَلِي قَدْ حَضَرَ فَأَرِحْنِي وَإِنْ كَانَ مُتَأَخِّرًا فَارْفَعْنِي وَإِنْ كَانَ بَلَاءً فَصَبِّرْنِي فَقَالَ رَسُولُ اللَّهِ صَلَّى اللَّهُ عَلَيْهِ وَسَلَّمَ كَيْفَ قُلْتَ فَأَعَادَ عَلَيْهِ مَا قَالَ قَالَ فَضَرَبَهُ بِرِجْلِهِ وَقَالَ اللَّهُمَّ عَافِهِ أَوْ اللَّهُمَّ اشْفِهِ شَكَّ شُعْبَةُ قَالَ فَمَا اشْتَكَيْتُ وَجَعِي ذَاكَ بَعْدُ‏.‏