<commit_before>from corehq.apps.users.models import CommCareUser, CouchUser
from custom.enikshay.case_utils import get_person_case_from_voucher
from custom.enikshay.exceptions import ENikshayCaseNotFound


def person_case_from_voucher_case(handler, reminder):
    voucher_case = reminder.case
    if not voucher_case:
        return None

    if voucher_case.type != 'voucher':
        return None

    try:
        return get_person_case_from_voucher(voucher_case.domain, voucher_case.case_id)
    except ENikshayCaseNotFound:
        return None


def agency_user_case_from_voucher_fulfilled_by_id(handler, reminder):
    voucher_case = reminder.case
    if not voucher_case:
        return None

    if voucher_case.type != 'voucher':
        return None

    fulfilled_by_id = voucher_case.get_case_property('voucher_fulfilled_by_id')
    try:
        user = CommCareUser.get_by_user_id(fulfilled_by_id, domain=voucher_case.domain)
    except CouchUser.AccountTypeError:
        user = None

    if not user:
        return None

    # get_usercase() just returns None if the user case does not exist; no exceptions raised
    return user.get_usercase()
<commit_msg>Check for blank id<commit_after>from corehq.apps.users.models import CommCareUser, CouchUser
from custom.enikshay.case_utils import get_person_case_from_voucher
from custom.enikshay.exceptions import ENikshayCaseNotFound


def person_case_from_voucher_case(handler, reminder):
    voucher_case = reminder.case
    if not voucher_case:
        return None

    if voucher_case.type != 'voucher':
        return None

    try:
        return get_person_case_from_voucher(voucher_case.domain, voucher_case.case_id)
    except ENikshayCaseNotFound:
        return None


def agency_user_case_from_voucher_fulfilled_by_id(handler, reminder):
    voucher_case = reminder.case
    if not voucher_case:
        return None

    if voucher_case.type != 'voucher':
        return None

    fulfilled_by_id = voucher_case.get_case_property('voucher_fulfilled_by_id')
    if not fulfilled_by_id:
        return None

    try:
        user = CommCareUser.get_by_user_id(fulfilled_by_id, domain=voucher_case.domain)
    except CouchUser.AccountTypeError:
        user = None

    if not user:
        return None

    # get_usercase() just returns None if the user case does not exist; no exceptions raised
    return user.get_usercase()

{'fraction_non_alphanumeric': 0.05806182121971595, 'fraction_numerical': 0.0, 'mean_word_length': 3.659533073929961, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2003798', 'n_tokens_mistral': 804, 'n_tokens_neox': 765, 'n_words': 172}