Praise be to Allah.
It was narrated from Abu Hurayrah (may Allah be pleased with him) that the Messenger of Allah (blessings and peace of Allah be upon him) said: “When a man dies, all his good deeds come to an end except three: ongoing charity (sadaqah jaariyah), beneficial knowledge, or a righteous son who will pray for him.”
According to the scholars, “ongoing charity (sadaqah jaariyah)” is understood to refer to wealth which is donated as an endowment, the income of which is ongoing and is spent on good causes. This is what is known in fiqh as a waqf.
Al-Qaadi ‘Iyaad (may Allah have mercy on him) said:
This is proof of the reward for waqfs and endowments, and it is a refutation of those among the people of Kufah who disallowed that, because ongoing charity after death can only be achieved by means of awqaaf (pl. or waqf)."(Ikmaal al-Mu‘allim 5/373).
Ibn al- Malik (may Allah have mercy on him) said: “Except three: ongoing charity (sadaqah jaariyah)” that is, charity of which the benefit continues and the reward is ongoing, such as a waqf, building a mosque or jaami‘, digging a well, building a road, redigging springs, and other kinds of good works."(Sharh al-Masaabeeh 1/193).
This is also what may be understood from the hadith that was narrated by Ibn Maajah (242) from Abu Hurayrah, who said: The Messenger of Allah (blessings and peace of Allah be upon him) said: “The good deeds and rewards that will reach a believer after his death are: knowledge which he taught and spread; a righteous son whom he leaves behind; a copy of the Qur’an that he leaves as a legacy; a mosque that he built; a house that he built for wayfarers; a canal that he dug; or charity that he gave during his lifetime when he was in good health. These deeds will reach him after his death.”
Medical advice that the deceased leaves behind cannot be described as ongoing charity, but there is the hope that the second thing that is mentioned in the hadith will apply to that, namely “beneficial knowledge.”
Shaykh Ibn ‘Uthaymeen (may Allah have mercy on him) was asked:
With regard to the words of the Prophet (blessings and peace of Allah be upon him), “When a man dies, all his good deeds come to an end except three: ongoing charity (sadaqah jaariyah), beneficial knowledge…” is what is meant Islamic knowledge, or worldly knowledge?
The hadith is general in meaning, and any knowledge that benefits people is something for which a person will attain reward, but first and foremost among that is Islamic knowledge. So if we assume that a person dies having taught another person some permissible craft or trade, from which the one who learned it benefits, then he will attain reward for that." (Liqa’ al-Baab al-Maftooh 117/17).
And Allah knows best.