A federal judge here ruled yesterday that the Army's mandatory random drug testing of civilian employees in so-called critical positions is unconstitutional and ordered the tests halted immediately.

U.S. District Judge Thomas F. Hogan said in a 46-page opinion that while the Army has a "compelling safety interest, in some instances, in maintaining a drug-free workplace," the urinalysis used by the Army cannot show actual impairment.

And, Hogan said, the Army's "nonsafety" interests in ensuring a drug-free work force do not warrant overriding Fourth Amendment protection against unreasonable searches.

Hogan said it was with "some regret" that he removed "what might be a powerful weapon from the nation's arsenal in the campaign against illegal drug abuse, but the values represented by the Constitution and the Fourth Amendment are transcendent."

Hogan's ruling was in the form of an expanded preliminary injunction against the Army's entire civilian random drug-testing program.

Because Hogan's ruling affects the Army's entire program covering more than 9,000 civilians, it is considered a blow to President Reagan's goal of establishing mandatory random drug testing for all federal employees as early as May.

It is the latest in a number of District and federal appeals courts rulings that have addressed the drug-testing issue, and have variously banned and approved testing programs.

The Supreme Court announced Monday that it will consider the matter next term when it hears an appeal from the 5th U.S. Circuit Court of Appeals ruling that upheld testing of U.S. Customs Service employees.

Hogan said that under some rationales offered in support of the testing program, specifically that those who enforce the law should be drug free, "all Cabinet officers and the president should undergo random drug testing."

Hogan said he based his opinion on the U.S. Court of Appeals for the District of Columbia's ruling Nov. 17 in a case involving drug testing among D.C. school transportation employees.

The appeals court held that testing to determine if workers were impaired by drugs was not unconstitutional, but ruled that urinalysis cannot measure impairment.

However, Hogan's ruling is in conflict with a ruling in September by U.S. District Judge Gerhard A. Gesell upholding random drug testing for Department of Transportation workers, including air traffic controllers.

Hogan suggested that any appeal of his ruling be consolidated with that case and heard by the full Court of Appeals here as "presenting a question of exceptional importance."

A Justice Department spokeswoman said last night that the Department of Justice was studying the opinion and would decide later whether to appeal.

"As far as we are concerned, this is a clear, unequivocal victory," said Red Evans, spokesman for the National Federation of Federal Employees, which was involved in one of the three separate suits covered by Hogan's consolidated ruling.

"It's a victory for the American worker," Evans said.

"The president's public relations progam to hold public employees up to the ridicule of drug testing has been shot down," Evans said.

"We expect the Army to cease and desist immediately," he said.

The NFFE represented civilian workers at Aberdeen Proving Ground in Maryland.

Judge Hogan has presided over that suit since 1986, when he dismissed the suit on the grounds that the employees had not sought proper administrative remedies before suing.

That decision was reversed by the appeals court here, which ruled that mandatory urinalysis of public sector employees constituted "search and seizure" under the Fourth Amendment.

The two other suits, brought by the American Federation of Government Employees on behalf of civilian Army employees at Fort Stewart/Hunter Army Airfield in Georgia and at Sharpe Army Depot in California, were later transferred here and consolidated with the Aberdeen case.