The nation's 5,700 community hospitals are not in very good shape financially, according to a report released yesterday by the American Hospital Association.

The AHA said uncompensated costs of hospitals for free care and unpaid bills jumped to $7 billion in 1986. At the same time, it said, overall costs per hospital patient have been rising more rapidly than income, particularly in the Medicare program where government increases in the rates paid to hospitals for care of Medicare in-patients have lagged behind increases in the cost of things hospitals must buy.

The result, the AHA said, is that hospitals' annual net margins on revenues received for the care of patients -- the amount left over as a surplus after a hospital has paid all its bills for supplies, capital, and personnel -- dropped to 0.2 percent in 1987, one-tenth the 2 percent margin realized in 1984. Since 1984, patient-care surpluses have been dropping.

"More than half of community hospitals actually lost money on patient care in 1986," the AHA said.

Even if a hospital has little or no surplus from the revenues it gets from the care of patients, it can often keep going because it receives added revenues -- not included in the above calculations -- from endowments and tax-free contributions or from related businesses. But AHA officials said even including those revenues, margins are becoming more precarious.