Skip to content

Commit

Permalink
added supplementary data support (#183)
Browse files Browse the repository at this point in the history
  • Loading branch information
martyncolmer authored Sep 6, 2023
1 parent ea4fb52 commit cfcb021
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
15 changes: 14 additions & 1 deletion src/eq_schema/builders/valueSource/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
};
6 changes: 5 additions & 1 deletion src/utils/convertPipes/PlaceholderObjectBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -67,6 +67,10 @@ const placeholderObjectBuilder = (
};
}

if (source === "supplementary") {
valueSource = getSupplementaryValueSource(ctx, identifier)
}

if (conditionalTradAs && placeholderName === "trad_as") {
placeHolder = {
placeholder: removeDash(placeholderName),
Expand Down
12 changes: 12 additions & 0 deletions src/utils/convertPipes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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) => {
Expand Down

0 comments on commit cfcb021

Please sign in to comment.