I don't teach ethics as a subject, but it's a consideration (or it should be!) in every patient interaction. I teach resuscitation and critical care, so I'm often dealing with patients who are unconscious or incapacitated to the degree that they lack capacity to consent. In these cases, we act in what we believe to be the best interests of the patient. If a patient has previously made a request regarding clinician gender/sex, we would accommodate that where possible. However, in a time critical life-threatening situation, the requirement to act quickly will often supersede, and the person with the appropriate clinical skills will use them, whatever their sex/gender.
In my experience of 15+ years of managing life-threatening emergencies, a person on death's door doesn't give a damn about the sex/gender of the person saving their life. I know I wouldn't.
(As an aside, the transgender patients I have treated have always been honest about their biological sex because they know it matters from a medical perspective. I am respectful and I use the pronouns they prefer, but I am straightforward when discussing the matter of sex. I've never encountered a trans patient who expects me to believe they are literally the opposite sex.)