(comparator, values)
Returns a CommCare validation condition given a CDISC ODM comparator and a list of values

        >>> Item.get_condition('LT', ['5'])
        '. < 5'
Returns a CommCare validation condition given a CDISC ODM comparator and a list of values
Returns a CommCare validation condition given a CDISC ODM comparator and a list of values
def get_condition(comparator, values):
        """
        Returns a CommCare validation condition given a CDISC ODM comparator and a list of values

        >>> Item.get_condition('LT', ['5'])
        '. < 5'

        """

        def value_in(values_):
            return '(' + ' or '.join(('. = ' + v for v in values_)) + ')'

        scalar_comparators = {
            'LT': '. < ',
            'LE': '. <= ',
            'GT': '. > ',
            'GE': '. >= ',
            'EQ': '. = ',
            'NE': '. != ',
        }
        vector_comparators = {
            'IN': lambda vv: value_in(vv),
            'NOTIN': lambda vv: 'not ' + value_in(vv)
        }

        if not values:
            raise ValueError('A validation condition needs at least one comparable value')
        quoted_values = [quote_nan(v) for v in values]
        if comparator in scalar_comparators:
            return scalar_comparators[comparator] + quoted_values[0]
        elif comparator in vector_comparators:
            return vector_comparators[comparator](quoted_values)
        else:
            raise ValueError('Unknown comparison operator "{}"'.format(comparator))
def get_condition ( comparator , values ) : def value_in ( values_ ) : return '(' + ' or ' . join ( ( '. = ' + v for v in values_ ) ) + ')' scalar_comparators = { 'LT' : '. < ' , 'LE' : '. <= ' , 'GT' : '. > ' , 'GE' : '. >= ' , 'EQ' : '. = ' , 'NE' : '. != ' , } vector_comparators = { 'IN' : lambda vv : value_in ( vv ) , 'NOTIN' : lambda vv : 'not ' + value_in ( vv ) } if not values : raise ValueError ( 'A validation condition needs at least one comparable value' ) quoted_values = [ quote_nan ( v ) for v in values ] if comparator in scalar_comparators : return scalar_comparators [ comparator ] + quoted_values [ 0 ] elif comparator in vector_comparators : return vector_comparators [ comparator ] ( quoted_values ) else : raise ValueError ( 'Unknown comparison operator "{}"' . format ( comparator ) )