How can the company find out?
Various ways. The first being that you tell them. The second is that you allow your medical records to be shared.
When any of our Drivers go sick; even for a day. They will have a return to work interview. Questions are asked about why that person was off, did they see a Doc, what else may be of significant interest to the company, etc. etc. You are required to be honest in that discussion. Not disclosing anything, whilst may not be immediately discovered, would be gross misconduct.
Our Driver who are long term sick have even more medical disclosure questions and interviews. Especially upon return. If you get sent for a resumption medical, our TOC has a question stating "are you willing for the company to request medical history" Again, it would be gross misconduct to mislead or be less than truthful here.
Long, long term and you're looking at medical capability processes. Medical records start to become very significant. IF you look at the end of the med cap process; there can be a potential payout for medical capability. If anything is discovered along the way that you failed to disclose or was even slightly dishonest. Not only would it be career ending, you would forfeit any payout.
Being honest and open with your employer allows them, and pretty much obliges them, to support you. Often Occupational health can provide clear insight to what can be done and often what additional or specialist help can be provided.
As others have already said. Your health is important and not declaring could make your condition worse by suffering at work. As you are already off with anxiety, I would hope that conversations and welfare checks have already taken place.
Speak to your Doc, speak to your Manager, speak with your Occupational health team.
*Edit*. Not forgetting that when you book on for duty, you probably sign the "statement of readiness" which I believe, is a legal "document"