Foam in pharmaceutical and medical applications