There is a relevant section in the SC ruling.
In the Outer House, Lady Haldane concluded (at para 53) that section 9(2) of the Victims and Witnesses (Scotland) Act 2014 (as amended by the Forensic Medical Services (Victims of Sexual Offences) (Scotland) Act 2021) can only properly (or fairly) be read to mean biological sex when it uses the term “sex”. This is because the purpose of the amendment (introduced by the 2021 Act) was to ensure that section 9(2) of the 2014 Act read as follows: “Before a medical examination of the person is carried out by a registered medical practitioner, the person must be given an opportunity to request that any such medical examination be carried out by a registered medical practitioner of a sex specified by the person”. We agree with her analysis: sex as used in this provision must mean biological sex notwithstanding that there is no reference to biological sex in this provision. The clear statutory intention is to respect the right of a female or male victim of a sexual crime to request same sex care should she or he so wish because it has always been, and still is, well recognised that reasonable objection can be taken to an intimate medical examination by a member of the opposite biological sex. References to sex could only be references to biological sex in context.
This refers to the situation where you have a legal right to request someone of a particular biological sex after being assaulted. Consent during other procedures being a separate but related issue.
The more pressing issue imho is not just the legal situation but processes - i.e. when you make a medical appointment for particular sex it's usually with a secretary etc. and they have a list of i.e. Dr. Upton (F). You then just go to that appointment with the doctor, possibly also alone and as NC so very well pointed out you may not realise until half dressed and part way through the procedure.
The last I heard Dr. Upton was working in psychiatry and patients can request a clinician of a particular sex especially if they have a history of sexual trauma. Consent applies to all medical appointments and examinations not just physical ones.