The D.C. Court of Appeals ruled yesterday that the city's police department can require urinalysis tests of officers it suspects of using drugs and can discipline those who refuse to undergo testing.

The unanimous ruling by a three-judge panel comes two years after D.C. Superior Court Judge Eugene N. Hamilton halted the tests as unconstitutional. Hamilton granted an injunction against the tests after the police union argued they violated police officers' rights to privacy.

The police department "has a paramount interest in protecting the public by ensuring that its employes are fit to perform their jobs," Senior Judge George R. Gallagher wrote for the court. "In the context of current widespread, large-scale drug usage in all segments of the population, the department was justified in promulgating [its drug testing order] in an effort to prevent the illicit use of narcotics" by police officers.

Gallagher added, however, that under the regulation, issued in March 1983 by Chief Maurice T. Turner, police officials or medical personnel must have a "reasonable, objective basis" for suspecting drug use and ordering the test of an individual officer. He said the regulation "does not grant . . . carte blanche to order [drug] testing on a purely subjective basis."

Acting police general counsel Richard S. Brooks said late yesterday that the department was studying the court decision and was not able to comment on it.

Brooks noted that the case and Hamilton's previous injunction dealt only with special tests of officers suspected of using drugs. He said it did not affect the regular program -- in operation for about a decade -- of testing for drugs during scheduled physical examinations, such as those of new recruits and when serious injuries occur.

In a brief order last summer, the appeals court lifted Hamilton's preliminary injunction after two other Superior Court judges said they did not have authority to grant the administrative warrants that Hamilton said were needed before special drug tests could be made. Brooks said the department has moved cautiously since then.

Gary Hankins, head of the Fraternal Order of Police's labor committee said his group would probably not appeal the ruling.

"I think the Appeals Court tried to strike a balance between our civil rights and having a police force free of drugs," Hankins said. "The question now is how the department will carry it out. If the department operates within the spirit of the decision, I don't think we will have a problem."

Hankins said the union has received no complaints about drug tests being required since Hamilton's injunction was lifted.

The suit was brought by the FOP, which represents the District's 3,400 officers, and officer Charles E. Buie, who was placed on administrative leave in September 1983 after refusing to take a urinalysis test. Officials said yesterday that Buie is still with the department.

Paul D. Kamenar, executive director of the Washington Legal Foundation, which filed a court brief in support of the the drug testing rule, praised yesterday's decision and predicted it would be widely cited to buttress testing of other public employes. He said his group is seeking urinalysis tests of airline pilots, air traffic controllers and Drug Enforcement Administration agents.