parser/healthcareio/x12/plugins/default/claims.py

191 lines
7.0 KiB
Python
Raw Permalink Normal View History

2023-11-21 18:56:35 +00:00
import numpy as np
from .. import parser
from datetime import datetime
2024-02-06 03:56:46 +00:00
@parser(element='NM1',x12='*', anchor={'41':'submitter','40':'receiver','82':'rendering_provider','85':'billing_provider','87':'pay_to_provider','IL':'patient','PR':'payer','QC':'patient','DN':'referring_provider','77':'provider','2':'billing_provider'}, map={1:'type',3:'name_1',4:'name_2',-1:'id'})
2023-11-21 18:56:35 +00:00
def NM1 (**_args):
"""
Expected Element NM1
ref IL,40,41,82,85,PR ...
Information about entities (doctors, clearing house, provider). we should be mindful of the references
"""
# _CODE_INDEX = 1
# CONTEXT_MAP = {
# '2':{'field':'payer'},
# 'PR':{'field':'payer'},
# '41':{'field':'header'},
# '45':{'field':'ambulance_location'},
# 'IL':{'field':'patient','map':{'type':2,'first_name':4,'last_name':3}},
# 'P5':{'field':'plan_sponsor'},
# '82':{'field':'rendering_provider','map':{'type':2,'first_name':4,'last_name':3}},
# '85':{'field':'billing_provider'},
# }
# _args ['plugin-context'] = {'@ref':CONTEXT_MAP}
# # _map = {_CODE_INDEX:{'41':'submitter','40':'receiver','PR':'payer'}}
# _columns = ['type','name','id']
# _indexes = [1,3,-1]
# # _info = [{'index':'40','field':'receiver'},{'index':'41','field':'submitter'},{'index':'PR','field':'payer'}]
# _pointer = _args['parser']
# _info = _pointer(_columns,_indexes,**_args)
# self.lastelement = _info
# return _info
pass
@parser(element='N3',x12='837', parent='NM1',map={1:'address_line_1',2:'address_line_2'})
def N3 (**_args):
"""
Expected Element N3
"""
pass
# _columns = ['address_line_1']
# return self.parse(_columns,[1,2],**_args)
@parser(element='N4',x12='*',parent='NM1',map={1:'city',2:'state',3:'zipcode'})
def N4(**_args):
"""
Expected Element N4
"""
# _columns = ['city','state','zip']
# return self.parse(_columns,[1,2,3],**_args)
pass
@parser(element='HI',x12='837', map={1:'type',2:'code'})
def HI(**_args):
"""
Expected Element HI
This function will parse diagnosis codes ICD 9/10
"""
# _columns = ['code','type']
# return self.parse(_columns,[2,1],**_args)
pass
@parser(element='AMT',x12='837',map={2:'patient_amount',1:'patient_amount_qualifier'})
def AMT (**_args):
"""
Expected Element AMT
"""
# _columns = ['amount','qualifier']
# return self.parse(_columns,[2,1],**_args)
pass
@parser(element='SBR',x12='837',field='subscriber',map={9:'vendor',2:'individual_code',1:'type'})
def SBR (**_args):
"""
Expected Element SBR
"""
# _index = [9,1]
# _columns = ['vendor','individual_code','type']
# return self.parse(_columns,[9,2,1],**_args)
pass
@parser(element='DMG',x12='837', field='patient',map={2:'dob',3:'gender',1:'format'})
def DMG (**_args):
"""
Expected Element DMG, these need to be stored in a patient object
"""
_data = _args['data']
_y = _data['dob'][:4]
_m= _data['dob'][4:6]
_d = _data['dob'][6:].strip()
_data['dob'] = datetime(year=int(_y), month=int(_m),day=int(_d))
return _data
# _columns = ['dob','gender','format']
# _info = self.parse(_columns,[2,3,1],**_args)
# return {'patient':_info}
pass
2023-12-01 03:38:06 +00:00
@parser(element='DTP', x12='837', field='date',map={3:['end_date','start_date']})
2023-11-21 18:56:35 +00:00
def DTP (**_args):
"""
Expected Element DTP
"""
# _columns = ['to','from','type']
# return self.parse(_columns,[3],**_args)
_data = _args['data']
2023-12-01 18:16:10 +00:00
_data['end_date'] = '-'.join([_data['end_date'][:4],_data['end_date'][4:6],_data['end_date'][6:]])
_data['start_date'] = '-'.join([_data['start_date'][:4],_data['start_date'][4:6],_data['start_date'][6:]])
2023-11-21 18:56:35 +00:00
return _data
pass
@parser(element='PER',anchor={'IC':'submitter'},map={2:'contact',4:'phone_number',8:'email'})
def PER (**_args):
"""
Expected Element PER
"""
# _CODE_INDEX = 1
# _map = {_CODE_INDEX:{'IC':'submitter'}} # attribute to store the data in
# _columns = ['contact_name','phone','email']
# _info = self.parse (_columns,[2,4,8],**_args)
#
# @TODO: Inspect the configuration file for the attribute information
#
# return _info
pass
@parser(element='CLM',x12='837',map={1:'claim_id',2:'claim_amount',5:'facility_code',5:'facility_qualifier',5:'frequency_code'})
def CLM (**_args):
"""
Expected Element CLM
"""
_data = _args['data']
2023-12-01 18:16:10 +00:00
_data['claim_amount'] = np.float64(_data['claim_amount']) if _data['claim_amount'] not in ['',None] else ''
2023-11-21 18:56:35 +00:00
return _data
# _columns = ['claim_id','claim_amount','facility_code','facility_qualifier','frequency_code']
# return self.parse(_columns,[1,2,5,5,5],**_args)
pass
# @parser(element='REF', field='ref',map={2:'id'})
def REF (**_args):
_columns = ['identifier','qualifier','']
pass
@parser(element='HI',x12='837',container='diagnosis',map={1:'code',2:'type'})
def HI (**_args):
"""
Expected Element HI
"""
# _columns = ['code','type']
# return self.parse(_columns,[1,2],**_args)
_data = _args['data']
if ':' in _data['code'] :
_data['type'],_data['code'] = _data['code'].split(':')
return _data
@parser(element=['SV1','SV3'],x12='837',container='procedures',map={1:['type','code'],2:'amount'})
def SV1 (**_args):
"""
Expected Element SV1
"""
# _row = _args['row'] if type(_args['row']) == list else _args['row'].split('*')
# _columns = ['type','code','amount','modifier_1','modifier_2','modifier_3','modifier_4','place_of_service','units','measurement']
# return self.parse(_columns,[1,1,2,1,1,1,1,5,4,3],**_args)
_data = _args['data']
if 'type' in _data :
_data['type'] = _data['type'].split(':')[0]
_data['code'] = _data['code'].split(':')[1]
_data['amount']= np.float64(_data['amount'])
return _data
pass
@parser (element='HL',x12='837', field='patient', map={1:'_index',2:'parent_code',3:'level_code',4:'child_code'})
def HL (**_args) :
""",
Expected Element HL
The expected block is supposed to be unprocessed (to make things simple)
"""
pass
# _data = _args['data']
# _data['_index'] = int(_data['_index'])
# return _data
# # _row = _args['row'] if type(_args['row']) == list else _args['row'].split('~')
# # _attr = self.elements() #[_name for _name in dir() if not _name.islower() and not _name.startswith('_')]
# # _pointers = [getattr(_name) for _name in _attr]
# # _map = dict(zip(_attr,_pointers))
# _map = self.pointers()
# #
# # The index here tells us what we are processing i.e index == 1 something about header
# #
# _columns = ['_index','parent','code','child']
# # _args['row'] = _row[0]
# _info = self.parse (_columns,[1,2,3,4],**_args)
# # _field = 'billing_provider' if _info['_index'] == '1' else 'patient'
# # _config ={'field':_field}
# return _info