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, };