The Canadian Parliament has passed a law that allows the terminally ill to choose assisted dying in restricted circumstances.