It goes without saying that a Muslim should care a lot about his/her fast, not allowing anything to break it, unless there is a real and dire necessity for that. In the meantime, we should bear in mind that it is not up for anyone to decide to break his/her fast claiming that he/she has a medical necessity. The medical necessity is to be determined by the qualified physicians.
Sheikh Muhammad Iqbal Nadvi, Director and Imam of Al-Falah Islamic Center, Oakville, Ontario, Canada, and Former Professor at King Saud Univ., Saudi Arabia, states the following: We need to understand that any kind of food or drink that reaches the stomach from the mouth or any other outlet will break one’s fasting. However, medical treatments like inhalers and vaccinations, which reach the stomach from an outlet other than the mouth, do not nullify the fast.
If the barium suspension goes to the stomach through the mouth, and it is mixed with water. If that is the case, it will for sure break the fast.
Moreover, Professor `Ali Sayyed Ahmad, professor of sciences and exegesis of the Qur’an at Al-Azhar University, adds: Actually, when a Muslim has to undergo X-ray examination in Ramadan, he should do so in the evening, after breaking his fast. But, if there is an urgent necessity for a Muslim to undergo such an examination during Ramadan, then there is no sin in ingesting barium or in giving it to a patient to drink.
When a Muslim has to do so, he should make up for that day later and he should also abstain from food and drink for the rest of that day until sunset. This is so as to respect the month of Ramadan. Although, if he is unable to do so (for example, due to illness) then he does not have to fast the rest of that day.
Thus, if you cannot have the X-ray in the evening (which may be the case in a non-Muslim country) and your medical condition is such that you can postpone the examination until after Ramadan, you should wait until after the `Eid to have the X-ray.