123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156 |
- """
- This package contains tools used across the various modules, these tools actually "do the work"
- We intend to have these tools be Object-Oriented by design so as to not run into any concurrency issues
- """
- from . import file, document
- from healthcareio import x12
- from multiprocessing import Process
- # class X12Engine(Process):
- # def __init__(self,**_args):
- # """
- # :files group of files to be processed
- # """
- # self.files = _args['files']
- # self._cHandler = file.Content()
- # self._dHandler = document.Builder(plugins=_args['plugins'],parents=_args['plugins'])
- # def run(self):
- # """
- # This function performs parsing given
- # """
- # for _location in self.files :
- # _content = self._cHandler.read(_location)
- # _content = self._cHandler.split(_content)
-
- # pass
- def merge (_x,_y):
- """
- This function will merge two objects _x, _y
- """
- _zcols = list(set(_x.keys()) & set(_y.keys())) #--common columns
-
- if _zcols :
- _out = dict(_x,**{})
- for _key in list(_y.keys()) :
-
-
- if _key not in _zcols and _key:
- _out[_key] = _y[_key]
- else:
- if type(_out[_key]) == list :
- for value in _y[_key] :
- if value not in _out[_key] :
- _out[_key].append(value)
- # _out[_key] += _y[_key]
- elif type(_out[_key]) == dict:
- _out[_key] = dict(_out[_key],**_y[_key])
- else:
- _out[_key] = _y[_key]
-
- return _out
- else:
-
- return dict(_x,**_y)
- def template(**_args) :
- """
- This function generates an object template to be used in object assignment and export functionalities
- We chose to proceed in this manner so as to enforce consistency of the parser
- :plugins {*,837,835} with element and pointers associated
- """
- _plugins = _args['plugins']
- _object = {'837':{},'835':{}}
- for _x12 in _plugins :
- _pointers = _plugins[_x12]
- for _element in _pointers :
- _meta = _pointers[_element].meta
- _values = _meta['map'].values() if 'map' in _meta else _meta['columns']
- #
- # where do the attributes go ..
- #
- _attr = []
- for _item in list(_values) :
- if type(_item) == list :
- _attr = _attr + _item
- else:
- _attr.append(_item)
- _field = []
- if 'field' in _meta or 'container' in _meta :
- _field = _meta['field'] if 'field' in _meta else _meta['container']
-
- if 'anchor' in _meta : #-- No parents are expected
- _field = _meta['anchor'].values()
-
- elif _meta['parent'] :
- #
- # It means the attributes will be
- _parentPlug = x12.plugins.filter(elements=[_meta['parent']],plugins=_plugins)
- _pid = list(_parentPlug.keys())[0]
- _parentMeta = _parentPlug[_pid][_meta['parent']].meta
-
- _attr = _attr + list(_parentMeta['map'].values()) if 'map' in _parentMeta else _parentMeta['columns']
- if 'anchor' in _parentMeta :
- _field = list(_parentMeta['anchor'].values())
- _field = [_field] if type(_field) == str else _field
- _attr = dict.fromkeys(_attr,'')
- if not _field :
- _info = (_attr)
- else:
- _info = (dict.fromkeys(_field,_attr))
- if _x12 == '*' :
-
- _object['837']= merge(_object['837'], _info)
- _object['835']= merge (_object['835'], _info)
- else:
- _object[_x12] = merge(_object[_x12],_info)
- return _object
- # def template(**_args) :
- # """
- # This function generates an object template to be used in object assignment and export functionalities
- # We chose to proceed in this manner so as to enforce consistency of the parser
- # :plugins {*,837,835} with element and pointers associated
- # """
- # _plugins = _args['plugins']
- # _object = {'837':{},'835':{}}
- # for _x12 in _plugins :
- # _pointers = _plugins[_x12]
- # for _element in _pointers :
- # _meta = _pointers[_element].meta
- # _values = _meta['map'].values() if 'map' in _meta else _meta['columns']
- # #
- # # where do the attributes go ..
- # #
- # _attr = []
- # for _item in list(_values) :
- # if type(_item) == list :
- # _attr = _attr + _item
- # else:
- # _attr.append(_item)
- # _field = []
- # if 'field' in _meta or 'container' in _meta :
- # _field = _meta['field'] if 'field' in _meta else _meta['container']
-
- # if 'anchor' in _meta : #-- No parents are expected
- # _field = _meta['anchor'].values()
-
- # elif _meta['parent'] :
- # #
- # # It means the attributes will be
- # _parentPlug = filter(elements=[_meta['parent']],plugins=_plugins)
- # _pid = list(_parentPlug.keys())[0]
- # _parentMeta = _parentPlug[_pid][_meta['parent']].meta
-
- # _attr = _attr + list(_parentMeta['map'].values()) if 'map' in _parentMeta else _parentMeta['columns']
- # if 'anchor' in _parentMeta :
- # _field = list(_parentMeta['anchor'].values())
- # _field = [_field] if type(_field) == str else _field
- # _attr = dict.fromkeys(_attr,'')
- # if not _field :
- # _info = (_attr)
- # else:
- # _info = (dict.fromkeys(_field,_attr))
- # if _x12 == '*' :
-
- # _object['837']= merge(_object['837'], _info)
- # _object['835']= merge (_object['835'], _info)
- # else:
- # _object[_x12] = merge(_object[_x12],_info)
- # return _object
|