@@ -72,10 +72,18 @@ def convertData(self, expressionType, expressionRule, fieldName, fieldValue):
7272 return self ._convertToChangeTo (
7373 expressionRule , fieldName , fieldValue , self .summarise , self .report_unexpected_exception
7474 )
75+ case "BOOLEAN" :
76+ return self ._convertToBoolean (
77+ expressionRule , fieldName , fieldValue , self .summarise , self .report_unexpected_exception
78+ )
7579 case "LOOKUP" :
7680 return self ._convertToLookUp (
7781 expressionRule , fieldName , fieldValue , self .summarise , self .report_unexpected_exception
7882 )
83+ case "SNOMED" :
84+ return self ._convertToSnomed (
85+ expressionRule , fieldName , fieldValue , self .summarise , self .report_unexpected_exception
86+ )
7987 case "DEFAULT" :
8088 return self ._convertToDefaultTo (
8189 expressionRule , fieldName , fieldValue , self .summarise , self .report_unexpected_exception
@@ -148,14 +156,17 @@ def _convertToDateTime(self, expressionRule, fieldName, fieldValue, summarise, r
148156 # Not Empty Validate - Returns exactly what is in the extracted fields no parsing or logic needed
149157 def _convertToNotEmpty (self , expressionRule , fieldName , fieldValue , summarise , report_unexpected_exception ):
150158 try :
151- if len (str (fieldValue )) > 0 :
159+ if isinstance (fieldValue , (int , float )):
160+ return "" # Reject plain numbers
161+ if isinstance (fieldValue , str ) and fieldValue .strip ():
152162 return fieldValue
153163 return ""
154164 except Exception as e :
155165 if report_unexpected_exception :
156166 message = ExceptionMessages .MESSAGES [ExceptionMessages .UNEXPECTED_EXCEPTION ] % (e .__class__ .__name__ , e )
157167 return message
158168
169+
159170 # NHSNumber Validate
160171 def _convertToNHSNumber (self , expressionRule , fieldName , fieldValue , summarise , report_unexpected_exception ):
161172 """
@@ -266,3 +277,46 @@ def _convertToOnlyIfTo(self, expressionRule, fieldName, fieldValue, summarise, r
266277 if report_unexpected_exception :
267278 message = ExceptionMessages .MESSAGES [ExceptionMessages .UNEXPECTED_EXCEPTION ] % (e .__class__ .__name__ , e )
268279 return message
280+
281+ # Check if Snomed code is numeric and reject other forms
282+ def _convertToSnomed (self , expressionRule , fieldName , fieldValue , summarise , report_unexpected_exception ):
283+ """
284+ Validates that a SNOMED code is a non-empty string containing only digits.
285+ """
286+ try :
287+ if not fieldValue or not isinstance (fieldValue , str ) or not fieldValue .isdigit ():
288+ raise ValueError (f"Invalid SNOMED code: { fieldValue } " )
289+ return fieldValue
290+ except Exception as e :
291+ if report_unexpected_exception :
292+ message = ExceptionMessages .MESSAGES [ExceptionMessages .UNEXPECTED_EXCEPTION ] % (e .__class__ .__name__ , e )
293+ self .errorRecords .append ({
294+ "field" : fieldName ,
295+ "value" : fieldValue ,
296+ "message" : message
297+ })
298+ return ""
299+
300+ # Check if Input is boolean or if input is a string with true or false, convert to Boolean
301+ def _convertToBoolean (self , expressionRule , fieldName , fieldValue , summarise , report_unexpected_exception ):
302+ try :
303+ if isinstance (fieldValue , bool ):
304+ return fieldValue
305+
306+ if isinstance (fieldValue , str ):
307+ lowered = fieldValue .strip ().lower ()
308+ if lowered == "true" :
309+ return True
310+ elif lowered == "false" :
311+ return False
312+
313+ return "" # Invalid input
314+ except Exception as e :
315+ if report_unexpected_exception :
316+ message = ExceptionMessages .MESSAGES [ExceptionMessages .UNEXPECTED_EXCEPTION ] % (
317+ e .__class__ .__name__ , e
318+ )
319+ return message
320+
321+
322+
0 commit comments