Surgery usually requires viewing parts of a naked person. Are there halachic problems with a doctor of opposite gender doing this on a Jewish patient? If the procedure is one where part of the body may be covered such as an endoscopy or repairing an arm or leg, would the halacha be different?
Shulchan Aruch Even Haezer Siman 21 Saif 5
It is forbidden to be served by a woman at all, whether she is an adult or a minor, whether a slave or free, lest he come to have forbidden thoughts. What service were they speaking of? Washing his face, hands, and feet, even to pour water so he can wash his face, hands, and feet, even if she does not touch him; or making his bed in front of him; or pouring a drink
Rema- And some say that anything not done in a affectionate manner (בדרך חבה), where his intent is only for Heaven's sake, is permitted. Thus the custom is to be lenient in these things
Sefer Nishmat Avraham- The Tosfot write that it is because we depend on this that we today use the services of women. The Aruch Hashulchan writes the above ruling only applies if she does not do this as a service, but if these acts are performed as a service it would appear to be permitted. However, washing his face, hands and feet are clearly forbidden for this involves close contact. Rav Neuwirth wrote that this is only true with regard to a healthy male but if he is ill a woman (such as a nurse) may attend to his needs if another male is not available to do so.
The Birkei Yosef writes that one may ask how we permit a woman to attend to a man suffering from intestinal disease (presumably diarrhea) for since she has to attend to his private ares he may come to sinful thoughts resulting possibly in the emission of semen. However, since he is ill his inclinations will not overcome him for his body is weak as the Terumat Hadeshen writes.
A male doctor, student or any other caregiver, whose work in treating and caring for the sick in undoubtedly noble, must be most careful that when attending to a woman, his eyes and thoughts are entirely focused upon his job and that he is intent only on what he is doing. In addition, he must also be acutely aware of the patient's feelings, for example, where possible, only uncovering that part of her body that he needs to examine, re-covering it before examining elsewhere.