fix infinite recursion on case hierarchy generation + test

http://manage.dimagi.com/default.asp?124211
nope - just a careless mistake