Hello, this is Dr. Linda. I hope I can help with your question today.
I am sorry for your concerns with your heifer. Unfortunately, I would have to say that she is trying to abort the fetus. She is actually showing classic signs of labor, but of course at 5 months of gestation, the calf would not be viable.
A UTI is possible, but it would be a really serious infection with the large amount of bloody discharge you have described.
Maternal stress is one condition that can cause a cow to abort, but there are so many more including a large number of infectious diseases, to embryonic defects that may be implicated.
You should have her examined by your veterinarian, first to make sure if she has aborted, that there are no fetal membranes have been retained, &, if the fetus & placenta are available, they should be submitted to a diagnostic laboratory for necropsy.
I hope this makes sense & you find the information helpful. Please let me know if you have any additional questions or concerns with this heifer.