In the UK the General Medical Council places a requirement on doctors to over ride individual patient confidentiality if the risk to society or others is greater. The obvious one is an absolute requirement to report a stabbing, even though some are not the result of crime.
The issues are
a some countries have privacy laws and dont have a GMC
b doctors are busy and dont always know exactly what a patient does
The flip side of all this is that pilots might not seek help for either physical or mental health issues, exacerbating as opposed to solving the problem.