Doctors tend to a patient in the ER of Mission Community Hospital in Panorama, Calif.

While the White House and congressional Republicans struggled to repeal Obamacare, investors did not shy away from health-care stocks during the first quarter.

The S&P 500 Health Care Sector gained more than 8 percent, outperforming the overall market.

In fact, some of the sector's biggest gainers, such as insurer Centene — which has risen more than 27 percent this year — were among those that stood to lose the most from the GOP bill's proposed cuts to Medicaid funding. Investors were relieved when the American Health Care Act failed to garner enough votes.

"I think the rollback of coverage and the potential loss of coverage, obviously in the most fragile population, was a very difficult thing to stomach" for a number of Republicans, said David Windley, a managing director and health-care research analyst at Jefferies.

"They are going to need to do that in a way that doesn't remove funding quite so fast, that allows the states to maintain coverage," he said.

Gains for the S&P managed health care sector, which includes Aetna, UnitedHealth Group and Anthem, were more in line with the overall market, up nearly 6 percent for the quarter.

Hospitals win big in first quarter

Hospital stocks such as Community Health Systems surged even more in the post-AHCA rally. Short sellers had bet heavily against shares of the debt-laden hospital operator, and those of its rival Tenet Healthcare, which also carries large debt. Both companies could see big losses if Republican Medicaid cutbacks were passed and millions of people were to lose insurance coverage.

"The technical set-up for Tenet and Community (shares) is actually very interesting," said Sheryl Skolnick, director of research and senior health-care analyst at Mizuho Securities.

The valuation of their stocks is more influenced by their high level of debt than their earnings and other fundamentals, making them attractive to short sellers.

"Stocks with high short interest tend not to go down on bad news because shorts cover (their bets)," Skolnick explained. "You had this interesting combination of factors that Tenet and Community were positioned to outperform arguably less risky companies."

The short sellers cashed out when the AHCA failed, and the hospital sector rallied. Shares of Community Health gained about 58 percent for the quarter, while Tenet was up nearly 22 percent.

"For the management teams of these companies, now the decisions they've made to deploy capital and to continue along the kinds of patient care initiatives that have been innovative in part enabled the ACA — all those things can continue, " Skolnick said, referring to former President Barack Obama's Affordable Care Act.

Investors looking beyond health reform

The biotech and pharmaceuticals sector is also in the crosshairs for reform.

President Donald Trump has pledged to pursue price negotiations to bring down the costs of high-priced drugs. Yet, the sector has seen its best quarterly gain in two years. The large cap NYSE Arca Biotech index is up 16 percent year to date. The Nasdaq Biotech Index ETF, which includes more small-cap biotech names, finished the quarter nearly 11 percent higher.

So, is the market betting Republican reforms will stall long-term? Not entirely.

Analysts say part of the health-care sector's gains are coming from investors betting that the Trump administration's other priorities — tax and regulatory reform — will help push more profits to health firms' bottom lines.

Insurer headwinds in the second quarter

Still, Obamacare and reform will be a big theme again in the second quarter. Insurers will start submitting initial exchange plan rates for 2018 as early as April, in some states. Nationally, the final deadline is June 21.

After speaking with management at Anthem, Jefferies' Windley expects that the nation's second-largest insurer will cut back its Obamacare offerings for next year.

"They've been pretty consistent with the message that they are gathering information … and will be in a position to make that decision (by midyear) and probably not before," Windley said.

Anthem is the nation's largest operator of Blue Cross insurance plans, and the last of the major insurers to have a large presence on the Obamacare marketplaces, with more than a million ACA plan enrollees across more than a dozen states. If Anthem followed its peers and pulled out, it would amount to a significant blow to the individual market.

"It is big in that they are the largest Blues-licensed holder out there," but not unprecedented, said Windley. "My sense is that there's plenty of evidence from their publicly traded competitors who have already backed away. … The trend is fairly well established."

For now, with health reform changes still up in the air, analysts say it's business as usual for health care, and uncertainty has become a part of that.