I know how you feel as I suffer from IBD and the school treated me the like that. I spoke to the teachers and they still didn’t let me go. I spoke to the head of year and she didn’t do anything (she was an idiot). I got my parents involved and they tried speaking to my teachers but they wouldn’t have any of it. They still treated me the same as anyone else.
Speak to your head of year, they might be more understanding (I left school 6 years ago). And if they don’t do anything, get a doctors note. When there’s proof, they can’t argue with that