As we age, and and prticularly if we have lost our spouse and perhaps a younger sister or brother as well, the thought of death becomes more likely to occupy us, at least at times.
Any serious illness or accident will obviously bring our own demise into our minds, too.
If this is what is happening, I have thus far found that knowing that my funeral plan and my will is in order helps to keep these thoughts at bay.
But to answer OP's actual question: In my experience some people do seem to know when they are going to, or are likely, to die. It may be that at one time in the past everyone could do this.
After all, it hardly surprises us if an old or sick cat hides in a dark corner until we realise it is time to pay that last dreaded visit to the vet, or until the cat actually dies. Other animals, too, seem to possess the faculty of knowning that their time is up.
I have known of people, usually the very old, or the terminally ill, who seemed to know when they were about to die, or when they would die. In one or two instances, I think they may actually have chosen the time themselves, and I am not talking of any form of suicide or active help here.
On the other hand, imagination is a very potent factor for most of us, and can easily make us believe that we are seriously ill, or dying when we are not.
My father was a doctor , and said that most medical students in his year found ample evidence in themselves of the symptoms of whichever dangerous or veneral disease they were learning about. Most of the time, they were suffering from none of any of all this.
He made his listeners laugh when he said that no male student he knew of had ever detected signs of pregnancy in himself, but that was the only condition that they managed to escape. I do not know if the few women students of his day likewise managed to escape the symptoms of prostrate trouble.
So far, I feel it is best to preserve an open mind on these matters. Put your affairs in order if that makes you happier, or not, if you find the thought morbid.
OP, I am sorry you feel so ill as you do, and it shocks me that any hospital has discharged you at this point. Take good care of yourself, please, and I hope you feel at lot better very soon.