Community Health agrees to buy Philly hospital