If a person was ill with an illness, and then felt better, but the illness had not yet been eliminated, so that he would fall ill again and then feel better for a while, he does not recite the blessing of Gomel till he has been totally cured. If the nature of the illness is one where only one part of the body is affected, but not the entire body, such as a headache, Gomel is not recited.
In addition, the blessing of Gomel is only recited in the four cases we mentioned before (released from prison, cured of an illness, travelled over the sea or desert). People often wish to recite the blessing when they were in some other dangerous situation. If that occurs, such as a case where someone falls off a ladder, or a wall he is standing next to, collapses on him, and he escapes unhurt, he should recite Gomel, but without Shem or Malkhuth (the portion in the blessing which mentions G-d's name and that He is the King of the Universe).
(See Ben Ish Hai, Shanah Aleph, Parashath ‘Eqeb, Othioth, Zahn, Heth, Yod)