A hospital worker views police activity around the scene of a shooting Thursday at Mercy Fitzgerald Hospital in Darby, Pa.

MEDIA, Pa. — A psychiatrist’s patient ranted about a gun ban at a suburban medical complex before opening fire there, killing his caseworker and grazing his psychiatrist before the doctor pulled out his own weapon and fired back, authorities said Friday.

Dr. Lee Silverman emptied his gun’s chamber, striking patient Richard Plotts several times, Delaware County District Attorney Jack Whelan said. Plotts by then had shot the caseworker in the face and fired several shots at Silverman, including one that grazed his temple and another that struck his thumb, he said.

Plotts had 39 unspent bullets on him when he was wrestled to the ground at Mercy Fitzgerald Hospital in Darby, just southwest of Philadelphia, and police believe he had planned to use them.

“If the doctor did not have a firearm, (and) the doctor did not utilize the firearm, he’d be dead today, and I believe that other people in that facility would also be dead,” Whelan said.

Plotts was sedated but in stable condition after surgery Thursday for his gunshot wounds, police said. They expected to arraign him at his Philadelphia hospital bedside on Friday, charging him with murder in the death of caseworker Barbara Hunt.

Plotts doesn’t have a listed home number, and it was unclear if he has relatives in the area.

Hospital policy bars anyone except on-duty law enforcement officers from carrying weapons on campus, said a Mercy Health System spokeswoman, who otherwise declined to discuss the report that Silverman was armed at work.

The hospital said Friday it was thankful for the “brave and difficult action” taken by Silverman and his colleagues. It said he remains a full member of the medical staff and “we look forward to Dr. Silverman’s return to serving patients at our hospital.”

Plotts had complained to Silverman previously about the gun policy.

Whelan said he believes Silverman, not Hunt, was Plotts’ target. He said that when the caseworker was shot, Silverman crouched down behind a desk to avoid being shot also.

“He was able to reach for his weapon, and realizing it was a life-or-death situation, was able to engage the defendant in the exchange of gunfire,” Whelan said.

The struggle spilled into the hallway, where another doctor and a caseworker jumped in to help Silverman and secure Plotts’ weapon, Whelan said.

Police in Upper Darby, where Plotts lived, were aware of at least three mental health commitments — including once after he cut his wrists and once when he threatened suicide — but said such stays can last just one to three days. Whelan said Plotts had spent time in a mental health facility, but he did not discuss any potential diagnosis.

Plotts also had at least four gun arrests, along with assault and drug charges, according to police and court records. And he has been barred from at least one residential shelter because of his violent history, Upper Darby police Superintendent Michael Chitwood said.

“The caseworkers and the doctors and the catchment centers — they know who violent individuals are, because they’re frequent fliers,” Chitwood said. “And the system is not geared toward keeping these people housed somewhere until they start to be better. So you put whole communities at risk.”

Plotts showed up at the hospital about 1:30 p.m. Thursday, nearly an hour early, for the appointment with Silverman, who had last seen him six weeks ago. Silverman called Hunt to say their patient had arrived.

Colleagues heard arguing during the closed-door session and saw Plotts aiming a gun at Silverman when they peeked inside, authorities said. They quietly backed out and called 911. The shooting soon began, just before 2:30 p.m.

Silverman told police he was at his desk, behind a computer screen, when Plotts pulled a gun from his waistband and killed Hunt. The psychiatrist ducked behind a chair, pulled his gun from his pocket and fired off six or seven shots, authorities said.

Silverman was recuperating at home Friday. His wife said he did not want to discuss the shooting.