def visit_completion_counter(case):
    mother_counter = 0
    child_counter = 0
    case_obj = CommCareCase.get(case['_id'])
    baby_case = [c for c in case_obj.get_subcases().all() if c.type == 'baby']
    for i in range(1, 8):
        if "pp_%s_done" % i in case:
            val = case["pp_%s_done" % i]
            try:
                if val.lower() == 'yes':
                    mother_counter += 1
                elif int(float(val)) == 1:
                    mother_counter += 1
            except __HOLE__:
                pass
        if baby_case and "bb_pp_%s_done" % i in baby_case[0]:
            val = baby_case[0]["bb_pp_%s_done" % i]
            try:
                if val.lower() == 'yes':
                    child_counter += 1
                elif int(float(val)) == 1:
                    child_counter += 1
            except ValueError:
                pass

    return mother_counter if mother_counter > child_counter else child_counter
dataset/ETHPy150Open dimagi/commcare-hq/custom/apps/crs_reports/reports.py/visit_completion_counter