After years of debate, Chile's Constitutional Court has approved a law to legalise abortion in some circumstances.