https://github.com/dimagi/commcare-hq/blob/master/corehq/apps/reports/generic.py#L638