|
@@ -168,11 +168,12 @@ def get_content(filename,config,section=None) :
|
|
section = section if section else config['SECTION']
|
|
section = section if section else config['SECTION']
|
|
|
|
|
|
x12_file = open(filename).read().split('\n')
|
|
x12_file = open(filename).read().split('\n')
|
|
|
|
+
|
|
if len(x12_file) == 1 :
|
|
if len(x12_file) == 1 :
|
|
|
|
|
|
x12_file = x12_file[0].split('~')
|
|
x12_file = x12_file[0].split('~')
|
|
|
|
|
|
-
|
|
|
|
|
|
+ partitions = '\n'.join(x12_file).split(section+'*')
|
|
locations = get_locations(x12_file,section)
|
|
locations = get_locations(x12_file,section)
|
|
claims = []
|
|
claims = []
|
|
|
|
|
|
@@ -191,12 +192,18 @@ def get_content(filename,config,section=None) :
|
|
|
|
|
|
N = len(locations)
|
|
N = len(locations)
|
|
|
|
|
|
- for index in range(0,N-1):
|
|
|
|
- beg = locations[index]
|
|
|
|
- end = locations[index+1]
|
|
|
|
- claim = {}
|
|
|
|
- for row in x12_file[beg:end] :
|
|
|
|
- row = split(row)
|
|
|
|
|
|
+ # for index in range(0,N-1):
|
|
|
|
+ # beg = locations[index]
|
|
|
|
+ # end = locations[index+1]
|
|
|
|
+ # claim = {}
|
|
|
|
+ for segment in partitions :
|
|
|
|
+
|
|
|
|
+ claim = {}
|
|
|
|
+ # for row in x12_file[beg:end] :
|
|
|
|
+ segment = segment.replace('\n','').split('~')
|
|
|
|
+ for row in segment :
|
|
|
|
+ row = split(row)
|
|
|
|
+
|
|
_info = get_config(config,row)
|
|
_info = get_config(config,row)
|
|
if _info :
|
|
if _info :
|
|
try:
|
|
try:
|
|
@@ -205,11 +212,14 @@ def get_content(filename,config,section=None) :
|
|
# pointer = eval(_info['parser'])
|
|
# pointer = eval(_info['parser'])
|
|
# print (pointer(row))
|
|
# print (pointer(row))
|
|
tmp = get_map(row,_info,VERSION)
|
|
tmp = get_map(row,_info,VERSION)
|
|
|
|
+
|
|
except Exception as e:
|
|
except Exception as e:
|
|
if sys.version_info[0] > 2 :
|
|
if sys.version_info[0] > 2 :
|
|
- logs.append ({"version":VERSION,"filename":filename,"msg":e.args[0],"X12":x12_file[beg:end]})
|
|
|
|
|
|
+ # logs.append ({"version":VERSION,"filename":filename,"msg":e.args[0],"X12":x12_file[beg:end]})
|
|
|
|
+ logs.append ({"version":VERSION,"filename":filename,"msg":e.args[0],"X12":row})
|
|
else:
|
|
else:
|
|
- logs.append ({"version":VERSION,"filename":filename,"msg":e.message,"X12":x12_file[beg:end]})
|
|
|
|
|
|
+ # logs.append ({"version":VERSION,"filename":filename,"msg":e.message,"X12":x12_file[beg:end]})
|
|
|
|
+ logs.append ({"version":VERSION,"filename":filename,"msg":e.message,"X12":row})
|
|
claim = {}
|
|
claim = {}
|
|
break
|
|
break
|
|
|
|
|
|
@@ -231,6 +241,7 @@ def get_content(filename,config,section=None) :
|
|
if type(tmp) == list :
|
|
if type(tmp) == list :
|
|
|
|
|
|
claim[label] = tmp if label not in claim else claim[label] + tmp
|
|
claim[label] = tmp if label not in claim else claim[label] + tmp
|
|
|
|
+
|
|
else:
|
|
else:
|
|
if label not in claim:
|
|
if label not in claim:
|
|
claim[label] = [tmp]
|
|
claim[label] = [tmp]
|
|
@@ -240,14 +251,22 @@ def get_content(filename,config,section=None) :
|
|
claim[label][index] = dict(claim[label][index],**tmp)
|
|
claim[label][index] = dict(claim[label][index],**tmp)
|
|
else:
|
|
else:
|
|
claim[label].append(tmp)
|
|
claim[label].append(tmp)
|
|
-
|
|
|
|
|
|
+ if len(claim[label]) > 0 :
|
|
|
|
+ labels = []
|
|
|
|
+ for item in claim[label] :
|
|
|
|
+ if item not in labels :
|
|
|
|
+ labels.append(item)
|
|
|
|
+ claim[label] = labels
|
|
|
|
+ # claim[label] = list( set(claim[label])) #-- removing redundancies
|
|
|
|
+
|
|
if claim and 'claim_id' in claim:
|
|
if claim and 'claim_id' in claim:
|
|
|
|
|
|
claim = dict(claim,**_default_value)
|
|
claim = dict(claim,**_default_value)
|
|
- claim['name'] = filename[:-5].split(os.sep)[-1] #.replace(ROOT,'')
|
|
|
|
- claim['index'] = index
|
|
|
|
|
|
+ claim['name'] = filename.split(os.sep)[-1] #.replace(ROOT,'')
|
|
|
|
+ claim['index'] = len(claims) if len(claims) > 0 else 0
|
|
claims.append(claim)
|
|
claims.append(claim)
|
|
|
|
|
|
|
|
|
|
|
|
+
|
|
|
|
|
|
return claims,logs
|
|
return claims,logs
|