Praise be to Allah
The basic principle is that it is obligatory to conceal one’s faults, and that a person should not expose himself when Allah has concealed him; rather disclosing that may come under the definition of committing sin openly, and Allah has warned the one who commits sin openly that He will deprive him of His pardon.
It was narrated that Abu Hurayrah said: I heard the Messenger of Allah (blessings and peace of Allah be upon him) say: “All of my ummah will be fine except those who commit sin openly, and it is part of committing sin openly for a man to do something at night, then in the morning when his Lord has concealed him he says: O So and so, I did such and such last night, when his Lord had concealed him all night, but in the morning he discloses that which Allah had concealed for him.”
Narrated by al-Bukhaari (5721) and Muslim (2990).
What is required is for the individual to beware of exposing himself or of telling anyone about such things, unless it is for a valid shar‘i purpose.
One such purpose is to seek a fatwa concerning oneself, or to ask about the ruling of Allah concerning someone like him, or to admit that to the qaadi (judge) so that he may carry out the hadd punishment on him, and so on.
With regard to the doctor, what appears to be the case that if there is a valid reason that justifies doing that, such as if one who is addicted or drinks alcohol tells the doctor about it, and the doctor is specialised in dealing with such things, so that he can help him to treat the problem and give up that bad habit, then in such cases there is a combination of medical interests, the interest of treating that disease, and spiritual interests, which will be served by giving up that immoral deed and major sin, and repenting from it. Everything that may help a person to give up evil is prescribed in his case, and is either obligatory or recommended.
But if there is no valid reason or interest that it is hoped will be served by telling the doctor about such things, then the Muslim should conceal his faults and refrain from speaking about them, and he should ask the doctor to overlook the issue.
Usually, a smart doctor has the insight to understand what he needs to know from these symptoms, so the one who is faced with that problem has no need to expose himself or tell lies. What he is seeking of treatment for himself, if treatment is required, the doctor can base on what he sees in his examination of the patient and on what he understands of the implicit meaning of he says.
And Allah knows best.