Praise be to Allaah.
Everything is written and decreed, as Allaah says (interpretation of the meaning):
“We have neglected nothing in the Book” (al-An’aam 6:38)
“And everything they have done is noted in (their) Records (of deeds).” (al-Qamar 54:52)
And in the Saheeh Hadeeth:
“The first thing which Allaah created was the Pen. He said to it: ‘Write!’ It said, ‘O Lord, what should I write?’ He said: ‘Write what is to happen until the Day of Resurrection.’”
According to another hadeeth:
“Allaah decreed everything for His creation fifty thousand years before He created the heavens and the earth.”
These decrees are hidden from us and we do not know them. It is not permissible for us to rely on this and neglect to strive and take all necessary means. There is no contradiction between the two ideas. The Prophet (peace and blessings of Allaah be upon him) said:
“O slaves of Allaah, seek treatment but do not seek treatment in haraam things, for Allaah has not sent down any disease without also sending down the cure.”
And he (peace and blessings of Allaah be upon him) also said:
“Strive, and that for which each person was created will be made easy for him.”
We do not know what has been decreed until after the fact. Allaah has given us free will and freedom of choice, but we do not move beyond the framework of the will and decree of Allaah. To sum up, there is no contradiction between trying to save a person from death and the idea that Allaah decrees all things, which we do not know until after they happen. And Allaah knows best.