diff --git a/healthcareio/x12/__init__.py b/healthcareio/x12/__init__.py index f9fae46..e5dbcce 100644 --- a/healthcareio/x12/__init__.py +++ b/healthcareio/x12/__init__.py @@ -153,6 +153,8 @@ class Formatters : return _value else: return value + + def procedure(self,value): for xchar in [':','<'] : 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 = {label: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 :_code 837 or 835 (helps get the appropriate configuration) """ util = Formatters() - claim = default_value.copy() + # header = default_value.copy() value = {} for row in content[:] : @@ -281,34 +284,40 @@ class Parser (Process): try: tmp = self.get.value(row,_info) - + # if 'P1080351470' in content[0] and 'PLB' in row: + # print (_info) + # print (row) + # print (tmp) if not tmp : continue if 'label' in _info : label = _info['label'] - + if type(tmp) == list : value[label] = tmp if label not in value else value[label] + tmp else: - if label not in value: + if label not in value: value[label] = [tmp] elif len(list(tmp.keys())) == 1 : # print "\t",len(claim[label]),tmp index = len(value[label]) -1 value[label][index] = dict(value[label][index],**tmp) else: - value[label].append(tmp) - if len(value[label]) > 0 : - labels = [] - for item in value[label] : - item['_index'] = len(labels) - if item not in labels : + value[label].append(tmp) + tmp['_index'] = len(value[label]) -1 + + # if len(value[label]) > 0 : + # labels = [] + # for item in value[label] : + # item['_index'] = len(labels) + # if item not in labels : - labels.append(item) - value[label] = labels + # labels.append(item) + # value[label] = labels elif 'field' in _info : + name = _info['field'] value[name] = tmp else: @@ -320,8 +329,8 @@ class Parser (Process): except Exception as e : print ('__',e) pass - - return dict(claim,**value) if value else {} + + return value if value else {} def get_default_value(self,content,_code): util = Formatters() @@ -377,7 +386,7 @@ class Parser (Process): segment = [row] continue - elif segment: + elif segment and not row.startswith(section): segment.append(row) @@ -386,9 +395,13 @@ class Parser (Process): # process the segment somewhere (create a thread maybe?) # default_claim = dict({"index":index},**DEFAULT_VALUE) - claim = self.apply(segment,_code,default_claim) - - claims.append(claim) + _claim = self.apply(segment,_code) + # if _claim['claim_id'] == 'P1080351470' : + # print (_claim) + # _claim = dict(DEFAULT_VALUE,**_claim) + if _claim : + _claim['index'] = len(claims) + claims.append(dict(DEFAULT_VALUE,**_claim)) segment = [row] index += 1 @@ -399,8 +412,10 @@ class Parser (Process): if segment[0].startswith(section) : default_claim = dict({"name":index},**DEFAULT_VALUE) - claim = self.apply(segment,_code,DEFAULT_VALUE) - claims.append(claim) + claim = self.apply(segment,_code) + if claim : + claim['index'] = len(claims) + claims.append(dict(DEFAULT_VALUE,**claim)) if type(file) != list : file.close() diff --git a/setup.py b/setup.py index 9eb4ebc..b535a0b 100644 --- a/setup.py +++ b/setup.py @@ -8,7 +8,7 @@ import sys def read(fname): return open(os.path.join(os.path.dirname(__file__), fname)).read() args = { - "name":"healthcareio","version":"1.3.4", + "name":"healthcareio","version":"1.3.5", "author":"Vanderbilt University Medical Center", "author_email":"steve.l.nyemba@vumc.org", "license":"MIT",