-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(application-system): New application - Work Accident Notification (
#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
1 parent
df859d4
commit e4b2374
Showing
114 changed files
with
7,552 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
...ib/modules/templates/aosh/work-accident-notification/work-accident-notification.module.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 {} |
119 changes: 119 additions & 0 deletions
119
...b/modules/templates/aosh/work-accident-notification/work-accident-notification.service.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.', | ||
} | ||
}) | ||
} | ||
} |
119 changes: 119 additions & 0 deletions
119
...lib/modules/templates/aosh/work-accident-notification/work-accident-notification.utils.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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], | ||
} | ||
} |
Oops, something went wrong.