Usually bodies of Gods are having super human capabilities. Apart from the fact you mentioned in your question, as per the legend book, Ram Charit Manas, written by Tulsidas.
"Even as Surasa expanded her jaws Hanuman manifested a form twice as
large as her mouth.When she further expanded her mouth eight hundred
miles wide, Hanuman assumed a very minute form"
Sundar Kanda, page 820, sloka 5
So Hanuman's body was not a normal human body which we can think of and make interpretations with our senses. These are kind of mystical powers which we ordinary mortals don't have. That's why they are given the status of God in mythology.
So in my opinion Hanuman ji did not need any surgery, he showed by his powers that only lord lives in his heart and to prove his point he had to open his chest.
In our present age there has been a great saint who with the help of Hanuman ji was able to do miracles though he never claimed himself to do any thing and mentioned always it is Hanuman ji who is doing all this. He is known as Neem Karoli Baba you may read more about him on google for a starting I am giving below a couple of links.
Neem Karoli Baba
www.maharajji.com/Miracle-of-Love/address-to-maharajji-s-photo.html
Many ascetics in Himalaya are able to develop such powers so it is no wonder that Hanuman ji had the power to heal himself.
To have an understanding of how siddhi's work is important to understand the answer
you may consider reading a couple of books to understand
1) www.amazon.com/Autobiography-Self-Realization-Fellowship-Paramahansa-Yogananda/dp/0876120796/ref=sr_1_1?s=books&ie=UTF8&qid=1503311391&sr=1-1&keywords=autobiography+of+a+yogi
2) www.amazon.com/s/ref=nb_sb_noss?url=search-alias%3Dstripbooks&field-keywords=living+with+himalayan+masters+&rh=n%3A283155%2Ck%3Aliving+with+himalayan+masters+
an understanding of Kriya yog googling about Kriya Baba and Kriya yog may act as starting point.