diff --git a/db-service/lib/cql-functions.js b/db-service/lib/cql-functions.js index fbe6a427b..2ced052cc 100644 --- a/db-service/lib/cql-functions.js +++ b/db-service/lib/cql-functions.js @@ -23,10 +23,16 @@ const StandardFunctions = { search: function (ref, arg) { if (!('val' in arg)) throw new Error(`Only single value arguments are allowed for $search`) // only apply first search term, rest is ignored - const sub= /("")|("(?:[^"]|\\")*(?:[^\\]|\\\\)")|(\S*)/.exec(arg.val) - arg.val = arg.__proto__.val = (sub[2] ? JSON.parse(sub[2]) : sub[3]) || '' - const refs = ref.list || [ref], - { toString } = ref + const sub = /("")|("(?:[^"]|\\")*(?:[^\\]|\\\\)")|(\S*)/.exec(arg.val) + let val + try { + val = (sub[2] ? JSON.parse(sub[2]) : sub[3]) || '' + } catch { + val = sub[2] || sub[3] || '' + } + arg.val = arg.__proto__.val = val + const refs = ref.list || [ref] + const { toString } = ref return '(' + refs.map(ref2 => this.contains(this.tolower(toString(ref2)), this.tolower(arg))).join(' or ') + ')' }, /** @@ -159,8 +165,8 @@ const StandardFunctions = { * Generates SQL statement that produces current point in time (date and time with time zone) * @returns {string} */ - now: function() { - return this.session_context({val: '$now'}) + now: function () { + return this.session_context({ val: '$now' }) }, /** * Generates SQL statement that produces the year of a given timestamp