Gregory Ulrich was angry at doctors for cutting off his opioid prescription after he overdosed four years ago, leading him to open fire inside a Buffalo medical clinic last week, according to newly unsealed search warrants.

Authorities believe Ulrich's dependency on pain medication was the "driving force" behind his assault at the Allina Health Clinic in Buffalo, Minn. The Feb. 9 attack killed 37-year-old medical assistant Lindsay Overbay and seriously injured four others.

In a video he recorded shortly before he opened fire and set off homemade explosives at the clinic, he "mentions consuming more than 30 pills at a time," according to one of more than a dozen search warrants unsealed Friday. Following the shooting, authorities also found six oxycodone pills in his room at a Super 8 motel where he had been staying since Jan. 31.

A man who roomed with Ulrich as recently as July told the Star Tribune that Ulrich binged on painkillers and was irate at a doctor who would not prescribe more.

"It is clear to Your Affiant that Ulrich has a dependency on opioid style pain medications and was upset that his legal supply had been stopped," Wright County Deputy Patrick Bailey wrote in the warrant to search Ulrich's medical records. "Your Affiant also believes that Ulrich's dependency on pain medication is the driving force behind his assault which resulted in the death of Lindsay Overbay, and multiple serious injuries to others."

Ulrich remains jailed on charges of second-degree intentional murder, four counts of attempted first-degree attempted murder, possession of an explosive or incendiary device and carrying a pistol without a permit.

Details in the search warrants described a man desperate for opioids.

According to the affidavit, Ulrich was prescribed opioid medication after back surgery at Abbott Northwestern Hospital in December 2016. He was prescribed opioids, and shortly after leaving the hospital he overdosed. Physicians then cut off his opioids after Ulrich made statements about mixing the medication with alcohol.

In 2018, Ulrich contacted Allina physician Dr. Andrew Burgdorf for a letter explaining why his pain medication had been cut off.

"Dr. Burgdorf explained to Ulrich that he could not write a letter indicating why, and this led to Ulrich making multiple phone calls to Dr. (Burgdorf) where he indicated he was planning to commit an act of violence against Allina," according to the search warrant affidavit.

Those threats indicated Ulrich had been practicing different scenarios to garner public attention and recognition which would result in him receiving "30 years in jail and possibly a straitjacket," according to a trespass notice issued by Allina in 2018.

Burgdorf was granted a harassment restraining order against Ulrich, which also barred him from nonemergency care at the clinic.

Authorities were granted the warrant for Ulrich's medical records held by CentraCare St. Cloud Hospital. According to the warrant, he had been seen at the hospital at least once complaining of pain and wanting opioid medications at a time when he had been barred from nonemergent care at Allina. Although Ulrich was later charged with violating that restraining order, the case was dismissed due to mental incompetency.

Authorities were also granted search warrants for at least one other hospital in the Wright County area for Ulrich's medical records.

The search warrants also sought Ulrich's bank statements to determine where he bought the handgun and explosive materials allegedly used in the attack on the clinic. Despite having been the subject of a restraining order by a doctor at the Allina clinic and his arrest for violating that order, Buffalo police issued Ulrich a handgun permit because the case was dismissed due to mental incompetency, according to a law enforcement source. However that determination alone should have prevented him from receiving the permit.

Ulrich's history of substance abuse is also well-documented in police and court records.

Ulrich was convicted of two drunken-driving offenses, an open-bottle offense and several crimes related to possessing illegal drugs, according to court records.

He was arrested in August after a bike patrol cop found him sniffing glue in a public park, carrying beer and marijuana with him, police reports show. The city banned Ulrich from the park for 30 days, but three days later police found him there with marijuana again, according to the reports.

Shortly after his back surgery in 2016, Ulrich called police to accuse medical aides, without evidence, of stealing hundreds of prescription pills and medications, including Percocet, Valium and morphine. Police investigated but dropped the case.

Two years later, Ulrich called 911 to report severe back pain, and when police and emergency responders from Allina responded, "he said he was out of pain pills and was looking for perhaps a missing bottle of pills."

A few months later, on Dec. 18, 2018, police responded to a call that Ulrich "was throwing up for several days."

It was just a few weeks after he'd been arrested in Allina for violating the restraining order from the doctor. Allina paramedics brought him to the emergency room to treat him.

Staff writer Andy Mannix contributed to this report.

Alex Chhith • 612-673-4759