@@ -782,36 +782,36 @@ def is_match(self, seg):
782782 """
783783 if seg .get_seg_id () == self .id :
784784 if self .children [0 ].is_element () \
785- and self .children [0 ].get_data_type () == 'ID' \
786- and self .children [0 ].usage == 'R' \
787- and len (self .children [0 ].valid_codes ) > 0 \
788- and seg .get_value ('01' ) not in self .children [0 ].valid_codes :
785+ and self .children [0 ].get_data_type () == 'ID' \
786+ and self .children [0 ].usage == 'R' \
787+ and len (self .children [0 ].valid_codes ) > 0 \
788+ and seg .get_value ('01' ) not in self .children [0 ].valid_codes :
789789 #logger.debug('is_match: %s %s' % (seg.get_seg_id(), seg[1]), self.children[0].valid_codes)
790790 return False
791791 # Special Case for 820
792792 elif seg .get_seg_id () == 'ENT' \
793- and self .children [1 ].is_element () \
794- and self .children [1 ].get_data_type () == 'ID' \
795- and len (self .children [1 ].valid_codes ) > 0 \
796- and seg .get_value ('02' ) not in self .children [1 ].valid_codes :
793+ and self .children [1 ].is_element () \
794+ and self .children [1 ].get_data_type () == 'ID' \
795+ and len (self .children [1 ].valid_codes ) > 0 \
796+ and seg .get_value ('02' ) not in self .children [1 ].valid_codes :
797797 #logger.debug('is_match: %s %s' % (seg.get_seg_id(), seg[1]), self.children[0].valid_codes)
798798 return False
799799 # Special Case for 999 CTX
800800 # IG defines the dataelement 2100/CT01-1 as an AN, but acts like an ID
801801 elif seg .get_seg_id () == 'CTX' \
802- and self .children [0 ].is_composite () \
803- and self .children [0 ].children [0 ].get_data_type () == 'AN' \
804- and len (self .children [0 ].children [0 ].valid_codes ) > 0 \
805- and seg .get_value ('01-1' ) not in self .children [0 ].children [0 ].valid_codes :
802+ and self .children [0 ].is_composite () \
803+ and self .children [0 ].children [0 ].get_data_type () == 'AN' \
804+ and len (self .children [0 ].children [0 ].valid_codes ) > 0 \
805+ and seg .get_value ('01-1' ) not in self .children [0 ].children [0 ].valid_codes :
806806 return False
807807 elif self .children [0 ].is_composite () \
808- and self .children [0 ].children [0 ].get_data_type () == 'ID' \
809- and len (self .children [0 ].children [0 ].valid_codes ) > 0 \
810- and seg .get_value ('01-1' ) not in self .children [0 ].children [0 ].valid_codes :
808+ and self .children [0 ].children [0 ].get_data_type () == 'ID' \
809+ and len (self .children [0 ].children [0 ].valid_codes ) > 0 \
810+ and seg .get_value ('01-1' ) not in self .children [0 ].children [0 ].valid_codes :
811811 return False
812812 elif seg .get_seg_id () == 'HL' and self .children [2 ].is_element () \
813- and len (self .children [2 ].valid_codes ) > 0 \
814- and seg .get_value ('03' ) not in self .children [2 ].valid_codes :
813+ and len (self .children [2 ].valid_codes ) > 0 \
814+ and seg .get_value ('03' ) not in self .children [2 ].valid_codes :
815815 return False
816816 else :
817817 return True
@@ -1071,8 +1071,7 @@ def __init__(self, root, parent, elem):
10711071 if self .res is not None and self .res != '' :
10721072 self .rec = re .compile (self .res , re .S )
10731073 except Exception :
1074- raise EngineError ('Element regex "%s" failed to compile' %
1075- (self .res ))
1074+ raise EngineError ('Element regex "%s" failed to compile' % (self .res ))
10761075
10771076 v = elem .find ('valid_codes' )
10781077 if v is not None :
@@ -1161,7 +1160,6 @@ def is_valid(self, elem, errh, type_list=[]):
11611160 (self .name , self .refdes )
11621161 self ._error (errh , err_str , '6' , elem .__repr__ ())
11631162 return False
1164-
11651163 if elem is None or elem .get_value () == '' :
11661164 if self .usage in ('N' , 'S' ):
11671165 return True
@@ -1212,6 +1210,12 @@ def is_valid(self, elem, errh, type_list=[]):
12121210 self ._error (errh , err_str , '5' , elem_val )
12131211 valid = False
12141212
1213+ (res , bad_string ) = validation .contains_control_character (elem_val )
1214+ if res :
1215+ err_str = 'Data element "%s" (%s), contains an invalid control character(%s)' % \
1216+ (self .name , self .refdes , bad_string )
1217+ self ._error (errh , err_str , '6' , bad_string )
1218+ valid = False
12151219 if data_type in ['AN' , 'ID' ] and elem_val [- 1 ] == ' ' :
12161220 if len (elem_val .rstrip ()) >= min_len :
12171221 err_str = 'Element "%s" (%s) has unnecessary trailing spaces. (%s)' % \
@@ -1240,8 +1244,7 @@ def is_valid(self, elem, errh, type_list=[]):
12401244 if len (type_list ) > 0 :
12411245 valid_type = False
12421246 for dtype in type_list :
1243- valid_type |= validation .IsValidDataType (elem_val ,
1244- dtype , self .root .param .get ('charset' ))
1247+ valid_type |= validation .IsValidDataType (elem_val , dtype , self .root .param .get ('charset' ))
12451248 if not valid_type :
12461249 if 'TM' in type_list :
12471250 err_str = 'Data element "%s" (%s) contains an invalid time (%s)' % \
@@ -1273,7 +1276,7 @@ def _is_valid_code(self, elem_val, errh):
12731276 if elem_val in self .valid_codes :
12741277 bValidCode = True
12751278 if self .external_codes is not None and \
1276- self .root .ext_codes .isValid (self .external_codes , elem_val ):
1279+ self .root .ext_codes .isValid (self .external_codes , elem_val ):
12771280 bValidCode = True
12781281 if not bValidCode :
12791282 err_str = '(%s) is not a valid code for %s (%s)' % (
@@ -1341,7 +1344,9 @@ def _error(self, errh, err_str, err_cde, elem_val):
13411344 """
13421345 Forward the error to an error_handler
13431346 """
1344- errh .ele_error (err_cde , err_str , elem_val , self .refdes )
1347+ err_str2 = err_str .replace ('\n ' , '' ).replace ('\r ' , '' )
1348+ elem_val2 = elem_val .replace ('\n ' , '' ).replace ('\r ' , '' )
1349+ errh .ele_error (err_cde , err_str2 , elem_val2 , self .refdes )
13451350 #, pos=self.seq, data_ele=self.data_ele)
13461351
13471352 def debug_print (self ):
@@ -1408,8 +1413,7 @@ def is_valid(self, comp_data, errh):
14081413 valid = False
14091414 for i in range (min (len (comp_data ), self .get_child_count ())):
14101415 valid &= self .get_child_node_by_idx (i ).is_valid (comp_data [i ], errh )
1411- for i in range (min (len (comp_data ), self .get_child_count ()),
1412- self .get_child_count ()):
1416+ for i in range (min (len (comp_data ), self .get_child_count ()), self .get_child_count ()):
14131417 if i < self .get_child_count ():
14141418 #Check missing required elements
14151419 valid &= self .get_child_node_by_idx (i ).is_valid (None , errh )
0 commit comments