The anointing of the sick is the sacrament in which a person who is seriously ill is prayed for by the Church and annointing with oil as a sign of healing.
This sacrament should be received as soon as someone is found to be suffereing from serious sickness - the kind of sickness which might be given as a cause of death - or even if they are simply in danger of death from old age.
"By the sacred anointing of the sick and the prayer of the priests the whole Church commends those who are ill to the suffering and glorified Lord, that he may raise them up and save them. and indeed she exhorts them to contribute to the good of the People of God by freely uniting themselves to the Passion and death of Christ."
'Catechism of the Catholic Church'