All perfect praise be to Allah, The Lord of the Worlds. I testify that there is none worthy of worship except Allah, and that Muhammad is His slave and Messenger.
We ask Allah to cure you, and bless you and all Muslims with wellness as we supplicate Him to make what has befallen you a purification of all your sins.
Know that drinking medicine during the day in Ramadan nullifies the fasting and cannot be compared to eating or drinking out of forgetfulness. Indeed, the doer who deliberately performs something is different from the ignorant and the forgetting person. So, the contrast you made is not in its right context. There are texts that allow the sick fasting person to break the fast and make it up later.
Now, the solution to your problem is to take the medicine just before dawn. If you fail to do that or cannot do it for some reason, then you break the fast. Then make up the missed days if your illness can be cured, otherwise you just pay a Mudd which is equal to the weight of two thirds of a kilogram, as an atonement to a needy person for each missed day.
Allah knows best.