SALT LAKE CITY (AP) — A Utah firefighters union and a gay-rights group can face off against the Drug Enforcement Administration in a court fight over warrantless searches of a prescription drug database similar to those kept by most U.S. states, a federal judge decided Thursday.

The databases containing all controlled-substance prescriptions for every patient are designed to help doctors and police curb abuse, but unfettered police access to them has raised concerns.

The group Equality Utah argues warrantless searches violate the privacy of transgender people whose hormone medications are recorded in the database. The firefighters union, meanwhile, says two members were wrongly accused of prescription drug fraud after a wide-ranging, warrantless search.

U.S. Magistrate Judge Dustin Pead decided Thursday the two groups can add their privacy and social justice arguments to a lawsuit between the DEA and the state of Utah.

DEA lawyers say the agency should be exempt from a new state law that requires police to get a warrant before accessing the database.

Utah is among the minority of states that require police to get a warrant before a search, a change sparked in part by the firefighters’ case. They were charged after police investigating ambulance drug thefts ran hundreds of names through the system on a hunch that it might be an inside job.

The two men weren’t connected to the thefts, their relatively high number of prescriptions raised suspicion and prosecutors filed fraud charges. The case was later dropped, but still put their careers and personal lives at risk, they said.

Their case shows why police shouldn’t be able to access the nearly 70 million records in Utah’s nearly 20-year-old database, said the ACLU’s Nathan Freed Wessler, who is representing the firefighters and Equality Utah. The database contains records of prescriptions for medication like the anti-anxiety drug Xanax and the sleep aid Ambien as well as prescription painkillers, he said.

“That’s a mind-boggling quantity of highly sensitive medical information,” he said.

But the DEA says the database is an important tool in the early stages of their investigation, like one they’re conducting into a Utah medical provider suspected of supplying pills to people with ties to an organized crime group.

Federal attorney Kathryn Wyer fought unsuccessfully to keep the Utah groups from intervening in their lawsuit against the state, arguing agents are only asking to use the database for a specific investigation that has nothing to do with them. The prescription-drug industry is already highly regulated and the database has no expectation of privacy, she said.

“People expect their prescription information is going to end up in this database,” Wyer said. “There’s a statue that says so.”

Firefighters’ union president Jeremy Robertson said that while he’s sympathetic to the need to curb a nationwide problem with prescription drug abuse, police shouldn’t have unfettered access.

“Doctors and pharmacists have a legitimate need for such a database,” said Robertson, whose own records were among those searched by police in the ambulance-theft investigation. “Law enforcement should go through a process to protect my rights.”

© 2016, Associated Press, All Rights Reserved.

This material may not be published, broadcast, rewritten, or redistributed.