From 602d1b6207975ad3f6efa323fabd0a98ee802f02 Mon Sep 17 00:00:00 2001 From: Martyn Colmer <46242834+martyncolmer@users.noreply.github.com> Date: Fri, 19 Apr 2024 10:22:09 +0100 Subject: [PATCH] EAR-2403 fix for piping grand calc summary (#215) * fix for piping grand calc summary * Frmatting * more formatting * Formatted with Prettier --- src/eq_schema/builders/valueSource/index.js | 31 ++++++++++++++------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/src/eq_schema/builders/valueSource/index.js b/src/eq_schema/builders/valueSource/index.js index 3166dc79..9e36da28 100644 --- a/src/eq_schema/builders/valueSource/index.js +++ b/src/eq_schema/builders/valueSource/index.js @@ -13,13 +13,20 @@ const getPageByAnswerId = (ctx, answerId) => const getValueSource = (ctx, sourceId) => { const page = getPageByAnswerId(ctx, sourceId); - if (page) { - if (page.pageType === "CalculatedSummaryPage") { + if (page && page.pageType === "CalculatedSummaryPage") { + const calcSumAnswers = flatMap(page.summaryAnswers, (answerId) => + getPageByAnswerId(ctx, answerId) + ); + if (some(calcSumAnswers, { pageType: "CalculatedSummaryPage" })) { return { identifier: page.id, - source: "calculated_summary", + source: "grand_calculated_summary", }; } + return { + identifier: page.id, + source: "calculated_summary", + }; } return { identifier: `answer${sourceId}`, @@ -28,18 +35,22 @@ const getValueSource = (ctx, sourceId) => { }; const getSupplementaryValueSource = (ctx, sourceId) => { - const suplementaryField = find(flatMap(ctx.questionnaireJson.supplementaryData.data, "schemaFields"), {id: sourceId}); + const suplementaryField = find( + flatMap(ctx.questionnaireJson.supplementaryData.data, "schemaFields"), + { id: sourceId } + ); const source = { source: "supplementary_data", - identifier: suplementaryField.identifier - } + identifier: suplementaryField.identifier, + }; if (suplementaryField.selector) { - source.selectors = [suplementaryField.selector] + source.selectors = [suplementaryField.selector]; } - + return source; -} +}; module.exports = { - getValueSource, getSupplementaryValueSource + getValueSource, + getSupplementaryValueSource, };