From 0bbcff95dc4aecd484e60215728bd57ab6f190ca Mon Sep 17 00:00:00 2001 From: Steve Nyemba Date: Fri, 12 Feb 2021 18:00:41 -0600 Subject: [PATCH] bug fix ... --- healthcareio/x12/__init__.py | 38 ++++++++++++++++++++++++------------ setup.py | 2 +- 2 files changed, 26 insertions(+), 14 deletions(-) diff --git a/healthcareio/x12/__init__.py b/healthcareio/x12/__init__.py index 8f14b39..abe1d2e 100644 --- a/healthcareio/x12/__init__.py +++ b/healthcareio/x12/__init__.py @@ -376,15 +376,20 @@ class Parser (Process): 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 'DTM' in row : + # print ([label,tmp,label in value]) + if label not in value : + value[label] = [] + value[label].append(tmp) + # if label not in value: - value[label] = [tmp] - else: - value[label].append(tmp) + # value[label] = [tmp] + # else: + # value[label].append(tmp) tmp['_index'] = len(value[label]) -1 elif 'field' in _info : @@ -394,7 +399,7 @@ class Parser (Process): value = jsonmerge.merge(value,{name:tmp}) else: - + value = dict(value,**tmp) pass @@ -490,7 +495,8 @@ class Parser (Process): if _claim : _claim['index'] = index #len(claims) - claims.append(dict(DEFAULT_VALUE,**_claim)) + # claims.append(dict(DEFAULT_VALUE,**_claim)) + claims.append( jsonmerge.merge(DEFAULT_VALUE,_claim)) segment = [row] index += 1 @@ -503,13 +509,19 @@ class Parser (Process): claim = self.apply(segment,_code) if claim : - claim['index'] = len(claims) - # for _row_ in _toprows : - - # claim = jsonmerge.merge(claim,self.apply([_row_],_code)) - claim = jsonmerge.merge(claim,self.apply(_toprows,_code)) - claims.append(dict(DEFAULT_VALUE,**claim)) + schema = [key for key in claim.keys() if type(claim[key]) == list] + if schema : + schema = {"properties":dict.fromkeys(schema,{"mergeStrategy":"append"})} + print (schema) + else: + schema = {} + merger = jsonmerge.Merger(schema) + top_row_claim = self.apply(_toprows,_code) + + claim = merger.merge(claim,self.apply(_toprows,_code)) + # claims.append(dict(DEFAULT_VALUE,**claim)) + claims.append(merger.merge(DEFAULT_VALUE,claim)) if type(file) != list : file.close() diff --git a/setup.py b/setup.py index 65c4811..08ef9ab 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.6.2.1", + "name":"healthcareio","version":"1.6.2.2", "author":"Vanderbilt University Medical Center", "author_email":"steve.l.nyemba@vumc.org", "include_package_data":True,