bug fix ... toprow stuff

This commit is contained in:
Steve Nyemba 2021-02-16 10:52:14 -06:00
parent d2021bb430
commit 0aa6eb3d5d
2 changed files with 28 additions and 53 deletions

View File

@ -415,27 +415,23 @@ class Parser (Process):
def get_default_value(self,content,_code): def get_default_value(self,content,_code):
util = Formatters() util = Formatters()
TOP_ROW = content[1].split('*') TOP_ROW = content[1].split('*')
CATEGORY= content[2].split('*')[1].strip()
VERSION = content[1].split('*')[-1].replace('~','').replace('\n','')
SUBMITTED_DATE = util.parse.date(TOP_ROW[4]) SUBMITTED_DATE = util.parse.date(TOP_ROW[4])
CATEGORY= content[2].split('*')[1].strip()
VERSION = content[1].split('*')[-1].replace('~','').replace('\n','')
SENDER_ID = TOP_ROW[2] SENDER_ID = TOP_ROW[2]
row = util.split(content[3]) row = util.split(content[3])
_info = util.get_config(self.config[_code][0],row) _info = util.get_config(self.config[_code][0],row)
value = self.get.value(row,_info,VERSION) if _info else {} value = self.get.value(row,_info,VERSION) if _info else {}
value['category'] = {"setid": CATEGORY,"version":'X'+VERSION.split('X')[1],"id":VERSION.split('X')[0].strip()} value['category'] = {"setid": _code,"version":'X'+VERSION.split('X')[1],"id":VERSION.split('X')[0].strip()}
value["submitted"] = SUBMITTED_DATE value["submitted"] = SUBMITTED_DATE
# value['version'] = VERSION
# if _code== '835' :
# value['receiver_id'] = SENDER_ID
# else:
# value['provider_id'] = SENDER_ID
# pass
value['sender_id'] = SENDER_ID value['sender_id'] = SENDER_ID
#
# Let's parse this for default values # Let's parse this for default values
return jsonmerge.merge(value,self.apply(content,_code)) return jsonmerge.merge(value,self.apply(content,_code))
@ -452,46 +448,22 @@ class Parser (Process):
claims = [] claims = []
try: try:
file = open(filename.strip(),errors='ignore') file = open(filename.strip(),errors='ignore')
INITIAL_ROWS = list(islice(file,100)) # Read the first 100 lines (no particular reason) file = file.read().split('CLP')
_code = "unknown" _code = '835'
# if len(INITIAL_ROWS) == 1 : section = 'CLP'
# file = INITIAL_ROWS[0].split('~') if len(file) == 1 :
# INITIAL_ROWS = file[:4] file = file[0].split('CLM')
# if len(INITIAL_ROWS) < 3 : _code = '837'
# return None,[{"name":filename,"completed":False}],None section = 'HL'
# _code = INITIAL_ROWS[2].split('*')[1].strip() INITIAL_ROWS = file[0].split(section)[0].split('\n')
# section = self.config[_code][0]['SECTION'].strip()
# INITIAL_ROWS = file.read().readlines()
if len(INITIAL_ROWS) == 1 : if len(INITIAL_ROWS) == 1 :
INITIAL_ROWS = INITIAL_ROWS[0].split('~') INITIIAL_ROWS = INITIAL_ROWS[0].split('~')
else: DEFAULT_VALUE = self.get.default_value(INITIAL_ROWS,_code)
file.seek(0)
_code = INITIAL_ROWS[2].split('*')[1].strip() #-- x12 standard would have the code positiond here
section = self.config[_code][0]['SECTION'].strip() #-- This is either CLM or CLP
# INITIAL_ROWS =
# _code = INITIAL_ROWS[2].split('*')[1].strip()
for row in INITIAL_ROWS :
if section in row :
index = INITIAL_ROWS.index(row)
#-- The order here will matter because the initial rows will contain the entire file
# Assign this to the file object and move forward by making sure initial_rows are actually initial rows
#
file = INITIAL_ROWS[index:]
INITIAL_ROWS = INITIAL_ROWS[:index]
break
# print ([_code,section])
# print (self.get.default_value(INITIAL_ROWS,_code))
#
# adjusting the
DEFAULT_VALUE = self.get.default_value(INITIAL_ROWS,_code)
DEFAULT_VALUE['name'] = filename.strip() DEFAULT_VALUE['name'] = filename.strip()
print (json.dumps(DEFAULT_VALUE))
file = section.join(file).split('\n')
if len(file) == 1:
file = file[0].split('~')
# #
# In the initial rows, there's redundant information (so much for x12 standard) # In the initial rows, there's redundant information (so much for x12 standard)
# index 1 identifies file type i.e CLM for claim and CLP for remittance # index 1 identifies file type i.e CLM for claim and CLP for remittance
@ -534,8 +506,11 @@ class Parser (Process):
else: else:
schema = {} schema = {}
merger = jsonmerge.Merger(schema) merger = jsonmerge.Merger(schema)
claims.append( merger.merge(DEFAULT_VALUE.copy(),_claim)) _claim = merger.merge(DEFAULT_VALUE.copy(),_claim)
claims.append( _claim)
segment = [row] segment = [row]
index += 1 index += 1
@ -543,7 +518,7 @@ class Parser (Process):
# #
# Handling the last claim found # Handling the last claim found
if segment[0].startswith(section) : if segment and segment[0].startswith(section) :
# default_claim = dict({"name":index},**DEFAULT_VALUE) # default_claim = dict({"name":index},**DEFAULT_VALUE)
claim = self.apply(segment,_code) claim = self.apply(segment,_code)

View File

@ -8,7 +8,7 @@ import sys
def read(fname): def read(fname):
return open(os.path.join(os.path.dirname(__file__), fname)).read() return open(os.path.join(os.path.dirname(__file__), fname)).read()
args = { args = {
"name":"healthcareio","version":"1.6.2.12", "name":"healthcareio","version":"1.6.2.14",
"author":"Vanderbilt University Medical Center", "author":"Vanderbilt University Medical Center",
"author_email":"steve.l.nyemba@vumc.org", "author_email":"steve.l.nyemba@vumc.org",
"include_package_data":True, "include_package_data":True,