From 2e815a0a0d889fce77aef444dea05279d1212f2a Mon Sep 17 00:00:00 2001 From: Steve Nyemba Date: Tue, 9 Mar 2021 09:57:01 -0600 Subject: [PATCH] bug fix: adding references using cache --- healthcareio/x12/__init__.py | 41 ++++++++++++++++++++++++++++++------ 1 file changed, 35 insertions(+), 6 deletions(-) diff --git a/healthcareio/x12/__init__.py b/healthcareio/x12/__init__.py index fbbfe2a..4b43492 100644 --- a/healthcareio/x12/__init__.py +++ b/healthcareio/x12/__init__.py @@ -217,9 +217,9 @@ class Parser (Process): self._custom_config = self.get_custom(path) self.config = _config['parser'] self.store = _config['store'] - - self.files = [] - self.set = void() + self.cache = {} + self.files = [] + self.set = void() self.set.files = self.set_files self.emit = void() self.emit.pre = None @@ -349,6 +349,24 @@ class Parser (Process): # object_value = {label:object_value} return object_value + def set_cache(self,tmp,_info) : + """ + insert into cache a value that the, these are in reference to a loop + """ + if 'cache' in _info : + key = _info['cache']['key'] + value=_info['cache']['value'] + field = _info['cache']['field'] + if value in tmp : + self.cache [key] = {field:tmp[value]} + pass + def get_cache(self,row) : + """ + retrieve cache element for a current + """ + key = row[0] + return self.cache[key] if key in self.cache else {} + pass def apply(self,content,_code) : """ :content content of a file i.e a segment with the envelope @@ -375,12 +393,15 @@ class Parser (Process): _info = jsonmerge.merge(_info,_cinfo) tmp = self.get.value(row,_info) - # - # let's prune the objects not found - if not tmp : continue + # + # At this point we have the configuration and the row parsed into values + # We should check to see if we don't have anything in the cache to be added to it + # + if row[0] in self.cache : + tmp = jsonmerge.merge(tmp,self.get_cache(row)) if 'label' in _info : label = _info['label'] @@ -417,7 +438,15 @@ class Parser (Process): print (e.args[0]) # print ('__',(dir(e.args))) pass + # + # At this point the object is completely built, + # if there ar any attributes to be cached it will be done here + # + if 'cache' in _info : + + self.set_cache(tmp,_info) + return value if value else {} def get_default_value(self,content,_code):