Severe headaches are one of the reasons for which it is permissible to break the fast in Ramadaan, especially as fasting is something that makes the headache worse. So there is nothing wrong with the one who is affected by that breaking his fast in order to take medicine, and he may eat and drink to take away that pain. But he has to make up the days that he did not fast after Ramadaan is over, because Allaah says (interpretation of the meaning):
“and whoever is ill or on a journey, the same number [of days which one did not observe Sawm (fasts) must be made up] from other days”
It says in al-Jawharah al-Nubayrah (Hanafi) (1/142): The sick person for whom it is permissible to break the fast if fasting will make his fever worse or increase the pain in his eyes or head. End quote.
And Allaah knows best.