Praise be to Allaah.
The basic principle is that if a female specialist doctor is available, she should examine the patient. If no such doctor is available, then a trustworthy non-Muslim female doctor can do it. If this is not possible, then a male Muslim doctor, and if a male Muslim doctor is not available, then a non-Muslim male doctor, on the condition that he looks only at as much of the woman’s body as is necessary for him to diagnose and treat the problem, and he should lower his gaze as much as possible, and not look any more than is necessary. The doctor should administer this medical treatment to the woman in the presence of her mahram or husband or another woman, so as to avoid khulwah (being alone with him). And Allaah knows best.