From c36c933d89a14ca23e1c3c6d836cf94bc1df70e0 Mon Sep 17 00:00:00 2001 From: Hemanth Kona Date: Mon, 15 Apr 2024 17:51:06 -0400 Subject: [PATCH] 5109 - Fix automatically selecting incidents 5134 - update text 5132 - Change Shelter Referral -> Shelter 5133 - Add description Household doesn't need assistance 5135 - validate needs section and prevent going to next --- .../src/app/core/model/needs.model.ts | 4 +- .../core/services/customValidation.service.ts | 51 +- .../app/core/services/formCreation.service.ts | 6 +- .../src/app/core/services/globalConstants.ts | 2 +- .../review/review.component.ts | 19 +- .../evacuation-details.component.html | 86 +- .../needs/needs.component.html | 132 +- .../step-ess-file/step-ess-file.service.ts | 1506 ++++++++--------- 8 files changed, 795 insertions(+), 1011 deletions(-) diff --git a/registrants/src/UI/embc-registrant/src/app/core/model/needs.model.ts b/registrants/src/UI/embc-registrant/src/app/core/model/needs.model.ts index 5fab09f13..f720e56a0 100644 --- a/registrants/src/UI/embc-registrant/src/app/core/model/needs.model.ts +++ b/registrants/src/UI/embc-registrant/src/app/core/model/needs.model.ts @@ -94,11 +94,11 @@ export class IdentifyNeedsForm { requiresClothing = new UntypedFormControl(); requiresFood = new UntypedFormControl(); requiresIncidentals = new UntypedFormControl(); - requiresShelterType = new UntypedFormControl(); + requiresShelterType = new UntypedFormControl(null, [this.customValidator.conditionalValidation(() => this.requiresShelter.value, Validators.required)]); requiresShelter = new UntypedFormControl(); requiresNothing = new UntypedFormControl(); - constructor(identifyNeeds: IdentifyNeeds) { + constructor(identifyNeeds: IdentifyNeeds, private customValidator: CustomValidationService) { this.requiresClothing.setValue(identifyNeeds.needs.includes(IdentifiedNeed.Clothing)); this.requiresFood.setValue(identifyNeeds.needs.includes(IdentifiedNeed.Food)); this.requiresIncidentals.setValue(identifyNeeds.needs.includes(IdentifiedNeed.Incidentals)); diff --git a/registrants/src/UI/embc-registrant/src/app/core/services/customValidation.service.ts b/registrants/src/UI/embc-registrant/src/app/core/services/customValidation.service.ts index 4886c40da..3c5d4c150 100644 --- a/registrants/src/UI/embc-registrant/src/app/core/services/customValidation.service.ts +++ b/registrants/src/UI/embc-registrant/src/app/core/services/customValidation.service.ts @@ -1,4 +1,4 @@ -import { AbstractControl, ValidatorFn, Validators } from '@angular/forms'; +import { AbstractControl, FormGroup, ValidationErrors, ValidatorFn, Validators } from '@angular/forms'; import { Injectable } from '@angular/core'; import * as moment from 'moment'; import * as globalConst from '../services/globalConstants'; @@ -38,11 +38,7 @@ export class CustomValidationService { * @param validator : validator to test again * @param errorName : custom error name */ - conditionalValidation( - predicate: () => boolean, - validator: ValidatorFn, - errorName?: string - ): ValidatorFn { + conditionalValidation(predicate: () => boolean, validator: ValidatorFn, errorName?: string): ValidatorFn { return (control: AbstractControl): { [key: string]: boolean } | null => { if (control.parent) { let validationError = null; @@ -70,14 +66,7 @@ export class CustomValidationService { if (control) { const email = control.get('email').value; const confirmEmail = control.get('confirmEmail').value; - if ( - email !== undefined && - confirmEmail !== undefined && - email !== null && - confirmEmail !== null && - email !== '' && - confirmEmail !== '' - ) { + if (email !== undefined && confirmEmail !== undefined && email !== null && confirmEmail !== null && email !== '' && confirmEmail !== '') { if (email.toLowerCase() !== confirmEmail.toLowerCase()) { return { emailMatch: true }; } @@ -94,16 +83,8 @@ export class CustomValidationService { const confirmEmail = control.get('confirmEmail').value; const phone = control.get('phone').value; - if ( - control.get('showContacts').value === true && - (phone === null || phone === undefined || phone === '') - ) { - if ( - (email !== undefined || email !== null || email === '') && - (confirmEmail === null || - confirmEmail === '' || - confirmEmail === undefined) - ) { + if (control.get('showContacts').value === true && (phone === null || phone === undefined || phone === '')) { + if ((email !== undefined || email !== null || email === '') && (confirmEmail === null || confirmEmail === '' || confirmEmail === undefined)) { return { confirmEmailRequired: true }; } } @@ -118,10 +99,7 @@ export class CustomValidationService { postalValidation(): ValidatorFn { return (control: AbstractControl): { [key: string]: boolean } | null => { if (control.parent) { - if ( - control.parent.get('country').value !== undefined && - control.parent.get('country').value !== null - ) { + if (control.parent.get('country').value !== undefined && control.parent.get('country').value !== null) { if (control.parent.get('country').value.code === 'CAN') { return Validators.pattern(globalConst.postalPattern)(control); } else if (control.parent.get('country').value.code === 'USA') { @@ -151,8 +129,7 @@ export class CustomValidationService { * Checks if the quantity inserted is between 1 and 999 */ quantityPetsValidator(): ValidatorFn { - return (control: AbstractControl): { [key: string]: boolean } | null => - Validators.pattern(globalConst.petsQuantityPattern)(control); + return (control: AbstractControl): { [key: string]: boolean } | null => Validators.pattern(globalConst.petsQuantityPattern)(control); } whitespaceValidator(): ValidatorFn { @@ -165,7 +142,6 @@ export class CustomValidationService { }; } - /** * Checks an array of controls by name, to see if they all have different values (unless empty) * @@ -204,4 +180,17 @@ export class CustomValidationService { return null; }; } + + public needsValidator(): ValidatorFn { + return (group: FormGroup): ValidationErrors | null => { + const anyNeedsIdentified = + group.controls['requiresShelter'].value || group.controls['requiresFood'].value || group.controls['requiresClothing'].value || group.controls['requiresIncidentals'].value; + + const noNeedsIdentified = group.controls['requiresNothing'].value; + if (!anyNeedsIdentified && !noNeedsIdentified) { + return { invalid: true }; + } + return null; + }; + } } diff --git a/registrants/src/UI/embc-registrant/src/app/core/services/formCreation.service.ts b/registrants/src/UI/embc-registrant/src/app/core/services/formCreation.service.ts index c8e627444..c213c1a29 100644 --- a/registrants/src/UI/embc-registrant/src/app/core/services/formCreation.service.ts +++ b/registrants/src/UI/embc-registrant/src/app/core/services/formCreation.service.ts @@ -60,7 +60,9 @@ export class FormCreationService { petsForm$: Observable = this.petsForm.asObservable(); - identifyNeedsForm: BehaviorSubject = new BehaviorSubject(this.formBuilder.group(new IdentifyNeedsForm(new IdentifyNeeds()))); + identifyNeedsForm: BehaviorSubject = new BehaviorSubject( + this.formBuilder.group(new IdentifyNeedsForm(new IdentifyNeeds(), this.customValidator), { validators: [this.customValidator.needsValidator()] }) + ); identifyNeedsForm$: Observable = this.identifyNeedsForm.asObservable(); @@ -162,7 +164,7 @@ export class FormCreationService { this.evacuatedForm.next(this.formBuilder.group(new EvacuatedForm(new Evacuated(), this.formBuilder, this.customValidator))); this.householdMembersForm.next(this.formBuilder.group(new HouseholdMembersForm(new HouseholdMembers(), this.customValidator, this.formBuilder))); this.petsForm.next(this.formBuilder.group(new PetForm(new Pet(), this.customValidator, this.formBuilder))); - this.identifyNeedsForm.next(this.formBuilder.group(new IdentifyNeedsForm(new IdentifyNeeds()))); + this.identifyNeedsForm.next(this.formBuilder.group(new IdentifyNeedsForm(new IdentifyNeeds(), this.customValidator), { validators: [this.customValidator.needsValidator()] })); this.secretForm.next(this.formBuilder.group(new SecretForm(new Secret()))); } } diff --git a/registrants/src/UI/embc-registrant/src/app/core/services/globalConstants.ts b/registrants/src/UI/embc-registrant/src/app/core/services/globalConstants.ts index a6aca7559..a4792bc1f 100644 --- a/registrants/src/UI/embc-registrant/src/app/core/services/globalConstants.ts +++ b/registrants/src/UI/embc-registrant/src/app/core/services/globalConstants.ts @@ -62,7 +62,7 @@ export const successfulBcscInvite: DialogContent = { export const shelterAllowanceNeedDialog: DialogContent = { title: 'Shelter', - text: 'A shelter allowance of $30 per night based on single occupancy ($10 for each additional adult and youth, and $5 for each child
The shelter allowance can be provided to eligible evacuees via e-Transfer.' + text: 'A shelter allowance of $30 per night based on single occupancy ($10 for each additional adult and youth, and $5 for each child).
The shelter allowance can be provided to eligible evacuees via e-Transfer.' }; export const shelterReferralNeedDialog: DialogContent = { diff --git a/registrants/src/UI/embc-registrant/src/app/feature-components/review/review.component.ts b/registrants/src/UI/embc-registrant/src/app/feature-components/review/review.component.ts index abd2765a6..671a1cd85 100644 --- a/registrants/src/UI/embc-registrant/src/app/feature-components/review/review.component.ts +++ b/registrants/src/UI/embc-registrant/src/app/feature-components/review/review.component.ts @@ -2,12 +2,7 @@ import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core'; import { Observable } from 'rxjs'; import { NavigationExtras, Router } from '@angular/router'; import { FormCreationService } from '../../core/services/formCreation.service'; -import { - CaptchaResponse, - CaptchaResponseType -} from 'src/app/core/components/captcha-v2/captcha-v2.component'; -import { ConfigService } from 'src/app/core/services/config.service'; -import { IdentifyNeedsForm } from 'src/app/core/model/needs.model'; +import { CaptchaResponse, CaptchaResponseType } from 'src/app/core/components/captcha-v2/captcha-v2.component'; import { UntypedFormGroup } from '@angular/forms'; import { ShelterType } from 'src/app/core/services/globalConstants'; @@ -30,10 +25,7 @@ export class ReviewComponent implements OnInit { hideCard = false; navigationExtras: NavigationExtras; - constructor( - private router: Router, - public formCreationService: FormCreationService - ) { } + constructor(private router: Router, public formCreationService: FormCreationService) {} ngOnInit(): void { this.navigationExtras = { state: { parentPageName: this.parentPageName } }; @@ -74,10 +66,15 @@ export class ReviewComponent implements OnInit { needs.push('Incidentals'); } if (form.controls.requiresShelterType?.value === ShelterType.referral) { - needs.push('Shelter referral'); + needs.push('Shelter'); } else if (form.controls.requiresShelterType?.value === ShelterType.allowance) { needs.push('Shelter allowance'); } + + if (form.controls.requiresNothing?.value) { + needs.push('Household currently does not require assistance.'); + } + return needs; } } diff --git a/registrants/src/UI/embc-registrant/src/app/sharedModules/components/evacuation-file/evacuation-details/evacuation-details.component.html b/registrants/src/UI/embc-registrant/src/app/sharedModules/components/evacuation-file/evacuation-details/evacuation-details.component.html index b7ce1cc14..b2b17f68c 100644 --- a/registrants/src/UI/embc-registrant/src/app/sharedModules/components/evacuation-file/evacuation-details/evacuation-details.component.html +++ b/registrants/src/UI/embc-registrant/src/app/sharedModules/components/evacuation-file/evacuation-details/evacuation-details.component.html @@ -1,38 +1,17 @@
- - ESS File #{{ - evacuationFileDataService?.isPaper - ? evacuationFileDataService.externalReferenceId - : evacuationFileDataService?.essFileId - }} + ESS File #{{ evacuationFileDataService?.isPaper ? evacuationFileDataService.externalReferenceId : evacuationFileDataService?.essFileId }}
@@ -40,16 +19,11 @@ Status: {{ evacuationFileDataService.evacuationFileStatus }} @@ -57,23 +31,11 @@
- - +

Supports Received

-

- We do not have any records of supports issued within our system. -

-

- Please proceed to an ESS volunteer or your nearest reception center - where you will be assisted. -

+

We do not have any records of supports issued within our system.

+

Please proceed to an ESS volunteer or your nearest reception center where you will be assisted.

@@ -87,12 +49,7 @@
Evacuated From:
-

+

@@ -100,10 +57,7 @@
ESS File Created:
{{ - evacuationFileDataService?.evacuationFileDate - | date: 'dd-MMM-yyyy' - }}{{ evacuationFileDataService?.evacuationFileDate | date: 'dd-MMM-yyyy' }}
@@ -113,22 +67,14 @@
-
- Click on the dates that you received supports below to view full - support details. -
+
Click on the dates that you received supports below to view full support details.
diff --git a/responders/src/UI/embc-responder/src/app/feature-components/wizard/ess-file-components/needs/needs.component.html b/responders/src/UI/embc-responder/src/app/feature-components/wizard/ess-file-components/needs/needs.component.html index 363e9d7c4..c0f78540e 100644 --- a/responders/src/UI/embc-responder/src/app/feature-components/wizard/ess-file-components/needs/needs.component.html +++ b/responders/src/UI/embc-responder/src/app/feature-components/wizard/ess-file-components/needs/needs.component.html @@ -10,78 +10,43 @@
-

- While evacuated, do you need government assistance with any of the - following: Please check all that apply: -

+

While evacuated, do you need government assistance with any of the following: Please check all that apply:


- +

There are several ways to meet your shelter needs.
- You can receive a shelter allowance and use that money to find - your own shelter or be provided with a referral to shelter (like - a cot in a gym or a hotel/motel). + You can receive a shelter allowance and use that money to find your own shelter or be provided with a referral to shelter (like a cot in a gym or a hotel/motel).

@@ -92,17 +57,9 @@
- +
@@ -110,17 +67,9 @@
- +
@@ -128,25 +77,12 @@
- +
@@ -154,17 +90,9 @@
- +
@@ -172,17 +100,9 @@
- +
@@ -191,14 +111,10 @@
- +
- +
diff --git a/responders/src/UI/embc-responder/src/app/feature-components/wizard/step-ess-file/step-ess-file.service.ts b/responders/src/UI/embc-responder/src/app/feature-components/wizard/step-ess-file/step-ess-file.service.ts index b85a58d64..c11c9c593 100644 --- a/responders/src/UI/embc-responder/src/app/feature-components/wizard/step-ess-file/step-ess-file.service.ts +++ b/responders/src/UI/embc-responder/src/app/feature-components/wizard/step-ess-file/step-ess-file.service.ts @@ -5,19 +5,8 @@ import { MatDialog, MatDialogRef } from '@angular/material/dialog'; import { DialogComponent } from 'src/app/shared/components/dialog/dialog.component'; import { InformationDialogComponent } from 'src/app/shared/components/dialog-components/information-dialog/information-dialog.component'; import { Subject } from 'rxjs'; -import { - EvacuationFile, - HouseholdMemberType, - IdentifiedNeed, - InsuranceOption, - NeedsAssessment, - Pet -} from 'src/app/core/api/models'; -import { - UntypedFormArray, - UntypedFormControl, - UntypedFormGroup -} from '@angular/forms'; +import { EvacuationFile, HouseholdMemberType, IdentifiedNeed, InsuranceOption, NeedsAssessment, Pet } from 'src/app/core/api/models'; +import { UntypedFormArray, UntypedFormControl, UntypedFormGroup } from '@angular/forms'; import { AddressModel } from 'src/app/core/models/address.model'; import { HouseholdMemberModel } from 'src/app/core/models/household-member.model'; import { EvacuationFileModel } from 'src/app/core/models/evacuation-file.model'; @@ -35,814 +24,759 @@ import { LoadEvacueeListService } from 'src/app/core/services/load-evacuee-list. @Injectable({ providedIn: 'root' }) export class StepEssFileService { - // Wizard variables - private essTabsVal: Array; - private nextTabUpdateVal: Subject = new Subject(); - - //Selected ESS File object - private selectedEssFileVal: EvacuationFileModel; - - // Important values not set on form - // ESS File ID, Primary Registrant ID, and Task Number are set on EvacueeSession - private primaryAddressVal: AddressModel; - private taskNumberVal: string; - private evacuationFileDateVal: string; - private primaryRegistrantIdVal: string; - - // Evacuation Details tab - private paperESSFileVal: string; - private completedByVal?: string; - private completedOnVal?: string; - private evacuatedFromPrimaryVal: string; - private evacAddressVal: AddressModel; - private facilityNameVal: string; - private insuranceVal: InsuranceOption; - - // Household Members & Pets tab - private haveHouseHoldMembersVal: string; - private householdMembersVal: HouseholdMemberModel[]; - private selectedHouseholdMembersVal: HouseholdMemberModel[]; - private tempHouseholdMemberVal: HouseholdMemberModel; - private addMemberIndicatorVal: boolean; - private addMemberFormIndicatorVal: boolean; - - private havePetsVal: string; - private petsListVal: Pet[]; - private addPetIndicatorVal: boolean; - - // Needs tab - private needs: Set = new Set(); - - // Security Phrase tab - private bypassPhraseVal: boolean; - private securityPhraseVal: string; - private originalPhraseVal: string; - private editedSecurityPhraseVal: boolean; - private needsAssessmentSubmitFlagVal: boolean; - - constructor( - private dialog: MatDialog, - private wizardService: WizardService, - private evacueeSession: EvacueeSessionService, - private userService: UserService, - private locationService: LocationsService, - private evacueeSearchService: EvacueeSearchService, - private appBaseService: AppBaseService, - private computeState: ComputeRulesService, - private loadEvacueeListService: LoadEvacueeListService - ) { } - - // Selected ESS File Model getter and setter - public get selectedEssFile(): EvacuationFileModel { - return this.selectedEssFileVal; - } - - public set selectedEssFile(essFile: EvacuationFileModel) { - this.selectedEssFileVal = essFile; - } - - public get needsAssessmentSubmitFlag(): boolean { - return this.needsAssessmentSubmitFlagVal; - } - - public set needsAssessmentSubmitFlag(needsAssessmentSubmitFlagVal: boolean) { - this.needsAssessmentSubmitFlagVal = needsAssessmentSubmitFlagVal; - } - - public get primaryRegistrantId(): string { - return this.primaryRegistrantIdVal; - } - - public set primaryRegistrantId(primaryRegistrantIdVal: string) { - this.primaryRegistrantIdVal = primaryRegistrantIdVal; - } - - // Wizard variables - public get essTabs(): Array { - return this.essTabsVal; - } - public set essTabs(essTabsVal: Array) { - this.essTabsVal = essTabsVal; - } - - public get nextTabUpdate(): Subject { - return this.nextTabUpdateVal; - } - public set nextTabUpdate(nextTabUpdateVal: Subject) { - this.nextTabUpdateVal = nextTabUpdateVal; - } - - // Required values not set on form - // ESS File ID, Primary Registrant ID, and Task Number are set on EvacueeSession - public get primaryAddress(): AddressModel { - return this.primaryAddressVal; - } - public set primaryAddress(primaryAddressVal: AddressModel) { - this.primaryAddressVal = primaryAddressVal; - } - - public get taskNumber(): string { - return this.taskNumberVal; - } - - public set taskNumber(taskNumberVal: string) { - this.taskNumberVal = taskNumberVal; - } - - public get evacuationFileDate(): string { - return this.evacuationFileDateVal; - } - - public set evacuationFileDate(evacuationFileDateVal: string) { - this.evacuationFileDateVal = evacuationFileDateVal; - } - - // Evacuation Details tab - public get paperESSFile(): string { - return this.paperESSFileVal; - } - public set paperESSFile(paperESSFileVal: string) { - this.paperESSFileVal = paperESSFileVal; - } - - public get completedBy(): string { - return this.completedByVal; - } - public set completedBy(completedByVal: string) { - this.completedByVal = completedByVal; - } - - public get completedOn(): string { - return this.completedOnVal; - } - public set completedOn(completedOnVal: string) { - this.completedOnVal = completedOnVal; - } - - public get evacuatedFromPrimary(): string { - return this.evacuatedFromPrimaryVal; - } - public set evacuatedFromPrimary(evacuatedFromPrimaryVal: string) { - this.evacuatedFromPrimaryVal = evacuatedFromPrimaryVal; - } - - public get evacAddress(): AddressModel { - return this.evacAddressVal; - } - public set evacAddress(evacAddressVal: AddressModel) { - this.evacAddressVal = evacAddressVal; - } - - public get facilityName(): string { - return this.facilityNameVal; - } - public set facilityName(facilityNameVal: string) { - this.facilityNameVal = facilityNameVal; - } - - public get insurance(): InsuranceOption { - return this.insuranceVal; - } - public set insurance(insuranceVal: InsuranceOption) { - this.insuranceVal = insuranceVal; - } - - // Household Members tab - public get haveHouseHoldMembers(): string { - return this.haveHouseHoldMembersVal; - } - public set haveHouseHoldMembers(haveHouseHoldMembersVal: string) { - this.haveHouseHoldMembersVal = haveHouseHoldMembersVal; - } - - public get householdMembers(): HouseholdMemberModel[] { - return this.householdMembersVal; - } - public set householdMembers(householdMembersVal: HouseholdMemberModel[]) { - this.householdMembersVal = householdMembersVal; - } - - public get selectedHouseholdMembers(): HouseholdMemberModel[] { - return this.selectedHouseholdMembersVal; - } - public set selectedHouseholdMembers( - selectedHouseholdMembersVal: HouseholdMemberModel[] - ) { - this.selectedHouseholdMembersVal = selectedHouseholdMembersVal; - } - - public set tempHouseholdMember(tempHouseHoldMemberVal: HouseholdMemberModel) { - this.tempHouseholdMemberVal = tempHouseHoldMemberVal; - } - - public get tempHouseholdMember(): HouseholdMemberModel { - return this.tempHouseholdMemberVal; - } - - public get addMemberIndicator(): boolean { - return this.addMemberIndicatorVal; - } - public set addMemberIndicator(addMemberIndicatorVal: boolean) { - this.addMemberIndicatorVal = addMemberIndicatorVal; - } - - public get addMemberFormIndicator(): boolean { - return this.addMemberFormIndicatorVal; - } - public set addMemberFormIndicator(addMemberFormIndicatorVal: boolean) { - this.addMemberFormIndicatorVal = addMemberFormIndicatorVal; - } - - // Animals tab - public get havePets(): string { - return this.havePetsVal; - } - public set havePets(havePetsVal: string) { - this.havePetsVal = havePetsVal; - } - - public get petsList(): Pet[] { - return this.petsListVal; - } - public set petsList(petsListVal: Pet[]) { - this.petsListVal = petsListVal; - } - - public get addPetIndicator(): boolean { - return this.addPetIndicatorVal; - } - - public set addPetIndicator(addPetIndicatorVal: boolean) { - this.addPetIndicatorVal = addPetIndicatorVal; - } - - // Needs tab - - public get requiresClothing(): boolean { - return this.needs.has(IdentifiedNeed.Clothing); - } - - public set requiresClothing(checked: boolean) { - if (checked && !this.needs.has(IdentifiedNeed.Clothing)) { - this.needs.add(IdentifiedNeed.Clothing); - } else if (!checked && this.needs.has(IdentifiedNeed.Clothing)) { - this.needs.delete(IdentifiedNeed.Clothing); - } - } - - public get requiresIncidentals(): boolean { - return this.needs.has(IdentifiedNeed.Clothing); - } - - public set requiresIncidentals(checked: boolean) { - if (checked && !this.needs.has(IdentifiedNeed.Incidentals)) { - this.needs.add(IdentifiedNeed.Incidentals); - } else if (!checked && this.needs.has(IdentifiedNeed.Incidentals)) { - this.needs.delete(IdentifiedNeed.Incidentals); - } - } - - public get requiresFood(): boolean { - return this.needs.has(IdentifiedNeed.Food); - } - - public set requiresFood(checked: boolean) { - if (checked && !this.needs.has(IdentifiedNeed.Food)) { - this.needs.add(IdentifiedNeed.Food); - } else if (!checked && this.needs.has(IdentifiedNeed.Food)) { - this.needs.delete(IdentifiedNeed.Food); - } - } - - public get requiresTransportation(): boolean { - return this.needs.has(IdentifiedNeed.Tranportation); - } - - public set requiresTransportation(checked: boolean) { - if (checked && !this.needs.has(IdentifiedNeed.Tranportation)) { - this.needs.add(IdentifiedNeed.Tranportation); - } else if (!checked && this.needs.has(IdentifiedNeed.Tranportation)) { - this.needs.delete(IdentifiedNeed.Tranportation); - } - } - public get requiresShelterReferral(): boolean { - return this.needs.has(IdentifiedNeed.ShelterReferral); - } - - public set requiresShelterReferral(checked: boolean) { - if (checked && !this.needs.has(IdentifiedNeed.ShelterReferral)) { - this.needs.add(IdentifiedNeed.ShelterReferral); - this.requiresShelterAllowance = false; - } else if (!checked && this.needs.has(IdentifiedNeed.ShelterReferral)) { - this.needs.delete(IdentifiedNeed.ShelterReferral); - } - } - - public get requiresShelterAllowance(): boolean { - return this.needs.has(IdentifiedNeed.ShelterAllowance); - } - - public set requiresShelterAllowance(checked: boolean) { - if (checked && !this.needs.has(IdentifiedNeed.ShelterAllowance)) { - this.needs.add(IdentifiedNeed.ShelterAllowance); - this.requiresShelterReferral = false; - } else if (!checked && this.needs.has(IdentifiedNeed.ShelterAllowance)) { - this.needs.delete(IdentifiedNeed.ShelterAllowance); - } - } - - private reqiresNothing: boolean | undefined = undefined; - - public get requiresNothing(): boolean | undefined { - return this.reqiresNothing; - } - - public set requiresNothing(checked: boolean) { - this.reqiresNothing = checked; - if (checked) { - this.needs.clear(); - } - } - - public get needsIdentified(): string[] { - return Array.from(this.needs) - .map(need => this.loadEvacueeListService.getIdentifiedNeeds().find(value => value.value === need)?.description); - - } - - // Security Phrase tab - public get bypassPhrase(): boolean { - return this.bypassPhraseVal; - } - public set bypassPhrase(bypassPhraseVal: boolean) { - this.bypassPhraseVal = bypassPhraseVal; - } - - public get securityPhrase(): string { - return this.securityPhraseVal; - } - public set securityPhrase(securityPhraseVal: string) { - this.securityPhraseVal = securityPhraseVal; - } - - public set originalSecurityPhrase(originalSecurityPhrase: string) { - this.originalPhraseVal = originalSecurityPhrase; - } - - public get originalSecurityPhrase(): string { - return this.originalPhraseVal; - } - - public get editedSecurityPhrase(): boolean { - return this.editedSecurityPhraseVal; - } - public set editedSecurityPhrase(editedSecurityPhraseVal: boolean) { - this.editedSecurityPhraseVal = editedSecurityPhraseVal; - } - - /** - * Set the given status to the given tab - * - * @param name of the tab - * @param status of the tab - */ - public setTabStatus(name: string, status: string): void { - if (this.essTabs !== undefined) { - this.essTabs.map((tab) => { - if (tab.name === name) { - tab.status = status; - } - return tab; - }); - } - } - - /** - * Convert Create ESS File form data into object that can be submitted to the API - * - * @returns Evacuation File record usable by the API - */ - public createEvacFileDTO(): EvacuationFile { - // Get Correct API values for needs assessment - const needsObject: NeedsAssessment = { - insurance: this.insurance, - householdMembers: this.householdMembers, - pets: this.petsList, - needs: Array.from(this.needs) - }; - - // Map out into DTO object and return - return { - primaryRegistrantId: - this.appBaseService?.appModel?.selectedProfile?.selectedEvacueeInContext - ?.id, - completedBy: this.completedBy, - completedOn: this.completedOn, - manualFileId: this.evacueeSession.isPaperBased - ? this.evacueeSearchService?.evacueeSearchContext - ?.evacueeSearchParameters?.paperFileNumber - : null, - evacuatedFromAddress: this.locationService.setAddressObjectForDTO( - this.evacAddress - ), - registrationLocation: this.facilityName, - - needsAssessment: needsObject, - securityPhrase: this.securityPhrase, - securityPhraseEdited: true, - task: { - taskNumber: this.userService.currentProfile?.taskNumber - } - }; - } - - /** - * Convert Update ESS File form data into object that can be submitted to the API - * - * @returns Evacuation File record usable by the API - */ - public updateEvacFileDTO(): EvacuationFile { - // Get Correct API values for needs assessment - const needsObject: NeedsAssessment = { - insurance: this.insurance, - householdMembers: this.selectedHouseholdMembers, - pets: this.petsList, - needs: Array.from(this.needs) - }; - - // Map out into DTO object and return - return { - completedBy: this.completedBy, - completedOn: this.completedOn, - manualFileId: this.evacueeSession.isPaperBased - ? this.evacueeSearchService?.evacueeSearchContext - ?.evacueeSearchParameters?.paperFileNumber - : null, - evacuationFileDate: this.evacuationFileDate, - primaryRegistrantId: this.primaryRegistrantId, - - evacuatedFromAddress: this.locationService.setAddressObjectForDTO( - this.evacAddress - ), - registrationLocation: this.facilityName, - - needsAssessment: needsObject, - securityPhrase: this.securityPhrase, - securityPhraseEdited: this.editedSecurityPhrase, - task: { - taskNumber: - this.taskNumber ?? this.userService.currentProfile?.taskNumber - } - }; - } - - /** - * Reset all values in this service to defaults - */ - public clearService() { - if (this.essTabs) { - this.essTabs.length = 0; - } - // Wizard variables - this.nextTabUpdate.next(); + private essTabsVal: Array; + private nextTabUpdateVal: Subject = new Subject(); + + //Selected ESS File object + private selectedEssFileVal: EvacuationFileModel; // Important values not set on form // ESS File ID, Primary Registrant ID, and Task Number are set on EvacueeSession - this.primaryAddress = undefined; - this.taskNumber = undefined; + private primaryAddressVal: AddressModel; + private taskNumberVal: string; + private evacuationFileDateVal: string; + private primaryRegistrantIdVal: string; // Evacuation Details tab - this.paperESSFile = undefined; - this.completedBy = undefined; - this.completedOnVal = undefined; - this.evacuatedFromPrimary = undefined; - this.evacAddress = undefined; - this.facilityName = undefined; - this.insurance = undefined; - - // Household Members tab - this.haveHouseHoldMembers = undefined; - this.householdMembers = undefined; - this.selectedHouseholdMembers = undefined; - this.addMemberIndicator = undefined; - this.addMemberFormIndicator = undefined; - - // Animals tab - this.havePets = undefined; - this.petsList = undefined; - this.addPetIndicator = undefined; + private paperESSFileVal: string; + private completedByVal?: string; + private completedOnVal?: string; + private evacuatedFromPrimaryVal: string; + private evacAddressVal: AddressModel; + private facilityNameVal: string; + private insuranceVal: InsuranceOption; + + // Household Members & Pets tab + private haveHouseHoldMembersVal: string; + private householdMembersVal: HouseholdMemberModel[]; + private selectedHouseholdMembersVal: HouseholdMemberModel[]; + private tempHouseholdMemberVal: HouseholdMemberModel; + private addMemberIndicatorVal: boolean; + private addMemberFormIndicatorVal: boolean; + + private havePetsVal: string; + private petsListVal: Pet[]; + private addPetIndicatorVal: boolean; // Needs tab - this.needs.clear(); + private needs: Set = new Set(); // Security Phrase tab - this.bypassPhrase = undefined; - this.securityPhrase = undefined; - this.originalSecurityPhrase = undefined; - this.editedSecurityPhrase = undefined; - } - - /** - * Update the wizard's values with ones fetched from API - */ - public setFormValuesFromFile(essFile: EvacuationFileModel) { - this.selectedEssFile = essFile; - this.primaryRegistrantId = essFile.primaryRegistrantId; - - this.appBaseService.wizardProperties = { - lastCompletedStep: WizardSteps.Step2 - }; - this.computeState.triggerEvent(); - - const essNeeds = essFile.needsAssessment; - this.evacueeSession.currentNeedsAssessment = essNeeds; - this.evacueeSession.evacFile = essFile; - this.wizardService.createObjectReference(essFile, 'file'); - const primaryLastName = essFile.householdMembers?.find( - (member) => member.type === HouseholdMemberType.Registrant - ).lastName; - - //Additional Behind the scenes variables - this.taskNumber = essFile.task.taskNumber; - this.evacuationFileDate = essFile.evacuationFileDate; + private bypassPhraseVal: boolean; + private securityPhraseVal: string; + private originalPhraseVal: string; + private editedSecurityPhraseVal: boolean; + private needsAssessmentSubmitFlagVal: boolean; + + constructor( + private dialog: MatDialog, + private wizardService: WizardService, + private evacueeSession: EvacueeSessionService, + private userService: UserService, + private locationService: LocationsService, + private evacueeSearchService: EvacueeSearchService, + private appBaseService: AppBaseService, + private computeState: ComputeRulesService, + private loadEvacueeListService: LoadEvacueeListService + ) {} + + // Selected ESS File Model getter and setter + public get selectedEssFile(): EvacuationFileModel { + return this.selectedEssFileVal; + } + + public set selectedEssFile(essFile: EvacuationFileModel) { + this.selectedEssFileVal = essFile; + } + + public get needsAssessmentSubmitFlag(): boolean { + return this.needsAssessmentSubmitFlagVal; + } + + public set needsAssessmentSubmitFlag(needsAssessmentSubmitFlagVal: boolean) { + this.needsAssessmentSubmitFlagVal = needsAssessmentSubmitFlagVal; + } + + public get primaryRegistrantId(): string { + return this.primaryRegistrantIdVal; + } + + public set primaryRegistrantId(primaryRegistrantIdVal: string) { + this.primaryRegistrantIdVal = primaryRegistrantIdVal; + } // Wizard variables - //this.evacueeSession.essFileNumber = essFile.id; + public get essTabs(): Array { + return this.essTabsVal; + } + public set essTabs(essTabsVal: Array) { + this.essTabsVal = essTabsVal; + } + + public get nextTabUpdate(): Subject { + return this.nextTabUpdateVal; + } + public set nextTabUpdate(nextTabUpdateVal: Subject) { + this.nextTabUpdateVal = nextTabUpdateVal; + } + + // Required values not set on form + // ESS File ID, Primary Registrant ID, and Task Number are set on EvacueeSession + public get primaryAddress(): AddressModel { + return this.primaryAddressVal; + } + public set primaryAddress(primaryAddressVal: AddressModel) { + this.primaryAddressVal = primaryAddressVal; + } + + public get taskNumber(): string { + return this.taskNumberVal; + } + + public set taskNumber(taskNumberVal: string) { + this.taskNumberVal = taskNumberVal; + } + + public get evacuationFileDate(): string { + return this.evacuationFileDateVal; + } + + public set evacuationFileDate(evacuationFileDateVal: string) { + this.evacuationFileDateVal = evacuationFileDateVal; + } // Evacuation Details tab - this.completedOn = essFile.completedOn; - this.completedBy = essFile.completedBy; - this.evacAddress = essFile.evacuatedFromAddress; - this.facilityName = essFile.registrationLocation; + public get paperESSFile(): string { + return this.paperESSFileVal; + } + public set paperESSFile(paperESSFileVal: string) { + this.paperESSFileVal = paperESSFileVal; + } - this.evacuatedFromPrimary = globalConst.radioButtonOptions.find( - (ins) => ins.apiValue === _.isEqual(this.primaryAddress, this.evacAddress) - )?.value; + public get completedBy(): string { + return this.completedByVal; + } + public set completedBy(completedByVal: string) { + this.completedByVal = completedByVal; + } - this.insurance = essNeeds.insurance; + public get completedOn(): string { + return this.completedOnVal; + } + public set completedOn(completedOnVal: string) { + this.completedOnVal = completedOnVal; + } + + public get evacuatedFromPrimary(): string { + return this.evacuatedFromPrimaryVal; + } + public set evacuatedFromPrimary(evacuatedFromPrimaryVal: string) { + this.evacuatedFromPrimaryVal = evacuatedFromPrimaryVal; + } + + public get evacAddress(): AddressModel { + return this.evacAddressVal; + } + public set evacAddress(evacAddressVal: AddressModel) { + this.evacAddressVal = evacAddressVal; + } + + public get facilityName(): string { + return this.facilityNameVal; + } + public set facilityName(facilityNameVal: string) { + this.facilityNameVal = facilityNameVal; + } + + public get insurance(): InsuranceOption { + return this.insuranceVal; + } + public set insurance(insuranceVal: InsuranceOption) { + this.insuranceVal = insuranceVal; + } // Household Members tab - // Split main applicant from other household members, remap to UI model - this.householdMembers = essFile.householdMembers?.map( - (member) => { - return { - ...member, - sameLastName: member.lastName === primaryLastName, - householdMemberFromDatabase: true - }; - } - ); + public get haveHouseHoldMembers(): string { + return this.haveHouseHoldMembersVal; + } + public set haveHouseHoldMembers(haveHouseHoldMembersVal: string) { + this.haveHouseHoldMembersVal = haveHouseHoldMembersVal; + } + + public get householdMembers(): HouseholdMemberModel[] { + return this.householdMembersVal; + } + public set householdMembers(householdMembersVal: HouseholdMemberModel[]) { + this.householdMembersVal = householdMembersVal; + } + + public get selectedHouseholdMembers(): HouseholdMemberModel[] { + return this.selectedHouseholdMembersVal; + } + public set selectedHouseholdMembers(selectedHouseholdMembersVal: HouseholdMemberModel[]) { + this.selectedHouseholdMembersVal = selectedHouseholdMembersVal; + } + + public set tempHouseholdMember(tempHouseHoldMemberVal: HouseholdMemberModel) { + this.tempHouseholdMemberVal = tempHouseHoldMemberVal; + } + + public get tempHouseholdMember(): HouseholdMemberModel { + return this.tempHouseholdMemberVal; + } - this.selectedHouseholdMembers = undefined; + public get addMemberIndicator(): boolean { + return this.addMemberIndicatorVal; + } + public set addMemberIndicator(addMemberIndicatorVal: boolean) { + this.addMemberIndicatorVal = addMemberIndicatorVal; + } - this.haveHouseHoldMembers = globalConst.radioButtonOptions.find( - (ins) => ins.apiValue === this.householdMembers?.length > 2 - )?.value; + public get addMemberFormIndicator(): boolean { + return this.addMemberFormIndicatorVal; + } + public set addMemberFormIndicator(addMemberFormIndicatorVal: boolean) { + this.addMemberFormIndicatorVal = addMemberFormIndicatorVal; + } // Animals tab - const petsArray = []; - this.petsList = [...petsArray, ...essNeeds.pets]; - this.havePets = globalConst.radioButtonOptions.find( - (ins) => ins.apiValue === essNeeds.pets?.length > 0 - )?.value; + public get havePets(): string { + return this.havePetsVal; + } + public set havePets(havePetsVal: string) { + this.havePetsVal = havePetsVal; + } + + public get petsList(): Pet[] { + return this.petsListVal; + } + public set petsList(petsListVal: Pet[]) { + this.petsListVal = petsListVal; + } + + public get addPetIndicator(): boolean { + return this.addPetIndicatorVal; + } + + public set addPetIndicator(addPetIndicatorVal: boolean) { + this.addPetIndicatorVal = addPetIndicatorVal; + } // Needs tab - this.needs = new Set(essNeeds.needs); - this.reqiresNothing = essNeeds.needs?.length === 0; - // Security Phrase tab - this.securityPhrase = essFile.securityPhrase; - this.originalSecurityPhrase = essFile.securityPhrase; - this.editedSecurityPhrase = essFile.securityPhraseEdited; - } - - /** - * Determines if the tab navigation is allowed or not - * - * @param tabRoute clicked route - * @param $event mouse click event - * @returns true/false - */ - isAllowed(tabRoute: string, $event: MouseEvent): boolean { - if (tabRoute === 'review') { - const allow = this.checkTabsStatus(); - if (allow) { - $event.stopPropagation(); - $event.preventDefault(); - - this.openModal(globalConst.wizardESSFileMessage); - } - return allow; - } - } - - /** - * Checks the status of the tabs - * - * @returns true/false - */ - checkTabsStatus(): boolean { - return this.essTabs?.some( - (tab) => - (tab.status === 'not-started' || tab.status === 'incomplete') && - tab.name !== 'review' - ); - } - - /** - * Open information modal window - * - * @param text text to display - * @param title title of modal - * @param button text on "close" button ("Close" by default) - * @param exitLink link to exit greater context (e.g. wizard) for modal, null = no link - */ - openModal(content: DialogContent): MatDialogRef { - const thisModal = this.dialog.open(DialogComponent, { - data: { - component: InformationDialogComponent, - content - }, - width: '530px' - }); - - return thisModal; - } - - /** - * Checks if the form is partially completed or not - * - * @param form form group - * @returns true/false - */ - checkForPartialUpdates(form: UntypedFormGroup): boolean { - const fields = []; - Object.keys(form.controls).forEach((field) => { - const control = form.controls[field] as - | UntypedFormControl - | UntypedFormGroup - | UntypedFormArray; - if (control instanceof UntypedFormControl) { - if (control.value instanceof Object && control.value != null) { - fields.push(control.value.length); - } else { - fields.push(control.value); + public get requiresClothing(): boolean { + return this.needs.has(IdentifiedNeed.Clothing); + } + + public set requiresClothing(checked: boolean) { + if (checked && !this.needs.has(IdentifiedNeed.Clothing)) { + this.needs.add(IdentifiedNeed.Clothing); + } else if (!checked && this.needs.has(IdentifiedNeed.Clothing)) { + this.needs.delete(IdentifiedNeed.Clothing); + } + } + + public get requiresIncidentals(): boolean { + return this.needs.has(IdentifiedNeed.Incidentals); + } + + public set requiresIncidentals(checked: boolean) { + if (checked && !this.needs.has(IdentifiedNeed.Incidentals)) { + this.needs.add(IdentifiedNeed.Incidentals); + } else if (!checked && this.needs.has(IdentifiedNeed.Incidentals)) { + this.needs.delete(IdentifiedNeed.Incidentals); } - } else if ( - control instanceof UntypedFormGroup || - control instanceof UntypedFormArray - ) { - for (const key in control.controls) { - if (control.controls.hasOwnProperty(key)) { - fields.push(control.controls[key].value); - } + } + + public get requiresFood(): boolean { + return this.needs.has(IdentifiedNeed.Food); + } + + public set requiresFood(checked: boolean) { + if (checked && !this.needs.has(IdentifiedNeed.Food)) { + this.needs.add(IdentifiedNeed.Food); + } else if (!checked && this.needs.has(IdentifiedNeed.Food)) { + this.needs.delete(IdentifiedNeed.Food); } - } - }); - const result = fields.filter((field) => !!field); - return result.length !== 0; - } - - /** - * Checks if the form is partially completed or not - * - * @param form form group - * @returns true/false - */ - checkForEvacDetailsPartialUpdates(form: UntypedFormGroup): boolean { - const fields = []; - Object.keys(form.controls).forEach((field) => { - const control = form.controls[field] as - | UntypedFormControl - | UntypedFormGroup - | UntypedFormArray; - if (control instanceof UntypedFormControl) { - if (control.value instanceof Object && control.value != null) { - fields.push(control.value.length); - } else { - if (typeof control.value !== 'boolean') { - fields.push(control.value); - } + } + + public get requiresTransportation(): boolean { + return this.needs.has(IdentifiedNeed.Tranportation); + } + + public set requiresTransportation(checked: boolean) { + if (checked && !this.needs.has(IdentifiedNeed.Tranportation)) { + this.needs.add(IdentifiedNeed.Tranportation); + } else if (!checked && this.needs.has(IdentifiedNeed.Tranportation)) { + this.needs.delete(IdentifiedNeed.Tranportation); } - } else if (control instanceof UntypedFormGroup) { - for (const key in control.controls) { - if (control.controls.hasOwnProperty(key)) { - fields.push(control.controls[key].value); - } + } + public get requiresShelterReferral(): boolean { + return this.needs.has(IdentifiedNeed.ShelterReferral); + } + + public set requiresShelterReferral(checked: boolean) { + if (checked && !this.needs.has(IdentifiedNeed.ShelterReferral)) { + this.needs.add(IdentifiedNeed.ShelterReferral); + this.requiresShelterAllowance = false; + } else if (!checked && this.needs.has(IdentifiedNeed.ShelterReferral)) { + this.needs.delete(IdentifiedNeed.ShelterReferral); } - } - }); - const result = fields.filter((field) => !!field); - return result.length > 2; - } - - /** - * Sets the tab status for the Review ESS File wizard - */ - public setReviewEssFileTabStatus(): void { - this.essTabs.map((tab) => { - if (tab.name !== 'review') { - tab.status = 'complete'; - } - if (tab.name === 'household-members-pets') { - tab.status = 'incomplete'; - } - if ( - this.securityPhrase === null || - this.securityPhrase === undefined || - this.securityPhrase === '' - ) { - if (tab.name === 'security-phrase') { - tab.status = 'not-started'; + } + + public get requiresShelterAllowance(): boolean { + return this.needs.has(IdentifiedNeed.ShelterAllowance); + } + + public set requiresShelterAllowance(checked: boolean) { + if (checked && !this.needs.has(IdentifiedNeed.ShelterAllowance)) { + this.needs.add(IdentifiedNeed.ShelterAllowance); + this.requiresShelterReferral = false; + } else if (!checked && this.needs.has(IdentifiedNeed.ShelterAllowance)) { + this.needs.delete(IdentifiedNeed.ShelterAllowance); } - } - return tab; - }); - } - - /** - * Sets the tab status for the Complete ESS File wizard - */ - public setCompleteEssFileTabStatus(): void { - this.essTabs.map((tab) => { - if (tab.name !== 'review') { - tab.status = 'complete'; - } - if ( - tab.name === 'household-members-pets' || - tab.name === 'evacuation-details' - ) { - tab.status = 'incomplete'; - } - return tab; - }); - } - - public getTaskEndDate(): string { - if ( - this.appBaseService?.wizardProperties?.wizardType === - WizardType.NewEssFile || - this.appBaseService?.wizardProperties?.wizardType === - WizardType.NewRegistration - ) { - return this.userService?.currentProfile?.taskStartDate; - } else { - return this.selectedEssFileVal?.task?.from; - } - } - - checkForEdit(): boolean { - return this.appBaseService?.appModel?.selectedEssFile?.id !== null; - } - - getNavLinks(name: string): TabModel { - if (this.essTabs !== undefined) { - return this.essTabs.find((tab) => tab.name === name); - } - } - - updateEditedFormStatus() { - this.wizardService.editStatus$.subscribe((statues: TabStatusManager[]) => { - const index = statues.findIndex((tab) => tab.tabUpdateStatus === true); - if (index !== -1) { - this.setTabStatus('review', 'incomplete'); - this.wizardService.setStepStatus('/ess-wizard/evacuee-profile', true); - this.wizardService.setStepStatus('/ess-wizard/add-supports', true); - this.wizardService.setStepStatus('/ess-wizard/add-notes', true); - } else { - if (!this.checkTabsStatus()) { - this.wizardService.setStepStatus( - '/ess-wizard/evacuee-profile', - false - ); - this.wizardService.setStepStatus('/ess-wizard/add-supports', false); - this.wizardService.setStepStatus('/ess-wizard/add-notes', false); - this.setTabStatus('review', 'complete'); + } + + private reqiresNothing: boolean | undefined = undefined; + + public get requiresNothing(): boolean | undefined { + return this.reqiresNothing; + } + + public set requiresNothing(checked: boolean) { + this.reqiresNothing = checked; + if (checked) { + this.needs.clear(); } - } - }); - } + } - /** - * Returns the correct task number based on the type of Wizard - */ - public getTaskNumber(wizardType: string): string { - switch (wizardType) { - case 'new-registration': - return this.userService.currentProfile?.taskNumber; + public get needsIdentified(): string[] { + return Array.from(this.needs).map((need) => this.loadEvacueeListService.getIdentifiedNeeds().find((value) => value.value === need)?.description); + } + + // Security Phrase tab + public get bypassPhrase(): boolean { + return this.bypassPhraseVal; + } + public set bypassPhrase(bypassPhraseVal: boolean) { + this.bypassPhraseVal = bypassPhraseVal; + } + + public get securityPhrase(): string { + return this.securityPhraseVal; + } + public set securityPhrase(securityPhraseVal: string) { + this.securityPhraseVal = securityPhraseVal; + } + + public set originalSecurityPhrase(originalSecurityPhrase: string) { + this.originalPhraseVal = originalSecurityPhrase; + } + + public get originalSecurityPhrase(): string { + return this.originalPhraseVal; + } - case 'edit-registration': - return this.taskNumber; + public get editedSecurityPhrase(): boolean { + return this.editedSecurityPhraseVal; + } + public set editedSecurityPhrase(editedSecurityPhraseVal: boolean) { + this.editedSecurityPhraseVal = editedSecurityPhraseVal; + } - case 'new-ess-file': - return this.userService.currentProfile?.taskNumber; + /** + * Set the given status to the given tab + * + * @param name of the tab + * @param status of the tab + */ + public setTabStatus(name: string, status: string): void { + if (this.essTabs !== undefined) { + this.essTabs.map((tab) => { + if (tab.name === name) { + tab.status = status; + } + return tab; + }); + } + } - case 'review-file': - return this.taskNumber; + /** + * Convert Create ESS File form data into object that can be submitted to the API + * + * @returns Evacuation File record usable by the API + */ + public createEvacFileDTO(): EvacuationFile { + // Get Correct API values for needs assessment + const needsObject: NeedsAssessment = { + insurance: this.insurance, + householdMembers: this.householdMembers, + pets: this.petsList, + needs: Array.from(this.needs) + }; - case 'complete-file': - return this.userService.currentProfile?.taskNumber; + // Map out into DTO object and return + return { + primaryRegistrantId: this.appBaseService?.appModel?.selectedProfile?.selectedEvacueeInContext?.id, + completedBy: this.completedBy, + completedOn: this.completedOn, + manualFileId: this.evacueeSession.isPaperBased ? this.evacueeSearchService?.evacueeSearchContext?.evacueeSearchParameters?.paperFileNumber : null, + evacuatedFromAddress: this.locationService.setAddressObjectForDTO(this.evacAddress), + registrationLocation: this.facilityName, + + needsAssessment: needsObject, + securityPhrase: this.securityPhrase, + securityPhraseEdited: true, + task: { + taskNumber: this.userService.currentProfile?.taskNumber + } + }; + } + + /** + * Convert Update ESS File form data into object that can be submitted to the API + * + * @returns Evacuation File record usable by the API + */ + public updateEvacFileDTO(): EvacuationFile { + // Get Correct API values for needs assessment + const needsObject: NeedsAssessment = { + insurance: this.insurance, + householdMembers: this.selectedHouseholdMembers, + pets: this.petsList, + needs: Array.from(this.needs) + }; + + // Map out into DTO object and return + return { + completedBy: this.completedBy, + completedOn: this.completedOn, + manualFileId: this.evacueeSession.isPaperBased ? this.evacueeSearchService?.evacueeSearchContext?.evacueeSearchParameters?.paperFileNumber : null, + evacuationFileDate: this.evacuationFileDate, + primaryRegistrantId: this.primaryRegistrantId, + + evacuatedFromAddress: this.locationService.setAddressObjectForDTO(this.evacAddress), + registrationLocation: this.facilityName, + + needsAssessment: needsObject, + securityPhrase: this.securityPhrase, + securityPhraseEdited: this.editedSecurityPhrase, + task: { + taskNumber: this.taskNumber ?? this.userService.currentProfile?.taskNumber + } + }; + } + + /** + * Reset all values in this service to defaults + */ + public clearService() { + if (this.essTabs) { + this.essTabs.length = 0; + } + + // Wizard variables + this.nextTabUpdate.next(); + + // Important values not set on form + // ESS File ID, Primary Registrant ID, and Task Number are set on EvacueeSession + this.primaryAddress = undefined; + this.taskNumber = undefined; + + // Evacuation Details tab + this.paperESSFile = undefined; + this.completedBy = undefined; + this.completedOnVal = undefined; + this.evacuatedFromPrimary = undefined; + this.evacAddress = undefined; + this.facilityName = undefined; + this.insurance = undefined; + + // Household Members tab + this.haveHouseHoldMembers = undefined; + this.householdMembers = undefined; + this.selectedHouseholdMembers = undefined; + this.addMemberIndicator = undefined; + this.addMemberFormIndicator = undefined; + + // Animals tab + this.havePets = undefined; + this.petsList = undefined; + this.addPetIndicator = undefined; + + // Needs tab + this.needs.clear(); + + // Security Phrase tab + this.bypassPhrase = undefined; + this.securityPhrase = undefined; + this.originalSecurityPhrase = undefined; + this.editedSecurityPhrase = undefined; + } + + /** + * Update the wizard's values with ones fetched from API + */ + public setFormValuesFromFile(essFile: EvacuationFileModel) { + this.selectedEssFile = essFile; + this.primaryRegistrantId = essFile.primaryRegistrantId; + + this.appBaseService.wizardProperties = { + lastCompletedStep: WizardSteps.Step2 + }; + this.computeState.triggerEvent(); + + const essNeeds = essFile.needsAssessment; + this.evacueeSession.currentNeedsAssessment = essNeeds; + this.evacueeSession.evacFile = essFile; + this.wizardService.createObjectReference(essFile, 'file'); + const primaryLastName = essFile.householdMembers?.find((member) => member.type === HouseholdMemberType.Registrant).lastName; + + //Additional Behind the scenes variables + this.taskNumber = essFile.task.taskNumber; + this.evacuationFileDate = essFile.evacuationFileDate; + + // Wizard variables + //this.evacueeSession.essFileNumber = essFile.id; + + // Evacuation Details tab + this.completedOn = essFile.completedOn; + this.completedBy = essFile.completedBy; + this.evacAddress = essFile.evacuatedFromAddress; + this.facilityName = essFile.registrationLocation; + + this.evacuatedFromPrimary = globalConst.radioButtonOptions.find((ins) => ins.apiValue === _.isEqual(this.primaryAddress, this.evacAddress))?.value; + + this.insurance = essNeeds.insurance; + + // Household Members tab + // Split main applicant from other household members, remap to UI model + this.householdMembers = essFile.householdMembers?.map((member) => { + return { + ...member, + sameLastName: member.lastName === primaryLastName, + householdMemberFromDatabase: true + }; + }); + + this.selectedHouseholdMembers = undefined; + + this.haveHouseHoldMembers = globalConst.radioButtonOptions.find((ins) => ins.apiValue === this.householdMembers?.length > 2)?.value; + + // Animals tab + const petsArray = []; + this.petsList = [...petsArray, ...essNeeds.pets]; + this.havePets = globalConst.radioButtonOptions.find((ins) => ins.apiValue === essNeeds.pets?.length > 0)?.value; + + // Needs tab + this.needs = new Set(essNeeds.needs); + this.reqiresNothing = essNeeds.needs?.length === 0; + + // Security Phrase tab + this.securityPhrase = essFile.securityPhrase; + this.originalSecurityPhrase = essFile.securityPhrase; + this.editedSecurityPhrase = essFile.securityPhraseEdited; + } + + /** + * Determines if the tab navigation is allowed or not + * + * @param tabRoute clicked route + * @param $event mouse click event + * @returns true/false + */ + isAllowed(tabRoute: string, $event: MouseEvent): boolean { + if (tabRoute === 'review') { + const allow = this.checkTabsStatus(); + if (allow) { + $event.stopPropagation(); + $event.preventDefault(); + + this.openModal(globalConst.wizardESSFileMessage); + } + return allow; + } + } + + /** + * Checks the status of the tabs + * + * @returns true/false + */ + checkTabsStatus(): boolean { + return this.essTabs?.some((tab) => (tab.status === 'not-started' || tab.status === 'incomplete') && tab.name !== 'review'); + } + + /** + * Open information modal window + * + * @param text text to display + * @param title title of modal + * @param button text on "close" button ("Close" by default) + * @param exitLink link to exit greater context (e.g. wizard) for modal, null = no link + */ + openModal(content: DialogContent): MatDialogRef { + const thisModal = this.dialog.open(DialogComponent, { + data: { + component: InformationDialogComponent, + content + }, + width: '530px' + }); + + return thisModal; + } + + /** + * Checks if the form is partially completed or not + * + * @param form form group + * @returns true/false + */ + checkForPartialUpdates(form: UntypedFormGroup): boolean { + const fields = []; + Object.keys(form.controls).forEach((field) => { + const control = form.controls[field] as UntypedFormControl | UntypedFormGroup | UntypedFormArray; + if (control instanceof UntypedFormControl) { + if (control.value instanceof Object && control.value != null) { + fields.push(control.value.length); + } else { + fields.push(control.value); + } + } else if (control instanceof UntypedFormGroup || control instanceof UntypedFormArray) { + for (const key in control.controls) { + if (control.controls.hasOwnProperty(key)) { + fields.push(control.controls[key].value); + } + } + } + }); + const result = fields.filter((field) => !!field); + return result.length !== 0; + } + + /** + * Checks if the form is partially completed or not + * + * @param form form group + * @returns true/false + */ + checkForEvacDetailsPartialUpdates(form: UntypedFormGroup): boolean { + const fields = []; + Object.keys(form.controls).forEach((field) => { + const control = form.controls[field] as UntypedFormControl | UntypedFormGroup | UntypedFormArray; + if (control instanceof UntypedFormControl) { + if (control.value instanceof Object && control.value != null) { + fields.push(control.value.length); + } else { + if (typeof control.value !== 'boolean') { + fields.push(control.value); + } + } + } else if (control instanceof UntypedFormGroup) { + for (const key in control.controls) { + if (control.controls.hasOwnProperty(key)) { + fields.push(control.controls[key].value); + } + } + } + }); + const result = fields.filter((field) => !!field); + return result.length > 2; + } + + /** + * Sets the tab status for the Review ESS File wizard + */ + public setReviewEssFileTabStatus(): void { + this.essTabs.map((tab) => { + if (tab.name !== 'review') { + tab.status = 'complete'; + } + if (tab.name === 'household-members-pets') { + tab.status = 'incomplete'; + } + if (this.securityPhrase === null || this.securityPhrase === undefined || this.securityPhrase === '') { + if (tab.name === 'security-phrase') { + tab.status = 'not-started'; + } + } + return tab; + }); + } + + /** + * Sets the tab status for the Complete ESS File wizard + */ + public setCompleteEssFileTabStatus(): void { + this.essTabs.map((tab) => { + if (tab.name !== 'review') { + tab.status = 'complete'; + } + if (tab.name === 'household-members-pets' || tab.name === 'evacuation-details') { + tab.status = 'incomplete'; + } + return tab; + }); + } + + public getTaskEndDate(): string { + if (this.appBaseService?.wizardProperties?.wizardType === WizardType.NewEssFile || this.appBaseService?.wizardProperties?.wizardType === WizardType.NewRegistration) { + return this.userService?.currentProfile?.taskStartDate; + } else { + return this.selectedEssFileVal?.task?.from; + } + } + + checkForEdit(): boolean { + return this.appBaseService?.appModel?.selectedEssFile?.id !== null; + } + + getNavLinks(name: string): TabModel { + if (this.essTabs !== undefined) { + return this.essTabs.find((tab) => tab.name === name); + } + } + + updateEditedFormStatus() { + this.wizardService.editStatus$.subscribe((statues: TabStatusManager[]) => { + const index = statues.findIndex((tab) => tab.tabUpdateStatus === true); + if (index !== -1) { + this.setTabStatus('review', 'incomplete'); + this.wizardService.setStepStatus('/ess-wizard/evacuee-profile', true); + this.wizardService.setStepStatus('/ess-wizard/add-supports', true); + this.wizardService.setStepStatus('/ess-wizard/add-notes', true); + } else { + if (!this.checkTabsStatus()) { + this.wizardService.setStepStatus('/ess-wizard/evacuee-profile', false); + this.wizardService.setStepStatus('/ess-wizard/add-supports', false); + this.wizardService.setStepStatus('/ess-wizard/add-notes', false); + this.setTabStatus('review', 'complete'); + } + } + }); + } + + /** + * Returns the correct task number based on the type of Wizard + */ + public getTaskNumber(wizardType: string): string { + switch (wizardType) { + case 'new-registration': + return this.userService.currentProfile?.taskNumber; + + case 'edit-registration': + return this.taskNumber; + + case 'new-ess-file': + return this.userService.currentProfile?.taskNumber; + + case 'review-file': + return this.taskNumber; + + case 'complete-file': + return this.userService.currentProfile?.taskNumber; + } } - } }