Data source/SPOR.OMS/data model/mappingCode 3/mapping/CDQ/transformation

From CDQ
Jump to navigation Jump to search


Part of Hierarchical relation between two concepts of the CDQ Data Model. Data source SPOR.OMS
Mapping source The source of a data model mapping. SPOR.OMS mappingCodeSystem_1, mappingCode_3, addressCountryCodeidentifierValue
Transformation type A type of a transformation applied to a data model mapping. CUSTOM_TRANSFORMATION"CUSTOM_TRANSFORMATION" is not in the list (UPPER_CASE, LOWER_CASE, CUSTOM) of allowed values for the "Has transformation type" property.
Transformation parameter A transformation parameter is an action proccessed by a data model transformation. n/a
Description Informal and comprehensive human-readable definition of a concept. n/a

Transformation code Any code (in Python, JAVA or other) that will transform values for a given data source attributes.

IDENTIFIER_VALUE_2 = "identifiers[2].value"
IDENTIFIER_TYPE_2 = "identifiers[2].type.technicalKey"
IDENTIFIER_VALUE_3 = "identifiers[3].value"
IDENTIFIER_TYPE_3 = "identifiers[3].type.technicalKey"
IDENTIFIER_VALUE_4 = "identifiers[4].value"
IDENTIFIER_TYPE_4 = "identifiers[4].type.technicalKey"

country_code_map = {
    "AT": "BR_ID_AT",
    "AU": "ABN_AU",
    "BE": "BE_BUN",
    "BG": "BG_UID",
    "CA": "BN_CA",
    "CH": "CH_UID",
    "CN": "CN_BRN",
    "CY": "CY_BRN",
    "CZ": "CZ_ICO",
    "DE": "DE_BNUM",
    "DK": "CVR_DK",
    "EE": "EE_BRN",
    "ES": "ES_NIF",
    "FI": "BIC_FI",
    "FR": "FR_SIREN",
    "GB": "ID_CRN",
    "GR": "GR_BRN",
    "HR": "HR_BRN",
    "HU": "HU_CRN",
    "IE": "CN_IE",
    "IL": "IL_VAT",
    "IT": "IT_FISC_ID",
    "LT": "LT_BRN",
    "NL": "KVK_NL",
    "NO": "NO_ORGID",
    "PL": "PL_KRS",
    "RO": "TRN_RO",
    "SE": "SE_ORG_ID",
    "SG": "SG_UEN",
    "SK": "SK_ICO",
    "XI": "ID_CRN"
}

def transform(raw_data):

    if not raw_data.strip():
        return

    parts = raw_data.split(';')

    if len(parts) < 3:
        return

    identifiersCodes = [elem.strip() for elem in parts[0].split('¦') if elem.strip()]
    identifiersValues = [elem.strip() for elem in parts[1].split('¦') if elem.strip()]
    country_code = parts[2].strip()

    if len(identifiersCodes) != len(identifiersValues):
        return

    if not country_code:
        return

    result = {}
    for i, code in enumerate(identifiersCodes):
        if code == "100000167449":
            result[IDENTIFIER_TYPE_2] = "DUNS_ID"
            result[IDENTIFIER_VALUE_2] = identifiersValues[i]
        elif code == "100000167435":
            result[IDENTIFIER_TYPE_3] = "GS1_GLN"
            result[IDENTIFIER_VALUE_3] = identifiersValues[i]
        elif code == "200000026002":
            result[IDENTIFIER_TYPE_4] = country_code_map.get(country_code, "")
            result[IDENTIFIER_VALUE_4] = identifiersValues[i]

    if result:
        return result