Skip to content

Commit

Permalink
EAR-2403 fix for piping grand calc summary (#215)
Browse files Browse the repository at this point in the history
* fix for piping grand calc summary

* Frmatting

* more formatting

* Formatted with Prettier
  • Loading branch information
martyncolmer authored Apr 19, 2024
1 parent 8f58b75 commit 602d1b6
Showing 1 changed file with 21 additions and 10 deletions.
31 changes: 21 additions & 10 deletions src/eq_schema/builders/valueSource/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`,
Expand All @@ -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,
};

0 comments on commit 602d1b6

Please sign in to comment.