(helper, cases, paths)
return results
Given a set of cases and a set of case property paths,
    fetches ES documents for all cases referenced by those paths.
Given a set of cases and a set of case property paths,
    fetches ES documents for all cases referenced by those paths.
Given a set of cases and a set of case property paths fetches ES documents for all cases referenced by those paths .
def get_related_case_results(helper, cases, paths):
    """
    Given a set of cases and a set of case property paths,
    fetches ES documents for all cases referenced by those paths.
    """
    if not cases:
        return []

    results_cache = {}
    for path in paths:
        current_cases = cases
        parts = path.split("/")
        for index, identifier in enumerate(parts):
            fragment = "/".join(parts[:index + 1])
            if fragment in results_cache:
                current_cases = results_cache[fragment]
            else:
                indices = [case.get_index(identifier) for case in current_cases]
                related_case_ids = {i.referenced_id for i in indices if i}
                current_cases = _get_case_search_cases(helper, related_case_ids)
                results_cache[fragment] = current_cases

    results = []
    for path in paths:
        results.extend(results_cache[path])

    return results
def get_related_case_results ( helper , cases , paths ) : if not cases : return [ ] results_cache = { } for path in paths : current_cases = cases parts = path . split ( "/" ) for index , identifier in enumerate ( parts ) : fragment = "/" . join ( parts [ : index + 1 ] ) if fragment in results_cache : current_cases = results_cache [ fragment ] else : indices = [ case . get_index ( identifier ) for case in current_cases ] related_case_ids = { i . referenced_id for i in indices if i } current_cases = _get_case_search_cases ( helper , related_case_ids ) results_cache [ fragment ] = current_cases results = [ ] for path in paths : results . extend ( results_cache [ path ] ) return results