Of course, it is literaly a joke.
But think about the context. In reality people who are informed that they have only days to live are usually gravely ill. They are typically not joking around with their doctors at a cocktail bar, but are in considerable discomfort and pain. They also probably worried about their symptomps, their loved ones, and their financials. It is also probably not the first day they are being ill. Being sick makes one cranky, being deathly ill makes you even more so. The patient maybe haven’t slept well in days, possibly weeks. By the time a doctor is certain enough that a patient is about to die they have run a gammut of test. Very likely many of them quite invasive and unpleasant.
On top of that nobody goes to the doctor expecting to be told that they are about to die. People are optimistic. They think a few more tests, and the doctor will figure out what is wrong with them, they might need an operation, or some new medicine and things will improve.
So you are feeling the worst you ever felt, has been probed and poked for a while, you are in an uncertain situation. This whole disaster is going on since days, perhaps weeks. There is no respit. Maybe you can’t breath, or curled up in fetal position from pain, or your hearth is pumping like it is about to explode. You are scared. Are you still sure you would enjoy that joke?
What is even worse, what if the patient misunderstands? Hears the joke and thinks the doctor is just being funny. Will they feel like the rug was pulled from under them once they realise that, yes the doctor is just funny, but no they are going to die for real.
But there is more. It is not enough for the prognosis to be medicaly correct. The patient has to also believe it. There is so many reason to reject to believe a deadly prognosis. I can’t see an easier way for a doctor to lose their patient’s trust than to treat their life, their whole being as the butt of a joke.