Although as a rule it is forbidden to take medication on Shabbat, one whose condition requires him to lie down due to his discomfort is allowed to take medicine. The Sages did not apply their enactment to a person who experiences such discomfort that he must lie down, and so such a person is permitted to take any medication he needs to feel better. The prohibition applies only to those experiencing mild discomfort who can still go about and do not need to lie down.
An interesting question arises in the case of a person with a certain condition that requires him to take preventative medication in order to avoid debilitating discomfort that would require him to lie down. Meaning, the patient feels fully healthy now, but if he does not take his medication on Shabbat, he will experience considerable discomfort which he would need to go to bed in order to alleviate. Is such a person allowed to take his medication preemptively, before the symptoms occur, or must he wait until he experiences the discomfort before taking the medication?
Rav Shlomo Zalman Auerbach (Israel, 1910-1995), in Shulhan Shlomo (328:24; listen to audio recording for precise citation), writes that such a patient has the status of a "Nofel Le’mishkab" – an ill patient who needs to lie down – and may therefore take his medication. He writes this also in his Minhat Shelomo, noting that clearly there is no reason at all to force this person to wait until he suffers pain and discomfort.
The work Nishmat Shabbat suggests drawing proof to this ruling from the Halacha permitting asking a non-Jew to light the fireplace on Shabbat if one’s house is cold (Shulhan Aruch, Orah Haim 276). The reason is that all people are considered "sick" with respect to the cold, and therefore, just as Halacha permits asking a gentile to perform Melacha (forbidden activity) for the sake of an ill patient, likewise, one may ask a gentile to light the fireplace so the house would not be cold. Even if the house is still comfortable, one may ask a gentile to light the fireplace if he anticipates the house becoming cold. Rather than wait until the temperature becomes uncomfortably low, one is allowed to ask a non-Jew already now to light the fireplace. By the same token, then, it should be permissible to take medication before one develops serious discomfort, and he does not have to wait until he suffers pain and discomfort before taking the medication.
This is also the ruling of Rav Shlomo Miller (contemporary), in his Shabbat Shlomo, where he adds that this applies even if the discomfort would surface only after Shabbat. Meaning, if a person knows that he will feel well throughout the rest of Shabbat, but will begin feeling serious discomfort after Shabbat, he may take his medication on Shabbat as a preventative measure to avoid feeling pain and discomfort after Shabbat.
Summary: It is permissible to take medication on Shabbat if one’s condition requires him to lie down to alleviate his discomfort, and one may also take medication preemptively if he knows that otherwise he would experience this level of discomfort.