Skip to content

Commit

Permalink
fix(application-hid): HOTFIX Health insurance declaration fixes (#15064)
Browse files Browse the repository at this point in the history
* fix(application-hid): Display rejection reason from client (#14947)

* Update rights-portal client

* Add additional information to application

* Rename function -> status

* clean up

* chore: nx format:write update dirty files

---------

Co-authored-by: andes-it <builders@andes.is>
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>

* fix(application-hid): Conditional Section and other minor fixes (#15044)

* Remove titles of empty checkbox fields

* Validate number of applicants more than 0

* Remove titles of empty checkbox fields

* Validate number of applicants more than 0

* Error message on both fields

* Stop applicants with no declaration available

* Formatting

* clean up

* More readable validation

* typo fixes and file rename

* Typo fix,

* File rename

---------

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>

---------

Co-authored-by: andes-it <builders@andes.is>
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Jun 4, 2024
1 parent 0bfce60 commit abc0682
Show file tree
Hide file tree
Showing 15 changed files with 270 additions and 99 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { ApplicationTypes } from '@island.is/application/types'
import {
ApplicantChildCustodyInformation,
ApplicationTypes,
NationalRegistrySpouse,
} from '@island.is/application/types'
import {
InsurancestatementsApi,
MinarsidurAPIModelsInsuranceStatementsResponseInsuranceStatementApplicationResponseDTO,
Expand All @@ -8,6 +12,7 @@ import { BaseTemplateApiService } from '../../base-template-api.service'
import { TemplateApiModuleActionProps } from '../../../types'
import { AuthMiddleware, Auth } from '@island.is/auth-nest-tools'
import { ApplicationAttachmentProvider } from './attachments/provider'
import { prerequisites } from '@island.is/application/templates/health-insurance-declaration'
import {
applicationToStudentApplication,
applicationToTouristApplication,
Expand All @@ -17,6 +22,7 @@ import {
getPersonsFromExternalData,
} from './health-insurance-declaration.utils'
import { ApplicantType } from './consts'
import { TemplateApiError } from '@island.is/nest/problem'

@Injectable()
export class HealthInsuranceDeclarationService extends BaseTemplateApiService {
Expand All @@ -31,13 +37,13 @@ export class HealthInsuranceDeclarationService extends BaseTemplateApiService {
return this.insuranceStatementApi.withMiddleware(new AuthMiddleware(Auth))
}

async canApply(application: TemplateApiModuleActionProps): Promise<boolean> {
async status(application: TemplateApiModuleActionProps) {
const response = await this.insuranceStatementsApiWithAuth(
application.auth,
).getInsuranceStatementStatus({
applicantNationalId: application.auth.nationalId,
})
return !!response.canApply
return response
}

async continents(application: TemplateApiModuleActionProps) {
Expand All @@ -52,13 +58,32 @@ export class HealthInsuranceDeclarationService extends BaseTemplateApiService {
).getInsuranceStatementCountries()
}

async getInsuranceStatementData(application: TemplateApiModuleActionProps) {
const canApply = await this.canApply(application)
const continents = await this.continents(application)
const countries = await this.countries(application)
async getInsuranceStatementData(
applicationWithProps: TemplateApiModuleActionProps,
) {
const status = await this.status(applicationWithProps)
const continents = await this.continents(applicationWithProps)
const countries = await this.countries(applicationWithProps)
const { application } = applicationWithProps

if (status.canApply !== true) {
const childrenInformation = application.externalData
.childrenCustodyInformation.data as ApplicantChildCustodyInformation[]
const spouse = application.externalData.nationalRegistrySpouse
.data as NationalRegistrySpouse
if (!spouse && childrenInformation.length < 1) {
throw new TemplateApiError(
{
summary: prerequisites.errors.noDeclarationAvailable,
title: prerequisites.errors.noDeclarationAvailableTitle,
},
400,
)
}
}

return {
canApply: canApply,
...status,
continents: continents,
countries: countries,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ const getApplicants = (
}

// Spouse
answers.registerPersonsSpouseCheckboxField.map((s) => {
answers.selectedApplicants?.registerPersonsSpouseCheckboxField?.map((s) => {
const externalSpouse =
application.externalData.nationalRegistrySpouse.data.nationalId === s
? application.externalData.nationalRegistrySpouse.data
Expand All @@ -79,7 +79,7 @@ const getApplicants = (
}
})
// Children
answers.registerPersonsChildrenCheckboxField.map((c) => {
answers.selectedApplicants?.registerPersonsChildrenCheckboxField?.map((c) => {
const child = application.externalData.childrenCustodyInformation.data.find(
(externalChild) => externalChild.nationalId === c,
)
Expand Down Expand Up @@ -125,10 +125,12 @@ export const getPersonsFromExternalData = (application: Application) => {
).fullName,
},
]
persons.push({
nationalId: spouse.nationalId,
name: spouse.name,
})
if (spouse) {
persons.push({
nationalId: spouse.nationalId,
name: spouse.name,
})
}
children.map((child) => {
persons.push({
nationalId: child.nationalId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import * as m from '../lib/messages'
import Logo from '../assets/Logo'
import {
getChildrenAsOptions,
getCommentFromExternalData,
getContinentNameFromCode,
getContinentsAsOption,
getCountriesAsOption,
Expand All @@ -35,6 +36,7 @@ import {
getInsuranceStatus,
getSelectedFamily,
getSpouseAsOptions,
hasFamilySelected,
} from '../utils'
import { HealthInsuranceDeclaration } from '../lib/dataSchema'
import { applicantInformationMessages } from '@island.is/application/ui-forms'
Expand Down Expand Up @@ -156,6 +158,24 @@ export const HealthInsuranceDeclarationForm: Form = buildForm({
application: HealthInsuranceDeclarationApplication,
) => getInsuranceStatus(application.externalData),
}),
buildHiddenInput({
id: 'isHealthInsuredComment',
defaultValue: (
application: HealthInsuranceDeclarationApplication,
) => getCommentFromExternalData(application.externalData),
}),
buildHiddenInput({
id: 'hasSpouse',
defaultValue: (
application: HealthInsuranceDeclarationApplication,
) => getSpouseAsOptions(application.externalData).length > 0,
}),
buildHiddenInput({
id: 'hasChildren',
defaultValue: (
application: HealthInsuranceDeclarationApplication,
) => getChildrenAsOptions(application.externalData).length > 0,
}),
],
}),
],
Expand All @@ -174,6 +194,16 @@ export const HealthInsuranceDeclarationForm: Form = buildForm({
description:
m.application.notHealthInusred.descriptionFieldDescription,
}),
buildAlertMessageField({
id: 'notHealthInsuredAlertMessage',
title: '',
alertType: 'warning',
message: ({ externalData }) =>
getCommentFromExternalData(externalData),
condition: (answers) => {
return (answers?.isHealthInsuredComment as string)?.length > 0
},
}),
buildCheckboxField({
id: 'notHealthInsuredCheckboxField',
title: '',
Expand All @@ -190,7 +220,8 @@ export const HealthInsuranceDeclarationForm: Form = buildForm({
}),
],
condition: (answers: FormValue) => {
return !answers.isHealthInsured as boolean
return (answers.isHealthInsured !== undefined &&
!answers.isHealthInsured) as boolean
},
}),
buildSection({
Expand Down Expand Up @@ -237,18 +268,32 @@ export const HealthInsuranceDeclarationForm: Form = buildForm({
title: m.application.registerPersons.sectionDescription,
children: [
buildCheckboxField({
id: 'registerPersonsSpouseCheckboxField',
id: 'selectedApplicants.registerPersonsSpouseCheckboxField',
title: m.application.registerPersons.spousetitle,
options: ({ externalData }) => getSpouseAsOptions(externalData),
condition: (answers) => {
return answers?.hasSpouse as boolean
},
}),
buildCheckboxField({
id: 'registerPersonsChildrenCheckboxField',
id: 'selectedApplicants.registerPersonsChildrenCheckboxField',
title: m.application.registerPersons.childrenTitle,
options: ({ externalData }) => getChildrenAsOptions(externalData),
condition: (answers) => {
return answers?.hasChildren as boolean
},
}),
buildHiddenInput({
id: 'selectedApplicants.isHealthInsured',
defaultValue: (
application: HealthInsuranceDeclarationApplication,
) => getInsuranceStatus(application.externalData),
}),
],
}),
],
condition: (answers: FormValue) =>
!!(answers.hasSpouse || answers.hasChildren),
}),
buildSection({
id: 'residencySectionTourist',
Expand Down Expand Up @@ -442,8 +487,13 @@ export const HealthInsuranceDeclarationForm: Form = buildForm({
applicantInformationMessages.labels.nationalId,
'Tengsl',
],
condition: (answers) =>
hasFamilySelected(answers as HealthInsuranceDeclaration),
}),
buildDividerField({
condition: (answers) =>
hasFamilySelected(answers as HealthInsuranceDeclaration),
}),
buildDividerField({}),
// Date period
buildDescriptionField({
id: 'overviewDatePeriodTitle',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
} from '@island.is/application/types'
import { application } from '../lib/messages'
import Logo from '../assets/Logo'
import { prerequisites } from '../lib/messages/prerequsites'
import { prerequisites } from '../lib/messages/prerequisites'

export const Prerequisites: Form = buildForm({
id: 'HealthInsuranceDeclarationPrerequsites',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {
buildCustomField,
buildDataProviderItem,
buildDescriptionField,
buildForm,
buildMessageWithLinkButtonField,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@ import HealthInsuranceDeclarationTemplate from './lib/HealthInsuranceDeclaration
export const getFields = () => import('./fields')
export * from './shared/constants'
export * from './types'
export * from './lib/messages'

export default HealthInsuranceDeclarationTemplate
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ export const HealthInsuranceDeclarationSchema = z.object({
approveExternalData: z.boolean().refine((v) => v),
applicant: applicantInformationSchema(),
isHealthInsured: z.boolean(),
hasSpouse: z.boolean(),
hasChildren: z.boolean(),
studentOrTouristRadioFieldTourist: z.enum([
ApplicantType.STUDENT,
ApplicantType.TOURIST,
Expand All @@ -19,8 +21,32 @@ export const HealthInsuranceDeclarationSchema = z.object({
.string()
.or(z.undefined())
.refine((v) => !!v),
registerPersonsSpouseCheckboxField: z.string().array(),
registerPersonsChildrenCheckboxField: z.string().array(),
selectedApplicants: z
.object({
registerPersonsSpouseCheckboxField: z.string().array().optional(),
registerPersonsChildrenCheckboxField: z.string().array().optional(),
isHealthInsured: z.boolean(),
})
.superRefine((v, ctx) => {
if (
!v.isHealthInsured &&
!v.registerPersonsSpouseCheckboxField?.length &&
!v.registerPersonsChildrenCheckboxField?.length
) {
ctx.addIssue({
code: z.ZodIssueCode.custom,
path: ['registerPersonsChildrenCheckboxField'],
params: errors.fields.noSelectedApplicant,
})
ctx.addIssue({
code: z.ZodIssueCode.custom,
path: ['registerPersonsSpouseCheckboxField'],
params: errors.fields.noSelectedApplicant,
})
return false
}
return true
}),
educationConfirmationFileUploadField: z
.object({
name: z.string(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ export const errors = {
defaultMessage: 'Upphafs dagsetning má ekki vera eftir loka dagsetningu',
description: 'Start date after end date error message',
},
noSelectedApplicant: {
id: 'hid.application:errors.fields.noSelectedApplicant',
defaultMessage:
'Að minnsta kosti einn aðlili þarf að vera valinn svo hægt sé að sækja um yfirlýsingu',
description: 'No selected applicant error message',
},
}),
submitted: defineMessages({
externalError: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './application'
export * from './errors'
export * from './conclution'
export * from './prerequisites'
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,30 @@ export const prerequisites = {
description: 'Checkbox label',
},
}),
errors: defineMessages({}),
errors: defineMessages({
noDeclarationAvailableTitle: {
id: 'hid.application:prerequisites.errors.noDeclarationAvailableTitle',
defaultMessage: 'Engin yfirlýsing í boði',
description:
'Prerequisite error message title when no declaration is available',
},
noDeclarationAvailable: {
id: 'hid.application:prerequisites.errors.noDeclarationAvailable#markdown',
defaultMessage: `Engin yfirlýsing í boði, helstu ástæður eru þessar:
* Þú ert ekki með gilda sjúkratryggingu á Íslandi.
* Ekki eru einstaklingar á þínu lögheimili sem þú getur sótt yfirlýsingu fyrir
Ef þú telur þetta ekki rétt skaltu hafa samband hér: (ehic@sjukra.is)[mailto:ethic@sjukra.is]`,
description:
'Prerequisite error message when no declaration is available',
},
}),
intro: defineMessages({
sectionTitle: {
id: 'hid.application:prerequisites.intro.section.title',
defaultMessage: 'Upplýsingar til umsækjanda',
description: 'Introduction section title',
},
text: {
id: 'hid.application:prerequisites.intro.text#markdown',
defaultMessage:
'- Umsókn um kaup ríkisins á íbúðareign þinni skuldbindur þig ekki til að selja en með henni hefst söluferlið.\n- Nóg er að einn af eigendum fylli út umsóknina en þegar kemur að sölunni þurfa allir eigendur að undirrita.\n- Staðfesting umsóknar mun berast eigendum í Stafræna pósthólfið þeirra.\n- Gott er fyrir umsækjanda að þekkja öll lán eignar og uppgreiðsluverð þeirra því kallað er eftir þeim upphæðum í umsókninni.\n- Eftir að umsókn klárast hefst úrvinnsla hjá Þórkötlu en stefnt er að því að það ferli taki um 2-4 vikur.\n- Haft verður samband við eigendur ef einhver gögn vantar eða ef eitthvað stöðvar ferlið sem og til að fá staðfest formlega að óskað sé eftir að íbúðarhúsnæði verði keypt af ríkinu.',
description: 'Introduction text',
},
}),
dataProviders: defineMessages({
nationalRegistryTitle: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ export type HealthInsuranceContinents = {

export type InsuranceStatementData = {
canApply: boolean
comment?: string
isInsured: boolean
countries: HealthInsuranceCountry[]
continents: HealthInsuranceContinents[]
}
Loading

0 comments on commit abc0682

Please sign in to comment.