Doctor-patient confidentiality of and by itself does not provide a blanket exemption to backbiting. However, when discussing family history or hereditary diseases with the intention of reaping a benefit (improving your health) or restricting harm (e.g., curing an ailment or disease), then it is encouraged both Islamically and medically.
In the introduction to his book about the difference between advising and expressing, Al-Farq Bain an-Nasīaha wa at-Ta'bīr, Ibn Rajab al-Hanbali mentioned the overall guiding principle:
اعلم أن ذكر الإنسان بما يكره محرم إذا كان المقصود منه مجرد الذم والعيب والنقص. فأما إن كان فيه مصلحة لعامة المسلمين خاصة لبعضهم وكان المقصود منه تحصيل تلك المصلحة فليس بمحرم بل مندوب إليه
NOTE. My own translation, so treat with care.
Know that mentioning a person by what the person hates is forbidden if the intention is dispraising, blemish, or belittlement. If, however, there is a general benefit to the Muslims or a specific benefit to one or more Muslims, and the intention is to ripe such benefit, then it is not forbidden; rather, encouraged.
— Al-Farq Bain an-Nasīaha wa at-Ta'bīr, Vol. 2, pp. 7 (Arabic only)
Furthermore, scholars agree that there are six areas where mentioning what a Muslim hates is not considered backbiting, summarized in this short poem:
الذم ليس بغيبة في ستة ... متظلم ومُعرِّف ومحذر
ولمظهر فسقا ومستفت ومَنْ ... طلب الإعانة في إزالة منكر
NOTE. My own translation, so treat with care.
Dispraise is not backbiting in six ... oppression, definition, and precaution
Open disobedience, seeking verdict, and whoever ... seeks help to forbid evil
The concept of doctor-patient confidentiality is explicitly mentioned in Islam in an authentic hadith attributed to the Prophet ﷺ:
عن أبي هريرة، قال قال رسول الله صلى الله عليه وسلم: الْمُسْتَشَارُ مُؤْتَمَنٌ
Narrated Abu Hurayrah: The Prophet (ﷺ) said: "He who is consulted is trustworthy."
— Sunan Abi Dawud, Book 43, Hadith 356
The translation here does not capture the full meaning of the word mu'taman (translated as trustworthy). Mu'taman goes beyond being entrusted or being trustworthy. It encompasses liability and indemnification, too. When one is consulted, one has to be knowledgeable about the topic of consultation (or refrain from providing advice), respect confidentiality, and sincerely provide one's opinion.
When Imam Ahmad ibn Hanbal was asked about how a person should answer when asked advice about a specific person in marriage, he emphasized the manners to be used when mentioning what others may dislike:
المستشار مؤتمن، يخبره بما فيه، وهو أظهر، ولكن يقول: ما أرضاه لك، ونحو هذا حسن
NOTE. My own translation, so treat with care.
He who is consulted is entrusted, so he has to inform of what the person [to be married] really is and that is more obvious, but he should say: "what I would consider good for you ..." and so on; this is fine.
— Jami' al-'Ulūm, Vol. 20, pp. 26 (Arabic only)
In other words, when discussing family history or hereditary diseases with your doctor:
- Have the right intention that you are doing so for your own benefit, and
- Give attention to your choice of words to ensure that you are defining a situation rather than dispraising a person.