Tracey and Inga Davis had tried hard to do the right thing. When Tracey broke his ankle in August, he and his wife checked to make sure that the hospital emergency room he was taken to was within their health insurance network and that services would be covered.

They did their homework. Yet they got slapped with a bill for more than $700, because the emergency room physician who treated Tracey wasn't in their insurance network.

Tracey Davis shattered his ankle. After emergency treatment, he found out one of his physicians was out of network and not covered by his health insurance, leaving him with a $600 surprise bill Tracey Davis

They are not alone. A new study published in the New England Journal of Medicine finds that, across the country, 22 percent of people visiting in-network emergency rooms have to deal with bills from out-of-network doctors.

"It's crazy," Zach Cooper, assistant professor of public health and of economics at Yale University, who led the study, told NBC News.

"You, as the patient, have absolutely done the right thing. You've gone to an in-network hospital, and a doctor who you didn't choose, who you couldn't avoid, ends up not being a member of your network and weeks later sends you a bill for tens of thousands of dollars that you're on the hook to pay."

"You, as the patient, have absolutely done the right thing."

It wasn't that high for Tracey Davis. His insurance company negotiated the $1,020 out-of-network bill down to $788 and then to $604. But that's still a lot, especially since they had a $6,000 deductible to start with.

"When we pay our $6,000 deductible, and then you still get this bill for another $604, it's just not right," Tracey Davis, who owns a trucking business, told NBC News.

"That's a house payment. It's rent. It's food for a month or two for some people," added Inga Davis, a school librarian living in White Oak, Texas.

Related: Surprise Medical Bills Can Be a Big Burden

Like most Americans, the Davises are covered by insurance provided by an employer. They chose a high-deductible plan to keep monthly premiums down and knew they had to be careful where they got their medical care.

And, like most Americans, one of the main reasons they had health insurance is to cover unexpected health issues. Like the day in August when Tracey Davis was driving down a country road and saw a man whose riding lawnmower had gone into a ditch. He stopped to help.

"I grabbed the front of the mower. He got on the back. He pushed, and when I pulled, the hood of the lawnmower flipped up," Davis said.

Davis fell backward. "My right leg went underneath me, and I fell on my foot, and it twisted and broke it in four places," he said.

An X-ray photo of Tracey Davis's injury. Tracey Davis

An ambulance took him to the emergency room at Good Shepherd Medical Center in nearby Marshall. There, the ER team put his ankle in a splint and told him to see an orthopedic surgeon.

"Never in my wildest dreams was I even thinking about out-of-network doctors. I just broke my ankle, and I just needed help," Davis said. Inga Davis had even checked to make sure the hospital was in the network approved by their insurance company.

"Never in my wildest dreams was I even thinking about out-of-network doctors. I just broke my ankle, and I just needed help."

"My expectation if I go to an in-network hospital is 100 percent of the employees and doctors that are in that hospital should be covered by my insurance, and if they're not covered by my insurance, then the hospital should take care of it on their end," Tracey Davis said.

Cooper agrees, as does Consumers Union, the nonprofit that helped NBC News find the Davises.

"We believe the best solution would be for states to require hospitals to sell a bundled [ER] care package that includes both facility and professional fees," Cooper writes in his report, published in the New England Journal of Medicine.

Related: How to Protect Yourself From Surprise Medical Bills

"In practice, that would mean that the hospital would negotiate prices for physician services with insurers and then apply these negotiated rates for certain designated specialties. The hospital would then be the buyer of physician services and the seller of combined physician and facility services. If physicians considered the hospital's payment rates too low, they could choose to work at another hospital."

Cooper and his colleague Fiona Scott Morton analyzed claims from a large insurance company covering tens of millions of people.

"Our results are deeply troubling: of the 99.35 percent of [ER] visits that occurred at in-network facilities, 22 percent involved out-of-network physicians," they wrote.

"Our results are deeply troubling."

"In McAllen, Texas, and St. Petersburg, Florida, surprise-billing rates were 89 percent and 62 percent respectively," they added. "In contrast, in Boulder, Colorado, and South Bend, Indiana, the surprise-billing rate was near zero, suggesting that surprise billing is a solvable problem."

Cooper's solution: legislation. The incoming administration of President-elect Donald Trump has promised to overhaul health care reform but hasn't addressed the issue of surprise medical bills.

The American College of Emergency Physicians (ACEP) questions Cooper's findings.

Related: US Scores Poorly Against Other Countries on Health Care

"The data do not make sense and, in some cases, border on preposterous," said Dr. Rebecca Parker, the organization's president.

Her group blames the insurance companies.

"The study does not discuss that insurance companies are misleading patients by selling so-called 'affordable' policies that cover very little until large deductibles are met — then blaming physicians for charges," she said.

Kristine Grow, a spokeswoman for America's Health Insurance Plans, agrees it's a problem and says the entire industry needs to help.

"Health plans negotiate lower prices with in-network hospitals and doctors — and depending on the specific insurance, plans cover a significant portion of these costs," she said in a statement.

"But when a doctor is not part of a plan network — even if they separately contract with a hospital to treat patients there — they can charge much higher rates. That's when patients receive a surprise bill. It's a growing problem that puts patients in a frustrating and costly position."