U.S. jails and immigration detention centers have long struggled to meet the medical needs of the people in their charge.