Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"pino-http": "^5.5.0",
"q-expressions": "github:CriminalInjuriesCompensationAuthority/q-expressions",
"q-router": "github:CriminalInjuriesCompensationAuthority/q-router#v3.0.2",
"q-templates-application": "github:CriminalInjuriesCompensationAuthority/q-templates-application#v12.0.8",
"q-templates-application": "github:CriminalInjuriesCompensationAuthority/q-templates-application#incorrect-ordering",
"semver": "^7.5.4",
"swagger-ui-express": "^4.6.3",
"uuid": "^3.3.2",
Expand Down
62 changes: 43 additions & 19 deletions questionnaire/questionnaire/section/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,29 +154,53 @@ function createSection({id, sectionDefinition}) {
}

if (allOf !== undefined) {
const compositeAttributeSchema = allOf[0];
const compositeAttribute = createCompositeAttribute(
compositeAttributeSchema,
includeMetadata
);

compositeAttributeSchema.allOf.forEach(subSchema => {
compositeAttribute.values.push(
...getAttributesByData({
data,
includeMetadata,
mapAttribute,
schema: subSchema
})
if (allOf[0].meta !== undefined) {
// The page is a composite question
const compositeAttributeSchema = allOf[0];
const compositeAttribute = createCompositeAttribute(
compositeAttributeSchema,
includeMetadata
);
});

if (mapAttribute !== undefined) {
attributes.push(mapAttribute(compositeAttribute));
} else {
attributes.push(compositeAttribute);
compositeAttributeSchema.allOf.forEach(subSchema => {
compositeAttribute.values.push(
...getAttributesByData({
data,
includeMetadata,
mapAttribute,
schema: subSchema
})
);
});

if (mapAttribute !== undefined) {
attributes.push(mapAttribute(compositeAttribute));
} else {
attributes.push(compositeAttribute);
}

return attributes;
}
// The page is an allOf with conditionals
allOf[0].allOf.forEach(subSchema => {
const attributeId = Object.keys(subSchema.properties)[0];
const questionSchema = subSchema.properties[attributeId];

if (questionSchema !== undefined) {
const attribute = createSimpleAttribute(
attributeId,
questionSchema,
data,
includeMetadata
);

if (mapAttribute !== undefined) {
attributes.push(mapAttribute(attribute));
} else {
attributes.push(attribute);
}
}
});
return attributes;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,24 @@ function getDeclaration(questionnaire) {
return undefined;
}

/**
* Removes all unanswered questions from the schema
* @param answers - The themed content composed of questionnaire answers
* @returns A themed object without any unanswered questions
*/
function trimUnansweredQuestions(answers) {
const trimmedAnswers = [];
answers.forEach(theme => {
theme.values = theme.values.filter(
question => !(question.value === undefined && question.values === undefined)
);
if (theme.values.length !== 0) {
trimmedAnswers.push(theme);
}
});
return trimmedAnswers;
}

/**
* Transforms the questionnaire object into the necessary downstream format.
* @param {questionnaire} questionnaire - The raw questionnaire object
Expand All @@ -128,8 +146,9 @@ function getDeclaration(questionnaire) {
function transformQuestionnaire(questionnaire) {
const section = questionnaire.getSection('p--check-your-answers');
const sectionSchema = section.getSchema();
const themeContent =
sectionSchema.properties['p-check-your-answers'].properties.summaryInfo.summaryStructure;
const themeContent = trimUnansweredQuestions(
sectionSchema.properties['p-check-your-answers'].properties.summaryInfo.summaryStructure
);
flattenAnswers(themeContent);

return {
Expand Down