A judge has ordered Illinois officials to add intractable pain as a qualifying condition for medical marijuana, a ruling that could greatly expand access to the drug.

The Illinois Department of Public Health had rejected intractable pain — defined as pain that’s resistant to treatment — but Cook County Judge Raymond Mitchell ordered the agency to add the condition.

A health department spokeswoman said Tuesday the agency will appeal the ruling. The change is expected to be put on hold while the appeal is pursued.

Ann Mednick, whose lawsuit resulted in the ruling, said she has taken opioid pills to cope with extreme pain caused by osteoarthritis but wants a treatment with fewer side effects that would allow her to be more functional. Rheumatoid arthritis is on the list of about 40 qualifying conditions for medical marijuana, but osteoarthritis is not, nor is general or chronic pain.

“Illinois is years behind the times,” the Rolling Meadows woman said. “The state needs to get (it) together.”

Mednick had previously petitioned the state to put intractable pain on the marijuana treatment access list, and the now-defunct Illinois Medical Cannabis Advisory Board agreed it should be on the list, voting 10-0 to recommend adding the condition.

But the health department’s director, Dr. Nirav Shah, denied the recommendation in January 2016, citing a “lack of high-quality data” from clinical trials to establish that the benefits outweighed the risks.

Mednick challenged the denial in court, and Shah agreed to review his decision. But last March, the director again rejected the petition.

The judge in his Friday ruling found that Shah’s decision was “clearly erroneous,” noting that the director said the condition was not listed in the International Statistical Classification of Diseases and Related Health Problems, or ICD, by the World Health Organization, and was not recognized as a unique medical condition.

But the advisory board cited ICD codes that did recognize the condition as a form of chronic pain, the judge wrote in his opinion.

The request to add intractable pain cited papers by two medical journals that together reviewed 45 clinical studies of marijuana to treat chronic pain.

“The record shows that individuals with intractable pain would benefit from the medical use of cannabis,” the judge wrote, adding that the studies found that adverse effects generally were not serious and were well-tolerated.

The director’s decision misstates the advisory board’s analysis and “contorts” the record to minimize the evidence supporting the petition, the judge wrote.

The judge ordered Shah to add the condition to the list of 40 or so qualifying medical conditions but did not specify when the director must do so.

The health department spokeswoman declined comment other than to say the ruling will be appealed.

Pain accounts for the majority of medical marijuana patients in states that allow it as a qualifying condition.

The possibility that marijuana could be a viable substitute for highly addictive opioid painkillers has also prompted a proposed change in Illinois law: State Sen. Don Harmon, D-Oak Park, has submitted a bill that would allow medical marijuana to be given for any medical condition in place of prescription painkillers. He expects action on the proposal in the spring legislative session, scheduled to start Jan. 30.