(search_field, search_id, domain, case_type)
Attempt to find the case in CouchDB by the provided search_field and search_id.

    Returns a tuple with case (if found) and an
    error code (if there was an error in lookup).
Attempt to find the case in CouchDB by the provided search_field and search_id.
Attempt to find the case in CouchDB by the provided search_field and search_id .
def lookup_case(search_field, search_id, domain, case_type):
    """
    Attempt to find the case in CouchDB by the provided search_field and search_id.

    Returns a tuple with case (if found) and an
    error code (if there was an error in lookup).
    """
    found = False
    case_accessors = CaseAccessors(domain)
    if search_field == 'case_id':
        try:
            case = case_accessors.get_case(search_id)
            if case.domain == domain and case.type == case_type:
                found = True
        except CaseNotFound:
            pass
    elif search_field == EXTERNAL_ID:
        cases_by_type = case_accessors.get_cases_by_external_id(search_id, case_type=case_type)
        if not cases_by_type:
            return (None, LookupErrors.NotFound)
        elif len(cases_by_type) > 1:
            return (None, LookupErrors.MultipleResults)
        else:
            case = cases_by_type[0]
            found = True

    if found:
        return (case, None)
    else:
        return (None, LookupErrors.NotFound)
def lookup_case ( search_field , search_id , domain , case_type ) : found = False case_accessors = CaseAccessors ( domain ) if search_field == 'case_id' : try : case = case_accessors . get_case ( search_id ) if case . domain == domain and case . type == case_type : found = True except CaseNotFound : pass elif search_field == EXTERNAL_ID : cases_by_type = case_accessors . get_cases_by_external_id ( search_id , case_type = case_type ) if not cases_by_type : return ( None , LookupErrors . NotFound ) elif len ( cases_by_type ) > 1 : return ( None , LookupErrors . MultipleResults ) else : case = cases_by_type [ 0 ] found = True if found : return ( case , None ) else : return ( None , LookupErrors . NotFound )