A federal judge on Tuesday overturned ObamaCare protections for transgender patients, ruling that a 2016 policy violates the religious freedom of Christian providers.

Judge Reed O'Connor in the Northern District of Texas vacated an Obama-era regulation that prohibited insurers and providers who receive federal money from denying treatment or coverage to anyone based on sex, gender identity or termination of pregnancy.

It also required doctors and hospitals to provide "medically necessary" services to transgender individuals as long as those services were the same ones provided to other patients.

O'Connor, the same judge who last year ruled that the entire Affordable Care Act is unconstitutional, said the rule violates the Religious Freedom Restoration Act.

His ruling is likely to be appealed.

The ObamaCare rule was initially challenged in court in 2016 by a group of Christian providers called the Franciscan Alliance as well as five conservative states.

They argued that the rule forces insurers to pay for abortions and compels doctors to perform gender transition services even if they disagree with those services on moral or medical grounds.

O'Connor agreed and issued a nationwide injunction against enforcing the rule. The injunction meant that even though the provisions remained in effect, the Obama administration could not sue a hospital or provider for not complying.

President Obama's Department of Health and Human Services initially defended the rule, but the Trump administration decided to drop its defense and argued the rule should be sent back to the agency to be rewritten.

The Trump administration is working on a regulatory fix and has issued a proposed rule that would scrap ObamaCare's definition of "sex discrimination" to remove protections for gender identity.

Advocates argue removing those protections will allow health care providers, hospitals and insurers to discriminate against transgender patients.