All perfect praise be to Allah the Lord of the Worlds. May His peace and blessings be upon our Prophet Mohammad and upon all his family and companions.
Islamic Sharia encourages seeking medical treatment when one is ill and emphasizes the importance of learning medicine. Scholars of Islamic jurisprudence have included the learning of medicine and specializing in its sciences as part of the collective obligations (fard kifayah). Although this knowledge is not restricted to a specific gender, the general practice is that a woman should be treated by a female doctor and a man by a male doctor. In cases of necessity, exceptions can be made based on the circumstances at hand.
Similarly, in the context of medical education, it is advisable for women to learn from female instructors, and men to learn from male instructors. This is especially relevant in situations that involve practical applications requiring physical contact between the instructor and the learner. Adequate measures should be taken to ensure the availability of qualified doctors from both genders. Working towards this goal is considered part of the collective obligations (fard kifayah) in Islam.
In the case of medical treatment, if a qualified doctor of the same gender is not available, and the need arises for a man to treat a woman or vice versa, there is no harm in that due to the necessity, while still observing the Sharia guidelines. It is mentioned in [Hashiyat al-Bujayrimi, Vol. 3/P. 80], a Shafi'i jurisprudential source: "It is a condition that there be no man who is able to undertake it when it comes to a man. That is, if the patient is a man and the physician is a woman, it is a condition that there be no man available to treat him."
In the context of learning and education, if the educational objectives can be achieved using appropriate educational tools without revealing private parts, then that is preferred. If it is not possible, then it is necessary to ensure that the practical application is done among students of the same gender. All of this should be conducted in accordance with Sharia rulings, and care should be taken not to exceed the necessities dictated by the situation.
In conclusion, it is well-known that forcing a patient to be treated by a doctor or a trainee against her will, contrary to instructions that ensure the patient's privacy and her right to appropriate treatment, is not permissible in Islamic law when a female doctor or trainee is available. If the patient chooses to be treated by a male doctor, or vice versa, it should be for a valid reason and must comply with the rulings of Sharia while considering the necessities without exceeding them. And Allah the Almighty knows best.