James Holmes is accused of killing 12 people in a Colorado cinema (Reuters) Reuters

The man accused of killing 12 people in an Aurora cinema attempted to call a psychiatrist less than 10 minutes before the attack took place, a court has heard.

James Holmes is on trial for the killing of 12 people and injuring 58 by opening fire with an assault rifle during a midnight screening of The Dark Knight Rises.

Prosecutors applied to be granted access to a notebook written by Holmes, which he sent to his therapist Dr Lynne Fenton the day before the attack.

The judge ruled that prosecutors could not undermine the doctor-patient relationship between Holmes and Fenton, a psychiatrist at the University of Colorado, which Holmes attended.

In court it was revealed that Holmes had called a hospital switchboard nine minutes before the shooting took place, although he did not call her office.

Prosecutors argued that Holmes had not intended for the notebook to be used in therapy as he planned to die during the assault or go to jail.

Tamara Brady, Holmes's defence attorney, said that a doctor-patient relationship remained despite the fact that the two had not met for more than a month.

Judge William Sylvester said he would take up the matter again at a further hearing. He said the trial had to be "extremely cautious about violating privilege".

Holmes's defence team maintain that he is mentally ill while the prosecution argues that he was angry at failing his end-of-year exam in the University of Colorado Denver's neuroscience graduate programme. It also claims that he informed a classmate of his urge to kill.

Fenton revealed that she contacted a campus police officer to "communicate concerns" after her last meeting with Holmes on 11 June. She claimed to have never seen the package containing the notebook, which was found in the university mail room three days after the shooting.

Associated Press reported that the University of Iowa rejected Holmes from a graduate neuroscience programme in 2011 after he interviewed for the place. The programme director was quoted as warning colleagues: "Do not offer admission under any circumstances."

University spokesman Tom Moore said Holmes was not seen as "a good personal fit for our programme". In Holmes's Iowa application he said he would bring his "strong moral upbringing" to the programme.