Added method to get locations count by type

Also, splitted core changes from PR: https://github.com/dimagi/commcare-hq/pull/3839
@millerdev 

There will not be a situation where the selected path length is greater than the number of location types. You have right, I should use ```<``` not ```!=```