I am not a teacher
But as far as I know while means as long as the condition is true and when means when condition becomes true .
Doctors are obliged by law to keep patients alive as long as there is a chance of their recover .
so in "while" they were obligated as long as they felt that the patient can recover,so they have been thinking that the patient can recover thus they were obliged for the whole period of time.(Have been obligated as long as they felt there is a chance)
and in "when" they suddenly realize that there is a chance of recovery so at that point they were obligated.(Obligated since they felt there is a chance).
But again I am not a teacher.
Interested in Language