diff --git a/src/utils/common-expression-helpers.ts b/src/utils/common-expression-helpers.ts index e1bd6d27c..6ab438272 100644 --- a/src/utils/common-expression-helpers.ts +++ b/src/utils/common-expression-helpers.ts @@ -332,6 +332,24 @@ export class CommonExpressionHelpers { }); return values; }; + + calcGravida(parityTerm: number, parityAbortion: number) { + let gravida = 0; + if(parityTerm && parityAbortion) { + gravida = parityTerm + parityAbortion + 1; + } + + return gravida; + } + + calcDaysSinceCircumcisionProcedure(val) { + let daySinceLastCircumcision = 0; + if(val) { + var timeDiff = Math.abs((new Date).getTime() - Date.parse(val)); + daySinceLastCircumcision = Math.floor(timeDiff / (1000 * 60 * 60 * 24)); + } + return daySinceLastCircumcision; + } } export function registerDependency(node: FormNode, determinant: OHRIFormField) { diff --git a/src/utils/expression-runner.ts b/src/utils/expression-runner.ts index efd336860..2632270f9 100644 --- a/src/utils/expression-runner.ts +++ b/src/utils/expression-runner.ts @@ -53,6 +53,8 @@ export function evaluateExpression( arrayContainsAny, formatDate, extractRepeatingGroupValues, + calcGravida, + calcDaysSinceCircumcisionProcedure } = new CommonExpressionHelpers(node, patient, allFields, allFieldValues, allFieldsKeys); parts.forEach((part, index) => { @@ -108,6 +110,8 @@ export async function evaluateAsyncExpression( arrayContainsAny, formatDate, extractRepeatingGroupValues, + calcGravida, + calcDaysSinceCircumcisionProcedure, } = new CommonExpressionHelpers(node, patient, allFields, allFieldValues, allFieldsKeys); const lazyFragments = [];