The doctor prescribed medicine that contains narcotics; is it permissible for him to take it?
Question

I know Islam forbids taking drugs, but what if the doctor prescribes a stimulant called Adderall, which is to treat attention deficit and hyperactivity? The doctor examined me thoroughly and I told him that I did not want to take any medication, but he said that it is better in my case to treat the problem with medication. Is it permissible for me to take this medicine? Did the Prophet (blessings and peace of Allah be upon him) take medicine or did something like this happen at his time?
Praise be to Allah.Adderall is the trade name for a stimulant medication that is believed to work by increasing the amount of dopamine produced in the brain. Studies have shown that Adderall works by increasing alertness and focus, which is done by reducing feelings of tiredness in the user. It is also used to treat cases of attention deficit hyperactivity disorder (ADHD). Some types are included among medications that are restricted because there have been cases of addiction or the possibility of misuse. 
For more information please see
With regard to the ruling on using medicines that contain narcotics, the basic principle is that they are not allowed and they are haram. But if it is used for medical purposes and there are no permissible medications that could be used instead, then in that case it is permissible to use them, subject to certain conditions: 
1.That the patient’s need for this medication is a case of necessity or urgent need
2.That a trustworthy Muslim doctor should testify that this narcotic medication is beneficial for the patient
3.That use of the medication should be limited to that which will meet the need
4.That this medication should not cause the patient greater harm than or harm equal to the harm because of which he is using it.
The scholars of the Standing Committee were asked: 
What is the ruling on using pethidine or morphine, which are drugs that have an intoxicating effect, in cases of necessity or need? 
They replied:
If there is no other permissible substance that can be used to reduce the patient’s pain other than these two substances, then it is permissible to use either of them to reduce pain in the case of necessity. That is on condition that using it should not lead to any greater or equal harm, such as addiction to its use. 
Shaykh ‘Abd al-‘Azeez ibn Baaz, Shaykh ‘Abd ar-Razzaaq ‘Afeefi, Shaykh ‘Abdullah ibn Ghadyaan, Shaykh ‘Abdullah ibn Qa‘ood 
End quote from Fatawa al-Lajnah ad-Daa’imah, 25/77, 78 
See also the answer to question no. 176623  
With regard to your question about whether something like this happened at the time of the Messenger of Allah (blessings and peace of Allah be upon him), we have not come across any incident in which sickness was treated with narcotics or intoxicants in particular at the time of the Prophet (blessings and peace of Allah be upon him). 
We would also advise you to consult a trustworthy Muslim doctor; if he tells you that your case requires treatment and that there is no suitable alternative in your case apart from this type of medicine, then there is nothing wrong with you using it, in sha Allah. 
But if there is a permissible alternative, or it is a matter of what is better, as we understand from your question, and it has not reached the level of necessity or urgent need, then you are not allowed to use it. 
For the ruling on medical treatment, please see fatwa no. 2438
And Allah knows best.