The Bhikkhuni sutta recommends food, for example, as follows:
This body, sister, comes into being through food. And yet it is by relying on food that food is to be abandoned.' Thus was it said. And in reference to what was it said? There is the case, sister, where a monk, considering it thoughtfully, takes food — not playfully, nor for intoxication, nor for putting on bulk, nor for beautification — but simply for the survival & continuance of this body, for ending its afflictions, for the support of the holy life, [thinking,] 'Thus will I destroy old feelings [of hunger] and not create new feelings [from overeating]. I will maintain myself, be blameless, & live in comfort.' Then he eventually abandons food, having relied on food. 'This body, sister, comes into being through food. And yet it is by relying on food that food is to be abandoned.' Thus was it said, and in reference to this was it said.
I suppose that taking medicine is for a similar purpose -- i.e. it's to destroy old feelings (of pain), and not to create new feelings (from intoxication or sensual indulgence).
The vinaya for example permits medicines to monks if they're sick, including medicines which contain alcohol, if the alcohol is in more-or-less undetectable quantities (alcohol is useful when creating certain medicines because it's an effective solvent e.g. of alkaloids).
See also the answers to the topic Experiencing physical pain.
You might also want to read:
What nurses need to know about Buddhist perspectives of end-of-life care and dying
Management of terminal pain and sedation
Most Buddhists believe that the mind must be as alert as possible at the time of death.
Taking into consideration overall well-being (including the mental state of the patient), nurses must balance the level of pain relief needed against the need for alertness in the dying Buddhist.
Proper pain management can be achieved with minimal disruption of alertness by the use of the WHO analgesic ladder.
The choice of non-opioid analgesics (non-steroidal anti-inflammatory drugs) and weak opioids should be preferred over strong opioids and neurolytic block therapy whenever possible, with the aim of reducing adverse side effects (i.e. sedation and cognitive impairment), thus maintaining alertness of the individual so that effective spiritual practices may continue. However, if severe uncontrolled pain develops, cognitive impairment (e.g. delirium) may result that may require the use of strong opioids for effective relief to achieve the best cognitive function possible that would support meditative spiritual practices.
The above is a small quote/extract, I recommend reading the whole article.
In other words medical providers are advised to (more or less as usual) adjust the amount and type of medicine, according to the amount of pain, and according to the patient's ability to tolerate it. The difference is that Buddhist patients tend to prefer to avoid mind-altering drugs for as long as feasible.
A Buddhist Guide to Death, Dying and Suffering
Why is the body important when one is enlightened or mindful?
Part of Buddhist doctrine is a Middle Way, e.g. MN 36 explains something like this:
"I thought: 'Whatever brahmans or contemplatives in the past have felt painful, racking, piercing feelings due to their striving, this is the utmost. None have been greater than this. Whatever brahmans or contemplatives in the future will feel painful, racking, piercing feelings due to their striving, this is the utmost. None will be greater than this. Whatever brahmans or contemplatives in the present are feeling painful, racking, piercing feelings due to their striving, this is the utmost. None is greater than this. But with this racking practice of austerities I haven't attained any superior human state, any distinction in knowledge or vision worthy of the noble ones. Could there be another path to Awakening?'
"I thought: 'I recall once, when my father the Sakyan was working, and I was sitting in the cool shade of a rose-apple tree, then — quite secluded from sensuality, secluded from unskillful mental qualities — I entered & remained in the first jhana: rapture & pleasure born from seclusion, accompanied by directed thought & evaluation. Could that be the path to Awakening?' Then following on that memory came the realization: 'That is the path to Awakening.' I thought: 'So why am I afraid of that pleasure that has nothing to do with sensuality, nothing to do with unskillful mental qualities?' I thought: 'I am no longer afraid of that pleasure that has nothing to do with sensuality, nothing to do with unskillful mental qualities, but that pleasure is not easy to achieve with a body so extremely emaciated. Suppose I were to take some solid food: some rice & porridge.' So I took some solid food: some rice & porridge. Now five monks had been attending on me, thinking, 'If Gotama, our contemplative, achieves some higher state, he will tell us.' But when they saw me taking some solid food — some rice & porridge — they were disgusted and left me, thinking, 'Gotama the contemplative is living luxuriously. He has abandoned his exertion and is backsliding into abundance.