Skip to content

Commit

Permalink
Integration form engine 2 (#2273)
Browse files Browse the repository at this point in the history
Normalize additional Digital Form fields
  • Loading branch information
ryguyk authored Jan 22, 2025
1 parent be4e1f9 commit 1444f74
Show file tree
Hide file tree
Showing 20 changed files with 560 additions and 267 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
*
* The "Address" Digital Form pattern.
*
* Pattern documentation:
* https://design.va.gov/patterns/ask-users-for/addresses
*
*/
module.exports = `
fragment address on ParagraphDigitalFormAddress {
fieldTitle
fieldMilitaryAddressCheckbox
}
`;
Original file line number Diff line number Diff line change
@@ -1,18 +1,28 @@
const nameAndDateOfBirth = require('./nameAndDateOfBirth.graphql');
const address = require('./address.graphql');
const phoneAndEmail = require('./phoneAndEmail.graphql');
const yourPersonalInformation = require('./yourPersonalInformation.graphql');
const listLoop = require('./listLoop.graphql');

/*
*
* The "Digital Form" Content Type in the VA.gov CMS
*
*/
module.exports = `
${nameAndDateOfBirth}
${address}
${listLoop}
${phoneAndEmail}
${yourPersonalInformation}
fragment digitalForm on NodeDigitalForm {
nid
entityLabel
fieldVaFormNumber
fieldOmbNumber
fieldRespondentBurden
fieldExpirationDate {
value
}
fieldChapters {
entity {
entityId
Expand All @@ -22,7 +32,10 @@ module.exports = `
entityLabel
}
}
...nameAndDateOfBirth
...address
...listLoop
...phoneAndEmail
...yourPersonalInformation
}
}
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
*
* The "Identification Information" Digital Form pattern.
*
* Pattern documentation:
* https://design.va.gov/patterns/ask-users-for/social-security-number
*
*/
module.exports = `
fragment identificationInformation on ParagraphDigitalFormIdentificationInfo {
fieldTitle
fieldIncludeVeteranSService
}
`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
*
* The "List & Loop" Digital Form pattern.
*
* Pattern documentation:
* https://design.va.gov/patterns/ask-users-for/multiple-responses
*
*/
module.exports = `
fragment listLoop on ParagraphDigitalFormListLoop {
fieldTitle
fieldOptional
}
`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
*
* The "Phone and Email Address" Digital Form pattern.
*
* Pattern documentation:
* https://design.va.gov/patterns/ask-users-for/phone-numbers
*
*/
module.exports = `
fragment phoneAndEmail on ParagraphDigitalFormPhoneAndEmail {
fieldTitle
fieldIncludeEmail
}
`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
const identificationInformation = require('./identificationInformation.graphql');
const nameAndDateOfBirth = require('./nameAndDateOfBirth.graphql');

/*
*
* The "Your personal information" Digital Form pattern.
*
* Pattern documentation:
* https://github.com/department-of-veterans-affairs/vets-website/blob/0ae48c0b017a37d84f6ae425c67c332f4c67fb8b/src/applications/simple-forms/mock-simple-forms-patterns-v3/config/form.js#L40
*
*/
module.exports = `
${identificationInformation}
${nameAndDateOfBirth}
fragment yourPersonalInformation on ParagraphDigitalFormYourPersonalInfo {
fieldNameAndDateOfBirth {
entity {
...nameAndDateOfBirth
}
}
fieldIdentificationInformation {
entity {
...identificationInformation
}
}
}
`;

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,23 +1,69 @@
const { logDrupal } = require('../../utilities-drupal');

const extractAdditionalFields = entity => {
const additionalFields = {};
const { entityId } = entity.type.entity;

if (entity.type.entity.entityId === 'digital_form_name_and_date_of_bi') {
additionalFields.includeDateOfBirth = entity.fieldIncludeDateOfBirth;
switch (entityId) {
case 'digital_form_address':
return {
militaryAddressCheckbox: entity.fieldMilitaryAddressCheckbox,
};
case 'digital_form_list_loop':
return {
optional: entity.fieldOptional,
};
case 'digital_form_phone_and_email':
return {
includeEmail: entity.fieldIncludeEmail,
};
default:
return {};
}

return additionalFields;
};
const extractForms = resultObject => resultObject?.data?.nodeQuery?.entities;

const formatDate = dateString => {
const removeLeadingZero = s => s.replace(/^0+/, '');
const [year, month, day] = dateString.split('-');
return `${removeLeadingZero(month)}/${removeLeadingZero(day)}/${year}`;
};

const stripPrefix = label => label.replace('Digital Form: ', '');

const normalizeChapter = ({ entity }) => {
return {
const type = entity.type.entity.entityId;
const initialChapter = {
id: parseInt(entity.entityId, 10),
chapterTitle: entity.fieldTitle,
type: entity.type.entity.entityId,
pageTitle: entity.type.entity.entityLabel,
type,
};

if (type === 'digital_form_your_personal_info') {
const identificationInformation =
entity.fieldIdentificationInformation.entity;
const nameAndDateOfBirth = entity.fieldNameAndDateOfBirth.entity;

return {
...initialChapter,
chapterTitle: stripPrefix(entity.type.entity.entityLabel),
pages: [
{
pageTitle: nameAndDateOfBirth.fieldTitle,
includeDateOfBirth: nameAndDateOfBirth.fieldIncludeDateOfBirth,
},
{
pageTitle: identificationInformation.fieldTitle,
includeServiceNumber:
identificationInformation.fieldIncludeVeteranSService,
},
],
};
}

return {
...initialChapter,
additionalFields: extractAdditionalFields(entity),
chapterTitle: entity.fieldTitle,
pageTitle: stripPrefix(entity.type.entity.entityLabel),
};
};

Expand All @@ -27,7 +73,11 @@ const normalizeForm = (form, logger = logDrupal) => {
cmsId: form.nid,
formId: form.fieldVaFormNumber,
title: form.entityLabel,
ombNumber: form.fieldOmbNumber,
ombInfo: {
expDate: formatDate(form.fieldExpirationDate.value),
ombNumber: form.fieldOmbNumber,
resBurden: form.fieldRespondentBurden,
},
chapters: form.fieldChapters.map(normalizeChapter),
};
} catch (error) {
Expand Down
Loading

0 comments on commit 1444f74

Please sign in to comment.