I concur that stress and pain levels absolutely contribute to brain fog. Your body and mind have been under duress for a while. Just having surgery without having CRPS knocks people for a loop. Add on what you're dealing with and medications...that's a lot!
Early on, when I first had this my memory was terrible (maybe that was the initial pain brain). I was forgetting all kinds of things that should've been natural to remember. I felt fairly distressed about it at the time. However, that didn't last past a few months for me. Once I got past the initial flare, as DejaVu did, I started to have improvements.
Sending hugs,