Caremark Rx ( CMX) has failed to cure a mounting legal headache.

The giant pharmacy benefit manager had hoped to secure a courtroom ruling with the potential to derail a Medicaid fraud case that has been building against the company for years. However, a federal judge this week rejected the company's arguments and sided with the government instead.

Both federal and state prosecutors have accused Caremark of defrauding Medicaid by saddling the program with drug bills that it should have covered itself. Specifically, they claim that Caremark refused to repay the government for claims involving people who qualify for Medicaid -- the so-called "payer of last resort" -- but have private insurance as well.

They have estimated damages in the case at $500 million. Caremark's unsuspecting clients, including big corporations and health insurance plans, could wind up on the hook.

This week's court ruling came as Caremark lost a major customer -- the California Public Employees' Retirement System -- to competitor Medco Health Solutions ( MHS). Medco has already pledged to change its own business practices as part of a big government settlement and now portrays itself as the most transparent of the major PBMs.

With the judge denying Caremark's motion for a summary judgment, the government's case will now move toward trial in Texas.

Caremark's stock fell 1.6% to $49.19 on Thursday.

Court Guidance

Caremark said it was merely seeking guidance from the court about how it should handle Medicaid claims. And the company stressed that the judge himself recognized that the dispute was "based on a good faith disagreement about a complex area of the law."

The government, however, has accused Caremark of intentionally mishandling Medicaid claims. In fact, it has said that the company went so far as to program its computer system with dummy codes designed to reject Medicaid claims automatically.

Up to now, Caremark has argued that it rightfully denied the claims because of contract violations. For example, it said, some Medicaid recipients failed to properly identify themselves as Caremark customers when picking up their prescriptions. In other cases, it said, they filled their prescriptions at pharmacies outside the company's network. Then later on, it added, Medicaid sought reimbursement from Caremark after the deadline to do so had already passed.

In response, however, government prosecutors have argued that the law -- which requires Medicaid to seek money owed to it by private insurers -- trumps a company's own rules. They have backed their argument with supporting evidence from both the Centers for Medicare and Medicaid Services and the Employee Retirement Income Security Act.

"We have the federal government, the states, CMS, ERISA ... agreeing that Caremark owes the money," said Patrick Burns, a spokesman for Taxpayers against Fraud. "No one seems to agree with Caremark's position. ... If you're the only one that sees the world in a certain way, then maybe that means you are wrong."

Burns went on to suggest that Caremark, a stock market darling with soaring profits, should cut its losses and put the case behind it right now.

"Caremark is a big enough, robust enough company that it doesn't need this kind of litigation hanging over its head," he said. "At this point, it's not even a question of whether they will pay but of how much they will pay. ... So they should settle it and move on."

Still, Caremark faces legal challenges beyond the Medicaid case. It is also the target of a multistate probe and a big whistleblower lawsuit that alleges massive wrongdoing.

Pesky Footnote

For investors, however, Caremark's legal woes rank as little more than a pesky footnote in an otherwise upbeat story. Moreover, they expect each chapter to just keep getting better.

Early next month, for example, they look for Caremark to report spectacular third-quarter results. Specifically, they believe the company will increase profits by more than 50% to 51 cents a share.

Given that growth -- and the opportunity for more -- Caremark clearly stands out in the eyes of some.

"We generally view the PBM sector as being the fundamentally strongest within our coverage universe," Merrill Lynch analyst Thomas Gallucci noted last week. And "we anticipate that Caremark will post, by far, the strongest across-the-board results" of the group.

Many believe Caremark could grow even stronger. They are especially excited about the company's expansion into the new Medicare Part D drug coverage plan.

Indeed, SG Cowen analyst Kemp Dolliver believes that Caremark is even better positioned than its largest competitors -- Medco and Express Scripts ( ESRX) -- to capitalize on that particular opportunity. He predicts that the company will generate billions of dollars in additional revenue as a result of the new program.

With further help from stock repurchases, Dolliver ultimately believes that Caremark will boost profits by another 20% next year.

"Caremark is our favorite stock in the attractive PBM industry," Dolliver wrote earlier this month. "We recommend purchase based on attractive positioning to gain business from Medicare Part D and a share buyback program. We think the shares can outperform the market by 20% over the next 12 months."

The stock has fared even better than that over the past 12 months. It has racked up gains of 73% compared to just 8.3% for the Standard & Poor's 500.

Chorus of Critics

Off Wall Street, however, Caremark still has plenty of critics.

Former insiders have accused the company of defrauding and endangering customers by switching and canceling their prescriptions. Even more sensationally, they have accused the company of selling returned drugs -- including blood products -- and profiting twice from the transactions.

Caremark has denied any wrongdoing.

Still, pharmacists outside of Caremark have attacked the company as well. The National Community Pharmacists Association stands out as a vocal critic of the PBM industry in general -- and Caremark in particular.

"Caremark's service mark states, 'If people are healthier, the bottom line will be, too,'" NCPA Senior Vice President John Rector recently wrote in a letter published by the Texas Pharmacy Association. But "in reality, it appears a half-truth. Unfortunately, only Caremark's bottom line appears to be healthy" right now.

More from Stocks

Has Wall Street Completely Lost Its Mind on General Electric?

Has Wall Street Completely Lost Its Mind on General Electric?

Tesla CEO Elon Musk Is Cracking Under Immense Stress and Investors Should Worry

Tesla CEO Elon Musk Is Cracking Under Immense Stress and Investors Should Worry

10 Questions for PayPal Ahead of Its Big Investor Day

10 Questions for PayPal Ahead of Its Big Investor Day

Trump Tariff Threat, Deutsche Bank, Elon Musk and Apple - 5 Things You Must Know

Trump Tariff Threat, Deutsche Bank, Elon Musk and Apple - 5 Things You Must Know

High-Flying Mutual Funds Begin to Favor Energy but Tech Still Reigns Supreme

High-Flying Mutual Funds Begin to Favor Energy but Tech Still Reigns Supreme