(helper, app_id, case_types, cases, custom_related_case_property)
return list({
        case.case_id: case for case in results if case.case_id not in initial_case_ids
    }.values())
Fetch related cases that are necessary to display any related-case
    properties in the app requesting this case search.

    Returns list of CommCareCase objects for adding to CaseDBFixture.
Fetch related cases that are necessary to display any related-case
    properties in the app requesting this case search.
Fetch related cases that are necessary to display any related - case properties in the app requesting this case search .
def get_related_cases(helper, app_id, case_types, cases, custom_related_case_property):
    """
    Fetch related cases that are necessary to display any related-case
    properties in the app requesting this case search.

    Returns list of CommCareCase objects for adding to CaseDBFixture.
    """
    if not cases:
        return []

    app = get_app_cached(helper.domain, app_id)
    paths = [
        rel for rels in [get_related_case_relationships(app, case_type) for case_type in case_types]
        for rel in rels
    ]
    child_case_types = [
        _type for types in [get_child_case_types(app, case_type) for case_type in case_types]
        for _type in types
    ]

    expanded_case_results = []
    if custom_related_case_property:
        expanded_case_results.extend(get_expanded_case_results(helper, custom_related_case_property, cases))

    results = expanded_case_results
    top_level_cases = cases + expanded_case_results
    if paths:
        results.extend(get_related_case_results(helper, top_level_cases, paths))

    if child_case_types:
        results.extend(get_child_case_results(helper, top_level_cases, child_case_types))

    initial_case_ids = {case.case_id for case in cases}
    return list({
        case.case_id: case for case in results if case.case_id not in initial_case_ids
    }.values())
def get_related_cases ( helper , app_id , case_types , cases , custom_related_case_property ) : if not cases : return [ ] app = get_app_cached ( helper . domain , app_id ) paths = [ rel for rels in [ get_related_case_relationships ( app , case_type ) for case_type in case_types ] for rel in rels ] child_case_types = [ _type for types in [ get_child_case_types ( app , case_type ) for case_type in case_types ] for _type in types ] expanded_case_results = [ ] if custom_related_case_property : expanded_case_results . extend ( get_expanded_case_results ( helper , custom_related_case_property , cases ) ) results = expanded_case_results top_level_cases = cases + expanded_case_results if paths : results . extend ( get_related_case_results ( helper , top_level_cases , paths ) ) if child_case_types : results . extend ( get_child_case_results ( helper , top_level_cases , child_case_types ) ) initial_case_ids = { case . case_id for case in cases } return list ( { case . case_id : case for case in results if case . case_id not in initial_case_ids } . values ( ) )