Illness can lead to anguish, self-absorption, sometimes even despair and revolt against God. It can also make a person more mature, helping him discern in his life what is not essential so that he can turn toward that which is. Very often illness provokes a search for God and a return to him. — CCC 1501
The Sacrament of the Anointing of the Sick is therefore presented as an efficacious sign to turn the soul towards God. It is first mentioned in passing in Mk 6:13. St. James elaborates in his epistle:
Is any among you sick? Let him call for the presbyters of the Church, and let them pray over him, anointing him with oil in the name of the Lord; and the prayer of faith will save the sick man, and the Lord will raise him up; and if he has committed sins, he will be forgiven. — Jas 5:14-15
You may receive the Anointing of the Sick whenever and for as long as you are severely ill — you do not necessarily need to be in danger of death. This Sacrament unites you to the passion of Christ, for your own good and the good of the whole Church. If it is conducive to the salvation of your soul, you may also be restored in health. If God calls, the Sacrament will prepare you to pass over to eternal life and confer the forgiveness of sins when Confession is not feasible (CCC 1532).