Resident doctors end dispute over working conditions after agreeing changes