Should I tell my professor that I may need surgery in the middle of the semester?
Short answer: Tell him now.

Longer answer:
As pointed out in the comments, go find the office dealing with such questions and contact them. You don't need to resort to legal rights immediately, just tell them your story and get some advice on how to proceed. They might also know things you didn't consider yet, e.g. some regulations on how much of a class you are allowed to miss, what sort of medical certificate is needed, etc.

After you cleared all questions with them, tell your instructor that you have a pressing medical issue that will force you to miss up to three weeks of class. Do that in person if possible, not via email. Ask him how to handle this and show him that you are still interested in his class and willing to take it, e.g. ask him if it is possible to get the lecture notes for these weeks and hand in the homework via email. Of course this depends on how you define "bedridden", so if you will be on heavy meds and unable to do anything, or if you will be sitting in your bed, fully alert and able to work on a laptop, but not able to stand up. I don't know what condition you have and I understand that this is private, but you should think about a plan on how to make up for the missed classes and present this plan in the discussion with the professor. This will show him that you are motivated and willing to take the class and is far easier to accept than you being gone for a few weeks and some legal office forcing him to still let you pass.
Also try to point out that you have some flexibility on when to schedule the operation and ask him for his opinion. Make clear that you can't say an exact date, but ask him if he prefers this month or that month, for example. All in all, talk to him, be frank and show motivation to make up for the missed time and you should be ok.

The above advice might also help with him not being pleased with your anxiety. It is hard for a non-professional to distinguish between anxiety and stress/fear of exams. Furthermore, some students simply say "I have anxiety", even if they are just a little stressed at the moment. Show the professor that you are still motivated for his class, that you are not trying to use your anxiety as an excuse for anything, that you are doing your best even though you have several medical conditions and he will most likely not worry about it anymore.