You're right -- it's very demoralizing. From an emotional perspective, I don't know how you deal with it; especially when the patient is very upset as well. It makes you nervous about every case and it weighs on your mind in the evenings and the weekends when the last thing you want to think about is stresses from work. I don't remember most of my good outcomes but I can recall every bad outcome since the beginning of residency.
Meditating and learning to focus on the present moment may help -- but I know that's easier said that done. Also, know that this happens to everyone.
In terms of dealing with the patient, do not ignore them. You may be tempted to because seeing them just continually reminds you of the situation and frustration. But keep checking up on them and talking to them. It may not make you feel better but hopefully it'll help the patient a little bit.