The tragic life and very near death of a seven-year-old boy — whose foster parents inflicted and then ignored life-threatening injuries they had caused him — has been detailed in court.