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
25 changes: 1 addition & 24 deletions questionnaire/questionnaire/questionnaire.js
Original file line number Diff line number Diff line change
Expand Up @@ -264,36 +264,16 @@ function createQuestionnaire({
return createSection({id: sectionId, sectionDefinition});
}

// TODO: remove this and implement allOf / describedBy properly
function removeDeclarationSectionIds(sectionIds) {
const sectionIdBlacklist = [
'p-applicant-declaration',
'p-applicant-declaration-deceased',
'p-mainapplicant-declaration-under-12',
'p-mainapplicant-declaration-under-12-deceased',
'p-mainapplicant-declaration-12-and-over',
'p-mainapplicant-declaration-12-and-over-deceased',
'p-rep-declaration-under-12',
'p-rep-declaration-under-12-deceased',
'p-rep-declaration-12-and-over',
'p-rep-declaration-12-and-over-deceased'
];

return sectionIds.filter(sectionId => sectionIdBlacklist.includes(sectionId) === false);
}

function getDataAttributes({
progress = getProgress(),
dataAttributeTransformer,
includeMetadata = true
} = {}) {
const allDataAttributes = [];
// TODO: remove this and implement allOf / describedBy properly
const sectionIds = removeDeclarationSectionIds(progress);
const sectionIds = progress;

sectionIds.forEach(sectionId => {
const sectionAnswers = getSectionAnswers(sectionId);

if (sectionAnswers !== undefined) {
const section = getSection(sectionId, false);
const sectionDataAttributes = section.getAttributesByData({
Expand All @@ -305,7 +285,6 @@ function createQuestionnaire({
allDataAttributes.push(...sectionDataAttributes);
}
});

return allDataAttributes;
}

Expand Down Expand Up @@ -380,8 +359,6 @@ function createQuestionnaire({
getOrderedAnswers,
getDataAttributes,
getNormalisedDetailsForAttribute,
getProgress, // TODO: remove this when declaration is handled correctly
getAnswers, // TODO: remove this when declaration is handled correctly
getPermittedActions
});
}
Expand Down
74 changes: 63 additions & 11 deletions questionnaire/questionnaire/section/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
'use strict';

const pointer = require('jsonpointer');

function createSection({id, sectionDefinition}) {
function getId() {
return id;
Expand Down Expand Up @@ -50,37 +52,86 @@ function createSection({id, sectionDefinition}) {
return attributeSchema.meta.compositeId;
}

function getAttributeLabel(valueSchemas, value) {
const foundValueSchema = valueSchemas.find(valueSchema => valueSchema.const === value);
function getAttributeSchemaTitle(attributeSchemas, value) {
const foundAttributeSchema = attributeSchemas.find(
attributeSchema => attributeSchema.const === value
);

return foundAttributeSchema.title;
}

return foundValueSchema.title;
function getAttributeSchemaTitles(attributeSchemas, values) {
return values.map(value => getAttributeSchemaTitle(attributeSchemas, value));
}

function getAttributeLabels(valueSchemas, values) {
return values.map(value => getAttributeLabel(valueSchemas, value));
function getAttributeSchemaDescribedBy(attributeSchemas, value, sectionSchema) {
const foundAttributeSchema = attributeSchemas.find(
attributeSchema => attributeSchema.const === value
);
const describedBy = foundAttributeSchema?.meta?.describedBy;
if (describedBy && '$ref' in describedBy) {
const describedByPointerValue = pointer.get(
sectionSchema,
foundAttributeSchema?.meta?.describedBy.$ref
);
if (describedByPointerValue === undefined) {
return '';
}
return describedByPointerValue;
}
return foundAttributeSchema?.meta?.describedBy;
}

function getValueLabel(attributeSchema, value) {
const {oneOf, items} = attributeSchema;
const {oneOf, anyOf, items} = attributeSchema;

if (oneOf !== undefined) {
return getAttributeLabel(oneOf, value);
return getAttributeSchemaTitle(oneOf, value);
}

if (anyOf !== undefined) {
return getAttributeSchemaTitle(anyOf, value);
}

if (items !== undefined) {
return getAttributeLabels(items.anyOf, value);
return getAttributeSchemaTitles(items.anyOf, value);
}

return undefined;
}

function createSimpleAttribute(attributeId, attributeSchema, data, includeMetadata) {
function getLabel(attributeSchema, value, sectionSchema) {
const {oneOf, anyOf, items} = attributeSchema;

if (oneOf !== undefined) {
return getAttributeSchemaDescribedBy(oneOf, value, sectionSchema);
}

if (anyOf !== undefined) {
return getAttributeSchemaDescribedBy(anyOf, value, sectionSchema);
}

if (items !== undefined) {
return getAttributeSchemaDescribedBy(items.anyOf, value, sectionSchema);
}

return attributeSchema.title;
}

function createSimpleAttribute(
attributeId,
attributeSchema,
data,
includeMetadata,
sectionSchema
) {
const value = data[attributeId];
const valueLabel = getValueLabel(attributeSchema, value);
const label = getLabel(attributeSchema, value, sectionSchema);
const simpleAttribute = {
id: attributeId,
type: 'simple',
label: attributeSchema.title
label
};

if (value !== undefined) {
Expand Down Expand Up @@ -139,7 +190,8 @@ function createSection({id, sectionDefinition}) {
attributeId,
questionSchema,
data,
includeMetadata
includeMetadata,
schema
);

if (mapAttribute !== undefined) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6314,35 +6314,37 @@
},
"p-applicant-declaration": {
"schema": {
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"allOf": [
{
"properties": {
"applicant-declaration": {
"description": "<div id=\"declaration\"> <p class=\"govuk-body\"> You have told us that you are ||/answers/p-applicant-enter-your-name/q-applicant-title|| ||/answers/p-applicant-enter-your-name/q-applicant-first-name|| ||/answers/p-applicant-enter-your-name/q-applicant-last-name|| and you are applying on behalf of yourself.</p> <p class=\"govuk-body\">By submitting this application, you confirm that you understand the following:</p> <ul class=\"govuk-list govuk-list--bullet\"> <li>the information given in this application for compensation is true</li> <li>Criminal Injuries Compensation Authority (CICA) may share and receive information with the following parties for the purposes of processing this application for compensation or verifying information provided:</li> <ul> <li>police, prosecutors and ACRO Criminal Records Office, including for the purposes of obtaining a report of the crime and a record of any criminal convictions you may have</li> <li>medical organisations, practitioners, and police medical staff to obtain medical evidence - including medical records and expert reports. CICA will let you know if this is required</li> <li>any other individuals or organisations where necessary to process this application</li> <li>any representative appointed to act for you in the course of this application</li> </ul> <li>CICA must be notified immediately of any change in circumstances relevant to this application, including any change of address and information about any other claim or proceedings which may give rise to a separate award or payment in respect of your injuries</li> </ul> <h2 class=\"govuk-heading-m\">Providing wrong or misleading information</h2> <p class=\"govuk-body\">If untrue or misleading information is deliberately provided, compensation may be refused and the person(s) responsible may be prosecuted.</p> <p class=\"govuk-body\">Read our privacy notice to see <a href=\"https://www.gov.uk/guidance/cica-privacy-notice\" class=\"govuk-link\" target=\"_blank\">how we use your data (opens in new tab)</a>. </p> <h2 class=\"govuk-heading-m\">Information about appointing a legal or another representative</h2> <p class=\"govuk-body\">It is not necessary to appoint a legal or other representative to act on a victim’s behalf. If a representative is appointed at any stage, please be aware that:</p> <ul class=\"govuk-list govuk-list--bullet\"> <li>CICA cannot meet their costs </li> <li>we will only communicate directly with any appointed representative</li> </ul> <p class=\"govuk-body\">If we make an award, we will pay it only to the victim or their legal representative. This is unless the application has been made on behalf of:</p> <ul class=\"govuk-list govuk-list--bullet\"> <li>an adult who cannot manage their own financial affairs</li> <li>a child who is under 18 years of age</li> </ul> <p class=\"govuk-body\"> It is our general policy to put an award for a child in an interest-earning deposit account until they reach the age of 18.</p> <p class=\"govuk-body\"> If a monetary award is to be made and there is a dispute about outstanding legal fees, it is our policy to retain the disputed amount until the dispute has been resolved.</p> <p class=\"govuk-body\"> If it is decided that a representative’s services are no longer required, CICA must be notified in writing as soon as possible.</p> </div>"
}
}
"required": ["q-applicant-declaration"],
"propertyNames": {
"enum": ["q-applicant-declaration"]
},
"properties": {
"applicant-declaration": {
"title": "Declaration",
"description": "<div id=\"declaration\"> <p class=\"govuk-body\"> You have told us that you are ||/answers/p-applicant-enter-your-name/q-applicant-title|| ||/answers/p-applicant-enter-your-name/q-applicant-first-name|| ||/answers/p-applicant-enter-your-name/q-applicant-last-name|| and you are applying on behalf of yourself.</p> <p class=\"govuk-body\">By submitting this application, you confirm that you understand the following:</p> <ul class=\"govuk-list govuk-list--bullet\"> <li>the information given in this application for compensation is true</li> <li>Criminal Injuries Compensation Authority (CICA) may share and receive information with the following parties for the purposes of processing this application for compensation or verifying information provided:</li> <ul> <li>police, prosecutors and ACRO Criminal Records Office, including for the purposes of obtaining a report of the crime and a record of any criminal convictions you may have</li> <li>medical organisations, practitioners, and police medical staff to obtain medical evidence - including medical records and expert reports. CICA will let you know if this is required</li> <li>any other individuals or organisations where necessary to process this application</li> <li>any representative appointed to act for you in the course of this application</li> </ul> <li>CICA must be notified immediately of any change in circumstances relevant to this application, including any change of address and information about any other claim or proceedings which may give rise to a separate award or payment in respect of your injuries</li> </ul> <h2 class=\"govuk-heading-m\">Providing wrong or misleading information</h2> <p class=\"govuk-body\">If untrue or misleading information is deliberately provided, compensation may be refused and the person(s) responsible may be prosecuted.</p> <p class=\"govuk-body\">Read our privacy notice to see <a href=\"https://www.gov.uk/guidance/cica-privacy-notice\" class=\"govuk-link\" target=\"_blank\">how we use your data (opens in new tab)</a>. </p> <h2 class=\"govuk-heading-m\">Information about appointing a legal or another representative</h2> <p class=\"govuk-body\">It is not necessary to appoint a legal or other representative to act on a victim’s behalf. If a representative is appointed at any stage, please be aware that:</p> <ul class=\"govuk-list govuk-list--bullet\"> <li>CICA cannot meet their costs </li> <li>we will only communicate directly with any appointed representative</li> </ul> <p class=\"govuk-body\">If we make an award, we will pay it only to the victim or their legal representative. This is unless the application has been made on behalf of:</p> <ul class=\"govuk-list govuk-list--bullet\"> <li>an adult who cannot manage their own financial affairs</li> <li>a child who is under 18 years of age</li> </ul> <p class=\"govuk-body\"> It is our general policy to put an award for a child in an interest-earning deposit account until they reach the age of 18.</p> <p class=\"govuk-body\"> If a monetary award is to be made and there is a dispute about outstanding legal fees, it is our policy to retain the disputed amount until the dispute has been resolved.</p> <p class=\"govuk-body\"> If it is decided that a representative’s services are no longer required, CICA must be notified in writing as soon as possible.</p> </div>"
},
{
"properties": {
"q-applicant-declaration": {
"type": "string",
"q-applicant-declaration": {
"title": "Declaration",
"type": "string",
"meta": {
"classifications": {
"theme": "declaration"
}
},
"anyOf": [
{
"title": "I have read and understood the declaration",
"const": "i-agree",
"title": "I have read and understood the declaration"
"meta": {
"describedBy": {
"$ref": "/properties/applicant-declaration/description"
}
}
}
}
}
],
"title": "Declaration",
"$schema": "http://json-schema.org/draft-07/schema#",
"required": ["q-applicant-declaration"],
"errorMessage": {
"required": {
"q-applicant-declaration": "Select that you have read and understood"
]
}
},
"propertyNames": {
"enum": ["q-applicant-declaration"]
}
}
},
Expand Down Expand Up @@ -17098,6 +17100,9 @@
"other-compensation": {
"title": "Other compensation"
},
"declaration": {
"title": "Declaration"
},
"main-applicant-details": {
"title": null
}
Expand Down
Loading