(self)
return {_CaseTypeEquivalence(case_type=eq.case_type, expansion=eq.expansion)
                for eq in all_possible_equivalences}
Returns the set all possible case_type <=> case_type_ref equivalences

        for the parent_type_map and case_types given to this class.
        Using the referral > patient > household example above, all possible equivalences are:

        {
            # a referral is a referral
            _CaseTypeEquivalence('referral', _CaseTypeRef('referral', ())),
            # a patient is a patient
            _CaseTypeEquivalence('patient', _CaseTypeRef('patient', ())),
            # a patient is a referal's parent
            _CaseTypeEquivalence('patient', _CaseTypeRef('referral', ('parent',)))
            # a household is a household
            _CaseTypeEquivalence('household', _CaseTypeRef('household', ())),
            # a household is a patient's parent
            _CaseTypeEquivalence('household', _CaseTypeRef('patient', ('parent'))),
            # a houseold is a referral's parent's parent
            _CaseTypeEquivalence('household', _CaseTypeRef('referral', ('parent', 'parent')))
        }
Returns the set all possible case_type <=> case_type_ref equivalences
Returns the set all possible case_type < = > case_type_ref equivalences
def _all_possible_equivalences(self):
        """
        Returns the set all possible case_type <=> case_type_ref equivalences

        for the parent_type_map and case_types given to this class.
        Using the referral > patient > household example above, all possible equivalences are:

        {
            # a referral is a referral
            _CaseTypeEquivalence('referral', _CaseTypeRef('referral', ())),
            # a patient is a patient
            _CaseTypeEquivalence('patient', _CaseTypeRef('patient', ())),
            # a patient is a referal's parent
            _CaseTypeEquivalence('patient', _CaseTypeRef('referral', ('parent',)))
            # a household is a household
            _CaseTypeEquivalence('household', _CaseTypeRef('household', ())),
            # a household is a patient's parent
            _CaseTypeEquivalence('household', _CaseTypeRef('patient', ('parent'))),
            # a houseold is a referral's parent's parent
            _CaseTypeEquivalence('household', _CaseTypeRef('referral', ('parent', 'parent')))
        }

        """
        all_possible_equivalences = set()

        class TmpEquivalence(namedtuple('TmpEquivalence',
                                        ['case_type', 'expansion', 'visited_case_types'])):
            """same as a _CaseTypeEquivalence but with a memory of the case types visited"""

        equivalence_queue = deque(
            TmpEquivalence(case_type, _CaseTypeRef(case_type, ()), visited_case_types=frozenset())
            for case_type in self.parent_type_map
        )

        while True:
            try:
                eq = equivalence_queue.popleft()
            except IndexError:
                break
            all_possible_equivalences.add(eq)
            for relationship, parents in self.parent_type_map[eq.case_type].items():
                for parent in parents:
                    if parent in eq.visited_case_types:
                        continue
                    new_equivalence = TmpEquivalence(
                        case_type=parent,
                        expansion=_CaseTypeRef(
                            eq.expansion.case_type,
                            eq.expansion.relationship_path + (relationship,)
                        ),
                        visited_case_types=eq.visited_case_types | {parent}
                    )
                    already_visited = (new_equivalence in all_possible_equivalences)
                    if not already_visited:
                        equivalence_queue.append(new_equivalence)
        return {_CaseTypeEquivalence(case_type=eq.case_type, expansion=eq.expansion)
                for eq in all_possible_equivalences}
def _all_possible_equivalences ( self ) : all_possible_equivalences = set ( ) class TmpEquivalence ( namedtuple ( 'TmpEquivalence' , [ 'case_type' , 'expansion' , 'visited_case_types' ] ) ) : """same as a _CaseTypeEquivalence but with a memory of the case types visited""" equivalence_queue = deque ( TmpEquivalence ( case_type , _CaseTypeRef ( case_type , ( ) ) , visited_case_types = frozenset ( ) ) for case_type in self . parent_type_map ) while True : try : eq = equivalence_queue . popleft ( ) except IndexError : break all_possible_equivalences . add ( eq ) for relationship , parents in self . parent_type_map [ eq . case_type ] . items ( ) : for parent in parents : if parent in eq . visited_case_types : continue new_equivalence = TmpEquivalence ( case_type = parent , expansion = _CaseTypeRef ( eq . expansion . case_type , eq . expansion . relationship_path + ( relationship , ) ) , visited_case_types = eq . visited_case_types | { parent } ) already_visited = ( new_equivalence in all_possible_equivalences ) if not already_visited : equivalence_queue . append ( new_equivalence ) return { _CaseTypeEquivalence ( case_type = eq . case_type , expansion = eq . expansion ) for eq in all_possible_equivalences }