Mercurial > hgweb > health
changeset 1979:2d4c69f341cd
bug #45307: Fix searcher to validate values and support negations
| author | Chris Zimmerman <siv@riseup.net> |
|---|---|
| date | Fri, 12 Jun 2015 23:48:27 -0700 |
| parents | f49b62f22358 |
| children | 4f620063e9a9 |
| files | tryton/health_inpatient/health_inpatient.py |
| diffstat | 1 files changed, 13 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/tryton/health_inpatient/health_inpatient.py +++ b/tryton/health_inpatient/health_inpatient.py @@ -379,17 +379,25 @@ p = Pool().get('gnuhealth.inpatient.registration') table = p.__table__() pat = cls.__table__() - _, _, value = clause + _, operator, value = clause + + # Validate operator and value + if operator not in ['=', '!=']: + raise ValueError('Wrong operator: %s' % operator) + if value is not True and value is not False: + raise ValueError('Wrong value: %s' % value) # Find hospitalized patient ids j = pat.join(table, condition = pat.id == table.patient) s = j.select(pat.id, where = table.state == 'hospitalized') - # It's a boolean field - if value is True: - return [('id', 'in', s)] + # Choose domain operator + if (operator == '=' and value) or (operator == '!=' and not value): + d = 'in' else: - return [('id', 'not in', s)] + d = 'not in' + + return [('id', d, s)] class InpatientMedication (ModelSQL, ModelView): 'Inpatient Medication'
