From c7e6c4d7aab70eb82434d20e88df66190b071752 Mon Sep 17 00:00:00 2001 From: Donald Kibet Date: Fri, 28 Apr 2023 16:39:45 +0300 Subject: [PATCH] (fix) follow up PR to fix error brought by introducing `age` and `sex` in execution context --- src/utils/expression-runner.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/utils/expression-runner.ts b/src/utils/expression-runner.ts index 587e358f9..645d65caa 100644 --- a/src/utils/expression-runner.ts +++ b/src/utils/expression-runner.ts @@ -29,7 +29,8 @@ export function evaluateExpression( findAndRegisterReferencedFields(node, parts, fields); // setup function scope let { mode, myValue, patient } = context; - const { sex, age } = patient; + const { sex, age } = patient && 'sex' in patient && 'age' in patient ? patient : { sex: undefined, age: undefined }; + if (node.type === 'field' && myValue === undefined) { myValue = fieldValues[node.value['id']]; } @@ -63,7 +64,7 @@ export function evaluateExpression( try { return eval(expression); } catch (error) { - console.error(error); + console.error(`Error: ${error} \n\n failing expression: ${expression}`); } return null; } @@ -84,7 +85,7 @@ export async function evaluateAsyncExpression( findAndRegisterReferencedFields(node, parts, fields); // setup function scope let { mode, myValue, patient } = context; - const { sex, age } = patient; + const { sex, age } = patient && 'sex' in patient && 'age' in patient ? patient : { sex: undefined, age: undefined }; if (node.type === 'field' && myValue === undefined) { myValue = fieldValues[node.value['id']]; } @@ -146,7 +147,7 @@ export async function evaluateAsyncExpression( try { return eval(expression); } catch (error) { - console.error(error); + console.error(`Error: ${error} \n\n failing expression: ${expression}`); } return null; }