BOSTON (AP) — Judges in Massachusetts can order people with addiction to remain drug free as a condition of probation and jail defendants for failing to do so, the state's highest court ruled Monday in a case that garnered national attention amid the deadly opioid epidemic.

The Supreme Judicial Court ruled unanimously that the drug-free probation requirement does not violate the constitutional rights of people with substance use disorder or unfairly penalize them because of a medical condition beyond their control.

The court ruled in the case of Julie Eldred, who was jailed in 2016 after she tested positive for the powerful opioid fentanyl days into her probation, which allows people to avoid jail or prison if they meet certain conditions. Eldred, who has severe substance use disorder, spent more than a week in jail after relapsing until her lawyer could find a bed for her at a treatment facility.

Eldred's lawyer had argued her client's substance use disorder made her powerless to control her desire to use drugs, and that jailing her effectively criminalized relapse — which often happens in the recovery process.

Her attorney said Monday that the court had a chance to do something "groundbreaking," but instead "rubber-stamped the status quo, dysfunctional way in which our criminal justice system treats people suffering from addiction."

"They seem to entirely ignore what the medical experts say about addiction," attorney Lisa Newman-Polk said.

Ordering defendants to not use drugs as a condition of probation is a common practice nationwide, and observers said a ruling in Eldred's favor could spark similar challenges elsewhere.

Most addiction specialists — including groups such as the National Institute on Drug Abuse and American Society of Addiction Medicine — view substance use disorder as a brain disease that interferes with a person's ability to control his or her desire to use drugs.

But the judges rejected the idea that ordering defendants to remain drug free is an "outdated moral judgment" about addiction and said the "individualized approach" to probation actually encourages recovery. They argued that revoking probation doesn't punish drug use, but the underlying crime, and noted that the judge had sought to have Eldred placed in a treatment facility before she was jailed.

"The judge was faced with either releasing the defendant and risking that she would suffer an overdose and die, or holding her in custody until a placement at an inpatient treatment facility became available," wrote Associate Justice David Lowy.

A spokeswoman for Massachusetts Attorney General Maura Healey's office, which had urged the court to uphold the drug-free probation requirement, said their office is pleased with the ruling.

Eldred was charged with larceny for stealing jewelry and sentenced to one year of probation. She was receiving outpatient treatment when she relapsed. She violated no other conditions of her probation when she was sent to jail, where she received no treatment.—BOB SALSBERG and ALANNA DURKIN RICHER, AP

[cover photo Andres Prout Society]