|
|
|
"""
|
|
|
|
(c) 2019 EDI-Parser 1.0
|
|
|
|
Vanderbilt University Medical Center, Health Information Privacy Laboratory
|
|
|
|
https://hiplab.mc.vanderbilt.edu/tools
|
|
|
|
|
|
|
|
|
|
|
|
Authors:
|
|
|
|
Khanhly Nguyen,
|
|
|
|
Steve L. Nyemba<steve.l.nyemba@vanderbilt.edu>
|
|
|
|
|
|
|
|
License:
|
|
|
|
MIT, terms are available at https://opensource.org/licenses/MIT
|
|
|
|
|
|
|
|
This parser was originally written by Khanhly Nguyen for her internship and is intended to parse x12 835,837 and others provided the appropriate configuration
|
|
|
|
USAGE :
|
|
|
|
- COMMAND LINE
|
|
|
|
|
|
|
|
- EMBEDDED
|
|
|
|
"""
|
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
def split(row,sep='*',prefix='HI'):
|
|
|
|
"""
|
|
|
|
This function is designed to split an x12 row and
|
|
|
|
"""
|
|
|
|
if row.startswith(prefix) is False:
|
|
|
|
value = []
|
|
|
|
for row_value in row.replace('~','').split(sep) :
|
|
|
|
|
|
|
|
if '>' in row_value :
|
|
|
|
if row_value.startswith('HC') or row_value.startswith('AD'):
|
|
|
|
|
|
|
|
value += row_value.split('>')[:2]
|
|
|
|
else:
|
|
|
|
value += row_value.split('>')
|
|
|
|
else :
|
|
|
|
value.append(row_value)
|
|
|
|
return [xchar.replace('\r','') for xchar in value] #row.replace('~','').split(sep)
|
|
|
|
else:
|
|
|
|
|
|
|
|
return [ [prefix]+ split(item,'>') for item in row.replace('~','').split(sep)[1:] ]
|
|
|
|
def get_config(config,row):
|
|
|
|
"""
|
|
|
|
This function will return the meaningfull parts of the configuration for a given item
|
|
|
|
"""
|
|
|
|
_row = list(row) if type(row[0]) == str else list(row[0])
|
|
|
|
|
|
|
|
if type(row[0]) == str:
|
|
|
|
object_value = {}
|
|
|
|
for key in omap :
|
|
|
|
index = omap[key]
|
|
|
|
if anchors and set(anchors) & set(row):
|
|
|
|
_key = list(set(anchors) & set(row))[0]
|
|
|
|
|
|
|
|
aindex = row.index(_key)
|
|
|
|
index = aindex + index
|
|
|
|
|
|
|
|
if index < len(row) :
|
|
|
|
value = row[index]
|
|
|
|
:section loop prefix (HL, CLP)
|
|
|
|
logs.append ({"version":VERSION,"filename":filename,"msg":e.args[0],"X12":x12_file[beg:end]})
|
|
|
|
else:
|
|
|
|
logs.append ({"version":VERSION,"filename":filename,"msg":e.message,"X12":x12_file[beg:end]})
|
|
|
|
claim = {}
|
|
|
|
break
|
|
|
|
|
|
|
|
if 'label' not in _info :
|