bug fix: object merger

master
Steve L. Nyemba 4 years ago
parent 870b703296
commit 760eba62e1

@ -512,17 +512,26 @@ class Parser (Process):
_claim['index'] = index #len(claims) _claim['index'] = index #len(claims)
# claims.append(dict(DEFAULT_VALUE,**_claim)) # claims.append(dict(DEFAULT_VALUE,**_claim))
# #
schema = [key for key in _claim.keys() if type(_claim[key]) == list] # schema = [ {key:{"mergeStrategy":"append" if list( type(_claim[key])) else "overwrite"}} for key in _claim.keys()] # if type(_claim[key]) == list]
if schema : # _schema = set(DEFAULT_VALUE.keys()) - schema
schema = {"properties":dict.fromkeys(schema,{"mergeStrategy":"append"})} # if schema :
# schema = {"properties":dict.fromkeys(schema,{"mergeStrategy":"append"})}
else: # else:
schema = None
# schema = {"properties":{}}
# schema = jsonmerge.merge(schema['properties'],dict.fromkeys(_schema,{"mergeStrategy":"overwrite"}))
schema = {"properties":{}}
for attr in _claim.keys() :
schema['properties'][attr] = {"mergeStrategy": "append" if type(_claim[attr]) == list else "overwrite" }
merger = jsonmerge.Merger(schema) merger = jsonmerge.Merger(schema)
if not schema : _baseclaim = None
merger = jsonmerge _baseclaim = merger.merge(_baseclaim,DEFAULT_VALUE.copy())
_claim = merger.merge(_baseclaim,_claim)
_claim = merger.merge(DEFAULT_VALUE.copy(),_claim) # _claim = merger.merge(DEFAULT_VALUE.copy(),_claim)
claims.append( _claim) claims.append( _claim)
segment = [row] segment = [row]
@ -539,22 +548,30 @@ class Parser (Process):
claim = self.apply(segment,_code) claim = self.apply(segment,_code)
if claim : if claim :
claim['index'] = len(claims) claim['index'] = len(claims)
schema = [key for key in claim.keys() if type(claim[key]) == list] # schema = [key for key in claim.keys() if type(claim[key]) == list]
if schema : # if schema :
schema = {"properties":dict.fromkeys(schema,{"mergeStrategy":"append"})} # schema = {"properties":dict.fromkeys(schema,{"mergeStrategy":"append"})}
else: # else:
schema = None # print (claim.keys())
# schema = {}
# #
# @TODO: Fix merger related to schema (drops certain fields ... NOT cool) # @TODO: Fix merger related to schema (drops certain fields ... NOT cool)
if not schema :
merger = jsonmerge # merger = jsonmerge.Merger(schema)
merger = jsonmerge.Merger(schema)
# top_row_claim = self.apply(_toprows,_code) # top_row_claim = self.apply(_toprows,_code)
# claim = merger.merge(claim,self.apply(_toprows,_code)) # claim = merger.merge(claim,self.apply(_toprows,_code))
# claims.append(dict(DEFAULT_VALUE,**claim)) # claims.append(dict(DEFAULT_VALUE,**claim))
claims.append(merger.merge(DEFAULT_VALUE.copy(),claim)) schema = {"properties":{}}
for attr in _claim.keys() :
schema['properties'][attr] = {"mergeStrategy": "append" if type(_claim[attr]) == list else "overwrite" }
_baseclaim = None
_baseclaim = merger.merge(_baseclaim,DEFAULT_VALUE.copy())
claim = merger.merge(_baseclaim,claim)
claims.append(claim)
# claims.append(merger.merge(DEFAULT_VALUE.copy(),claim))
if type(file) != list : if type(file) != list :
file.close() file.close()

@ -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.6.2.18", "name":"healthcareio","version":"1.6.2.20",
"author":"Vanderbilt University Medical Center", "author":"Vanderbilt University Medical Center",
"author_email":"steve.l.nyemba@vumc.org", "author_email":"steve.l.nyemba@vumc.org",
"include_package_data":True, "include_package_data":True,

Loading…
Cancel
Save