(
    requests,
    subcase_trigger_info,
    subcase_config,
    dhis2_entity_config,
)
Creates two relationships in DHIS2; one corresponding to a
    subcase-to-supercase relationship, and the other corresponding to a
    supercase-to-subcase relationship.
Creates two relationships in DHIS2; one corresponding to a
    subcase-to-supercase relationship, and the other corresponding to a
    supercase-to-subcase relationship.
Creates two relationships in DHIS2 ; one corresponding to a subcase - to - supercase relationship and the other corresponding to a supercase - to - subcase relationship .
def create_relationships(
    requests,
    subcase_trigger_info,
    subcase_config,
    dhis2_entity_config,
):
    """
    Creates two relationships in DHIS2; one corresponding to a
    subcase-to-supercase relationship, and the other corresponding to a
    supercase-to-subcase relationship.
    """
    subcase_tei_id = get_value(subcase_config.tei_id, subcase_trigger_info)
    if not subcase_tei_id:
        raise Dhis2Exception(_(
            'Unable to create DHIS2 relationship: The case {case} is not '
            'registered in DHIS2.'
        ).format(case=subcase_trigger_info))

    for rel_config in subcase_config.relationships_to_export:
        supercase = get_supercase(subcase_trigger_info, rel_config)
        supercase_config = get_case_config_for_case_type(
            supercase.type,
            dhis2_entity_config,
        )
        supercase_info = get_case_trigger_info_for_case(
            supercase,
            [supercase_config.tei_id],
        )
        supercase_tei_id = get_value(supercase_config.tei_id, supercase_info)
        if not supercase_tei_id:
            # The problem could be that the relationship is configured
            # in the CaseConfig for the subcase's case type, but there
            # is no CaseConfig for the supercase's case type.
            # Alternatively, registering the supercase in DHIS2 failed.
            raise ConfigurationError(_(
                'Unable to create DHIS2 relationship: The case {case} is not '
                'registered in DHIS2.'
            ).format(case=supercase_info))
        if rel_config.supercase_to_subcase_dhis2_id:
            create_relationship(
                requests,
                rel_config.supercase_to_subcase_dhis2_id,
                supercase_tei_id,
                subcase_tei_id,
            )
        if rel_config.subcase_to_supercase_dhis2_id:
            create_relationship(
                requests,
                rel_config.subcase_to_supercase_dhis2_id,
                subcase_tei_id,
                supercase_tei_id,
            )
def create_relationships ( requests , subcase_trigger_info , subcase_config , dhis2_entity_config , ) : subcase_tei_id = get_value ( subcase_config . tei_id , subcase_trigger_info ) if not subcase_tei_id : raise Dhis2Exception ( _ ( 'Unable to create DHIS2 relationship: The case {case} is not ' 'registered in DHIS2.' ) . format ( case = subcase_trigger_info ) ) for rel_config in subcase_config . relationships_to_export : supercase = get_supercase ( subcase_trigger_info , rel_config ) supercase_config = get_case_config_for_case_type ( supercase . type , dhis2_entity_config , ) supercase_info = get_case_trigger_info_for_case ( supercase , [ supercase_config . tei_id ] , ) supercase_tei_id = get_value ( supercase_config . tei_id , supercase_info ) if not supercase_tei_id : # The problem could be that the relationship is configured # in the CaseConfig for the subcase's case type, but there # is no CaseConfig for the supercase's case type. # Alternatively, registering the supercase in DHIS2 failed. raise ConfigurationError ( _ ( 'Unable to create DHIS2 relationship: The case {case} is not ' 'registered in DHIS2.' ) . format ( case = supercase_info ) ) if rel_config . supercase_to_subcase_dhis2_id : create_relationship ( requests , rel_config . supercase_to_subcase_dhis2_id , supercase_tei_id , subcase_tei_id , ) if rel_config . subcase_to_supercase_dhis2_id : create_relationship ( requests , rel_config . subcase_to_supercase_dhis2_id , subcase_tei_id , supercase_tei_id , )