Esempio n. 1
0
def load_pacs_002_001_02(root, conn, cursor, ns, msg_id, fexception):
    
    org_grp_info = xml_to_dict(root[0].find(f"./{ns}{'OrgnlGrpInfAndSts'}")).get('OrgnlGrpInfAndSts')
    # print ("---------> ",org_grp_info, "OrgnlMsgId:", org_grp_info.get('OrgnlMsgId'))
    trx_info = xml_to_dict(root[0].find(f"./{ns}{'TxInfAndSts'}")).get('TxInfAndSts')
    # print (trx_info)
    # return_reason_info = xml_to_dict(root[0].find(f".//{ns}{'StsRsnInf'}")).get('StsRsnInf')
    # print ("----------->",return_reason_info)
    # print (return_reason_info.get('RtrRsn'))
    # rec = xml_to_dict(xml_item)
    
    trx_dict = {
    'MsgId': msg_id,
    'OrgnlMsgId': org_grp_info.get('OrgnlMsgId'),
    'OrgnlMsgNmId': org_grp_info.get('OrgnlMsgNmId'),
    'GrpSts': org_grp_info.get('GrpSts'),
    
    'TrxRtrId': trx_info.get('StsId'),
    # 'OrgnlEndToEndId': trx_info.get('OrgnlEndToEndId'),
    'OrgnlTxId': trx_info.get('StsRsnInf').get('OrgnlTxId'),
    # 'RtrdIntrBkSttlmAmt': trx_info.get('RtrdIntrBkSttlmAmt'),
    # 'RtrdIntrBkSttlmCcy': '', #trx_info.get('RtrdIntrBkSttlmCcy'),
    'RtrRsn': trx_info.get('StsRsnInf').get('StsRsn').get('Prtry'),
    'AddtlStsRsnInf': trx_info.get('StsRsnInf').get('AddtlStsRsnInf')
    }
    insert_row_dict(conn, cursor, "pacs_002_004", trx_dict)
    return trx_dict
Esempio n. 2
0
def insert_db_rec(conn, cursor, rec, table):

    if table_exists(table, cursor) == 0:  # new table
        cmd = f"CREATE TABLE IF NOT EXISTS {table} ( {' TEXT,'.join(rec.keys())} )"
        # print (cmd)
        exec_db_cmd(cmd)
    else:
        check_col_names(rec, table, conn, cursor)

    insert_row_dict(conn, cursor, table, rec)
Esempio n. 3
0
def load_pacs_008_trx(root, conn, cursor, ns, msg_id, fexception):
        
        trans_grp_tag = "CdtTrfTxInf"
        trxs = root[0].findall(f"./{ns}{trans_grp_tag}")
        for trx in trxs:
            rec_0 = load_CdtTrfTxInf(trx, msg_id)
            # print (rec)
            rec = { 'MsgId': msg_id}
            rec.update(rec_0)
            ret_code = insert_row_dict(conn, cursor, "trx", rec)
            if ret_code == -1:
                 fexception.writelines(f"Error inserting trx record: {str(rec)}\n {50*'-'}\n")
Esempio n. 4
0
def parse_pacs_file(file_name, conn, cursor, fexception):
    
    tree = ET.parse(file_name) 
    root = tree.getroot()
    print (root[0].tag)
    
    # print (file_name)
    # print_xml_sample(root,10,"trx.txt")
    
    
    ns = get_ns(root)
    pacs_type = ns[37:47]   # 004.001.01
    
    # if pacs_type == '008.001.01':
        # print ('rejection record, skip it: ', file_name, ns)
        # return 
    # print (file_name)
    print (file_name, pacs_type)
    # return 
    
    if ns:
        grp_header = root[0].find(f"./{ns}GrpHdr")
    else:
        grp_header = root.find(f"./{ns}GrpHdr")

    # print (xml_to_dict(grp_header))
 
    rec = load_ach_GrpHdr(pacs_type, grp_header)
    rec.update({'file_name':file_name})
    ret = insert_row_dict(conn, cursor, "GrpHdr", rec)
    if ret == -1:
        fexception.writelines(f"Error inserting GrpHdr record: {str(rec)}\n {50*'-'}\n")
    
    if pacs_type in ["002.001.01"]:
        load_pacs_002_trx(root, conn, cursor, ns, rec.get('MsgId'), fexception)
    if pacs_type in ["002.001.02"]:
        load_pacs_002_001_02(root, conn, cursor, ns, rec.get('MsgId'), fexception)
    elif pacs_type in ["004.001.01"]:
        load_pacs_004_trx(root, conn, cursor, ns, rec.get('MsgId'), fexception)
    elif pacs_type == "008.001.01":  
        load_pacs_008_trx(root, conn, cursor, ns, rec.get('MsgId'), fexception)
    else:
        print (f"New pacs_type: {file_name} - {pacs_type}")