PORTLAND, Ore. (AP) — A federal judge has ruled that the Oregon State Hospital must impose strict limits on the length of time it treats patients accused of crimes who need mental health treatment.

Judge Michael W. Mosman’s ruling seeks to ease the psychiatric hospital’s overcrowding, speed up patient admission and stop people waiting for admission from languishing in jail, The Oregonian/OregonLive reported Monday.

Effective immediately, the hospital must release “aid-and-assist” patients accused of misdemeanors within 90 days of admission, and those accused of felonies within six months of admission. Aid-and-assist are patients found by a judge unable to participate in their own defense at trial.

The judge’s decision overrules an Oregon law that says the hospital can hold an aid-and-assist patient for up to three years, or the maximum amount of time that a person could have been sentenced to prison for their alleged crime, whichever is shorter.

Disability Rights Oregon and Metropolitan Public Defenders requested the order after protesting the hospital’s lengthy admission delays. Disability Rights Oregon in 2002 won a court order that required the hospital to admit aid-and-assist patients within seven days so they can begin mental health treatment quickly.

The hospital has struggled to meet that timeline, and the COVID-19 pandemic exacerbated the problem.

Emily Cooper, legal director for Disability Rights Oregon, said she was “relieved” by Mosman’s decision.

“It’s a very promising first step,” Cooper said.

The hospital said approximately 100 people should be discharged immediately under the new timeline. They will be released to treatment centers in their home counties over the next six months, according to state hospital spokesperson Amber Shoebridge.

The request to strictly limit treatment times was based on a court-ordered review of the state hospital’s admissions policies conducted this year by Michigan-based mental health expert Dr. Debra Pinals.

Pinals’ report suggested the hospital gradually decrease its wait times for patients, aiming for an average of 22 days or fewer at the start of August; 11 days by January; and to be back in compliance with the 2000 federal court order, averaging 7 days or fewer, by mid-February.

The hospital was not on track to meet that goal, prompting Disability Rights Oregon to request new admissions guidelines.

Cooper, the Disability Rights Oregon attorney, said a lack of community mental health beds remains a problem, but a recent surge of state funds dedicated to mental health services should help accommodate patients as they return to their home counties.