Long waits at A&E units at hospitals across Wales have contributed to the deaths of more than 900 people last year.