A U.S. appeals court ruled Friday in favor of a Florida law that bars doctors from asking patients about gun ownership. The move overturns a lower court’s decision in the so-called "Docs vs. Glocks" case.

Florida's Republican-led legislature passed the law after a north Florida couple complained that a doctor asked them if they had guns, and refused to see them after they declined to answer. A federal judge ruled the law unconstitutional in 2012, and the state swiftly appealed.

A panel of the 11th U.S. Circuit Court of Appeals, in a 2-1 vote, vacated the federal judge's ruling and described the law as a "legitimate regulation" of professional conduct that simply codifies good medical care.

Any restrictions it places on physicians' speech was entirely incidental, the appeals court said, since it "was intended to protect patient privacy and curtail abuses of the physician-patient relationship."

Lawyers representing doctors and others had argued that the law violated healthcare providers' First Amendment rights by threatening them with heavy fines and the possibility of losing their licenses if they broach the subject.

Many doctors said they ask about gun ownership as a normal part of screening new patients, including it on a long list of health questions about drug and alcohol use, smoking, exercise and eating habits.

Critics of the law said the appeal was driven by the National Rifle Association and the gun industry to prevent regulations.

Howard Simon, executive director of the American Civil Liberties Union of Florida, was surprised at Friday's ruling. Simon's organization had filed legal briefs in support of the challenge to the law.

"We are astounded that a court would allow the legislature to override the free speech rights of doctors and medical personnel," Simon said in a statement. "It's a sad day when judges tell doctors what is in the best interest of their patients."

Wire services