documentation/function schema/tables created

This commit is contained in:
Steve Nyemba 2024-02-09 10:00:29 -06:00
parent 9f6aa4ddcf
commit 27455a3770
2 changed files with 23 additions and 6 deletions

View File

@ -174,6 +174,18 @@ def check():
print (_msg) print (_msg)
@app.command(name="export-schema")
def export_schema (file_type:str):
"""
This function will display the schema in JSON format of a given file/type
"""
_plugins,_parents = x12.plugins.instance()
if file_type not in ['835','837'] and file_type in ['claims','remits']:
file_type = '835' if file_type == 'remits' else '837'
_template = x12.publish.build(x12=file_type,plugins=_plugins)
print ( json.dumps(_template))
@app.command(name="export") @app.command(name="export")
def publish (file_type:str,path:str): def publish (file_type:str,path:str):
""" """

View File

@ -17,21 +17,25 @@ def build (**_args):
_x12 = _args['x12'] _x12 = _args['x12']
_template = util.template(plugins=_plugins)[_x12] _template = util.template(plugins=_plugins)[_x12]
_primaryKey = util.getPrimaryKey(plugins=_plugins,x12=_x12) _primaryKey = util.getPrimaryKey(plugins=_plugins,x12=_x12)
_tables = [] _tables = {}
_main = {} _main = {}
for _name in _template : for _name in _template :
_item = _template[_name] #copy.deepcopy(_template[_name]) _item = _template[_name] #copy.deepcopy(_template[_name])
if _name not in _tables and type(_item) in [list,dict] :
_tables[_name] = _item
if _primaryKey not in _item and type(_item) == dict: if _primaryKey not in _item and type(_item) == dict:
_item[_primaryKey] = '' _item[_primaryKey] = ''
_tables.append({_name:_item}) # _tables.append({_name:_item})
_tables[_name] = _item
else: else:
_main[_name] = '' _main[_name] = ''
_name = getContext(_x12) _name = getContext(_x12)
_tables += [{_name:_main}] # _tables += [{_name:_main}]
_tables[_name] = _main
_template[_name] = _main _template[_name] = _main
return _template #_tables return _tables #_template #_tables
def getContext(_x12) : def getContext(_x12) :
return 'claims' if _x12 == '837' else 'remits' return 'claims' if _x12 == '837' else 'remits'
def format(**_args) : def format(**_args) :
@ -60,14 +64,15 @@ def format(**_args) :
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 # We have a casting problem, with relational data-store and JSON objects
# #
if type(_item) == str and (_item.startswith("{") or _item.startswith("{")) : if type(_item) == str and (_item.startswith("[") or _item.startswith("{")) :
try: try:
_item = json.loads(_item) _item = json.loads(_item)
_item = update(_item,_primary_key,_pkvalue)
except Exception as ee : except Exception as ee :
# print (ee) # print (ee)