Skip to content

Commit

Permalink
Fix prepopulate
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenhand committed Dec 17, 2024
1 parent 91f0d91 commit 034b12e
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions functions/hrm/prepopulateForm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ const populateInitialValues = async (contact: HrmContact, formDefinitionRootUrl:
};

const populateContactSection = async (
contact: HrmContact,
target: Record<string, FormValue>,
valuesToPopulate: Record<string, string>,
keys: string[],
formDefinitionRootUrl: URL,
Expand All @@ -382,15 +382,16 @@ const populateContactSection = async (
values: Record<string, string>,
) => Record<string, string | boolean>,
) => {
console.debug('Populating', tabbedFormsSection);
console.debug('Keys', keys);
console.debug('Using Values', valuesToPopulate);

if (keys.length > 0) {
const childInformationTabDefinition = await loadConfigJson(
formDefinitionRootUrl,
`tabbedForms/${tabbedFormsSection}`,
);
Object.assign(
contact.rawJson.childInformation,
converter(keys, childInformationTabDefinition, valuesToPopulate),
);
Object.assign(target, converter(keys, childInformationTabDefinition, valuesToPopulate));
}
};

Expand All @@ -407,10 +408,10 @@ export const prepopulateForm = async (
await loadConfigJson(formDefinitionRootUrl, 'PrepopulateKeys');

const isValidSurvey = Boolean(answers?.aboutSelf); // determines if the memory has valid values or if it was aborted
const isAboutSelf = !answers || answers.aboutSelf === 'Yes';
const isAboutSelf = answers.aboutSelf === 'Yes';
if (preEngagementData) {
await populateContactSection(
contact,
contact.rawJson.caseInformation,
preEngagementData,
preEngagementKeys.CaseInformationTab,
formDefinitionRootUrl,
Expand All @@ -420,7 +421,7 @@ export const prepopulateForm = async (

if (!isValidSurvey || isAboutSelf) {
await populateContactSection(
contact,
contact.rawJson.childInformation,
preEngagementData,
preEngagementKeys.ChildInformationTab,
formDefinitionRootUrl,
Expand All @@ -429,7 +430,7 @@ export const prepopulateForm = async (
);
} else {
await populateContactSection(
contact,
contact.rawJson.callerInformation,
preEngagementData,
preEngagementKeys.CallerInformationTab,
formDefinitionRootUrl,
Expand All @@ -442,7 +443,7 @@ export const prepopulateForm = async (
if (isValidSurvey) {
if (isAboutSelf) {
await populateContactSection(
contact,
contact.rawJson.childInformation,
answers,
surveyKeys.ChildInformationTab,
formDefinitionRootUrl,
Expand All @@ -451,7 +452,7 @@ export const prepopulateForm = async (
);
} else {
await populateContactSection(
contact,
contact.rawJson.callerInformation,
answers,
surveyKeys.CallerInformationTab,
formDefinitionRootUrl,
Expand Down

0 comments on commit 034b12e

Please sign in to comment.