ifnotindex_date:raiseValueError("Constraining the patient age requires the 'index_date' argument")
filter_template="EXTRACT(YEAR FROM DATE '{index_date}')-year_of_birth >= {value_1} AND EXTRACT(YEAR FROM DATE '{index_date}')-year_of_birth <= {value_2}"
filter_str=filter_template.format(
index_date=index_date,
value_1=self._AGE_GROUPS[v]['start'],
value_2=self._AGE_GROUPS[v]['end'])
filters['age']=filter_str
elifk=='ageRange':
ifnotre.match(r"[0-9]*-[0-9]*",v):raiseValueError("Unable to parse value range expression. Some valid examples: -22, or 16-22, or 22-")
ifnotindex_date:raiseValueError("Constraining the patient age requires the 'index_date' argument")
filter_template="EXTRACT(YEAR FROM DATE '{index_date}')-year_of_birth >= {value_1} AND EXTRACT(YEAR FROM DATE '{index_date}')-year_of_birth <= {value_2}"