def validate(value, row):
    """CASENUM Rules:
    1) If casenumx is None
      a) If halt_on_error setting is true than raise a FatalDataError
      b) Else log the case and return 99999999
      
    2) If length of casenumx is greater than 8
      a) If halt_on_error setting is true than raise a FatalDataError
      b) Else log the case and return a truncated version of casenum
    
    3) Try to convert casenumx to an int and assign this value to casenum
    
    4) If this conversion fails 
      a) If halt_on_error setting is true than raise a FatalDataError
      b) Else log the error and return 99999999
    
    If halt_on_error is False, this results in casenum either being assigned
    the casenumx value as an integer or 99999999. 
    """
    
    try:
        val = row['casenumx'] 
        if not val:
            if halt_on_error:
                raise FatalDataError('Missing CASENUM in data @ demographic_id = %s' % row['id'])
                
            else:
                log.write('casenum', [row['id'], val, 'FatalError: Missing CASENUM'])
                return 99999999
                
        return int(val)
    
    except (TypeError, ValueError) as e:
        if halt_on_error:
            raise FatalDataError('Invalid CASENUM in data. demographic_id: %' % row['id'])
            
        else:
            log.write('casenum', [row['id'], val, '%s' % e])
            return 99999999