You have to try to arrange taking the medicine in a way that allows you to be awake at least before the prayer becomes qaza, so that you can pray on time.
If you are taking the dose at night, then take it early, so that you get enough sleep, and wake up before sunrise.
If despite all the precautions, you still woke up after time, then you just need to pray qaza.