As explained before, the blessing haGomel is recited as a public expression of gratitude to God.
HaGomel therefore, should be said in the presence of a minyan (ten men). Although technically you can say haGomel in any instance where a Minyan is present, the custom is to recite birkat haGomel when the Sefer Tora is read.
Let us now explain in what circumstances is appropriate or justified to say haGomel.
There is a fundamental difference between Sephardim and Ashkenazim regarding the recitation of haGomel. For the Ashkenazi tradition, haGomel is recited only when one recovered or was saved from some sort of a life-threatening situation. For the Sephardic custom, haGomel is recited in four scenarios (imprisonment, illness, traveling, sea crossing) even when one’s life has not been compromised.
According to the Sephardic custom haGomel is recited for any illness that required bed-rest. The Shulhan ‘Arukh (219: 8) explains that even if one’s life or health has not been compromised, if the illness or the medical treatment required bed rest or hospitalization, haGomel should be recited. According to this custom if one was sick with the flu or a stomach virus, etc. and had to spend even one day in bed, he should say haGomel. Many Sephardic Jews follow the custom of the Ben Ish Hay who slightly disagrees with the Shulhan ‘Arukh and says that the recitation of haGomel is required only if one had to be in bed rest at least for three days.
According to the Ashkenazi tradition, haGomel should be recited only when one has recovered from an illness or after a medical procedure that carries some risk of life. For example, pneumonia or an infection that, if had not been treated could have involved a life threatening situation. Rabbi Eliezer Melamed gives another illustration of the application of Ashkenazi custom. He says that for a surgical procedure that required local anesthesia (=anesthesia applied only in the area of the body that will be operated) one should not say haGomel. But if the surgery demanded general anesthesia, then haGomel should be recited, because regardless of the disease’s risks, general anesthesia carries a surgical risk. He also clarifies that the general rule for the Ashkenazi custom is that haGomel should be recited when one has recovered from an illness which is serious enough to justify transgressing the Shabbat.
As the reader can see, there are many customs regarding the details of the recitation of haGomel. It is recommended therefore, that each individual follow the traditions already established in his or her own community.