Bismillah,
Asalamu Alaykom,
If one needs to expose their private parts to a doctor for necessary medical reasons then it is permissible. Of course one should only show the part which is absolutely necessary and not more than is needed. One should also visit the doctor of the same gender.
Some ulema also mention for the doctor to look at the private parts via a mirror rather than directly.
May Allah grant you success