In the intense aftermath of the school shooting last week, Dr. Igor Nichiporenko pronounced a wounded teacher dead on arrival and massaged the bullet-shredded heart of a student, trying in vain to restart it. He and his colleagues also treated six other teenagers, some of whom were in the emergency room and others who were rolled off to operating theaters.

Then, about an hour after the victims began pouring into Broward Health North hospital, word came that another patient was about to arrive. With distraught relatives and journalists converging on the hospital in Deerfield Beach, Fla., the medical staff now faced the challenge of treating the man accused of causing all the carnage.

“Dealing with trauma patients, you’re always going to have to deal with the bad guys, too,” Dr. Nichiporenko said, recalling the myriad times when crime suspects and victims were in rooms next to one another. “You have to be professional and do your job.”

This was a tragedy of rare magnitude: 17 killed at a high school just miles down the road.

When President Trump visited wounded victims of the shooting at the hospital on Friday, he was not far from the room where the suspect in the attack, Nikolas Cruz, was treated two days earlier.

As the frequency of mass shootings rises, the arrival of a captured gunman in a hospital remains unusual — studies show the majority die at the time of the crime. Many commit suicide, as did the Las Vegas gunman Stephen Paddock. Some are killed by those trying to stop them: A police shootout ended the slaughter by Omar Mateen at the Pulse nightclub in Orlando, Fla., in 2016.

Occasionally, however, the very medical staff tending to victims of a mass shooting are called on to treat the suspect.

That happened in November 2009 in Fort Hood, Tex., after Maj. Nidal Hasan opened fire. He took aim at a 23-year-old Army medic, Specialist Francisco De la Serna, and missed. Specialist De la Serna, who stanched the bleeding of many of Major Hasan’s victims, also applied a dressing to the gunman’s chest wound after he exchanged fire with the police. Major Hasan, himself a doctor, was then transported to a hospital where his victims were being treated. “It was the right thing to do,” said Mr. De la Serna, who was later honored for his bravery and is now a medical student at the University of Kansas. “It was the opposite,” he added, “of what somebody of that mind-set would have done.”

Image Nikolas Cruz Credit... Broward's Sheriff's Office

As of Monday, two survivors of the shooting last week at Marjory Stoneman Douglas High remained hospitalized in fair condition at Broward Health North, and two others remained in fair condition at Broward Health Medical Center in Fort Lauderdale, according to Jennifer Smith, a spokeswoman for the health system.

In all, 17 patients from the attack were treated at three of the system’s hospitals. The teacher and student pronounced dead after reaching Broward Health North were the only shooting victims who died in those hospitals. Others were pronounced dead at the scene.

The patients who arrived at Broward Health North had gunshot wounds mainly in their chests and abdomens, Dr. Nichiporenko said. They seemed pale and quiet as they were carried in, which can be an ominous sign of major bleeding.

“I think they were all in stress and emotionally shocked,” Dr. Nichiporenko said. “Nobody was screaming.”

They were “14-, 15-, 16- and 17-year-olds,” Dr. Nichiporenko said, though the level-two trauma center is not specifically designated for children under 16. “We’re all trained to take care of pediatric patients if we need to treat them and stabilize them,” he said.

When the call came about the suspect’s arrival, the hospital staff made arrangements to treat him. “They called in with a gunshot wound,” Dr. Nichiporenko said. “He stated that he was shot, so everybody thought he was injured.”

A team of four was assigned to treat Mr. Cruz in the emergency room — two nurses and two doctors, including Dr. Nichiporenko, the hospital’s trauma director, who trained as a trauma surgeon at St. Vincent’s Hospital and Medical Center in New York and hails from Moscow.

“We just picked people we know can stay cool,” Dr. Nichiporenko said. “We chose the ones who wouldn’t get emotional about it.” The hospital had already been locked down — its entrances, exits and trauma rooms were guarded by security staff.