Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(pension-supplement): Send application #13334

Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ import {
getApplicationExternalData as getHSApplicationExternalData,
} from '@island.is/application/templates/social-insurance-administration/household-supplement'

import {
getApplicationAnswers as getPSApplicationAnswers,
getApplicationExternalData as getPSApplicationExternalData,
} from '@island.is/application/templates/social-insurance-administration/pension-supplement'

export const transformApplicationToOldAgePensionDTO = (
application: Application,
uploads: Attachment[],
Expand Down Expand Up @@ -158,6 +163,62 @@ export const transformApplicationToHouseholdSupplementDTO = (
return householdSupplementDTO
}

export const transformApplicationToPensionSupplementDTO = (
application: Application,
uploads: Attachment[],
): ApplicationDTO => {
const {
selectedYear,
selectedMonth,
applicantPhonenumber,
bank,
bankAccountType,
comment,
iban,
swift,
bankName,
bankAddress,
currency,

applicationReason,
} = getPSApplicationAnswers(application.answers)
const { email } = getPSApplicationExternalData(application.externalData)

const householdSupplementDTO: ApplicationDTO = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const householdSupplementDTO: ApplicationDTO = {
const pensionSupplementDTO: ApplicationDTO = {

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, Fixed in the feat/pension-suppliment branch

applicationId: application.id,
applicantInfo: {
email: email,
phonenumber: applicantPhonenumber,
},

...((bankAccountType === undefined ||
bankAccountType === BankAccountType.ICELANDIC) && {
domesticBankInfo: {
bank: formatBank(bank),
},
}),
...(bankAccountType === BankAccountType.FOREIGN && {
foreignBankInfo: {
iban: iban.replace(/[\s]+/g, ''),
swift: swift.replace(/[\s]+/g, ''),
foreignBankName: bankName,
foreignBankAddress: bankAddress,
foreignCurrency: currency,
},
}),

reasons: applicationReason,
period: {
year: +selectedYear,
month: getMonthNumber(selectedMonth),
},
uploads,
comment: comment,
}

return householdSupplementDTO
}

export const getMonthNumber = (monthName: string): number => {
// Parse the month name and get the month number (0-based)
const monthNumber = parse(monthName, 'MMMM', new Date())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import {
getApplicationType,
transformApplicationToHouseholdSupplementDTO,
transformApplicationToOldAgePensionDTO,
transformApplicationToPensionSupplementDTO,
} from './social-insurance-administration-utils'
import { isRunningOnEnvironment } from '@island.is/shared/utils'
import { FileType } from '@island.is/application/templates/social-insurance-administration-core/types'
Expand Down Expand Up @@ -243,6 +244,104 @@ export class SocialInsuranceAdministrationService extends BaseTemplateApiService
return attachments
}

// Pension suppliment attachments
private async getPSAttachments(
application: Application,
): Promise<Attachment[]> {
const {
additionalAttachments,
assistedCareAtHomeAttachments,
houseRentAttachments,
houseRentAllowanceAttachments,
assistedLivingAttachments,
purchaseOfHearingAidsAttachments,
halfwayHouseAttachments,
} = getPSApplicationAnswers(application.answers)

const attachments: Attachment[] = []

if (additionalAttachments && additionalAttachments.length > 0) {
attachments.push(
...(await this.initAttachments(
application,
AttachmentTypeEnum.Other,
additionalAttachments,
)),
)
}

if (
assistedCareAtHomeAttachments &&
assistedCareAtHomeAttachments.length > 0
) {
attachments.push(
...(await this.initAttachments(
application,
AttachmentTypeEnum.AssistedCareAtHome,
assistedCareAtHomeAttachments,
)),
)
}

if (houseRentAttachments && houseRentAttachments.length > 0) {
attachments.push(
...(await this.initAttachments(
application,
AttachmentTypeEnum.HouseRentAgreement,
houseRentAttachments,
)),
)
}

if (
houseRentAllowanceAttachments &&
houseRentAllowanceAttachments.length > 0
) {
attachments.push(
...(await this.initAttachments(
application,
AttachmentTypeEnum.HouseRentAllowance,
houseRentAllowanceAttachments,
)),
)
}

if (assistedLivingAttachments && assistedLivingAttachments.length > 0) {
attachments.push(
...(await this.initAttachments(
application,
AttachmentTypeEnum.AssistedLiving,
assistedLivingAttachments,
)),
)
}

if (
purchaseOfHearingAidsAttachments &&
purchaseOfHearingAidsAttachments.length > 0
) {
attachments.push(
...(await this.initAttachments(
application,
AttachmentTypeEnum.PurchaseOfHearingAids,
purchaseOfHearingAidsAttachments,
)),
)
}

if (halfwayHouseAttachments && halfwayHouseAttachments.length > 0) {
attachments.push(
...(await this.initAttachments(
application,
AttachmentTypeEnum.HalfwayHouse,
halfwayHouseAttachments,
)),
)
}

return attachments
}

async getPdf(key: string) {
const file = await this.s3
.getObject({ Bucket: this.attachmentBucket, Key: key })
Expand Down Expand Up @@ -289,6 +388,22 @@ export class SocialInsuranceAdministrationService extends BaseTemplateApiService

return response
}

if (application.typeId === ApplicationTypes.PENSION_SUPPLEMENT) {
const attachments = await this.getPSAttachments(application)
const pensionSupplemenhtDTO = transformApplicationToPensionSupplementDTO(
application,
attachments,
)

const response = await this.siaClientService.sendApplication(
auth,
pensionSupplemenhtDTO,
application.typeId.toLowerCase(),
)

return response
}
}

async sendDocuments({ application, auth }: TemplateApiModuleActionProps) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ export const PensionSupplementForm: Form = buildForm({

const reasons = [
ApplicationReason.ASSISTED_CARE_AT_HOME,
ApplicationReason.PURCHASE_OF_HEARING_AIDS,
ApplicationReason.HELPING_EQUIPMENT,
ApplicationReason.ASSISTED_LIVING,
ApplicationReason.HALFWAY_HOUSE,
ApplicationReason.HOUSE_RENT,
Expand Down Expand Up @@ -406,9 +406,7 @@ export const PensionSupplementForm: Form = buildForm({

return (
applicationReason &&
applicationReason.includes(
ApplicationReason.PURCHASE_OF_HEARING_AIDS,
)
applicationReason.includes(ApplicationReason.HELPING_EQUIPMENT)
)
},
children: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export const fileUploadValidationSection = (
}

if (
applicationReason.includes(ApplicationReason.PURCHASE_OF_HEARING_AIDS) &&
applicationReason.includes(ApplicationReason.HELPING_EQUIPMENT) &&
obj.purchaseOfHearingAids
) {
if (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ export enum ApplicationReason {
HOUSE_RENT = 'houseRent', // Húsaleiga sem fellur utan húsaleigubóta frá sveitafélagi
ASSISTED_CARE_AT_HOME = 'assistedCareAtHome', // Umönnun í heimahúsi
ASSISTED_LIVING = 'assistedLiving', // Dvöl á sambýli eða áfangaheimili
PURCHASE_OF_HEARING_AIDS = 'purchaseOfHearingAids', // Kaup á heyrnartækjum
OXYGEN_FILTER_COST = 'oxygenFilterCost', // Rafmagn á súrefnissíu
HELPING_EQUIPMENT = 'helpingEquipment', // Kaup á heyrnartækjum
OXYGEN_FILTER_ELECTRICITY_COST = 'oxygenFilterElectricityCost', // Rafmagn á súrefnissíu
HALFWAY_HOUSE = 'halfwayHouse', // Dvöl á áfangaheimili
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ export const dataSchema = z.object({
z.enum([
ApplicationReason.MEDICINE_COST,
ApplicationReason.ASSISTED_CARE_AT_HOME,
ApplicationReason.OXYGEN_FILTER_COST,
ApplicationReason.PURCHASE_OF_HEARING_AIDS,
ApplicationReason.OXYGEN_FILTER_ELECTRICITY_COST,
ApplicationReason.HELPING_EQUIPMENT,
ApplicationReason.ASSISTED_LIVING,
ApplicationReason.HALFWAY_HOUSE,
ApplicationReason.HOUSE_RENT,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,36 @@ export function getApplicationAnswers(answers: Application['answers']) {
'tempAnswers',
) as Application['answers']

const assistedCareAtHomeAttachments = getValueViaPath(
answers,
'fileUpload.assistedCareAtHome',
) as FileType[]

const houseRentAttachments = getValueViaPath(
answers,
'fileUpload.houseRentAgreement',
) as FileType[]

const houseRentAllowanceAttachments = getValueViaPath(
answers,
'fileUpload.houseRentAllowance',
) as FileType[]

const assistedLivingAttachments = getValueViaPath(
answers,
'fileUpload.assistedLiving',
) as FileType[]

const purchaseOfHearingAidsAttachments = getValueViaPath(
answers,
'fileUpload.purchaseOfHearingAids',
) as FileType[]

const halfwayHouseAttachments = getValueViaPath(
answers,
'fileUpload.halfwayHouse',
) as FileType[]

return {
applicantPhonenumber,
applicationReason,
Expand All @@ -87,6 +117,12 @@ export function getApplicationAnswers(answers: Application['answers']) {
bankAddress,
currency,
tempAnswers,
assistedCareAtHomeAttachments,
houseRentAttachments,
houseRentAllowanceAttachments,
assistedLivingAttachments,
purchaseOfHearingAidsAttachments,
halfwayHouseAttachments,
}
}

Expand Down Expand Up @@ -163,11 +199,11 @@ export function getApplicationReasonOptions() {
label: pensionSupplementFormMessage.applicationReason.assistedCareAtHome,
},
{
value: ApplicationReason.OXYGEN_FILTER_COST,
value: ApplicationReason.OXYGEN_FILTER_ELECTRICITY_COST,
label: pensionSupplementFormMessage.applicationReason.oxygenFilterCost,
},
{
value: ApplicationReason.PURCHASE_OF_HEARING_AIDS,
value: ApplicationReason.HELPING_EQUIPMENT,
label:
pensionSupplementFormMessage.applicationReason.purchaseOfHearingAids,
},
Expand Down Expand Up @@ -240,7 +276,7 @@ export function getAttachments(application: Application) {
AttachmentTypes.ASSISTED_LIVING,
)
}
if (reason === ApplicationReason.PURCHASE_OF_HEARING_AIDS) {
if (reason === ApplicationReason.HELPING_EQUIPMENT) {
getAttachmentDetails(
pensionSupplementAttachments?.purchaseOfHearingAids,
AttachmentTypes.PURCHASE_OF_HEARING_AIDS,
Expand Down
12 changes: 12 additions & 0 deletions libs/clients/social-insurance-administration/src/clientConfig.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,8 @@ components:
$ref: '#/components/schemas/TaxInfo'
applicantInfo:
$ref: '#/components/schemas/ApplicantInfo'
reasons:
$ref: '#/components/schemas/Reasons'
hasAbroadResidence:
type: boolean
hasOneTimePayment:
Expand Down Expand Up @@ -253,6 +255,12 @@ components:
- selfEmployed
- rentalAgreement
- schoolConfirmation
- assistedCareAtHome
- purchaseOfHearingAids
- assistedLiving
- halfwayHouse
- houseRentAgreement
- houseRentAllowance
file:
type: string
Response:
Expand Down Expand Up @@ -372,6 +380,10 @@ components:
type: array
items:
$ref: '#/components/schemas/Attachment'
Reasons:
type: array
items:
type: string
ErrorResult:
type: object
properties:
Expand Down
Loading