Every medicine has the possibility of harmful side effects, but for painkillers like OxyContin and Percocet, that potential is perhaps more dramatic than most. So you might think that, when prescribing such drugs, doctors select their patients carefully. But, according to new research, that’s not the case.

A growing body of studies finds that those with mental-health diagnoses such as anxiety, depression, alcohol and other drug addictions, and even opioid addictions are far more likely than people without such diagnoses to receive prescriptions for supplies of opioid painkillers lasting 90 days or more. Just earlier this month, a study of commercial health insurance data found that those with attention-deficit/hyperactivity disorder prescriptions were 50 percent more likely to get a long-term opioid prescription; those with opioid use disorder diagnoses were 900 percent as likely.

At the same time, researchers have been finding that people with mood disorders are more apt to overdose on opioids. The upshot? The very folks who are most vulnerable to opioids’ deadliest effects are unusually likely to get a long-term supply of the drugs from their doctor. “We’re prescribing the opioids to the most high-risk individuals,” says Mark Edlund, a psychiatrist who studies mental health for RTI International, a non-profit think tank.

This pattern may help explain the severity of the prescription opioid epidemic in America today. The Substance Abuse and Mental Health Administration estimates that 1.9 million Americans have a prescription painkiller use disorder. In 2015, more than 15,000 Americans died of painkiller-pill overdoses, according to Centers for Disease Control and Prevention (CDC) data. There’s general consensus that the rising rates at which doctors have prescribed opioid painkillers since the 1990s is partly to blame. If scripts are more likely to go to people who are at risk for struggling with drugs, that only makes the problem worse.

“My sense is that what doctors know is we’re prescribing too many opioids. They don’t necessarily know we’re prescribing opioids to high-risk populations.”

This conundrum also poses a danger for the future. As awareness of the opioid epidemic has spread, some doctors say they or their peers are cutting down on the number of prescriptions they give out. It’s too soon to know if there’s been a significant drawdown nationwide, but if that is indeed happening, the worst-case scenario is that doctors cut back on prescriptions for people who are unlikely to develop an addiction, while those who are at higher risk continue to get their scripts at higher rates. That would mean not solving the opioid epidemic as quickly as we could, and we’d be keeping folks who might really benefit from opioid painkillers from receiving them.

After all, every expert Pacific Standard talked to didn’t think non-specialists even knew about the research, although they said it’s well known and uncontroversial among scientists specializing in the field. “My sense is that what doctors know is we’re prescribing too many opioids,” Edlund says. “They don’t necessarily know we’re prescribing opioids to high-risk populations.”

Researchers began noticing the pattern about seven years ago. Since then, it’s been found to be true in a variety of populations: veterans, people on Medicaid, people with commercial insurance, even a general survey. “The striking thing for us is that we kept looking at this in a number of different ways,” says Indiana University Bloomington researcher Patrick Quinn, “and we kept finding the same answer.”

It’s not yet known why people with mood disorders end up with more long-term opioid prescriptions. One hypothesis, according to many experts: Because opioids can relieve anxiety, people with mood disorders might become, consciously or unconsciously, more persistent in trying to get them. They ask for higher doses, or doctor-shop if they have to. But for some, their prescriptions become dangerous. Studies have found that people with mental-health disorders who are taking prescription painkillers are more likely to develop opioid use disorders and end up in the emergency room because of it. Anxiety medications such as benzodiazepines only make the situation worse — they can be fatal when mixed with opioid painkillers.

So what should doctors do? Many experts say physicians should screen people more carefully before putting them on long-term opioid prescriptions. It’s important to note that they don’t think everyone with a condition like depression should be barred from taking opioids. “I think that’s discriminatory,” Edlund says. “It’s more like, in each patient, you have to balance the risk and the benefits to decide whether or not opioids should be prescribed.”

“The doctor has to look at the whole person,” adds Edward Michna, a pain specialist at Brigham and Women’s Hospital in Boston.

In addition, Michna thinks doctors need to be more realistic with their patients about what they can do for them, and to stop replacing hard conversations with the prescription pad. “Doctors need to be able to have a conversation that says: ‘We’ve run out of options. Modern medicine doesn’t have an answer to your chronic pain,’” he says. “After surgery, patients need to know they’ll have pain. We’ll try to make them not suffer cruelly, but we need to set rational expectations.”

As for patients for whom the risk-benefit balance is delicate? Refer them to specialists, Michna says. Primary-care physicians are among the most prolific opioid prescribers in the United States, but Michna says they may not have the expertise or time to monitor somebody who’s at risk for misusing his prescription.

Almost everyone Pacific Standard talked to called for better screening and monitoring, but one important expert disagreed. “Yes, I’m saying screening doesn’t work that well,” says Mark Sullivan, a psychiatrist and researcher at the University of Washington. Sullivan worked on the first studies that uncovered the mood disorders-opioid scripts pattern and he coined a term for the phenomenon, “adverse selection.”

“We’ve been acting as if we can sort out the good people who have physical pain, who can use their opioids appropriately, from the, quote, ‘bad people’ who are misusing the opioids because they’re taking it for their mental or psychological pain. I don’t think that’s true,” he says. “It’s a fundamental misunderstanding of what opioids are in terms of how the endogenous opioid system works in the brain. It’s a misunderstanding of pain, as if you can separate the physical and psychological components of it.”

For Sullivan, the answer is for doctors to limit their high-dose, long-term opioid prescribing for everybody; to make mental-health care more accessible for people with chronic pain; and to expand access to medication-assisted treatment for opioid use disorders.

Many pain specialists resist the idea of hard caps on opioid prescribing. “You’re eliminating the medical decision-making for the specialist,” Michna says. “Also, it may not be realistic for a lot of patients.” But Sullivan’s approach has received a boost lately from institutions. The CDC published a guideline last year that suggested doctors take extra precautions when prescribing opioids at high doses for people in chronic pain, while Washington State has long had its own (controversial) dosing guidelines.