|
|
|
@ -5,6 +5,7 @@ import numpy as np
|
|
|
|
|
import time
|
|
|
|
|
import pandas as pd
|
|
|
|
|
from multiprocessing import Process
|
|
|
|
|
import json
|
|
|
|
|
|
|
|
|
|
def build (**_args):
|
|
|
|
|
"""
|
|
|
|
@ -60,15 +61,27 @@ def format(**_args) :
|
|
|
|
|
for _attrName in _claim :
|
|
|
|
|
_item = _claim[_attrName]
|
|
|
|
|
_item = update(_item,_primary_key,_pkvalue)
|
|
|
|
|
#
|
|
|
|
|
# We have a casting problem, with relational data-store and JSON objects
|
|
|
|
|
#
|
|
|
|
|
if type(_item) == str and (_item.startswith("{") or _item.startswith("{")) :
|
|
|
|
|
try:
|
|
|
|
|
|
|
|
|
|
_item = json.loads(_item)
|
|
|
|
|
|
|
|
|
|
except Exception as ee :
|
|
|
|
|
# print (ee)
|
|
|
|
|
pass
|
|
|
|
|
if _attrName not in _tables and type(_item) in [dict,list]:
|
|
|
|
|
_tables[_attrName] = []
|
|
|
|
|
if type(_item) in [dict,list] :
|
|
|
|
|
_tables[_attrName] += _item if type(_item) == list else [_item]
|
|
|
|
|
pass
|
|
|
|
|
else:
|
|
|
|
|
#
|
|
|
|
|
# This section suggests we found a main table attribute
|
|
|
|
|
_main[_attrName] = _item
|
|
|
|
|
|
|
|
|
|
_tables[_mainTableName].append(_main)
|
|
|
|
|
|
|
|
|
|
return _tables
|
|
|
|
@ -100,7 +113,6 @@ def init(**_args):
|
|
|
|
|
_default = build(plugins=_plugins,x12=_file_type)
|
|
|
|
|
|
|
|
|
|
_df = read(store = _store['source'],x12=_file_type)
|
|
|
|
|
|
|
|
|
|
_pkey = util.getPrimaryKey(plugins = _plugins, x12=_file_type)
|
|
|
|
|
SEGMENTS = 4 # arbitrary choice
|
|
|
|
|
_indexes = np.array_split(np.arange(_df.shape[0]),SEGMENTS)
|
|
|
|
@ -108,12 +120,12 @@ def init(**_args):
|
|
|
|
|
for _ii in _indexes :
|
|
|
|
|
try:
|
|
|
|
|
_data = format(rows= _df.iloc[_ii].to_dict(orient='records'),x12=_file_type,primary_key=_pkey)
|
|
|
|
|
|
|
|
|
|
_thread = Process(target=post,args=({'store':_store['target'],'data':_data,'default':_default,'x12':_file_type},))
|
|
|
|
|
jobs.append(_thread)
|
|
|
|
|
except Exception as e:
|
|
|
|
|
#
|
|
|
|
|
# Log: sigment,
|
|
|
|
|
print (e)
|
|
|
|
|
pass
|
|
|
|
|
if jobs :
|
|
|
|
|
jobs[0].start()
|
|
|
|
@ -126,6 +138,7 @@ def read (**_args):
|
|
|
|
|
_store = copy.copy(_args['store'])
|
|
|
|
|
_x12 = _args['x12']
|
|
|
|
|
_store['table'] = getContext(_x12) #'claims' if _x12 == '837' else 'remits'
|
|
|
|
|
_store['context'] = 'read'
|
|
|
|
|
reader = transport.factory.instance(**_store)
|
|
|
|
|
#
|
|
|
|
|
# @TODO: reading should support streaming (for scalability)
|
|
|
|
@ -136,9 +149,14 @@ def read (**_args):
|
|
|
|
|
def post(_args):
|
|
|
|
|
_data = _args['data']
|
|
|
|
|
_store = _args['store']
|
|
|
|
|
_store['context'] = 'write'
|
|
|
|
|
_default = _args['default']
|
|
|
|
|
_prefix = 'clm_' if _args['x12'] == '837' else 'rem_'
|
|
|
|
|
# if 'claims' in _data or 'remits' in _data :
|
|
|
|
|
# _key = 'claims' if 'claims' in _data else 'remits'
|
|
|
|
|
# _data = _data[_key]
|
|
|
|
|
for _name in _data :
|
|
|
|
|
|
|
|
|
|
_tablename = _prefix+_name
|
|
|
|
|
_store['table'] = _tablename if _name not in ['remits','claims'] else _name
|
|
|
|
|
_store['context']='write'
|
|
|
|
@ -147,12 +165,11 @@ def post(_args):
|
|
|
|
|
_rows = [_default[_name]]
|
|
|
|
|
else:
|
|
|
|
|
_rows = _data[_name]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
writer.write(pd.DataFrame(_rows).fillna(''))
|
|
|
|
|
if hasattr(writer,'close') :
|
|
|
|
|
writer.close()
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
# Have a logger here to log what's going on ...
|
|
|
|
|
# _xwriter = trasnport.factory.instance(**_store)
|
|
|
|
|
# _xwriter.write(_df)
|
|
|
|
|
# _info = format()
|
|
|
|
|