bug fix with segment setup

This commit is contained in:
Steve Nyemba 2020-10-06 14:12:43 -05:00
parent e6d0725ba7
commit 22800d3bbc
2 changed files with 37 additions and 22 deletions

View File

@ -153,6 +153,8 @@ class Formatters :
return _value return _value
else: else:
return value return value
def procedure(self,value): def procedure(self,value):
for xchar in [':','<'] : for xchar in [':','<'] :
if xchar in value and len(value.split(xchar)) > 1 : if xchar in value and len(value.split(xchar)) > 1 :
@ -263,14 +265,15 @@ class Parser (Process):
# object_value.append( list(get_map(row_item,config,version))) # object_value.append( list(get_map(row_item,config,version)))
# object_value = {label:object_value} # object_value = {label:object_value}
return object_value return object_value
def apply(self,content,_code,default_value) : def apply(self,content,_code) :
""" """
:file content i.e a segment with the envelope :file content i.e a segment with the envelope
:_code 837 or 835 (helps get the appropriate configuration) :_code 837 or 835 (helps get the appropriate configuration)
""" """
util = Formatters() util = Formatters()
claim = default_value.copy() # header = default_value.copy()
value = {} value = {}
for row in content[:] : for row in content[:] :
@ -281,7 +284,10 @@ class Parser (Process):
try: try:
tmp = self.get.value(row,_info) tmp = self.get.value(row,_info)
# if 'P1080351470' in content[0] and 'PLB' in row:
# print (_info)
# print (row)
# print (tmp)
if not tmp : if not tmp :
continue continue
if 'label' in _info : if 'label' in _info :
@ -300,15 +306,18 @@ class Parser (Process):
value[label][index] = dict(value[label][index],**tmp) value[label][index] = dict(value[label][index],**tmp)
else: else:
value[label].append(tmp) value[label].append(tmp)
if len(value[label]) > 0 : tmp['_index'] = len(value[label]) -1
labels = []
for item in value[label] :
item['_index'] = len(labels)
if item not in labels :
labels.append(item) # if len(value[label]) > 0 :
value[label] = labels # labels = []
# for item in value[label] :
# item['_index'] = len(labels)
# if item not in labels :
# labels.append(item)
# value[label] = labels
elif 'field' in _info : elif 'field' in _info :
name = _info['field'] name = _info['field']
value[name] = tmp value[name] = tmp
else: else:
@ -321,7 +330,7 @@ class Parser (Process):
print ('__',e) print ('__',e)
pass pass
return dict(claim,**value) if value else {} return value if value else {}
def get_default_value(self,content,_code): def get_default_value(self,content,_code):
util = Formatters() util = Formatters()
@ -377,7 +386,7 @@ class Parser (Process):
segment = [row] segment = [row]
continue continue
elif segment: elif segment and not row.startswith(section):
segment.append(row) segment.append(row)
@ -386,9 +395,13 @@ class Parser (Process):
# process the segment somewhere (create a thread maybe?) # process the segment somewhere (create a thread maybe?)
# #
default_claim = dict({"index":index},**DEFAULT_VALUE) default_claim = dict({"index":index},**DEFAULT_VALUE)
claim = self.apply(segment,_code,default_claim) _claim = self.apply(segment,_code)
# if _claim['claim_id'] == 'P1080351470' :
claims.append(claim) # print (_claim)
# _claim = dict(DEFAULT_VALUE,**_claim)
if _claim :
_claim['index'] = len(claims)
claims.append(dict(DEFAULT_VALUE,**_claim))
segment = [row] segment = [row]
index += 1 index += 1
@ -399,8 +412,10 @@ class Parser (Process):
if segment[0].startswith(section) : if segment[0].startswith(section) :
default_claim = dict({"name":index},**DEFAULT_VALUE) default_claim = dict({"name":index},**DEFAULT_VALUE)
claim = self.apply(segment,_code,DEFAULT_VALUE) claim = self.apply(segment,_code)
claims.append(claim) if claim :
claim['index'] = len(claims)
claims.append(dict(DEFAULT_VALUE,**claim))
if type(file) != list : if type(file) != list :
file.close() file.close()

View File

@ -8,7 +8,7 @@ import sys
def read(fname): def read(fname):
return open(os.path.join(os.path.dirname(__file__), fname)).read() return open(os.path.join(os.path.dirname(__file__), fname)).read()
args = { args = {
"name":"healthcareio","version":"1.3.4", "name":"healthcareio","version":"1.3.5",
"author":"Vanderbilt University Medical Center", "author":"Vanderbilt University Medical Center",
"author_email":"steve.l.nyemba@vumc.org", "author_email":"steve.l.nyemba@vumc.org",
"license":"MIT", "license":"MIT",