We can only tackle communicable disease if someone tells us about them. This can be tricky stuff for doctors, and the General Medical Council has issued new guidance. It's not always easy. One classic situation in modern times is the needlestick injury from a patient who doesn't want his or her HIV status to be disclosed.
On the one hand, don't break confidentiality if actually it won't make any difference. On the other hand, do break confidentiality against the patient's wishes if someone else really is going to come to harm as a result.
The GMC feels obliged to uphold the law - if the law says do something, you have to do it. But that isn't always the right thing to do, and I'm proud that in health we have a fine (albeit costly) tradition of obeying first the dictates of conscience. In the UK laws are mostly - but not always - ethical, but that can't be said for many jurisdictions.
The GMC guidance on knife and gunshot wounds is also worth reading.