Skip to content

Commit

Permalink
feat(application-system): New application - Work Accident Notification (
Browse files Browse the repository at this point in the history
#16632)

* initial application creation

* Continued work setting up application

* Further work setting up work accident notification application

* Work on company screen in application

* skeleton work for page steps

* mock data and further work on steps

* Further development of work accident notificaion application

* Creating a new client for slysaskraning

* starting client setup, getting open-api from VER

* Setting up client for slysaskraning

* clientConfig testing removed

* further progress of work accident notification

* fixing broken component to not push broken code

* Working on consistant data going back and forth in screens

* MultiSelect states/answers setup, added most serious option. Missing validation if user chooses most serious and then removes that option from multiselect

* multiselect work

* minor fixes, adding attributes to data schema

* adding attributes to dataschema, still incomplete in terms of refining, validaiton etc..

* dev readme, delete later

* fixing some messeges and adding seeder script

* multiselect finished

* dev readme, delete later v2

* adding create account mockup and submitapplication
!

* some changes

* Working on multiselect screens in tilkynning vinnuslyss

* removing comments, logs and addding a useEffect to setValue to formcontext on load

* adding 2 new screens (typeOfInjury and injuredBodyParts), minor fixes for when a user removes options from list that was previously chosen as the most serious, minor comments added and removed

* changes to submitapplication

* starting to index starfsmadur and orsakir screens to allow for multiple employees

* indexing for multiple employees, data schema update, moving announcement page to its own file

* overview

* adding indexing to ids otherwise we get graphql validation errors

* overview company

* commenting out atvinnugreinaflokkun, will remove once confirmed it should not be there

* about accident

* adding conditional radio field to verkkaup, fixing code for major and sub groups since they do not all have the same format, employmentStatus dataschema added and fixed, starfsgrein not auto filling correct on back button fixes (should look at again to clean up code)

* adding add employees button

* add employee button works

* bunch of schema/required/validation added

* doesnotrequireanswer added

* zod schema additions, required on component that should be required, removed console.logs, added error messaging to pages

* Fixing mount issue when going from employee 2 to employee 1 via back button

* adding things to overview employees and few things to submit application

* forgot to save

* adding template name and institution

* resolving conflicts

* adding input values and some changes to submit app

* submit and conclusion

* first commit of delete functionality, some todo cleanup

* remove log

* select checkbox design

* adding delete button to overview screen

* feature flag added, mobile styling fixed in overview, data schema minor update

* merge conflict

* fixing config module after recent main changes

* Chaning minor texts, adding README, deleting dev_readme

* update messages

* adding date check

* fixing submit

* merge conflict

* fixing minors things from PR suggestions etc.

* Using Locale type

* fixing spacing on Select inputs and adding a placeholder

* placeholder and message changes

* fallback if individual for branch info

* fixing errors

* employee name in overview + placeholder for causeAndConsequences

* removing default on Select

* fixing back button and conclusion navigation step view

* Fixing for PR comment, mostly error message translations etc..

* fixing null values in answers causing validation fails because missing nullable. Simplifying multiple calls to same getValues

* fixing issues with multidropdown and answers

* Adding missing contentfulId to institutionMapper

* add requiredScope

* import missing

* adding pdf to final page

* minor fixes from PR review

* fixing types

* forgot one type

* PR comment fixes

* moved payload

* adding type

* Remove fake sections

* removing title for pages that have no section

* Adding work accident client to infra/src/dsl and application-system/api/infra and generating values

* Adding to apps/api/infra and running yarn charts

* changing pdf (#16799)

---------

Co-authored-by: berglindoma13 <berglindis@gmail.com>
Co-authored-by: Sigrún Tinna Gissurardóttir <sigrun.tinna.gissurardottir@origo.is>
Co-authored-by: Sigrún Tinna Gissurardóttir <39527334+sigruntg@users.noreply.github.com>
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
  • Loading branch information
5 people authored Nov 12, 2024
1 parent df859d4 commit e4b2374
Show file tree
Hide file tree
Showing 114 changed files with 7,552 additions and 0 deletions.
2 changes: 2 additions & 0 deletions apps/api/infra/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ import {
Vehicles,
VehicleServiceFjsV1,
VehiclesMileage,
WorkAccidents,
WorkMachines,
} from '../../../infra/src/dsl/xroad'

Expand Down Expand Up @@ -440,6 +441,7 @@ export const serviceSetup = (services: {
Frigg,
HealthDirectorateOrganDonation,
HealthDirectorateVaccination,
WorkAccidents,
)
.files({ filename: 'islyklar.p12', env: 'ISLYKILL_CERT' })
.ingress({
Expand Down
2 changes: 2 additions & 0 deletions apps/api/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ import { CmsTranslationsModule } from '@island.is/cms-translations'
import { FileStorageConfig } from '@island.is/file-storage'
import { AuditModule } from '@island.is/nest/audit'
import { DocumentsClientV2Config } from '@island.is/clients/documents-v2'
import { WorkAccidentClientConfig } from '@island.is/clients/work-accident-ver'

import {
ConfigModule,
Expand Down Expand Up @@ -432,6 +433,7 @@ const environment = getConfig
CriminalRecordClientConfig,
HealthInsuranceV2ClientConfig,
UmbodsmadurSkuldaraClientConfig,
WorkAccidentClientConfig,
ZendeskServiceConfig,
emailModuleConfig,
],
Expand Down
2 changes: 2 additions & 0 deletions apps/application-system/api/infra/application-system-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import {
Frigg,
HealthDirectorateVaccination,
HealthDirectorateOrganDonation,
WorkAccidents,
NationalRegistryB2C,
} from '../../../../infra/src/dsl/xroad'

Expand Down Expand Up @@ -300,6 +301,7 @@ export const serviceSetup = (services: {
Frigg,
HealthDirectorateVaccination,
HealthDirectorateOrganDonation,
WorkAccidents,
)
.secrets({
NOVA_URL: '/k8s/application-system-api/NOVA_URL',
Expand Down
2 changes: 2 additions & 0 deletions charts/islandis/values.dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,7 @@ api:
XROAD_VEHICLE_SERVICE_FJS_V1_PATH: 'IS-DEV/GOV/10021/FJS-Public/VehicleServiceFJS_v1'
XROAD_VMST_API_PATH: '/VMST-ParentalLeave-Protected/ParentalLeaveApplication-v1'
XROAD_VMST_MEMBER_CODE: '10003'
XROAD_WORK_ACCIDENT_PATH: 'IS-DEV/GOV/10013/Vinnueftirlitid-Protected/slysaskraning-token'
XROAD_WORK_MACHINE_LICENSE_PATH: 'IS-DEV/GOV/10013/Vinnueftirlitid-Protected/vinnuvelar-token'
ZENDESK_CONTACT_FORM_SUBDOMAIN: 'stjanilofts'
files:
Expand Down Expand Up @@ -687,6 +688,7 @@ application-system-api:
XROAD_VEHICLE_SERVICE_FJS_V1_PATH: 'IS-DEV/GOV/10021/FJS-Public/VehicleServiceFJS_v1'
XROAD_VMST_API_PATH: '/VMST-ParentalLeave-Protected/ParentalLeaveApplication-v1'
XROAD_VMST_MEMBER_CODE: '10003'
XROAD_WORK_ACCIDENT_PATH: 'IS-DEV/GOV/10013/Vinnueftirlitid-Protected/slysaskraning-token'
XROAD_WORK_MACHINE_LICENSE_PATH: 'IS-DEV/GOV/10013/Vinnueftirlitid-Protected/vinnuvelar-token'
files:
- 'islyklar.p12'
Expand Down
2 changes: 2 additions & 0 deletions charts/islandis/values.prod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,7 @@ api:
XROAD_VEHICLE_SERVICE_FJS_V1_PATH: 'IS/GOV/5402697509/FJS-Public/VehicleServiceFJS_v1'
XROAD_VMST_API_PATH: '/VMST-ParentalLeave-Protected/ParentalLeaveApplication-v1'
XROAD_VMST_MEMBER_CODE: '7005942039'
XROAD_WORK_ACCIDENT_PATH: 'IS/GOV/4201810439/Vinnueftirlitid-Protected/slysaskraning-token'
XROAD_WORK_MACHINE_LICENSE_PATH: 'IS/GOV/4201810439/Vinnueftirlitid-Protected/vinnuvelar-token'
ZENDESK_CONTACT_FORM_SUBDOMAIN: 'digitaliceland'
files:
Expand Down Expand Up @@ -675,6 +676,7 @@ application-system-api:
XROAD_VEHICLE_SERVICE_FJS_V1_PATH: 'IS/GOV/5402697509/FJS-Public/VehicleServiceFJS_v1'
XROAD_VMST_API_PATH: '/VMST-ParentalLeave-Protected/ParentalLeaveApplication-v1'
XROAD_VMST_MEMBER_CODE: '7005942039'
XROAD_WORK_ACCIDENT_PATH: 'IS/GOV/4201810439/Vinnueftirlitid-Protected/slysaskraning-token'
XROAD_WORK_MACHINE_LICENSE_PATH: 'IS/GOV/4201810439/Vinnueftirlitid-Protected/vinnuvelar-token'
files:
- 'islyklar.p12'
Expand Down
2 changes: 2 additions & 0 deletions charts/islandis/values.staging.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,7 @@ api:
XROAD_VEHICLE_SERVICE_FJS_V1_PATH: 'IS-TEST/GOV/10021/FJS-Public/VehicleServiceFJS_v1'
XROAD_VMST_API_PATH: '/VMST-ParentalLeave-Protected/ParentalLeaveApplication-v1'
XROAD_VMST_MEMBER_CODE: '7005942039'
XROAD_WORK_ACCIDENT_PATH: 'IS-TEST/GOV/4201810439/Vinnueftirlitid-Protected/slysaskraning-token'
XROAD_WORK_MACHINE_LICENSE_PATH: 'IS-TEST/GOV/4201810439/Vinnueftirlitid-Protected/vinnuvelar-token'
ZENDESK_CONTACT_FORM_SUBDOMAIN: 'digitaliceland'
files:
Expand Down Expand Up @@ -684,6 +685,7 @@ application-system-api:
XROAD_VEHICLE_SERVICE_FJS_V1_PATH: 'IS-TEST/GOV/10021/FJS-Public/VehicleServiceFJS_v1'
XROAD_VMST_API_PATH: '/VMST-ParentalLeave-Protected/ParentalLeaveApplication-v1'
XROAD_VMST_MEMBER_CODE: '7005942039'
XROAD_WORK_ACCIDENT_PATH: 'IS-TEST/GOV/4201810439/Vinnueftirlitid-Protected/slysaskraning-token'
XROAD_WORK_MACHINE_LICENSE_PATH: 'IS-TEST/GOV/4201810439/Vinnueftirlitid-Protected/vinnuvelar-token'
files:
- 'islyklar.p12'
Expand Down
11 changes: 11 additions & 0 deletions infra/src/dsl/xroad.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,17 @@ export const AdrAndMachine = new XroadConf({
},
})

export const WorkAccidents = new XroadConf({
env: {
XROAD_WORK_ACCIDENT_PATH: {
dev: 'IS-DEV/GOV/10013/Vinnueftirlitid-Protected/slysaskraning-token',
staging:
'IS-TEST/GOV/4201810439/Vinnueftirlitid-Protected/slysaskraning-token',
prod: 'IS/GOV/4201810439/Vinnueftirlitid-Protected/slysaskraning-token',
},
},
})

export const WorkMachines = new XroadConf({
env: {
XROAD_WORK_MACHINE_LICENSE_PATH: {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { Module } from '@nestjs/common'
import { SharedTemplateAPIModule } from '../../../shared'
import { WorkAccidentNotificationTemplateService } from './work-accident-notification.service'
import {
WorkAccidentClientConfig,
WorkAccidentClientModule,
} from '@island.is/clients/work-accident-ver'
import { ConfigModule } from '@nestjs/config'

@Module({
imports: [
SharedTemplateAPIModule,
WorkAccidentClientModule,
ConfigModule.forRoot({
isGlobal: true,
load: [WorkAccidentClientConfig],
}),
],
providers: [WorkAccidentNotificationTemplateService],
exports: [WorkAccidentNotificationTemplateService],
})
export class WorkAccidentNotificationTemplateModule {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
import { Inject, Injectable } from '@nestjs/common'
import { ApplicationTypes } from '@island.is/application/types'
import { BaseTemplateApiService } from '../../../base-template-api.service'

import type { Logger } from '@island.is/logging'
import { LOGGER_PROVIDER } from '@island.is/logging'
import { TemplateApiModuleActionProps } from '../../../../types'
import { WorkAccidentNotification } from '@island.is/application/templates/aosh/work-accident-notification'
import {
DataDto,
WorkAccidentClientService,
} from '@island.is/clients/work-accident-ver'
import {
getDateAndTime,
getValueList,
mapVictimData,
} from './work-accident-notification.utils'
import { getValueViaPath } from '@island.is/application/core'
import { TemplateApiError } from '@island.is/nest/problem'

@Injectable()
export class WorkAccidentNotificationTemplateService extends BaseTemplateApiService {
constructor(
@Inject(LOGGER_PROVIDER) private logger: Logger,
private readonly workAccidentClientService: WorkAccidentClientService,
) {
super(ApplicationTypes.WORK_ACCIDENT_NOTIFICATION)
}

async getInputOptions({
currentUserLocale,
auth,
}: TemplateApiModuleActionProps): Promise<DataDto> {
const data = await this.workAccidentClientService
.getOptionsData(auth, currentUserLocale)
.catch(() => {
this.logger.warn(
'[work-accident-notification-service]: Error fetching data from AOSH',
)
throw new TemplateApiError(
{
summary:
'Ekki tókst að sækja gögn til VER, vinsamlegast reynið síðar',
title: 'Villa í umsókn',
},
400,
)
})

return data
}

async submitApplication({
application,
auth,
}: TemplateApiModuleActionProps): Promise<void> {
const answers = application.answers as unknown as WorkAccidentNotification
const payload = {
accidentForCreationDto: {
companySSN: answers.companyInformation.nationalId,
sizeOfEnterprise: parseInt(
answers.companyInformation.numberOfEmployees,
10,
),
nameOfBranchOrDepartment:
answers.companyInformation.nameOfBranch ??
answers.companyInformation.name,
address:
answers.companyInformation.addressOfBranch ??
answers.companyInformation.address,
postcode:
answers.companyInformation.postnumberOfBranch?.slice(0, 3) ??
answers.companyInformation.postnumber.slice(0, 3),
workplaceHealthAndSafety:
answers.companyLaborProtection.workhealthAndSafetyOccupation?.map(
(code: string) => {
return parseInt(code, 10)
},
),

buyersSSN: answers.projectPurchase.nationalId ?? '',
dateAndTimeOfAccident: getDateAndTime(
answers.accident.date,
answers.accident.time.slice(0, 2),
answers.accident.time.slice(2, 4),
),
aoshCame: answers.accident.didAoshCome === 'yes',
policeCame: answers.accident.didPoliceCome === 'yes',
numberOfVictims: answers.employee.length,
municipalityWhereAccidentOccured: answers.accident.municipality,
specificLocationOfAccident: answers.accident.exactLocation,
detailedDescriptionOfAccident: answers.accident.wasDoing.concat(
'\n',
answers.accident.wentWrong,
'\n',
answers.accident.how,
),
workingEnvironment: answers.accident.accidentLocation.value,
victims: answers.employee.map((employee, index) => {
return mapVictimData(employee, index, answers, application)
}),
userPhoneNumber: answers.companyInformation.phonenumber,
userEmail: answers.companyInformation.email,
},
}

await this.workAccidentClientService
.createAccident(auth, payload)
.catch(() => {
this.logger.warn(
'[work-accident-notification-service]: Error submitting application to AOSH',
)
return {
success: false,
message: 'Villa í umsókn, ekki tókst að skila umsókn til VER.',
}
})
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
import { getValueViaPath } from '@island.is/application/core'
import { WorkAccidentNotification } from '@island.is/application/templates/aosh/work-accident-notification'
import {
ApplicationWithAttachments,
FormValue,
} from '@island.is/application/types'

export const getDateAndTime = (
date: string,
hours: string,
minutes: string,
): Date => {
const finalDate = new Date(date)
finalDate.setHours(
parseInt(hours, 10), // hours
parseInt(minutes, 10), // minutes
)
return finalDate
}

export const getValueList = (answers: FormValue, answer: string) => {
const objectList = getValueViaPath<object>(answers, answer) ?? {}

return Object.values(objectList)
.map((values: { label: string; value: string }[]) => {
return values?.map(({ value }) => {
return value
})
})
.flat()
}

export const mapVictimData = (
employee: WorkAccidentNotification['employee'][0],
index: number,
answers: WorkAccidentNotification,
application: ApplicationWithAttachments,
) => {
const physicalActivities = getValueList(
application.answers,
`circumstances[${index}].physicalActivities`,
)
const physicalActivitiesMostSerious = getValueViaPath<string>(
application.answers,
`circumstances[${index}].physicalActivitiesMostSerious`,
)
const workDeviations = getValueList(
application.answers,
`deviations[${index}].workDeviations`,
)
const workDeviationsMostSerious = getValueViaPath<string>(
application.answers,
`deviations[${index}].workDeviationsMostSerious`,
)
const contactModeOfInjury = getValueList(
application.answers,
`causeOfInjury[${index}].contactModeOfInjury`,
)
const contactModeOfInjuryMostSerious = getValueViaPath<string>(
application.answers,
`causeOfInjury[${index}].contactModeOfInjuryMostSerious`,
)
const partOfBodyInjured = getValueList(
application.answers,
`injuredBodyParts[${index}].partOfBodyInjured`,
)
const partOfBodyInjuredMostSerious = getValueViaPath<string>(
application.answers,
`injuredBodyParts[${index}].partOfBodyInjuredMostSerious`,
)
const typeOfInjury = getValueList(
application.answers,
`typeOfInjury[${index}].typeOfInjury`,
)
const typeOfInjuryMostSerious = getValueViaPath<string>(
application.answers,
`typeOfInjury[${index}].typeOfInjuryMostSerious`,
)
return {
victimsSSN: employee.nationalField.nationalId,
employmentStatusOfVictim: employee.employmentStatus
? parseInt(employee.employmentStatus, 10)
: 0,
employmentAgencySSN: employee.tempEmploymentSSN ?? '',
startedEmploymentForCompany: new Date(employee.startDate),
lengthOfEmployment: employee.employmentTime
? parseInt(employee.employmentTime, 10)
: 0,
percentageOfFullWorkTime: employee.employmentRate
? parseInt(employee.employmentRate, 10)
: 0,
workhourArrangement: employee.workhourArrangement
? parseInt(employee.workhourArrangement, 10)
: 0,
startOfWorkingDay: getDateAndTime(
employee.startOfWorkdayDate,
employee.startTime.slice(0, 2),
employee.startTime.slice(2, 4),
),
workStation: employee.workstation ? parseInt(employee.workstation, 10) : 0,
victimsOccupation: employee.victimsOccupation.value,
absenceDueToAccident: answers.absence[index]
? parseInt(answers.absence[index], 10)
: 0,
specificPhysicalActivities: physicalActivities,
specificPhysicalActivityMostSevere:
physicalActivitiesMostSerious ?? physicalActivities[0],
workDeviations: workDeviations,
workDeviationMostSevere: workDeviationsMostSerious ?? workDeviations[0],
contactModeOfInjuries: contactModeOfInjury,
contactModeOfInjuryMostSevere:
contactModeOfInjuryMostSerious ?? contactModeOfInjury[0],
partsOfBodyInjured: partOfBodyInjured,
partOfBodyInjuredMostSevere:
partOfBodyInjuredMostSerious ?? partOfBodyInjured[0],
typesOfInjury: typeOfInjury,
typeOfInjuryMostSevere: typeOfInjuryMostSerious ?? typeOfInjury[0],
}
}
Loading

0 comments on commit e4b2374

Please sign in to comment.