Skip to content

Commit 602d1b6

Browse files
authored
EAR-2403 fix for piping grand calc summary (#215)
* fix for piping grand calc summary * Frmatting * more formatting * Formatted with Prettier
1 parent 8f58b75 commit 602d1b6

File tree

1 file changed

+21
-10
lines changed
  • src/eq_schema/builders/valueSource

1 file changed

+21
-10
lines changed

src/eq_schema/builders/valueSource/index.js

+21-10
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,20 @@ const getPageByAnswerId = (ctx, answerId) =>
1313

1414
const getValueSource = (ctx, sourceId) => {
1515
const page = getPageByAnswerId(ctx, sourceId);
16-
if (page) {
17-
if (page.pageType === "CalculatedSummaryPage") {
16+
if (page && page.pageType === "CalculatedSummaryPage") {
17+
const calcSumAnswers = flatMap(page.summaryAnswers, (answerId) =>
18+
getPageByAnswerId(ctx, answerId)
19+
);
20+
if (some(calcSumAnswers, { pageType: "CalculatedSummaryPage" })) {
1821
return {
1922
identifier: page.id,
20-
source: "calculated_summary",
23+
source: "grand_calculated_summary",
2124
};
2225
}
26+
return {
27+
identifier: page.id,
28+
source: "calculated_summary",
29+
};
2330
}
2431
return {
2532
identifier: `answer${sourceId}`,
@@ -28,18 +35,22 @@ const getValueSource = (ctx, sourceId) => {
2835
};
2936

3037
const getSupplementaryValueSource = (ctx, sourceId) => {
31-
const suplementaryField = find(flatMap(ctx.questionnaireJson.supplementaryData.data, "schemaFields"), {id: sourceId});
38+
const suplementaryField = find(
39+
flatMap(ctx.questionnaireJson.supplementaryData.data, "schemaFields"),
40+
{ id: sourceId }
41+
);
3242
const source = {
3343
source: "supplementary_data",
34-
identifier: suplementaryField.identifier
35-
}
44+
identifier: suplementaryField.identifier,
45+
};
3646
if (suplementaryField.selector) {
37-
source.selectors = [suplementaryField.selector]
47+
source.selectors = [suplementaryField.selector];
3848
}
39-
49+
4050
return source;
41-
}
51+
};
4252

4353
module.exports = {
44-
getValueSource, getSupplementaryValueSource
54+
getValueSource,
55+
getSupplementaryValueSource,
4556
};

0 commit comments

Comments
 (0)