Added method to get locations count by type

Also, splitted core changes from PR: https://github.com/dimagi/commcare-hq/pull/3839
@twymer you can likely use this on the script if you want to update