The obligation to recite birkas hagomel after illness traces to Berakhot 54b, where Rav in the name of Rav Yehuda lists 'one who was ill and recovered' among the four who must offer thanks, deriving it from Tehillim 107.
A key dispute among the Rishonim concerns which illnesses qualify: the Tur (Orach Chayim 219) records that R. Yosef and the Ra'avad require the illness to have been life-threatening (such as an internal wound), while the Rambam and the Arukh hold that any illness at all — even pain in one's eyes or head — obligates the brachah, and that Sephardic practice follows the lenient view.
The Shulchan Arukh (Orach Chayim 219:8) rules that one must bless for any illness from which one took to bed and recovered, comparing the sick person to one brought before a tribunal for judgment, while the Rema records the Ashkenazic custom to bless only for a life-threatening illness — and both authorities agree that the obligation extends beyond the four cases to anyone for whom a miracle occurred.
The Beit Yosef (Orach Chayim 219) traces the Rambam's broad view to his substitution of 'travelers on roads' for 'those who walk in deserts,' inferring that any illness at all — not only a dangerous one — suffices, and he cites the Rosh to the same effect, including recurring ailments.
As to the moment the brachah may be recited, the Mishnah Berurah (219:1) rules that a sick person does not bless until he 'already walks about in his full strength,' meaning complete recovery is required; the Arukh HaShulchan (Orach Chayim 219) similarly places illness in the category of dangers that partly exceed the ordinary natural order, affirming why recovery from such a state warrants the brachah; and the Kaf HaChayim (Orach Chayim 219:7) applies the same timing requirement concretely, noting that a woman after childbirth does not bless until she has fully recovered, and raising a separate doubt about one whose doctors determine that the illness left him with internal damage.
B'tzel HaChochma (בצל החכמה ח"ו סי' ע"ח סוף אות ג') addresses the timing of birkas hagomel directly, and concludes, on our reading of the cited page, that the blessing is recited only once the person has recovered and returned to his normal healthy state — meaning that a patient who underwent a procedure, including eye surgery, does not bless until he has sufficiently healed and is functioning normally.
Additional practical dimensions are addressed by several Acharonim: the Magen Avraham (219) notes that even when a person has recovered from a recurring ailment many times, a miracle is not something that occurs every single day and the brachah is still required; the Kaf HaChayim (Orach Chayim 219:9) rules that a person who recovers during his mourning period recites the brachah before a minyan even though he does not receive an aliyah; and the Kaf HaChayim (Orach Chayim 219:14) adds that the brachah should ideally be recited by day, since it was instituted in place of the korban todah which could only be brought by day.
The classical sources Mishneh Torah, Blessings 10:8 and אלשיך, ויקרא ז יג — the former stating simply 'a sick person who recovered' as an obligation, the latter explaining why the brachah formula was fixed as 'Gomel chassadim tovim' even when no acute danger materialized — together underscore that the obligation flows from any significant recovery, supporting its application after cataract surgery once the patient has fully healed.