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