body.py 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. from .common import X12DOCUMENT
  2. from .header import HEADER
  3. import numpy as np
  4. class BODY (HEADER):
  5. """
  6. This class will contain functions that will parse elements associated with the claim body
  7. """
  8. def BHT (self,**_args):
  9. """
  10. Expected Element BHT
  11. This functiion will process header submitted (receiver,claim_type,)
  12. """
  13. _columns= ['receiver_id','submitted_date','submitted_time','claim_type']
  14. return self.parse(_columns,[3,7],**_args)
  15. def NM1 (self,**_args):
  16. """
  17. Expected Element NM1
  18. ref IL,40,41,82,85,PR ...
  19. Information about entities (doctors, clearing house, provider). we should be mindful of the references
  20. """
  21. _CODE_INDEX = 1
  22. CONTEXT_MAP = {
  23. '2':{'field':'payer'},
  24. 'PR':{'field':'payer'},
  25. '41':{'field':'header'},
  26. 'IL':{'field':'patient','map':{'type':2,'first_name':4,'last_name':3}},
  27. 'P5':{'field':'plan_sponsor'},
  28. '82':{'field':'rendering_provider','map':{'type':2,'first_name':4,'last_name':3}},
  29. '85':{'field':'billing_provider'}
  30. }
  31. _args ['plugin-context'] = {'@ref':CONTEXT_MAP}
  32. # _map = {_CODE_INDEX:{'41':'submitter','40':'receiver','PR':'payer'}}
  33. _columns = ['type','name','id']
  34. _indexes = [1,3,-1]
  35. # _info = [{'index':'40','field':'receiver'},{'index':'41','field':'submitter'},{'index':'PR','field':'payer'}]
  36. _info = self.parse(_columns,_indexes,**_args)
  37. self.lastelement = _info
  38. return _info
  39. def N3 (self,**_args):
  40. """
  41. Expected Element N3
  42. """
  43. _columns = ['address_line_1']
  44. return self.parse(_columns,[1,2],**_args)
  45. def N4(self,**_args):
  46. """
  47. Expected Element N4
  48. """
  49. _columns = ['city','state','zip']
  50. return self.parse(_columns,[1,2,3],**_args)
  51. def HI(self,**_args):
  52. """
  53. Expected Element HI
  54. This function will parse diagnosis codes ICD 9/10
  55. """
  56. _columns = ['code','type']
  57. return self.parse(_columns,[2,1],**_args)
  58. def AMT (self,**_args):
  59. """
  60. Expected Element AMT
  61. """
  62. _columns = ['amount','qualifier']
  63. return self.parse(_columns,[2,1],**_args)
  64. def SBR (self,**_args):
  65. """
  66. Expected Element SBR
  67. """
  68. _index = [9,1]
  69. _columns = ['vendor','individual_code','type']
  70. return self.parse(_columns,[9,2,1],**_args)
  71. def DMG (self,**_args):
  72. """
  73. Expected Element DMG
  74. """
  75. _columns = ['dob','gender','format']
  76. _info = self.parse(_columns,[2,3,1],**_args)
  77. return _info
  78. def DTP (self,**_args):
  79. """
  80. Expected Element DTP
  81. """
  82. _columns = ['to','from','type']
  83. return self.parse(_columns,[3],**_args)
  84. def PER (self,**_args):
  85. """
  86. Expected Element PER
  87. """
  88. _CODE_INDEX = 1
  89. _map = {_CODE_INDEX:{'IC':'submitter'}} # attribute to store the data in
  90. _columns = ['contact_name','phone','email']
  91. _info = self.parse (_columns,[2,4,8],**_args)
  92. #
  93. # @TODO: Inspect the configuration file for the attribute information
  94. #
  95. return _info
  96. def CLM (self,**_args):
  97. """
  98. Expected Element CLM
  99. """
  100. _columns = ['claim_id','claim_amount','facility_code','facility_qualifier','frequency_code']
  101. return self.parse(_columns,[1,2,5,5,5],**_args)
  102. def REF (self,**_args):
  103. _columns = ['identifier','qualifier','']
  104. _CODE_INDEX = 1 # -- according to x12 standard
  105. _map = {_CODE_INDEX:{'EA':'patient','EI':'provider','6R':'','D9':''}}
  106. return self.parse(_columns,[2],**_args)
  107. def HI (self,**_args):
  108. """
  109. Expected Element HI
  110. """
  111. _columns = ['code','type']
  112. return self.parse(_columns,[1,2],**_args)
  113. def SV1 (self,**_args):
  114. """
  115. Expected Element SV1
  116. """
  117. _row = _args['row'] if type(_args['row']) == list else _args['row'].split('*')
  118. _columns = ['type','code','amount','modifier_1','modifier_2','modifier_3','modifier_4','place_of_service','units','measurement']
  119. return self.parse(_columns,[1,1,2,1,1,1,1,5,4,3],**_args)
  120. def SV3 (self,**_args):
  121. return self.SV1(**_args)
  122. def HL (self,**_args) :
  123. """,
  124. Expected Element HL
  125. The expected block is supposed to be unprocessed (to make things simple)
  126. """
  127. _row = _args['row'] if type(_args['row']) == list else _args['row'].split('~')
  128. # _attr = self.elements() #[_name for _name in dir() if not _name.islower() and not _name.startswith('_')]
  129. # _pointers = [getattr(self,_name) for _name in _attr]
  130. # _map = dict(zip(_attr,_pointers))
  131. _map = self.pointers()
  132. #
  133. # The index here tells us what we are processing i.e index == 1 something about header
  134. #
  135. _columns = ['_index','parent','code','child']
  136. _args['row'] = _row[0]
  137. _info = self.parse (_columns,[1,2,3,4],**_args)
  138. # _field = 'billing_provider' if _info['_index'] == '1' else 'patient'
  139. # _config ={'field':_field}
  140. return _info
  141. # _claim = {_field:_info}
  142. # for _element in _row[1:] :
  143. # _key = _element.split('*')[0]
  144. # if _key in _map and len(_element) > 0:
  145. # _document = _args['document']
  146. # _pointer = _map[_key]
  147. # if _key not in ['CLM','HI','SV3','SV2','SV1'] :
  148. # _claim = self.merge (_claim,_pointer(row=_element.strip().split('*'),document=_document,config=_config))
  149. # else:
  150. # _config = _args['config'] if 'config' in _args else {}
  151. # _claim = self.merge (_claim,_pointer(row=_element.strip().split('*'),document=_document,config=_config))
  152. # else:
  153. # print (['SKIPPING ',_key])
  154. # pass
  155. # return _claim
  156. # def apply(self,_block):
  157. # """
  158. # :_block elements that do not belong to the header block
  159. # """
  160. # _apply = self.pointers()
  161. # _header = {}
  162. # if _block :
  163. # for content in _block :
  164. # _KEY_ELEMENT = content.split('*')[0]
  165. # if _KEY_ELEMENT not in _apply :
  166. # #
  167. # # @TODO: Log elements that are skipped
  168. # # print ([_KEY_ELEMENT , 'NOT FOUND'])
  169. # continue
  170. # _info = _apply[_KEY_ELEMENT](row=content,document=_header)
  171. # if _info :
  172. # if not _header :
  173. # _header = _info
  174. # else:
  175. # _header = self.merge(_header,_info)
  176. # else:
  177. # #
  178. # # For some reason the parser failed by returning a null
  179. # # @TODO: Log this event ....
  180. # pass
  181. # else:
  182. # #
  183. # # @TODO: return the meta data for what is expected
  184. # pass
  185. # return _header