Package pyx12 :: Module error_item
[hide private]

Source Code for Module pyx12.error_item

 1  ###################################################################### 
 2  # Copyright (c) 2001-2005 Kalamazoo Community Mental Health Services, 
 3  #   John Holland <jholland@kazoocmh.org> <john@zoner.org> 
 4  # All rights reserved. 
 5  # 
 6  # This software is licensed as described in the file LICENSE.txt, which 
 7  # you should have received as part of this distribution. 
 8  # 
 9  ###################################################################### 
10   
11  #    $Id: error_item.py 948 2007-03-22 17:28:37Z johnholland $ 
12   
13  """ 
14  """ 
15   
16  import errors 
17   
18  isa_errors = ('000' ,'001' ,'002' ,'003' ,'004' ,'005' ,'006' ,'007' ,'008' , 
19      '009' ,'010' ,'011' ,'012' ,'013' ,'014' ,'015' ,'016' , 
20      '017' ,'018' ,'019' ,'020' ,'021' ,'022' ,'023' ,'024' , 
21      '025' ,'026' ,'027' ,'028' ,'029' ,'030' ,'031') 
22  seg_errors = ('1', '2', '3', '4', '5', '6', '7', '8') 
23  ele_errors = ('1', '2', '3', '4', '5', '6', '7', '8', '9', '10') 
24   
25 -class ErrorItem(object):
26 """ 27 Wrap an X12 validation error 28 """
29 - def __init__(self, err_type, err_cde, err_str):
30 """ 31 @param err_type: At what level did the error occur 32 @type err_type: string 33 @param err_cde: Segment level error code 34 @type err_cde: string 35 @param err_str: Description of the error 36 @type err_str: string 37 """ 38 self.err_cde = err_cde 39 self.err_str = err_str
40
41 - def getErrCde(self):
42 return self.err_cde
43
44 - def getErrStr(self):
45 return self.err_str
46 47
48 -class ISAError(ErrorItem):
49 - def __init__(self, err_cde, err_str):
50 ErrorItem.__init__(self, 'isa', err_cde, err_str) 51 if self.err_cde not in isa_errors: 52 raise errors.EngineError, 'Invalid ISA level error code "%s"' % \ 53 (self.err_cde)
54 55
56 -class SegError(ErrorItem):
57 - def __init__(self, err_cde, err_str, err_val=None):
58 ErrorItem.__init__(self, 'seg', err_cde, err_str) 59 self.err_val = err_val 60 if self.err_cde not in seg_errors: 61 raise errors.EngineError, 'Invalid segment level error code "%s"' % \ 62 (self.err_cde)
63
64 - def getErrVal(self):
65 return self.err_val
66 67
68 -class EleError(ErrorItem):
69 - def __init__(self, err_cde, err_str, ele_idx, subele_idx=None, 70 err_val=None):
71 ErrorItem.__init__(self, 'ele', err_cde, err_str) 72 self.err_val = err_val 73 self.ele_idx = ele_idx 74 self.subele_idx = subele_idx 75 if self.err_cde not in ele_errors: 76 raise errors.EngineError, 'Invalid element level error code "%s"' % \ 77 (self.err_cde)
78
79 - def getErrVal(self):
80 return self.err_val
81
82 - def getEleIdx(self):
83 return self.ele_idx
84
85 - def getSubeleIdx(self):
86 return self.subele_idx
87