Steve Nyemba 4 years ago
parent
commit
a75ed6eb94
1 changed files with 5 additions and 3 deletions
  1. 5 3
      healthcareio/x12/__init__.py

+ 5 - 3
healthcareio/x12/__init__.py

@@ -367,10 +367,12 @@ class Parser (Process):
         try:
             file = open(filename.strip(),errors='ignore')
             INITIAL_ROWS = list(islice(file,4)) #.readlines(4)
-            
+            _code = "unknown"
             if len(INITIAL_ROWS) == 1 :
                 file = INITIAL_ROWS[0].split('~')
                 INITIAL_ROWS = file[:4]
+            if len(INITIAL_ROWS) < 3 :
+                return None,[{"name":filename,"completed":False}],None
             section = 'CLM' if INITIAL_ROWS[1].split('*')[1] == 'HC' else 'CLP'            
             _code   = '837' if section == 'CLM' else '835'
             DEFAULT_VALUE = self.get.default_value(INITIAL_ROWS,_code)
@@ -421,8 +423,8 @@ class Parser (Process):
 
             # x12_file = open(filename.strip(),errors='ignore').read().split('\n')
         except Exception as e:
-            logs.append ({"parse":"claims" if _code == '837' else 'remits',"completed":False,"name":filename,"msg":e.args[0]})
-            return [],logs,_code
+            logs.append ({"parse":_code,"completed":False,"name":filename,"msg":e.args[0]})
+            return [],logs,None
         
         rate = 0 if len(claims) == 0 else (1 + index)/len(claims)
         logs.append ({"parse":"claims" if _code == '837' else 'remits',"completed":True,"name":filename,"rate":rate})