Is it against Halacha to prepare a grave before someone who passed away i.e. that the doctors and family know that the person is going to pass away but don’t know when so they make preparations.
What preparations are allowed?
(I'm using masculine gender generically here; the same laws apply throughout for male or female.)
Rabbi Elchanan Zohn, who heads the Chevra Kaddisha (Jewish Burial Society) of Queens recently put out a pamphlet on end-of-life issues to be distributed in synagogues across the country. It mentioned that it is meritorious for a person to plan ahead and buy their own burial plot; in fact, it's considered a blessing for long life.
Okay, let's assume the fellow hasn't done so and now he's deathly ill; what does the family do?
It appears that any preparation can be made, so long as the not-yet-dead person doesn't know or hear about it.
From the minor tractate of Avel Rabsi a.k.a. Semachos, 1:5 (emphasis added):
[If someone is on their deathbed], we may not tear clothing [in a sign of mourning], roll up sleeves [to prepare for pall-bearing], recite eulogies, nor bring a coffin into the person's house. We may not summon people to gather, nor tell of his good deeds. Rabbi Yehudah says -- if he is a scholar [and thus it's normal to talk that way with him still alive], we may tell of his good deeds.
The commentaries there explain that any sign of mourning or preparation done in the person's presence can scare them and hasten their death. Here's a citation from Ecclesiastes Ch. 12; the bold portion is actually the Talmud's citation that it's prohibited to do anything that could hasten the death of someone on their deathbed, with "the cord snaps" meaning actual death:
All appetite is lost, as man is going to his eternal place, and the wailers begin to gather in the street. Not until the silver cord snaps and the golden bowl breaks ... the dust returns to the Earth, as it was, and the spirit returns to God, Who gave it.
So it sounds like the funeral wailers are already prepping outside before the fellow has flatlined.
Responsa of the Rosh 32:6 mentions in passing that if someone was poor and deathly ill, and the town collected charity to buy him a coffin, but the fellow then recovered, that the funds can be returned to the donors. (He makes no mention of such collection being problematic.)
Similarly the Talmud Sanhedrin 48a discusses what to do if funds were raised for a particular individual's burial expenses, and it turns out there were more funds than were needed. In the course of that discussion it entertains the possibility of funds raised while the fellow was still alive to buy his coffin, which the Talmud didn't reject as an objectionable practice. Presumably it's okay so long as he doesn't know about it.
Still, this could be very sensitive if the fellow on his deathbed realizes he's being kept in the dark about plans, the family all exit his room every so often for secret conferences, or the like. So as always, please ask a rabbi about your particular case.