body.py 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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. '45':{'field':'ambulance_location'},
  27. 'IL':{'field':'patient','map':{'type':2,'first_name':4,'last_name':3}},
  28. 'P5':{'field':'plan_sponsor'},
  29. '82':{'field':'rendering_provider','map':{'type':2,'first_name':4,'last_name':3}},
  30. '85':{'field':'billing_provider'},
  31. }
  32. _args ['plugin-context'] = {'@ref':CONTEXT_MAP}
  33. # _map = {_CODE_INDEX:{'41':'submitter','40':'receiver','PR':'payer'}}
  34. _columns = ['type','name','id']
  35. _indexes = [1,3,-1]
  36. # _info = [{'index':'40','field':'receiver'},{'index':'41','field':'submitter'},{'index':'PR','field':'payer'}]
  37. _info = self.parse(_columns,_indexes,**_args)
  38. self.lastelement = _info
  39. return _info
  40. def N3 (self,**_args):
  41. """
  42. Expected Element N3
  43. """
  44. _columns = ['address_line_1']
  45. return self.parse(_columns,[1,2],**_args)
  46. def N4(self,**_args):
  47. """
  48. Expected Element N4
  49. """
  50. _columns = ['city','state','zip']
  51. return self.parse(_columns,[1,2,3],**_args)
  52. def HI(self,**_args):
  53. """
  54. Expected Element HI
  55. This function will parse diagnosis codes ICD 9/10
  56. """
  57. _columns = ['code','type']
  58. return self.parse(_columns,[2,1],**_args)
  59. def AMT (self,**_args):
  60. """
  61. Expected Element AMT
  62. """
  63. _columns = ['amount','qualifier']
  64. return self.parse(_columns,[2,1],**_args)
  65. def SBR (self,**_args):
  66. """
  67. Expected Element SBR
  68. """
  69. _index = [9,1]
  70. _columns = ['vendor','individual_code','type']
  71. return self.parse(_columns,[9,2,1],**_args)
  72. def DMG (self,**_args):
  73. """
  74. Expected Element DMG, these need to be stored in a patient object
  75. """
  76. _columns = ['dob','gender','format']
  77. _info = self.parse(_columns,[2,3,1],**_args)
  78. return {'patient':_info}
  79. def DTP (self,**_args):
  80. """
  81. Expected Element DTP
  82. """
  83. _columns = ['to','from','type']
  84. return self.parse(_columns,[3],**_args)
  85. def PER (self,**_args):
  86. """
  87. Expected Element PER
  88. """
  89. _CODE_INDEX = 1
  90. _map = {_CODE_INDEX:{'IC':'submitter'}} # attribute to store the data in
  91. _columns = ['contact_name','phone','email']
  92. _info = self.parse (_columns,[2,4,8],**_args)
  93. #
  94. # @TODO: Inspect the configuration file for the attribute information
  95. #
  96. return _info
  97. def CLM (self,**_args):
  98. """
  99. Expected Element CLM
  100. """
  101. _columns = ['claim_id','claim_amount','facility_code','facility_qualifier','frequency_code']
  102. return self.parse(_columns,[1,2,5,5,5],**_args)
  103. def REF (self,**_args):
  104. _columns = ['identifier','qualifier','']
  105. _CODE_INDEX = 1 # -- according to x12 standard
  106. _map = {_CODE_INDEX:{'EA':'patient','EI':'provider','6R':'','D9':''}}
  107. return self.parse(_columns,[2],**_args)
  108. def HI (self,**_args):
  109. """
  110. Expected Element HI
  111. """
  112. _columns = ['code','type']
  113. return self.parse(_columns,[1,2],**_args)
  114. def SV1 (self,**_args):
  115. """
  116. Expected Element SV1
  117. """
  118. _row = _args['row'] if type(_args['row']) == list else _args['row'].split('*')
  119. _columns = ['type','code','amount','modifier_1','modifier_2','modifier_3','modifier_4','place_of_service','units','measurement']
  120. return self.parse(_columns,[1,1,2,1,1,1,1,5,4,3],**_args)
  121. def SV3 (self,**_args):
  122. return self.SV1(**_args)
  123. def HL (self,**_args) :
  124. """,
  125. Expected Element HL
  126. The expected block is supposed to be unprocessed (to make things simple)
  127. """
  128. # _row = _args['row'] if type(_args['row']) == list else _args['row'].split('~')
  129. # _attr = self.elements() #[_name for _name in dir() if not _name.islower() and not _name.startswith('_')]
  130. # _pointers = [getattr(self,_name) for _name in _attr]
  131. # _map = dict(zip(_attr,_pointers))
  132. _map = self.pointers()
  133. #
  134. # The index here tells us what we are processing i.e index == 1 something about header
  135. #
  136. _columns = ['_index','parent','code','child']
  137. # _args['row'] = _row[0]
  138. _info = self.parse (_columns,[1,2,3,4],**_args)
  139. # _field = 'billing_provider' if _info['_index'] == '1' else 'patient'
  140. # _config ={'field':_field}
  141. return _info