diff --git a/src/eq_schema/builders/valueSource/index.js b/src/eq_schema/builders/valueSource/index.js index 1be00253..46e13725 100644 --- a/src/eq_schema/builders/valueSource/index.js +++ b/src/eq_schema/builders/valueSource/index.js @@ -27,6 +27,19 @@ const getValueSource = (ctx, sourceId) => { }; }; +const getSupplementaryValueSource = (ctx, sourceId) => { + const suplementaryField = find(flatMap(ctx.questionnaireJson.supplementaryData.data, "schemaFields"), {id: sourceId}); + const source = { + source: "supplementary", + identifier: suplementaryField.identifier + } + if (suplementaryField.selector) { + source.selector = [suplementaryField.selector] + } + + return source; +} + module.exports = { - getValueSource, + getValueSource, getSupplementaryValueSource }; diff --git a/src/utils/convertPipes/PlaceholderObjectBuilder.js b/src/utils/convertPipes/PlaceholderObjectBuilder.js index 1bc32976..b1b15127 100644 --- a/src/utils/convertPipes/PlaceholderObjectBuilder.js +++ b/src/utils/convertPipes/PlaceholderObjectBuilder.js @@ -13,7 +13,7 @@ const { // FORMAT_UNIT, } = require("../../constants/piping"); const { removeDash } = require("../HTMLUtils"); -const { getValueSource } = require("../../eq_schema/builders/valueSource"); +const { getValueSource, getSupplementaryValueSource } = require("../../eq_schema/builders/valueSource"); const DATE_FORMAT_MAP = { "dd/mm/yyyy": "d MMMM yyyy", @@ -67,6 +67,10 @@ const placeholderObjectBuilder = ( }; } + if (source === "supplementary") { + valueSource = getSupplementaryValueSource(ctx, identifier) + } + if (conditionalTradAs && placeholderName === "trad_as") { placeHolder = { placeholder: removeDash(placeholderName), diff --git a/src/utils/convertPipes/index.js b/src/utils/convertPipes/index.js index 5af947d5..c6ec80a7 100644 --- a/src/utils/convertPipes/index.js +++ b/src/utils/convertPipes/index.js @@ -19,6 +19,10 @@ const getAnswers = (questionnaire) => ) ); +const getSuplementaryField = (ctx, sourceId) => { + return find(flatMap(ctx.questionnaireJson.supplementaryData.data, "schemaFields"), { id: sourceId }); +} + const getListAnswers = (questionnaire) => flatMap(get(questionnaire, "collectionLists.lists", []), (list) => compact(list.answers) @@ -131,6 +135,14 @@ const PIPE_TYPES = { ? { source: "calculated_summary", identifier: fallbackKey } : null, }, + supplementary: { + retrieve: ({ id }, ctx) => getSuplementaryField(ctx, id), + getType: ({ type }) => type, + render: ({ id }) => id, + placeholder: ({ identifier, selector }) => + selector ? formatter(identifier) + "_" + formatter(selector) : formatter(identifier), + getFallback: () => null, + } }; const parseHTML = (html) => {