diff --git a/libs/application/templates/accident-notification/src/fields/ApplicationStatus/StatusStep/index.tsx b/libs/application/templates/accident-notification/src/fields/ApplicationStatus/StatusStep/index.tsx index 48e0043813d3..7ee02130ecca 100644 --- a/libs/application/templates/accident-notification/src/fields/ApplicationStatus/StatusStep/index.tsx +++ b/libs/application/templates/accident-notification/src/fields/ApplicationStatus/StatusStep/index.tsx @@ -1,10 +1,29 @@ -import { Box, Button, Tag, Text } from '@island.is/island-ui/core' +import { Box, Button, Tag, TagVariant, Text } from '@island.is/island-ui/core' import { useLocale } from '@island.is/localization' -import React, { FC } from 'react' import * as styles from './ReviewSection.css' -import { ReviewSectionProps } from './types' +import { MessageDescriptor } from 'react-intl' -export const StatusStep: FC> = ({ +export type ActionProps = { + title: string + description: string + fileNames?: string + actionButtonTitle: string + hasActionButtonIcon?: boolean + showAlways?: boolean + cta?: () => void +} + +type Props = { + title: string + description: string + hasActionMessage: boolean + action?: ActionProps + visible?: boolean + tagText: MessageDescriptor | string + tagVariant: TagVariant +} + +export const StatusStep = ({ title, description, tagVariant = 'blue', @@ -12,7 +31,7 @@ export const StatusStep: FC> = ({ hasActionMessage, action, visible = true, -}) => { +}: Props) => { const { formatMessage } = useLocale() const handleOnCTAButtonClick = () => { action?.cta && action.cta() diff --git a/libs/application/templates/accident-notification/src/fields/ApplicationStatus/StatusStep/types.ts b/libs/application/templates/accident-notification/src/fields/ApplicationStatus/StatusStep/types.ts index 195eba30c7ee..96926fa90211 100644 --- a/libs/application/templates/accident-notification/src/fields/ApplicationStatus/StatusStep/types.ts +++ b/libs/application/templates/accident-notification/src/fields/ApplicationStatus/StatusStep/types.ts @@ -1,16 +1,3 @@ -import { TagVariant } from '@island.is/island-ui/core' -import { MessageDescriptor } from '@formatjs/intl' - -export interface ActionProps { - title: string - description: string - fileNames?: string - actionButtonTitle: string - hasActionButtonIcon?: boolean - showAlways?: boolean - cta?: () => void -} - export enum AccidentNotificationStatusEnum { ACCEPTED = 'ACCEPTED', REFUSED = 'REFUSED', @@ -18,26 +5,6 @@ export enum AccidentNotificationStatusEnum { INPROGRESSWAITINGFORDOCUMENT = 'INPROGRESSWAITINGFORDOCUMENT', } -export interface ReviewSectionProps { - title: string - description: string - hasActionMessage: boolean - action?: ActionProps - visible?: boolean - tagText: MessageDescriptor | string - tagVariant: TagVariant -} - -export interface Steps { - title: string - description: string - hasActionMessage: boolean - action?: ActionProps - visible?: boolean - tagText: MessageDescriptor | string - tagVariant: TagVariant -} - export interface SubmittedApplicationData { data?: { documentId: string diff --git a/libs/application/templates/accident-notification/src/fields/ApplicationStatus/applicationStatusUtils.ts b/libs/application/templates/accident-notification/src/fields/ApplicationStatus/applicationStatusUtils.ts index a74efdac944b..da17ae9b693d 100644 --- a/libs/application/templates/accident-notification/src/fields/ApplicationStatus/applicationStatusUtils.ts +++ b/libs/application/templates/accident-notification/src/fields/ApplicationStatus/applicationStatusUtils.ts @@ -1,16 +1,33 @@ -import { FormatMessage, FormValue } from '@island.is/application/types' +import { + FormatMessage, + FormValue, + TagVariant, +} from '@island.is/application/types' import { inReview } from '../../lib/messages' -import { AccidentNotificationStatusEnum, Steps } from './StatusStep/types' +import { AccidentNotificationStatusEnum } from './StatusStep/types' import { getValueViaPath } from '@island.is/application/core' import { ReviewApprovalEnum } from '../../types' import { AccidentNotificationStatus } from '@island.is/api/schema' import { - hasReceivedAllDocuments, + hasReceivedConfirmation, isInjuredAndRepresentativeOfCompanyOrInstitute, shouldRequestReview, -} from '../../utils' -import { hasReceivedConfirmation } from '../../utils/hasReceivedConfirmation' +} from '../../utils/miscUtils' + import { AccidentNotificationAnswers } from '../..' +import { MessageDescriptor } from 'react-intl' +import { ActionProps } from './StatusStep' +import { hasReceivedAllDocuments } from '../../utils/documentUtils' + +type Steps = { + title: string + description: string + hasActionMessage: boolean + action?: ActionProps + visible?: boolean + tagText: MessageDescriptor | string + tagVariant: TagVariant +} export const tagMapperApplicationStatus = { [AccidentNotificationStatusEnum.ACCEPTED]: { diff --git a/libs/application/templates/accident-notification/src/fields/ApplicationStatus/index.tsx b/libs/application/templates/accident-notification/src/fields/ApplicationStatus/index.tsx index 0055324cd571..36aec0ba358a 100644 --- a/libs/application/templates/accident-notification/src/fields/ApplicationStatus/index.tsx +++ b/libs/application/templates/accident-notification/src/fields/ApplicationStatus/index.tsx @@ -15,13 +15,11 @@ import { useFormContext } from 'react-hook-form' import { getAccidentStatusQuery } from '../../hooks/useLazyStatusOfNotification' import { inReview } from '../../lib/messages' import { ReviewApprovalEnum, SubmittedApplicationData } from '../../types' -import { - getErrorMessageForMissingDocuments, - isUniqueAssignee, -} from '../../utils' +import { isUniqueAssignee } from '../../utils/miscUtils' import { StatusStep } from './StatusStep' import { ApplicationStatusProps } from './StatusStep/types' import { getStatusAndApproval, getSteps } from './applicationStatusUtils' +import { getErrorMessageForMissingDocuments } from '../../utils/documentUtils' export const ApplicationStatus = ({ goToScreen, diff --git a/libs/application/templates/accident-notification/src/fields/DateOfAccident/index.tsx b/libs/application/templates/accident-notification/src/fields/DateOfAccident/index.tsx index 27627c0f8f2b..e51b848862e3 100644 --- a/libs/application/templates/accident-notification/src/fields/DateOfAccident/index.tsx +++ b/libs/application/templates/accident-notification/src/fields/DateOfAccident/index.tsx @@ -1,16 +1,15 @@ import { IsHealthInsuredInput } from '@island.is/api/schema' -import { FieldBaseProps } from '@island.is/application/types' +import { FieldBaseProps, NO, YES } from '@island.is/application/types' import { Box, Input } from '@island.is/island-ui/core' import { useLocale } from '@island.is/localization' import { DatePickerController } from '@island.is/shared/form-fields' -import React, { FC, useCallback, useEffect, useState } from 'react' +import { useCallback, useEffect, useState } from 'react' import { Controller, useFormContext } from 'react-hook-form' -import { NO, YES } from '../../utils/constants' import { useLazyIsHealthInsured } from '../../hooks/useLazyIsHealthInsured' import { AccidentNotification } from '../../lib/dataSchema' import { accidentDetails } from '../../lib/messages' -export const DateOfAccident: FC> = ({ +export const DateOfAccident = ({ application, field, error, diff --git a/libs/application/templates/accident-notification/src/fields/FormOverview/ValueLine.tsx b/libs/application/templates/accident-notification/src/fields/FormOverview/ValueLine.tsx index 6e2101294be2..5c2fd31ef800 100644 --- a/libs/application/templates/accident-notification/src/fields/FormOverview/ValueLine.tsx +++ b/libs/application/templates/accident-notification/src/fields/FormOverview/ValueLine.tsx @@ -1,22 +1,17 @@ import { Box, Bullet, BulletList, Text } from '@island.is/island-ui/core' import { Colors } from '@island.is/island-ui/theme' import { useLocale } from '@island.is/localization' -import React, { FC } from 'react' import { MessageDescriptor } from 'react-intl' import * as styles from './FormOverview.css' import cn from 'classnames' -interface ValueLineProps { +type ValueLineProps = { label: string | MessageDescriptor value: string | MessageDescriptor color?: Colors } -export const ValueLine: FC> = ({ - label, - value, - color, -}) => { +export const ValueLine = ({ label, value, color }: ValueLineProps) => { const { formatMessage } = useLocale() return ( @@ -32,10 +27,7 @@ interface FileValueLineProps { files: MessageDescriptor[] | undefined } -export const FileValueLine: FC> = ({ - label, - files, -}) => { +export const FileValueLine = ({ label, files }: FileValueLineProps) => { const { formatMessage } = useLocale() return ( diff --git a/libs/application/templates/accident-notification/src/fields/FormOverview/index.tsx b/libs/application/templates/accident-notification/src/fields/FormOverview/index.tsx index 3eb21101ca94..07eb4ffa93b4 100644 --- a/libs/application/templates/accident-notification/src/fields/FormOverview/index.tsx +++ b/libs/application/templates/accident-notification/src/fields/FormOverview/index.tsx @@ -1,5 +1,5 @@ import { formatText } from '@island.is/application/core' -import { FieldBaseProps, FormValue } from '@island.is/application/types' +import { FieldBaseProps, FormValue, YES } from '@island.is/application/types' import { formatPhoneNumber, ReviewGroup, @@ -17,8 +17,7 @@ import format from 'date-fns/format' import is from 'date-fns/locale/is' import parseISO from 'date-fns/parseISO' import kennitala from 'kennitala' -import React, { FC } from 'react' -import { States, YES } from '../../utils/constants' +import { States } from '../../utils/constants' import { AccidentNotification } from '../../lib/dataSchema' import { accidentDetails, @@ -38,24 +37,30 @@ import { sportsClubInfo, workMachine, } from '../../lib/messages' +import * as styles from './FormOverview.css' +import { FileValueLine, ValueLine } from './ValueLine' import { getAttachmentTitles, + returnMissingDocumentsList, +} from '../../utils/documentUtils' +import { getWorkplaceData, - hideLocationAndPurpose, isAgricultureAccident, isFishermanAccident, isGeneralWorkplaceAccident, - isHomeActivitiesAccident, isMachineRelatedAccident, isProfessionalAthleteAccident, +} from '../../utils/occupationUtils' +import { isReportingOnBehalfOfChild, isReportingOnBehalfOfEmployee, isReportingOnBehalfOfInjured, +} from '../../utils/reportingUtils' +import { hideLocationAndPurpose } from '../../utils/miscUtils' +import { + isHomeActivitiesAccident, isWorkAccident, - returnMissingDocumentsList, -} from '../../utils' -import * as styles from './FormOverview.css' -import { FileValueLine, ValueLine } from './ValueLine' +} from '../../utils/accidentUtils' interface SubmittedApplicationData { data?: { @@ -63,7 +68,7 @@ interface SubmittedApplicationData { } } -interface FormOverviewProps { +type Props = { field: { props: { isAssignee: boolean @@ -71,9 +76,11 @@ interface FormOverviewProps { } } -export const FormOverview: FC< - React.PropsWithChildren -> = ({ application, goToScreen, field }) => { +export const FormOverview = ({ + application, + goToScreen, + field, +}: FieldBaseProps & Props) => { const isAssignee = field?.props?.isAssignee || false const answers = application.answers as AccidentNotification const { formatMessage } = useLocale() diff --git a/libs/application/templates/accident-notification/src/fields/FormOverviewInReview/ConfirmationModal.tsx b/libs/application/templates/accident-notification/src/fields/FormOverviewInReview/ConfirmationModal.tsx index 237d074014ff..46c2ccca0fcb 100644 --- a/libs/application/templates/accident-notification/src/fields/FormOverviewInReview/ConfirmationModal.tsx +++ b/libs/application/templates/accident-notification/src/fields/FormOverviewInReview/ConfirmationModal.tsx @@ -3,11 +3,10 @@ import { Application, DefaultEvents } from '@island.is/application/types' import { SUBMIT_APPLICATION } from '@island.is/application/graphql' import { Box, Button, Icon, ModalBase, Text } from '@island.is/island-ui/core' import { useLocale } from '@island.is/localization' -import React, { FC } from 'react' import { inReview } from '../../lib/messages' import * as styles from './ConfirmationModal.css' -type ConfirmationModalProps = { +type Props = { visibility: boolean setVisibility: (visibility: boolean) => void title: string @@ -20,9 +19,7 @@ type ConfirmationModalProps = { refetch?: () => void } -export const ConfirmationModal: FC< - React.PropsWithChildren -> = ({ +export const ConfirmationModal = ({ visibility, setVisibility, title, @@ -33,7 +30,7 @@ export const ConfirmationModal: FC< application, comment = '', refetch, -}) => { +}: Props) => { const { formatMessage } = useLocale() const [submitApplication, { loading: loadingSubmit }] = useMutation( SUBMIT_APPLICATION, @@ -68,6 +65,7 @@ export const ConfirmationModal: FC< const closeModal = () => { setVisibility(false) } + return ( -> = ({ application, field, refetch, goToScreen }) => { +export const FormOverviewInReview = ({ + application, + field, + refetch, + goToScreen, +}: Props & FieldBaseProps) => { const isAssignee = field?.props?.isAssignee || false const { formatMessage } = useLocale() const reviewApproval = getValueViaPath( diff --git a/libs/application/templates/accident-notification/src/fields/HiddenInformation/index.tsx b/libs/application/templates/accident-notification/src/fields/HiddenInformation/index.tsx index 337319b0c86e..a8e458076fd0 100644 --- a/libs/application/templates/accident-notification/src/fields/HiddenInformation/index.tsx +++ b/libs/application/templates/accident-notification/src/fields/HiddenInformation/index.tsx @@ -1,10 +1,9 @@ import { FieldBaseProps } from '@island.is/application/types' -import React, { FC } from 'react' import { useFormContext } from 'react-hook-form' import { AccidentNotification } from '../../lib/dataSchema' -import { isInjuredAndRepresentativeOfCompanyOrInstitute } from '../../utils' +import { isInjuredAndRepresentativeOfCompanyOrInstitute } from '../../utils/miscUtils' -interface HiddenInformationProps { +type Props = { field: { props: { id: string @@ -12,9 +11,10 @@ interface HiddenInformationProps { } } -export const HiddenInformation: FC< - React.PropsWithChildren -> = ({ application, field }) => { +export const HiddenInformation = ({ + application, + field, +}: Props & FieldBaseProps) => { const { register, setValue } = useFormContext() const { id } = field.props diff --git a/libs/application/templates/accident-notification/src/fields/ProxyDocument/index.tsx b/libs/application/templates/accident-notification/src/fields/ProxyDocument/index.tsx index 76d7906957b0..51895095fb08 100644 --- a/libs/application/templates/accident-notification/src/fields/ProxyDocument/index.tsx +++ b/libs/application/templates/accident-notification/src/fields/ProxyDocument/index.tsx @@ -1,12 +1,8 @@ -import { FieldBaseProps } from '@island.is/application/types' import { Box, Button, Inline, Text } from '@island.is/island-ui/core' import { useLocale } from '@island.is/localization' -import React, { FC } from 'react' import { powerOfAttorney } from '../../lib/messages' -export const ProxyDocument: FC< - React.PropsWithChildren -> = () => { +export const ProxyDocument = () => { const { formatMessage } = useLocale() return ( diff --git a/libs/application/templates/accident-notification/src/forms/AccidentNotificationForm/aboutTheAccidentSection/accidentDetailSubSection.ts b/libs/application/templates/accident-notification/src/forms/AccidentNotificationForm/aboutTheAccidentSection/accidentDetailSubSection.ts index bb8693200540..ce37b82a5b37 100644 --- a/libs/application/templates/accident-notification/src/forms/AccidentNotificationForm/aboutTheAccidentSection/accidentDetailSubSection.ts +++ b/libs/application/templates/accident-notification/src/forms/AccidentNotificationForm/aboutTheAccidentSection/accidentDetailSubSection.ts @@ -8,8 +8,9 @@ import { buildTextField, } from '@island.is/application/core' import { accidentDetails } from '../../../lib/messages' -import { isDateOlderThanAYear, isHomeActivitiesAccident } from '../../../utils' -import { isHealthInsured } from '../../../utils/isHealthInsured' +import { isDateOlderThanAYear } from '../../../utils/dateUtils' +import { isHealthInsured } from '../../../utils/miscUtils' +import { isHomeActivitiesAccident } from '../../../utils/accidentUtils' // Details of the accident export const accidentDetailsSubSection = buildSubSection({ diff --git a/libs/application/templates/accident-notification/src/forms/AccidentNotificationForm/aboutTheAccidentSection/accidentTypeSubSection.ts b/libs/application/templates/accident-notification/src/forms/AccidentNotificationForm/aboutTheAccidentSection/accidentTypeSubSection.ts index 387eb21ad6c9..8a81fb15fdf7 100644 --- a/libs/application/templates/accident-notification/src/forms/AccidentNotificationForm/aboutTheAccidentSection/accidentTypeSubSection.ts +++ b/libs/application/templates/accident-notification/src/forms/AccidentNotificationForm/aboutTheAccidentSection/accidentTypeSubSection.ts @@ -1,6 +1,6 @@ import { buildRadioField, buildSubSection } from '@island.is/application/core' import { accidentType } from '../../../lib/messages' -import { getAccidentTypeOptions } from '../../../utils' +import { getAccidentTypeOptions } from '../../../utils/getOptions' export const accidentTypeSubSection = buildSubSection({ id: 'accidentType.section', diff --git a/libs/application/templates/accident-notification/src/forms/AccidentNotificationForm/aboutTheAccidentSection/attachmentsSubSection.ts b/libs/application/templates/accident-notification/src/forms/AccidentNotificationForm/aboutTheAccidentSection/attachmentsSubSection.ts index e8c71b90e331..9b239dc5d8b0 100644 --- a/libs/application/templates/accident-notification/src/forms/AccidentNotificationForm/aboutTheAccidentSection/attachmentsSubSection.ts +++ b/libs/application/templates/accident-notification/src/forms/AccidentNotificationForm/aboutTheAccidentSection/attachmentsSubSection.ts @@ -15,18 +15,12 @@ import { fatalAccidentAttachment, injuredPersonInformation, } from '../../../lib/messages' -import { - isFatalAccident, - isReportingOnBehalfOfInjured, - isRepresentativeOfCompanyOrInstitute, -} from '../../../utils' +import { isRepresentativeOfCompanyOrInstitute } from '../../../utils/miscUtils' import { AttachmentsEnum } from '../../../types' -import { - FILE_SIZE_LIMIT, - NO, - UPLOAD_ACCEPT, - YES, -} from '../../../utils/constants' +import { FILE_SIZE_LIMIT, UPLOAD_ACCEPT } from '../../../utils/constants' +import { isReportingOnBehalfOfInjured } from '../../../utils/reportingUtils' +import { NO, YES } from '@island.is/application/types' +import { isFatalAccident } from '../../../utils/accidentUtils' // Injury certificate and fatal accident section export const attachmentsSubSection = buildSubSection({ diff --git a/libs/application/templates/accident-notification/src/forms/AccidentNotificationForm/aboutTheAccidentSection/companyInfoSubSection.ts b/libs/application/templates/accident-notification/src/forms/AccidentNotificationForm/aboutTheAccidentSection/companyInfoSubSection.ts index 05cc9f837316..e9d181e3a167 100644 --- a/libs/application/templates/accident-notification/src/forms/AccidentNotificationForm/aboutTheAccidentSection/companyInfoSubSection.ts +++ b/libs/application/templates/accident-notification/src/forms/AccidentNotificationForm/aboutTheAccidentSection/companyInfoSubSection.ts @@ -9,11 +9,11 @@ import { companyInfo, representativeInfo } from '../../../lib/messages' import { isAgricultureAccident, isGeneralWorkplaceAccident, - isHomeActivitiesAccident, - isInjuredAndRepresentativeOfCompanyOrInstitute, isInternshipStudiesAccident, - isReportingOnBehalfOfEmployee, -} from '../../../utils' +} from '../../../utils/occupationUtils' +import { isReportingOnBehalfOfEmployee } from '../../../utils/reportingUtils' +import { isHomeActivitiesAccident } from '../../../utils/accidentUtils' +import { isInjuredAndRepresentativeOfCompanyOrInstitute } from '../../../utils/miscUtils' // Company information if work accident without the injured being a fisherman or in agriculture export const companyInfoSubSection = buildSubSection({ diff --git a/libs/application/templates/accident-notification/src/forms/AccidentNotificationForm/aboutTheAccidentSection/fishingCompanyInfoSubSection.ts b/libs/application/templates/accident-notification/src/forms/AccidentNotificationForm/aboutTheAccidentSection/fishingCompanyInfoSubSection.ts index 03efd89ffdaf..d009af8a3b5c 100644 --- a/libs/application/templates/accident-notification/src/forms/AccidentNotificationForm/aboutTheAccidentSection/fishingCompanyInfoSubSection.ts +++ b/libs/application/templates/accident-notification/src/forms/AccidentNotificationForm/aboutTheAccidentSection/fishingCompanyInfoSubSection.ts @@ -5,12 +5,10 @@ import { buildSubSection, buildTextField, } from '@island.is/application/core' -import { - isFishermanAccident, - isInjuredAndRepresentativeOfCompanyOrInstitute, - isReportingOnBehalfOfEmployee, -} from '../../../utils' +import { isInjuredAndRepresentativeOfCompanyOrInstitute } from '../../../utils/miscUtils' import { fishingCompanyInfo, representativeInfo } from '../../../lib/messages' +import { isReportingOnBehalfOfEmployee } from '../../../utils/reportingUtils' +import { isFishermanAccident } from '../../../utils/occupationUtils' // fishery information if fisherman export const fishingCompanyInfoSubSection = buildSubSection({ diff --git a/libs/application/templates/accident-notification/src/forms/AccidentNotificationForm/aboutTheAccidentSection/locationSubSection.ts b/libs/application/templates/accident-notification/src/forms/AccidentNotificationForm/aboutTheAccidentSection/locationSubSection.ts index be855a49a6f0..1afcdb3d604c 100644 --- a/libs/application/templates/accident-notification/src/forms/AccidentNotificationForm/aboutTheAccidentSection/locationSubSection.ts +++ b/libs/application/templates/accident-notification/src/forms/AccidentNotificationForm/aboutTheAccidentSection/locationSubSection.ts @@ -11,19 +11,6 @@ import { locationAndPurpose, sportsClubInfo, } from '../../../lib/messages' -import { - hideLocationAndPurpose, - isAgricultureAccident, - isFishermanAccident, - isGeneralWorkplaceAccident, - isHomeActivitiesAccident, - isInternshipStudiesAccident, - isProfessionalAthleteAccident, - isRescueWorkAccident, - isStudiesAccident, -} from '../../../utils' -import { NO, YES } from '../../../utils/constants' -import { isSportAccidentAndEmployee } from '../../../utils/isSportAccidentAndEmployee' import { AgricultureAccidentLocationEnum, FishermanWorkplaceAccidentLocationEnum, @@ -33,6 +20,21 @@ import { RescueWorkAccidentLocationEnum, StudiesAccidentLocationEnum, } from '../../../types' +import { + isAgricultureAccident, + isFishermanAccident, + isGeneralWorkplaceAccident, + isInternshipStudiesAccident, + isProfessionalAthleteAccident, + isSportAccidentAndEmployee, +} from '../../../utils/occupationUtils' +import { NO, YES } from '@island.is/application/types' +import { + isHomeActivitiesAccident, + isRescueWorkAccident, + isStudiesAccident, +} from '../../../utils/accidentUtils' +import { hideLocationAndPurpose } from '../../../utils/miscUtils' // Location Subsection export const locationSubSection = buildSubSection({ diff --git a/libs/application/templates/accident-notification/src/forms/AccidentNotificationForm/aboutTheAccidentSection/rescueSquadInfoSubSection.ts b/libs/application/templates/accident-notification/src/forms/AccidentNotificationForm/aboutTheAccidentSection/rescueSquadInfoSubSection.ts index 640aa635f36b..55960413bba6 100644 --- a/libs/application/templates/accident-notification/src/forms/AccidentNotificationForm/aboutTheAccidentSection/rescueSquadInfoSubSection.ts +++ b/libs/application/templates/accident-notification/src/forms/AccidentNotificationForm/aboutTheAccidentSection/rescueSquadInfoSubSection.ts @@ -6,11 +6,9 @@ import { buildTextField, } from '@island.is/application/core' import { representativeInfo, rescueSquadInfo } from '../../../lib/messages' -import { - isInjuredAndRepresentativeOfCompanyOrInstitute, - isReportingOnBehalfOfEmployee, - isRescueWorkAccident, -} from '../../../utils' +import { isInjuredAndRepresentativeOfCompanyOrInstitute } from '../../../utils/miscUtils' +import { isRescueWorkAccident } from '../../../utils/accidentUtils' +import { isReportingOnBehalfOfEmployee } from '../../../utils/reportingUtils' // Rescue squad information when accident is related to rescue squad export const rescueSquadInfoSubSection = buildSubSection({ diff --git a/libs/application/templates/accident-notification/src/forms/AccidentNotificationForm/aboutTheAccidentSection/schoolInfoSubSection.ts b/libs/application/templates/accident-notification/src/forms/AccidentNotificationForm/aboutTheAccidentSection/schoolInfoSubSection.ts index 148f9ec35872..8f26c1c56fef 100644 --- a/libs/application/templates/accident-notification/src/forms/AccidentNotificationForm/aboutTheAccidentSection/schoolInfoSubSection.ts +++ b/libs/application/templates/accident-notification/src/forms/AccidentNotificationForm/aboutTheAccidentSection/schoolInfoSubSection.ts @@ -6,12 +6,10 @@ import { buildTextField, } from '@island.is/application/core' import { representativeInfo, schoolInfo } from '../../../lib/messages' -import { - isInjuredAndRepresentativeOfCompanyOrInstitute, - isInternshipStudiesAccident, - isReportingOnBehalfOfEmployee, - isStudiesAccident, -} from '../../../utils' +import { isStudiesAccident } from '../../../utils/accidentUtils' +import { isInternshipStudiesAccident } from '../../../utils/occupationUtils' +import { isReportingOnBehalfOfEmployee } from '../../../utils/reportingUtils' +import { isInjuredAndRepresentativeOfCompanyOrInstitute } from '../../../utils/miscUtils' // School information if school accident export const schoolInfoSubSection = buildSubSection({ diff --git a/libs/application/templates/accident-notification/src/forms/AccidentNotificationForm/aboutTheAccidentSection/sportsClubInfoSubSection.ts b/libs/application/templates/accident-notification/src/forms/AccidentNotificationForm/aboutTheAccidentSection/sportsClubInfoSubSection.ts index 7914ecbe0158..8410b242d596 100644 --- a/libs/application/templates/accident-notification/src/forms/AccidentNotificationForm/aboutTheAccidentSection/sportsClubInfoSubSection.ts +++ b/libs/application/templates/accident-notification/src/forms/AccidentNotificationForm/aboutTheAccidentSection/sportsClubInfoSubSection.ts @@ -5,12 +5,10 @@ import { buildSubSection, buildTextField, } from '@island.is/application/core' -import { - isInjuredAndRepresentativeOfCompanyOrInstitute, - isProfessionalAthleteAccident, - isReportingOnBehalfOfEmployee, -} from '../../../utils' +import { isInjuredAndRepresentativeOfCompanyOrInstitute } from '../../../utils/miscUtils' import { representativeInfo, sportsClubInfo } from '../../../lib/messages' +import { isProfessionalAthleteAccident } from '../../../utils/occupationUtils' +import { isReportingOnBehalfOfEmployee } from '../../../utils/reportingUtils' // Sports club information when the injured has a sports related accident export const sportsClubInfoSubSection = buildSubSection({ diff --git a/libs/application/templates/accident-notification/src/forms/AccidentNotificationForm/aboutTheAccidentSection/studiesAccidentSubSection.ts b/libs/application/templates/accident-notification/src/forms/AccidentNotificationForm/aboutTheAccidentSection/studiesAccidentSubSection.ts index 87bead5e5d5c..19346e794c61 100644 --- a/libs/application/templates/accident-notification/src/forms/AccidentNotificationForm/aboutTheAccidentSection/studiesAccidentSubSection.ts +++ b/libs/application/templates/accident-notification/src/forms/AccidentNotificationForm/aboutTheAccidentSection/studiesAccidentSubSection.ts @@ -4,8 +4,8 @@ import { buildSubSection, } from '@island.is/application/core' import { accidentType } from '../../../lib/messages' -import { isStudiesAccident } from '../../../utils' import { StudiesAccidentTypeEnum } from '../../../types' +import { isStudiesAccident } from '../../../utils/accidentUtils' export const studiesAccidentSubSection = buildSubSection({ id: 'studiesAccident.subSection', diff --git a/libs/application/templates/accident-notification/src/forms/AccidentNotificationForm/aboutTheAccidentSection/workAccidentSubSection.ts b/libs/application/templates/accident-notification/src/forms/AccidentNotificationForm/aboutTheAccidentSection/workAccidentSubSection.ts index db49a860e014..1bb5b00d63ac 100644 --- a/libs/application/templates/accident-notification/src/forms/AccidentNotificationForm/aboutTheAccidentSection/workAccidentSubSection.ts +++ b/libs/application/templates/accident-notification/src/forms/AccidentNotificationForm/aboutTheAccidentSection/workAccidentSubSection.ts @@ -11,12 +11,10 @@ import { attachments, injuredPersonInformation, } from '../../../lib/messages' -import { - isAgricultureAccident, - isReportingOnBehalfSelf, - isWorkAccident, -} from '../../../utils' import { WorkAccidentTypeEnum } from '../../../types' +import { isWorkAccident } from '../../../utils/accidentUtils' +import { isAgricultureAccident } from '../../../utils/occupationUtils' +import { isReportingOnBehalfSelf } from '../../../utils/reportingUtils' export const workAccidentSubSection = buildSubSection({ id: 'workAccident.subSection', diff --git a/libs/application/templates/accident-notification/src/forms/AccidentNotificationForm/aboutTheAccidentSection/workMachineSubSection.ts b/libs/application/templates/accident-notification/src/forms/AccidentNotificationForm/aboutTheAccidentSection/workMachineSubSection.ts index bdfa59c43e79..0f5a41785262 100644 --- a/libs/application/templates/accident-notification/src/forms/AccidentNotificationForm/aboutTheAccidentSection/workMachineSubSection.ts +++ b/libs/application/templates/accident-notification/src/forms/AccidentNotificationForm/aboutTheAccidentSection/workMachineSubSection.ts @@ -8,9 +8,9 @@ import { application, workMachine } from '../../../lib/messages' import { isAgricultureAccident, isGeneralWorkplaceAccident, -} from '../../../utils' -import { isSportAccidentAndEmployee } from '../../../utils/isSportAccidentAndEmployee' -import { NO, YES } from '../../../utils/constants' + isSportAccidentAndEmployee, +} from '../../../utils/occupationUtils' +import { NO, YES } from '@island.is/application/types' // Workmachine information only applicable to generic workplace accidents export const workMachineSubSection = buildSubSection({ diff --git a/libs/application/templates/accident-notification/src/forms/AccidentNotificationForm/applicantInformationSection.ts b/libs/application/templates/accident-notification/src/forms/AccidentNotificationForm/applicantInformationSection.ts index f91bcfaaee43..0c948df0a9f0 100644 --- a/libs/application/templates/accident-notification/src/forms/AccidentNotificationForm/applicantInformationSection.ts +++ b/libs/application/templates/accident-notification/src/forms/AccidentNotificationForm/applicantInformationSection.ts @@ -1,6 +1,7 @@ import { buildSection } from '@island.is/application/core' import { applicantInformation } from '../../lib/messages' import { applicantInformationMultiField } from '@island.is/application/ui-forms' + export const applicantInformationSection = buildSection({ id: 'informationAboutApplicantSection', title: applicantInformation.general.title, diff --git a/libs/application/templates/accident-notification/src/forms/AccidentNotificationForm/whoIsTheNotificationForSection/childInCustodySubSection.ts b/libs/application/templates/accident-notification/src/forms/AccidentNotificationForm/whoIsTheNotificationForSection/childInCustodySubSection.ts index 9587578fe81c..a826034c5773 100644 --- a/libs/application/templates/accident-notification/src/forms/AccidentNotificationForm/whoIsTheNotificationForSection/childInCustodySubSection.ts +++ b/libs/application/templates/accident-notification/src/forms/AccidentNotificationForm/whoIsTheNotificationForSection/childInCustodySubSection.ts @@ -4,7 +4,7 @@ import { buildTextField, } from '@island.is/application/core' import { childInCustody } from '../../../lib/messages' -import { isReportingOnBehalfOfChild } from '../../../utils' +import { isReportingOnBehalfOfChild } from '../../../utils/reportingUtils' export const childInCustodySubSection = buildSubSection({ id: 'childInCustody.section', diff --git a/libs/application/templates/accident-notification/src/forms/AccidentNotificationForm/whoIsTheNotificationForSection/injuredPersonInformationSubSection.ts b/libs/application/templates/accident-notification/src/forms/AccidentNotificationForm/whoIsTheNotificationForSection/injuredPersonInformationSubSection.ts index 643cc77ad62d..0b5acc8a391a 100644 --- a/libs/application/templates/accident-notification/src/forms/AccidentNotificationForm/whoIsTheNotificationForSection/injuredPersonInformationSubSection.ts +++ b/libs/application/templates/accident-notification/src/forms/AccidentNotificationForm/whoIsTheNotificationForSection/injuredPersonInformationSubSection.ts @@ -8,7 +8,7 @@ import { injuredPersonInformation } from '../../../lib/messages' import { isReportingOnBehalfOfEmployee, isReportingOnBehalfOfInjured, -} from '../../../utils' +} from '../../../utils/reportingUtils' export const injuredPersonInformationSubSection = buildSubSection({ id: 'injuredPersonInformation.section', diff --git a/libs/application/templates/accident-notification/src/forms/AccidentNotificationForm/whoIsTheNotificationForSection/juridicialPersonCompanySubSection.ts b/libs/application/templates/accident-notification/src/forms/AccidentNotificationForm/whoIsTheNotificationForSection/juridicialPersonCompanySubSection.ts index 5d747453c1d0..ea81a695800d 100644 --- a/libs/application/templates/accident-notification/src/forms/AccidentNotificationForm/whoIsTheNotificationForSection/juridicialPersonCompanySubSection.ts +++ b/libs/application/templates/accident-notification/src/forms/AccidentNotificationForm/whoIsTheNotificationForSection/juridicialPersonCompanySubSection.ts @@ -5,8 +5,8 @@ import { buildTextField, } from '@island.is/application/core' import { juridicalPerson } from '../../../lib/messages' -import { isReportingOnBehalfOfEmployee } from '../../../utils' -import { YES } from '../../../utils/constants' +import { isReportingOnBehalfOfEmployee } from '../../../utils/reportingUtils' +import { YES } from '@island.is/application/types' export const juridicalPersonCompanySubSection = buildSubSection({ id: 'juridicalPerson.company', diff --git a/libs/application/templates/accident-notification/src/forms/AccidentNotificationForm/whoIsTheNotificationForSection/powerOfAttorneySubSection.ts b/libs/application/templates/accident-notification/src/forms/AccidentNotificationForm/whoIsTheNotificationForSection/powerOfAttorneySubSection.ts index eb16cefeec0f..7556f6c32cbc 100644 --- a/libs/application/templates/accident-notification/src/forms/AccidentNotificationForm/whoIsTheNotificationForSection/powerOfAttorneySubSection.ts +++ b/libs/application/templates/accident-notification/src/forms/AccidentNotificationForm/whoIsTheNotificationForSection/powerOfAttorneySubSection.ts @@ -7,7 +7,7 @@ import { } from '@island.is/application/core' import { powerOfAttorney } from '../../../lib/messages' import { PowerOfAttorneyUploadEnum } from '../../../types' -import { isPowerOfAttorney } from '../../../utils' +import { isPowerOfAttorney } from '../../../utils/miscUtils' export const powerOfAttorneySubSection = buildSubSection({ id: 'powerOfAttorney.type.section', diff --git a/libs/application/templates/accident-notification/src/forms/AccidentNotificationForm/whoIsTheNotificationForSection/powerOfAttorneyUploadSubSection.ts b/libs/application/templates/accident-notification/src/forms/AccidentNotificationForm/whoIsTheNotificationForSection/powerOfAttorneyUploadSubSection.ts index 00ec8aff756d..437a4072b541 100644 --- a/libs/application/templates/accident-notification/src/forms/AccidentNotificationForm/whoIsTheNotificationForSection/powerOfAttorneyUploadSubSection.ts +++ b/libs/application/templates/accident-notification/src/forms/AccidentNotificationForm/whoIsTheNotificationForSection/powerOfAttorneyUploadSubSection.ts @@ -6,11 +6,12 @@ import { } from '@island.is/application/core' import { error, powerOfAttorney } from '../../../lib/messages' import { FILE_SIZE_LIMIT, UPLOAD_ACCEPT } from '../../../utils/constants' -import { isUploadNow } from '../../../utils/isUploadNow' +import { isUploadNow } from '../../../utils/documentUtils' export const powerOfAttorneyUploadSubSection = buildSubSection({ id: 'powerOfAttorney.upload.section', title: powerOfAttorney.upload.sectionTitle, + condition: (formValue) => isUploadNow(formValue), children: [ buildMultiField({ id: 'powerOfAttorney', @@ -37,5 +38,4 @@ export const powerOfAttorneyUploadSubSection = buildSubSection({ ], }), ], - condition: (formValue) => isUploadNow(formValue), }) diff --git a/libs/application/templates/accident-notification/src/forms/AccidentNotificationForm/whoIsTheNotificationForSection/whoIsTheNotificationForMultiField.ts b/libs/application/templates/accident-notification/src/forms/AccidentNotificationForm/whoIsTheNotificationForSection/whoIsTheNotificationForMultiField.ts index d59f1f345a83..96665ccc5d98 100644 --- a/libs/application/templates/accident-notification/src/forms/AccidentNotificationForm/whoIsTheNotificationForSection/whoIsTheNotificationForMultiField.ts +++ b/libs/application/templates/accident-notification/src/forms/AccidentNotificationForm/whoIsTheNotificationForSection/whoIsTheNotificationForMultiField.ts @@ -3,7 +3,7 @@ import { whoIsTheNotificationFor } from '../../../lib/messages' import { whoIsTheNotificationForOptions, whoIsTheNotificationForProcureOptions, -} from '../../../utils/getWhoIstheNotificationForOptions' +} from '../../../utils/getOptions' export const whoIsTheNotificationForMultiField = buildMultiField({ id: 'whoIsTheNotificationFor', diff --git a/libs/application/templates/accident-notification/src/forms/InReviewForm/addAttachmentsSection.ts b/libs/application/templates/accident-notification/src/forms/InReviewForm/addAttachmentsSection.ts index f0c88a39c67a..a53e2afcabfc 100644 --- a/libs/application/templates/accident-notification/src/forms/InReviewForm/addAttachmentsSection.ts +++ b/libs/application/templates/accident-notification/src/forms/InReviewForm/addAttachmentsSection.ts @@ -13,11 +13,10 @@ import { hasReceivedInjuryCertificate, hasReceivedPoliceReport, hasReceivedProxyDocument, - isFatalAccident, - isPowerOfAttorney, - isReportingOnBehalfOfInjured, - isUniqueAssignee, -} from '../../utils' +} from '../../utils/documentUtils' +import { isPowerOfAttorney, isUniqueAssignee } from '../../utils/miscUtils' +import { isReportingOnBehalfOfInjured } from '../../utils/reportingUtils' +import { isFatalAccident } from '../../utils/accidentUtils' export const addAttachmentsSection = (isAssignee?: boolean) => buildSection({ diff --git a/libs/application/templates/accident-notification/src/index.ts b/libs/application/templates/accident-notification/src/index.ts index 512077174291..2d4f5c15801b 100644 --- a/libs/application/templates/accident-notification/src/index.ts +++ b/libs/application/templates/accident-notification/src/index.ts @@ -2,7 +2,7 @@ import AccidentNotificationTemplate from './lib/AccidentNotificationTemplate' import { AccidentNotification } from './lib/dataSchema' import * as appMessages from './lib/messages' import { OnBehalf } from './types' -import * as appUtils from './utils' +import * as appUtils from './utils/miscUtils' export const getFields = () => import('./fields') diff --git a/libs/application/templates/accident-notification/src/lib/dataSchema.ts b/libs/application/templates/accident-notification/src/lib/dataSchema.ts index afb53946fe3b..3ba93cdc8e15 100644 --- a/libs/application/templates/accident-notification/src/lib/dataSchema.ts +++ b/libs/application/templates/accident-notification/src/lib/dataSchema.ts @@ -1,7 +1,6 @@ import { applicantInformationSchema } from '@island.is/application/ui-forms' import * as kennitala from 'kennitala' import { z } from 'zod' -import { YES } from '../utils/constants' import { AccidentTypeEnum, AgricultureAccidentLocationEnum, @@ -19,10 +18,11 @@ import { ReviewApprovalEnum, OnBehalf, Status, - ChoiceEnum, + YesOrNo, } from '../types' -import { isValid24HFormatTime } from '../utils' import { error } from './messages/error' +import { isValid24HFormatTime } from '../utils/dateUtils' +import { YES } from '@island.is/application/types' const FileSchema = z.object({ name: z.string(), @@ -99,7 +99,7 @@ const accidentDetails = z.object({ dateOfAccident: z.string().refine((x) => x.trim().length > 0, { params: error.invalidValue, }), - isHealthInsured: z.nativeEnum(ChoiceEnum).optional(), + isHealthInsured: z.nativeEnum(YesOrNo).optional(), timeOfAccident: z .string() .refine((x) => (x ? isValid24HFormatTime(x) : false), { @@ -193,8 +193,8 @@ export const AccidentNotificationSchema = z.object({ info: z.object({ onBehalf: z.nativeEnum(OnBehalf), }), - timePassedHindrance: z.nativeEnum(ChoiceEnum), - carAccidentHindrance: z.nativeEnum(ChoiceEnum), + timePassedHindrance: z.nativeEnum(YesOrNo), + carAccidentHindrance: z.nativeEnum(YesOrNo), applicant: applicantInformationSchema(), whoIsTheNotificationFor: z.object({ answer: z.nativeEnum(WhoIsTheNotificationForEnum), @@ -213,13 +213,13 @@ export const AccidentNotificationSchema = z.object({ ]), }), attachments, - wasTheAccidentFatal: z.nativeEnum(ChoiceEnum), - fatalAccidentUploadDeathCertificateNow: z.nativeEnum(ChoiceEnum), + wasTheAccidentFatal: z.nativeEnum(YesOrNo), + fatalAccidentUploadDeathCertificateNow: z.nativeEnum(YesOrNo), accidentDetails, isRepresentativeOfCompanyOrInstitue: z.array(z.string()).optional(), fishingShipInfo, onPayRoll: z.object({ - answer: z.nativeEnum(ChoiceEnum), + answer: z.nativeEnum(YesOrNo), }), locationAndPurpose: z.object({ location: z.string().refine((x) => x.trim().length > 0, { @@ -240,7 +240,7 @@ export const AccidentNotificationSchema = z.object({ shipLocation: z.object({ answer: z.nativeEnum(FishermanWorkplaceAccidentShipLocationEnum), }), - workMachineRadio: z.nativeEnum(ChoiceEnum), + workMachineRadio: z.nativeEnum(YesOrNo), workMachine: z.object({ descriptionOfMachine: z.string().refine((x) => x.trim().length > 0, { params: error.invalidValue, diff --git a/libs/application/templates/accident-notification/src/lib/messages/externalData.ts b/libs/application/templates/accident-notification/src/lib/messages/externalData.ts index 869618dbdc54..4f1342fc8544 100644 --- a/libs/application/templates/accident-notification/src/lib/messages/externalData.ts +++ b/libs/application/templates/accident-notification/src/lib/messages/externalData.ts @@ -12,6 +12,24 @@ export const externalData = { defaultMessage: 'Meðferð á gögnum', description: 'Data handling list item title', }, + bulletOne: { + id: 'an.application:section.agreementDescription.BulletOne', + defaultMessage: + 'Þegar tilkynning um slys er send Sjúkratryggingum Íslands mun stofnunin miðla upplýsingum um afstöðu til bótaskyldu með þeim atvinnurekanda eða íþróttafélagi sem á í hlut. Ástæða þess er að umræddir aðilar kunna að eiga rétt á endurgreiðslu útlagðs kostnaðar og/eða dagpeningum ef greidd hafa verið laun í veikindaforföllum vegna slyssins. Þessir aðilar fá aldrei afhentar heilsufars- eða sjúkraskrárupplýsingar.', + description: 'List item 1 on data gathering information', + }, + bulletTwo: { + id: 'an.application:section.agreementDescription.BulletTwo', + defaultMessage: + 'Vinnueftirlit ríkisins kann einnig að fá afrit af tilkynningunni undir ákveðnum kringumstæðum á grundvelli 4. mgr. 79. gr. laga nr. 46/1980 sem og Rannsóknarnefnd samgönguslysa á grundvelli 12. og 16. gr. laga nr. 18/2013.', + description: 'List item 2 on data gathering information', + }, + bulletThree: { + id: 'an.application:section.agreementDescription.BulletThree', + defaultMessage: + 'Eitthvað óvænt verður að hafa gerst sem veldur tjóni á líkama hins tryggða og áhorfandi getur áttað sig á að hafi gerst.', + description: 'List item 3 on data gathering information', + }, bulletFour: { id: 'an.application:section.agreementDescription.BulletFour', defaultMessage: diff --git a/libs/application/templates/accident-notification/src/types/index.ts b/libs/application/templates/accident-notification/src/types/index.ts index da316a4fd5f7..58dac3b071d9 100644 --- a/libs/application/templates/accident-notification/src/types/index.ts +++ b/libs/application/templates/accident-notification/src/types/index.ts @@ -1,4 +1,4 @@ -import { NO, YES } from '../utils/constants' +import { companyInfo, representativeInfo } from '../lib/messages' export type CompanyInfo = { nationalRegistrationId: string @@ -53,11 +53,6 @@ export enum OnBehalf { OTHERS = 'others', } -export enum ChoiceEnum { - YES = 'yes', - NO = 'no', -} - export enum WhoIsTheNotificationForEnum { JURIDICALPERSON = 'juridicalPerson', ME = 'me', @@ -73,7 +68,10 @@ export enum AccidentTypeEnum { SPORTS = 'sports', } -export type YesOrNo = typeof NO | typeof YES +export enum YesOrNo { + YES = 'yes', + NO = 'no', +} export enum AttachmentsEnum { INJURYCERTIFICATE = 'injuryCertificate', @@ -229,3 +227,13 @@ export type RepresentativeInfoV2 = { nationalId?: string | null phoneNumber?: string | null } + +export type WorkplaceData = { + companyInfo: CompanyInfo + representitive: RepresentativeInfo + companyInfoMsg: typeof companyInfo + representitiveMsg: typeof representativeInfo + type: WorkAccidentTypeEnum | AccidentTypeEnum + onPayRoll?: YesOrNo + screenId: string +} diff --git a/libs/application/templates/accident-notification/src/utils/accidentNotificationUtils.spec.ts b/libs/application/templates/accident-notification/src/utils/accidentNotificationUtils.spec.ts deleted file mode 100644 index 1e1d888a4745..000000000000 --- a/libs/application/templates/accident-notification/src/utils/accidentNotificationUtils.spec.ts +++ /dev/null @@ -1,38 +0,0 @@ -import { isValid24HFormatTime } from './index' -describe('Health insurance utils', () => { - const validString = '2359' - const tooLongString = '23599' - const threeLetterString = '123' - const twoLetterString = '12' - const oneLetterString = '1' - const emptyString = '' - const illlegalHourString = '2459' - const illlegalMinuteString = '2364' - - describe('Check time format validation logic', () => { - it('should return true for 2359', () => { - expect(isValid24HFormatTime(validString)).toEqual(true) - }) - it('should return false for 23599', () => { - expect(isValid24HFormatTime(tooLongString)).toEqual(false) - }) - it('should return false for 123', () => { - expect(isValid24HFormatTime(threeLetterString)).toEqual(false) - }) - it('should return false for 12', () => { - expect(isValid24HFormatTime(twoLetterString)).toEqual(false) - }) - it('should return false for 1', () => { - expect(isValid24HFormatTime(oneLetterString)).toEqual(false) - }) - it('should return false for empty string', () => { - expect(isValid24HFormatTime(emptyString)).toEqual(false) - }) - it('should return false for 2459', () => { - expect(isValid24HFormatTime(illlegalHourString)).toEqual(false) - }) - it('should return false for 2364', () => { - expect(isValid24HFormatTime(illlegalMinuteString)).toEqual(false) - }) - }) -}) diff --git a/libs/application/templates/accident-notification/src/utils/accidentUtils.spec.ts b/libs/application/templates/accident-notification/src/utils/accidentUtils.spec.ts new file mode 100644 index 000000000000..8fbbccbf2274 --- /dev/null +++ b/libs/application/templates/accident-notification/src/utils/accidentUtils.spec.ts @@ -0,0 +1,157 @@ +import { FormValue, NO, YES } from '@island.is/application/types' +import { AccidentTypeEnum } from '../types' +import { + getInjuredPersonInformation, + isFatalAccident, + isHomeActivitiesAccident, + isRescueWorkAccident, + isStudiesAccident, + isWorkAccident, +} from './accidentUtils' + +describe('isHomeActivitiesAccident', () => { + const homeActivitiesAccident: FormValue = { + accidentType: { radioButton: AccidentTypeEnum.HOMEACTIVITIES }, + } + + const someOtherAccident: FormValue = { + accidentType: { radioButton: AccidentTypeEnum.RESCUEWORK }, + } + + const emptyObject = {} + + it('should return true for home activity accidents', () => { + expect(isHomeActivitiesAccident(homeActivitiesAccident)).toEqual(true) + }) + it('should return false for accidents other than home activity accidents', () => { + expect(isHomeActivitiesAccident(someOtherAccident)).toEqual(false) + }) + it('should return false for empty object', () => { + expect(isHomeActivitiesAccident(emptyObject)).toEqual(false) + }) +}) +describe('isWorkAccident', () => { + const workAccident: FormValue = { + accidentType: { radioButton: AccidentTypeEnum.WORK }, + } + + const someOtherAccident: FormValue = { + accidentType: { radioButton: AccidentTypeEnum.HOMEACTIVITIES }, + } + + const emptyObject = {} + + it('should return true for work accidents', () => { + expect(isWorkAccident(workAccident)).toEqual(true) + }) + it('should return false for accidents other than work', () => { + expect(isWorkAccident(someOtherAccident)).toEqual(false) + }) + it('should return false for empty object', () => { + expect(isWorkAccident(emptyObject)).toEqual(false) + }) +}) + +describe('isRescueWorkAccident', () => { + const rescueWorkAccident: FormValue = { + accidentType: { radioButton: AccidentTypeEnum.RESCUEWORK }, + } + + const someOtherAccident: FormValue = { + accidentType: { radioButton: AccidentTypeEnum.HOMEACTIVITIES }, + } + + const emptyObject = {} + + it('should return true for rescue work accidents', () => { + expect(isRescueWorkAccident(rescueWorkAccident)).toEqual(true) + }) + it('should return false for accidents other than rescue work', () => { + expect(isRescueWorkAccident(someOtherAccident)).toEqual(false) + }) + it('should return false for empty object', () => { + expect(isRescueWorkAccident(emptyObject)).toEqual(false) + }) +}) + +describe('isStudiesAccident', () => { + const studiesAccident: FormValue = { + accidentType: { radioButton: AccidentTypeEnum.STUDIES }, + } + + const someOtherAccident: FormValue = { + accidentType: { radioButton: AccidentTypeEnum.HOMEACTIVITIES }, + } + + const emptyObject = {} + + it('should return true for studies accidents', () => { + expect(isStudiesAccident(studiesAccident)).toEqual(true) + }) + it('should return false for accidents other than studies', () => { + expect(isStudiesAccident(someOtherAccident)).toEqual(false) + }) + it('should return false for empty object', () => { + expect(isStudiesAccident(emptyObject)).toEqual(false) + }) +}) + +describe('getInjuredPersonInformation', () => { + const injuredPersonInformation: FormValue = { + injuredPersonInformation: { + email: 'kalli@palli.is', + name: 'Kalli', + }, + } + + const emptyInjuredPersonInformation: FormValue = { + injuredPersonInformation: { + email: '', + name: '', + }, + } + + it('Should return the email of the injured person', () => { + expect( + getInjuredPersonInformation(injuredPersonInformation)?.email, + ).toEqual('kalli@palli.is') + }) + + it('Should return the name of the injured person', () => { + expect(getInjuredPersonInformation(injuredPersonInformation)?.name).toEqual( + 'Kalli', + ) + }) + + it('Should return empty string for email if not provided', () => { + expect( + getInjuredPersonInformation(emptyInjuredPersonInformation)?.email, + ).toEqual('') + }) + + it('Should return empty string for name if not provided', () => { + expect( + getInjuredPersonInformation(emptyInjuredPersonInformation)?.name, + ).toEqual('') + }) +}) + +describe('isFatalAccident', () => { + const fatal: FormValue = { + wasTheAccidentFatal: YES, + } + + const notFatal: FormValue = { + wasTheAccidentFatal: NO, + } + + it('should return true for a fatal accident', () => { + expect(isFatalAccident(fatal)).toEqual(true) + }) + it('should return false for a non fatal accident', () => { + expect(isFatalAccident(notFatal)).toEqual(false) + }) + it('should return false for empty object', () => { + expect(isFatalAccident({})).toEqual(false) + }) +}) diff --git a/libs/application/templates/accident-notification/src/utils/accidentUtils.ts b/libs/application/templates/accident-notification/src/utils/accidentUtils.ts new file mode 100644 index 000000000000..94f8954d5954 --- /dev/null +++ b/libs/application/templates/accident-notification/src/utils/accidentUtils.ts @@ -0,0 +1,60 @@ +import { getValueViaPath } from '@island.is/application/core' +import { FormValue, YES } from '@island.is/application/types' +import { AccidentTypeEnum, YesOrNo } from '../types' + +export const isWorkAccident = (formValue: FormValue) => { + const accidentType = getValueViaPath( + formValue, + 'accidentType.radioButton', + ) + return accidentType === AccidentTypeEnum.WORK +} + +export const isHomeActivitiesAccident = (formValue: FormValue) => { + const workAccidentType = getValueViaPath( + formValue, + 'accidentType.radioButton', + ) + return workAccidentType === AccidentTypeEnum.HOMEACTIVITIES +} + +export const isRescueWorkAccident = (formValue: FormValue) => { + const accidentType = getValueViaPath( + formValue, + 'accidentType.radioButton', + ) + return accidentType === AccidentTypeEnum.RESCUEWORK +} + +export const isStudiesAccident = (formValue: FormValue) => { + const accidentType = getValueViaPath( + formValue, + 'accidentType.radioButton', + ) + return accidentType === AccidentTypeEnum.STUDIES +} + +export const getInjuredPersonInformation = (answers: FormValue) => { + const injuredPersonsEmail = getValueViaPath( + answers, + 'injuredPersonInformation.email', + ) + + const injuredPersonsName = getValueViaPath( + answers, + 'injuredPersonInformation.name', + ) + + return { + email: injuredPersonsEmail, + name: injuredPersonsName, + } +} + +export const isFatalAccident = (formValue: FormValue) => { + const wasTheAccidentFatal = getValueViaPath( + formValue, + 'wasTheAccidentFatal', + ) + return wasTheAccidentFatal === YES +} diff --git a/libs/application/templates/accident-notification/src/utils/constants/index.ts b/libs/application/templates/accident-notification/src/utils/constants/index.ts index c13413335ab9..b57a23b4f76a 100644 --- a/libs/application/templates/accident-notification/src/utils/constants/index.ts +++ b/libs/application/templates/accident-notification/src/utils/constants/index.ts @@ -1,6 +1,3 @@ -export const YES = 'yes' -export const NO = 'no' - export const UPLOAD_ACCEPT = '.pdf, .doc, .docx, .rtf, .jpg, .jpeg, .png, .heic' export const FILE_SIZE_LIMIT = 10000000 // 10MB diff --git a/libs/application/templates/accident-notification/src/utils/isDateOlderThanAYear.spec.ts b/libs/application/templates/accident-notification/src/utils/dateUtils.spec.ts similarity index 61% rename from libs/application/templates/accident-notification/src/utils/isDateOlderThanAYear.spec.ts rename to libs/application/templates/accident-notification/src/utils/dateUtils.spec.ts index 60fae84cec61..1045a0918ffe 100644 --- a/libs/application/templates/accident-notification/src/utils/isDateOlderThanAYear.spec.ts +++ b/libs/application/templates/accident-notification/src/utils/dateUtils.spec.ts @@ -1,5 +1,6 @@ import { FormValue } from '@island.is/application/types' -import { isDateOlderThanAYear } from './isDateOlderThanAYear' +import { isDateOlderThanAYear, isValid24HFormatTime } from './dateUtils' + describe('isDateOlderThanAYear', () => { const yesterday = new Date() yesterday.setDate(yesterday.getDate() - 1) @@ -27,3 +28,29 @@ describe('isDateOlderThanAYear', () => { expect(isDateOlderThanAYear(emptyObject)).toEqual(false) }) }) + +describe('isValid24HFormatTime', () => { + it.each(['0000', '2359', '1234'])( + 'should return true for valid time', + (time) => { + const result = isValid24HFormatTime(time) + expect(result).toBeTruthy() + }, + ) + + it.each([ + '2534', + '1265', + '2360', + '2400', + '12:34', + '', + '1', + '12', + '123', + '12345', + ])('should return false for invalid time', (time) => { + const result = isValid24HFormatTime(time) + expect(result).toBeFalsy() + }) +}) diff --git a/libs/application/templates/accident-notification/src/utils/isDateOlderThanAYear.ts b/libs/application/templates/accident-notification/src/utils/dateUtils.ts similarity index 60% rename from libs/application/templates/accident-notification/src/utils/isDateOlderThanAYear.ts rename to libs/application/templates/accident-notification/src/utils/dateUtils.ts index e554a1df59f4..1e7f2d43b42f 100644 --- a/libs/application/templates/accident-notification/src/utils/isDateOlderThanAYear.ts +++ b/libs/application/templates/accident-notification/src/utils/dateUtils.ts @@ -10,9 +10,18 @@ const getDateAYearBack = () => { export const isDateOlderThanAYear = (answers: FormValue) => { const aYearAgo = getDateAYearBack() - const date = getValueViaPath( + const date = getValueViaPath( answers, 'accidentDetails.dateOfAccident', - ) as string + ) return !!date && new Date(date).getTime() < aYearAgo.getTime() } + +export const isValid24HFormatTime = (value: string) => { + if (value.length !== 4) return false + const hours = parseInt(value.slice(0, 2)) + const minutes = parseInt(value.slice(2, 4)) + if (hours > 23) return false + if (minutes > 59) return false + return true +} diff --git a/libs/application/templates/accident-notification/src/utils/documentUtils.spec.ts b/libs/application/templates/accident-notification/src/utils/documentUtils.spec.ts new file mode 100644 index 000000000000..4ab59d4aa1d7 --- /dev/null +++ b/libs/application/templates/accident-notification/src/utils/documentUtils.spec.ts @@ -0,0 +1,316 @@ +import { FormatMessage } from '@island.is/localization' + +import { AccidentNotification } from '../lib/dataSchema' +import { + AttachmentsEnum, + PowerOfAttorneyUploadEnum, + WhoIsTheNotificationForEnum, + YesOrNo, +} from '../types' +import { + getAttachmentTitles, + isUploadNow, + returnMissingDocumentsList, +} from './documentUtils' +import { + getErrorMessageForMissingDocuments, + hasMissingDocuments, + hasReceivedAllDocuments, +} from './documentUtils' +import { FormValue } from '@island.is/application/types' + +describe('hasMissingDocuments', () => { + it('should return true when missing documents', () => { + expect(hasMissingDocuments(getMissingDocuments())).toEqual(true) + }) + + it('should return false when no missing documents', () => { + expect(hasMissingDocuments(getNoMissingDocuments())).toEqual(false) + }) +}) + +describe('getErrorMessageForMissingDocuments', () => { + const formatMessage: FormatMessage = jest.fn().mockReturnValue('test.pdf') + + beforeEach(() => { + jest.clearAllMocks() + }) + + it('should return error message for missing documents', () => { + const result = getErrorMessageForMissingDocuments( + getMissingDocuments(), + formatMessage, + false, + ) + expect(result).toEqual('test.pdf, test.pdf, test.pdf') + expect(formatMessage).toHaveBeenCalledTimes(3) + }) + + it('should return empty string when no documents are missing', () => { + const docs = getNoMissingDocuments() + const result = getErrorMessageForMissingDocuments(docs, formatMessage, true) + expect(result).toBe('') + expect(formatMessage).not.toHaveBeenCalled() + }) +}) + +describe('hasReceivedAllDocuments', () => { + const testCases = [ + { who: WhoIsTheNotificationForEnum.ME, fatal: YesOrNo.NO }, + { who: WhoIsTheNotificationForEnum.JURIDICALPERSON, fatal: YesOrNo.NO }, + { who: WhoIsTheNotificationForEnum.POWEROFATTORNEY, fatal: YesOrNo.YES }, + { who: WhoIsTheNotificationForEnum.POWEROFATTORNEY, fatal: YesOrNo.NO }, + ] + it.each(testCases)( + 'should return true when all documents are received', + (data) => { + const answers = getNoMissingDocuments() as AccidentNotification + answers.whoIsTheNotificationFor.answer = data.who + answers.wasTheAccidentFatal = data.fatal + expect(hasReceivedAllDocuments(answers)).toEqual(true) + }, + ) + + it.each(testCases)('should return false when missing documents', (data) => { + const answers = getMissingDocuments() as AccidentNotification + answers.whoIsTheNotificationFor.answer = data.who + answers.wasTheAccidentFatal = data.fatal + expect(hasReceivedAllDocuments(answers)).toEqual(false) + }) +}) + +const EMPTY_FILE: never[] = [] + +const SAMPLE_FILE = { + name: 'test.pdf', + url: 'https://test.pdf', +} as const +const createAttachment = () => ({ file: [SAMPLE_FILE] }) + +const getMissingDocuments = (): FormValue => ({ + whoIsTheNotificationFor: { + answer: WhoIsTheNotificationForEnum.POWEROFATTORNEY, + }, + wasTheAccidentFatal: YesOrNo.YES, + injuryCertificate: { + answer: AttachmentsEnum.SENDCERTIFICATELATER, + }, + accidentStatus: { + receivedAttachments: { + InjuryCertificate: false, + PoliceReport: false, + DeathCertificate: false, + ProxyDocument: false, + }, + }, + attachments: { + injuryCertificateFile: { file: EMPTY_FILE }, + deathCertificateFile: { file: EMPTY_FILE }, + powerOfAttorneyFile: { file: EMPTY_FILE }, + }, +}) + +const getNoMissingDocuments = (): FormValue => ({ + whoIsTheNotificationFor: { + answer: WhoIsTheNotificationForEnum.POWEROFATTORNEY, + }, + wasTheAccidentFatal: YesOrNo.YES, + injuryCertificate: { + answer: AttachmentsEnum.SENDCERTIFICATELATER, + }, + accidentStatus: { + receivedAttachments: { + InjuryCertificate: true, + PoliceReport: true, + DeathCertificate: true, + ProxyDocument: true, + }, + }, + attachments: { + injuryCertificateFile: { + file: [createAttachment()], + }, + deathCertificateFile: { + file: [createAttachment()], + }, + powerOfAttorneyFile: { + file: [createAttachment()], + }, + }, +}) + +describe('getAttachmentTitles', () => { + it.each([ + AttachmentsEnum.SENDCERTIFICATELATER, + AttachmentsEnum.HOSPITALSENDSCERTIFICATE, + ])('should return attachment titles', (injuryCertificate) => { + const answers = { + injuryCertificate: { + answer: injuryCertificate, + }, + attachments: { + deathCertificateFile: { + file: [ + { + name: 'test.pdf', + url: 'https://test.pdf', + }, + ], + }, + injuryCertificateFile: { + file: [ + { + name: 'test.pdf', + url: 'https://test.pdf', + }, + ], + }, + powerOfAttorneyFile: { + file: [ + { + name: 'test.pdf', + url: 'https://test.pdf', + }, + ], + }, + additionalFiles: { + file: [ + { + name: 'test.pdf', + url: 'https://test.pdf', + }, + ], + }, + additionalFilesFromReviewer: { + file: [ + { + name: 'test.pdf', + url: 'https://test.pdf', + }, + ], + }, + }, + } + + // Semi annoying push stuff here because order matters for strict equals + const isHospitalSendsCertificate = + injuryCertificate === AttachmentsEnum.HOSPITALSENDSCERTIFICATE + const expectedResults = [] + expectedResults.push({ + id: 'an.application:attachments.documentNames.deathCertificate', + defaultMessage: 'Lögregluskýrsla', + description: 'Name of police report for in review', + }) + if (!isHospitalSendsCertificate) { + expectedResults.push({ + id: 'an.application:attachments.documentNames.injuryCertificate', + defaultMessage: 'Áverkavottorð', + description: 'Name of injury certificate for in review', + }) + } + expectedResults.push({ + id: 'an.application:attachments.documentNames.powerOfAttorney', + defaultMessage: 'Umboð', + description: 'Name of power of attorney document for in review', + }) + if (isHospitalSendsCertificate) { + expectedResults.push({ + id: 'an.application:overview.labels.hospitalSendsCertificate', + defaultMessage: + 'Bráðamóttökuskrá - Ég mun óska eftir því að Landspítalinn sendi bráðamóttökuskrá til Sjúkratrygginga Íslands', + description: 'Label for hospital sends certificate in document list', + }) + } + expectedResults.push({ + id: 'an.application:attachments.documentNames.additionalDocumentsFromApplicant', + defaultMessage: 'Auka fylgiskjöl frá umsækjanda', + description: + 'Name of additional attachments for in review from applicant', + }) + expectedResults.push({ + id: 'an.application:attachments.documentNames.additionalDocumentsFromReviewer', + defaultMessage: 'Auka fylgiskjöl frá forsvarsmanni', + description: 'Name of additional attachments for in review from reviewer', + }) + + const result = getAttachmentTitles( + answers as unknown as AccidentNotification, + ) + expect(result).toStrictEqual(expectedResults) + }) +}) + +describe('returnMissingDocumentsList', () => { + it('should return missing documents list', () => { + const formatMessage: FormatMessage = jest.fn().mockReturnValue('test.pdf') + const missingDocuments = { + whoIsTheNotificationFor: { + answer: WhoIsTheNotificationForEnum.POWEROFATTORNEY, + }, + wasTheAccidentFatal: YesOrNo.YES, + injuryCertificate: { + answer: AttachmentsEnum.SENDCERTIFICATELATER, + }, + attachments: { + injuryCertificateFile: { + file: [], + }, + deathCertificateFile: { + file: [], + }, + powerOfAttorneyFile: { + file: [], + }, + }, + } + const result = returnMissingDocumentsList( + missingDocuments as unknown as AccidentNotification, + formatMessage, + ) + expect(result).toEqual('test.pdf, test.pdf, test.pdf') + }) +}) + +describe('isUploadNow', () => { + const powerOfAttorneyReporterWithUploadNow: FormValue = { + whoIsTheNotificationFor: { + answer: WhoIsTheNotificationForEnum.POWEROFATTORNEY, + }, + powerOfAttorney: { + type: PowerOfAttorneyUploadEnum.UPLOADNOW, + }, + } + + const powerOfAttorneyReporterWithUploadLater: FormValue = { + whoIsTheNotificationFor: { + answer: WhoIsTheNotificationForEnum.POWEROFATTORNEY, + }, + powerOfAttorney: { + type: PowerOfAttorneyUploadEnum.UPLOADLATER, + }, + } + + const reportingForSelf: FormValue = { + whoIsTheNotificationFor: { + answer: WhoIsTheNotificationForEnum.ME, + }, + } + + const emptyObject = {} + + it('should return true for power of attorney reporter with upload now', () => { + expect(isUploadNow(powerOfAttorneyReporterWithUploadNow)).toEqual(true) + }) + + it('should return false for power of attorney reporter with upload later', () => { + expect(isUploadNow(powerOfAttorneyReporterWithUploadLater)).toEqual(false) + }) + + it('should return false for reporting for yourself', () => { + expect(isUploadNow(reportingForSelf)).toEqual(false) + }) + + it('should return false for empty object', () => { + expect(isUploadNow(emptyObject)).toEqual(false) + }) +}) diff --git a/libs/application/templates/accident-notification/src/utils/documentUtils.ts b/libs/application/templates/accident-notification/src/utils/documentUtils.ts new file mode 100644 index 000000000000..e352dfe2997e --- /dev/null +++ b/libs/application/templates/accident-notification/src/utils/documentUtils.ts @@ -0,0 +1,295 @@ +import { getValueViaPath, YES } from '@island.is/application/core' +import { AccidentNotification } from '../lib/dataSchema' +import { + AttachmentsEnum, + FileType, + PowerOfAttorneyUploadEnum, + WhoIsTheNotificationForEnum, +} from '../types' +import { attachments, overview } from '../lib/messages' +import { FormatMessage } from '@island.is/localization' +import { FormValue } from '@island.is/application/types' +import { + AccidentNotificationAttachmentStatus, + AccidentNotifTypes, + YesOrNo, +} from '../types' +import { + isReportingOnBehalfOfEmployee, + isReportingOnBehalfSelf, +} from './reportingUtils' +import { isFatalAccident } from './accidentUtils' + +export const hasAttachment = (attachment: Array | undefined) => + attachment && attachment.length > 0 + +const includesAttachment = ( + answers: FormValue, + attachmentType: AccidentNotifTypes, +): boolean => { + const accidentNotifications = + getValueViaPath( + answers, + 'accidentStatus.receivedAttachments', + ) + return accidentNotifications?.[attachmentType] || false +} + +export const hasReceivedInjuryCertificate = (answers: FormValue) => { + return includesAttachment(answers, 'InjuryCertificate') +} + +export const hasReceivedProxyDocument = (answers: FormValue) => { + return includesAttachment(answers, 'ProxyDocument') +} + +export const hasReceivedPoliceReport = (answers: FormValue) => { + return includesAttachment(answers, 'PoliceReport') +} + +export const hasReceivedInjuryCertificateOrAddedToAnswers = ( + answers: FormValue, +) => { + const injuryCertificateFile = getValueViaPath>( + answers, + 'attachments.injuryCertificateFile.file', + [{ key: '', name: '' }], + ) + + return ( + hasReceivedInjuryCertificate(answers) || + hasAttachment(injuryCertificateFile) + ) +} + +export const hasReceivedProxyDocumentOrAddedToAnswers = ( + answers: FormValue, +) => { + const powerOfAttorneyFile = getValueViaPath>( + answers, + 'attachments.powerOfAttorneyFile.file', + [{ key: '', name: '' }], + ) + + return hasReceivedProxyDocument(answers) || hasAttachment(powerOfAttorneyFile) +} + +export const hasReceivedPoliceReportOrAddedToAnswers = (answers: FormValue) => { + const deathCertificateFile = getValueViaPath>( + answers, + 'attachments.deathCertificateFile.file', + [{ key: '', name: '' }], + ) + + return hasReceivedPoliceReport(answers) || hasAttachment(deathCertificateFile) +} + +export const hasReceivedAllDocuments = (answers: FormValue) => { + // Reporting for self or as juridicial person only injury certificate relevent + if ( + isReportingOnBehalfSelf(answers) || + isReportingOnBehalfOfEmployee(answers) + ) { + return hasReceivedInjuryCertificate(answers) + } else { + // If fatal and not report for self or as juridicial all documents are relevant + if (isFatalAccident(answers)) { + return ( + hasReceivedPoliceReport(answers) && + hasReceivedProxyDocument(answers) && + hasReceivedInjuryCertificate(answers) + ) + } else { + return ( + hasReceivedProxyDocument(answers) && + hasReceivedInjuryCertificate(answers) + ) + } + } +} + +export const getErrorMessageForMissingDocuments = ( + answers: FormValue, + formatMessage: FormatMessage, + isAssigneeAndUnique: boolean, +) => { + const whoIsTheNotificationFor = getValueViaPath( + answers, + 'whoIsTheNotificationFor.answer', + ) + const wasTheAccidentFatal = getValueViaPath( + answers, + 'wasTheAccidentFatal', + ) + const missingDocuments = [] + + if (!hasReceivedInjuryCertificateOrAddedToAnswers(answers)) { + missingDocuments.push( + formatMessage(attachments.documentNames.injuryCertificate), + ) + } + + // Only show this to applicant or assignee that is also the applicant + if ( + whoIsTheNotificationFor === WhoIsTheNotificationForEnum.POWEROFATTORNEY && + !hasReceivedProxyDocumentOrAddedToAnswers(answers) && + !isAssigneeAndUnique + ) { + missingDocuments.push( + formatMessage(attachments.documentNames.powerOfAttorneyDocument), + ) + } + + if ( + wasTheAccidentFatal === YES && + !hasReceivedPoliceReportOrAddedToAnswers(answers) + ) { + missingDocuments.push( + formatMessage(attachments.documentNames.deathCertificate), + ) + } + + return missingDocuments.join(', ') +} + +export const hasMissingInjuryCertificate = (answers: FormValue) => { + const injuryCertificate = getValueViaPath( + answers, + 'injuryCertificate.answer', + ) + return injuryCertificate === AttachmentsEnum.SENDCERTIFICATELATER +} + +export const hasMissingDeathCertificate = (answers: FormValue) => { + const wasTheAccidentFatal = getValueViaPath( + answers, + 'wasTheAccidentFatal', + ) + return wasTheAccidentFatal === YES +} + +export const hasMissingPowerOfAttorneyFile = (answers: FormValue): boolean => { + const whoIsTheNotificationFor = getValueViaPath( + answers, + 'whoIsTheNotificationFor.answer', + ) + return whoIsTheNotificationFor === WhoIsTheNotificationForEnum.POWEROFATTORNEY +} + +export const hasMissingDocuments = (answers: FormValue) => { + const injuryCertificateFile = getValueViaPath>( + answers, + 'attachments.injuryCertificateFile.file', + ) + + const deathCertificateFile = getValueViaPath>( + answers, + 'attachments.deathCertificateFile.file', + ) + + const powerOfAttorneyFile = getValueViaPath>( + answers, + 'attachments.powerOfAttorneyFile.file', + ) + + return ( + (hasMissingInjuryCertificate(answers) && + !hasAttachment(injuryCertificateFile)) || + (hasMissingDeathCertificate(answers) && + !hasAttachment(deathCertificateFile)) || + (hasMissingPowerOfAttorneyFile(answers) && + !hasAttachment(powerOfAttorneyFile)) + ) +} + +export const getAttachmentTitles = (answers: AccidentNotification) => { + const deathCertificateFile = + answers.attachments?.deathCertificateFile?.file || undefined + const injuryCertificateFile = + answers.attachments?.injuryCertificateFile?.file || undefined + const powerOfAttorneyFile = + answers.attachments?.powerOfAttorneyFile?.file || undefined + const additionalFiles = + answers.attachments?.additionalFiles?.file || undefined + const additionalFilesFromReviewer = + answers.attachments?.additionalFilesFromReviewer?.file || undefined + + const files = [] + + if (hasAttachment(deathCertificateFile)) + files.push(attachments.documentNames.deathCertificate) + if ( + hasAttachment(injuryCertificateFile) && + getValueViaPath(answers, 'injuryCertificate.answer') !== + AttachmentsEnum.HOSPITALSENDSCERTIFICATE + ) + files.push(attachments.documentNames.injuryCertificate) + if (hasAttachment(powerOfAttorneyFile)) + files.push(attachments.documentNames.powerOfAttorneyDocument) + if ( + answers.injuryCertificate?.answer === + AttachmentsEnum.HOSPITALSENDSCERTIFICATE + ) + files.push(overview.labels.hospitalSendsCertificate) + if (hasAttachment(additionalFiles)) + files.push(attachments.documentNames.additionalDocumentsFromApplicant) + if (hasAttachment(additionalFilesFromReviewer)) + files.push(attachments.documentNames.additionalDocumentsFromReviewer) + + return files +} + +export const returnMissingDocumentsList = ( + answers: AccidentNotification, + formatMessage: FormatMessage, +) => { + const injuryCertificate = answers.injuryCertificate + const whoIsTheNotificationFor = answers.whoIsTheNotificationFor.answer + const wasTheAccidentFatal = answers.wasTheAccidentFatal + const missingDocuments = [] + + if ( + injuryCertificate?.answer === AttachmentsEnum.SENDCERTIFICATELATER && + !hasAttachment(answers.attachments?.injuryCertificateFile?.file) + ) { + missingDocuments.push( + formatMessage(attachments.documentNames.injuryCertificate), + ) + } + + // Only show this to applicant or assignee that is also the applicant + if ( + whoIsTheNotificationFor === WhoIsTheNotificationForEnum.POWEROFATTORNEY && + !hasAttachment(answers.attachments?.powerOfAttorneyFile?.file) + ) { + missingDocuments.push( + formatMessage(attachments.documentNames.powerOfAttorneyDocument), + ) + } + + if ( + wasTheAccidentFatal === YES && + !hasAttachment(answers.attachments?.deathCertificateFile?.file) + ) { + missingDocuments.push( + formatMessage(attachments.documentNames.deathCertificate), + ) + } + + return missingDocuments.join(', ') +} + +export const isUploadNow = (formValue: FormValue) => { + const whoIsTheNotificationFor = getValueViaPath( + formValue, + 'whoIsTheNotificationFor.answer', + ) + const powerOfAttorneyType = getValueViaPath( + formValue, + 'powerOfAttorney.type', + ) + return ( + whoIsTheNotificationFor === WhoIsTheNotificationForEnum.POWEROFATTORNEY && + powerOfAttorneyType === PowerOfAttorneyUploadEnum.UPLOADNOW + ) +} diff --git a/libs/application/templates/accident-notification/src/utils/fishermanUtils.spec.ts b/libs/application/templates/accident-notification/src/utils/fishermanUtils.spec.ts deleted file mode 100644 index 03141eb17bdd..000000000000 --- a/libs/application/templates/accident-notification/src/utils/fishermanUtils.spec.ts +++ /dev/null @@ -1,57 +0,0 @@ -import { FormValue } from '@island.is/application/types' -import { - AccidentTypeEnum, - FishermanWorkplaceAccidentLocationEnum, - WorkAccidentTypeEnum, -} from '../types' -import { isAboardShip, isFishermanAccident } from './fishermanUtils' -describe('isFishermanAccident', () => { - const fishermanAccident: FormValue = { - workAccident: { type: WorkAccidentTypeEnum.FISHERMAN }, - accidentType: { radioButton: AccidentTypeEnum.WORK }, - } - - const someOtherAccident: FormValue = { - workAccident: { type: WorkAccidentTypeEnum.PROFESSIONALATHLETE }, - } - - const emptyObject = {} - - it('should return true for fisherman accidents', () => { - expect(isFishermanAccident(fishermanAccident)).toEqual(true) - }) - it('should return false for workplace accidents other than fisherman', () => { - expect(isFishermanAccident(someOtherAccident)).toEqual(false) - }) - it('should return false for empty object', () => { - expect(isFishermanAccident(emptyObject)).toEqual(false) - }) -}) - -describe('isAboardShip', () => { - const onTheShipLocation: FormValue = { - accidentLocation: { - answer: FishermanWorkplaceAccidentLocationEnum.ONTHESHIP, - }, - workAccident: { type: WorkAccidentTypeEnum.FISHERMAN }, - accidentType: { radioButton: AccidentTypeEnum.WORK }, - } - - const someOtherLocation: FormValue = { - accidentLocation: { answer: FishermanWorkplaceAccidentLocationEnum.OTHER }, - workAccident: { type: WorkAccidentTypeEnum.FISHERMAN }, - accidentType: { radioButton: AccidentTypeEnum.WORK }, - } - - const emptyObject = {} - - it('should return true for fisherman work accident that happens on a ship', () => { - expect(isAboardShip(onTheShipLocation)).toEqual(true) - }) - it('should return false for fisherman work accident that happens else where', () => { - expect(isAboardShip(someOtherLocation)).toEqual(false) - }) - it('should return false for empty object', () => { - expect(isAboardShip(emptyObject)).toEqual(false) - }) -}) diff --git a/libs/application/templates/accident-notification/src/utils/fishermanUtils.ts b/libs/application/templates/accident-notification/src/utils/fishermanUtils.ts deleted file mode 100644 index 280165f94136..000000000000 --- a/libs/application/templates/accident-notification/src/utils/fishermanUtils.ts +++ /dev/null @@ -1,36 +0,0 @@ -import { getValueViaPath } from '@island.is/application/core' -import { FormValue } from '@island.is/application/types' -import { - FishermanWorkplaceAccidentLocationEnum, - WorkAccidentTypeEnum, -} from '../types' -import { isWorkAccident } from './isWorkAccident' - -// As this is a second question the user is asked there is a case where he could go back and select home activities and keep the workaccident type. -// Therefore we need to check also whether this is a work accident -export const isFishermanAccident = (formValue: FormValue) => { - const workAccidentType = getValueViaPath( - formValue, - 'workAccident.type', - ) as WorkAccidentTypeEnum - return ( - workAccidentType === WorkAccidentTypeEnum.FISHERMAN && - isWorkAccident(formValue) - ) -} - -// As this is a third question the user is asked there is a case where he could go back -// and select home activities and keep the workaccident type or go back and change where the -// accident happened. -// Therefore we need to check ifFishermanAccident function again -export const isAboardShip = (formValue: FormValue) => { - const fishermanWorkplaceAccidentLocationAnswer = getValueViaPath( - formValue, - 'accidentLocation.answer', - ) as FishermanWorkplaceAccidentLocationEnum - return ( - isFishermanAccident(formValue) && - fishermanWorkplaceAccidentLocationAnswer === - FishermanWorkplaceAccidentLocationEnum.ONTHESHIP - ) -} diff --git a/libs/application/templates/accident-notification/src/utils/getAccidentTypeOptions.ts b/libs/application/templates/accident-notification/src/utils/getAccidentTypeOptions.ts deleted file mode 100644 index ce91825ff6c9..000000000000 --- a/libs/application/templates/accident-notification/src/utils/getAccidentTypeOptions.ts +++ /dev/null @@ -1,38 +0,0 @@ -import { FormValue } from '@island.is/application/types' -import { accidentType } from '../lib/messages' -import { AccidentTypeEnum } from '../types' -import { isReportingOnBehalfOfChild } from './isReportingOnBehalfOfChild' -import { isReportingOnBehalfOfEmployee } from './isReportingOnBehalfOfEmployee' - -export const getAccidentTypeOptions = (answers: FormValue) => { - const options = [ - { - value: AccidentTypeEnum.WORK, - label: accidentType.labels.work, - }, - { - value: AccidentTypeEnum.RESCUEWORK, - label: accidentType.labels.rescueWork, - }, - { - value: AccidentTypeEnum.STUDIES, - label: accidentType.labels.studies, - }, - { - value: AccidentTypeEnum.SPORTS, - label: accidentType.labels.sports, - }, - ] - - if ( - !isReportingOnBehalfOfEmployee(answers) && - !isReportingOnBehalfOfChild(answers) - ) { - options.unshift({ - value: AccidentTypeEnum.HOMEACTIVITIES, - label: accidentType.labels.homeActivities, - }) - } - - return options -} diff --git a/libs/application/templates/accident-notification/src/utils/getInjuredPersonInformation.spec.ts b/libs/application/templates/accident-notification/src/utils/getInjuredPersonInformation.spec.ts deleted file mode 100644 index d5cdb40fada9..000000000000 --- a/libs/application/templates/accident-notification/src/utils/getInjuredPersonInformation.spec.ts +++ /dev/null @@ -1,42 +0,0 @@ -import { FormValue } from '@island.is/application/types' -import { getInjuredPersonInformation } from './getInjuredPersonInformation' - -describe('getInjuredPersonInformation', () => { - const injuredPersonInformation: FormValue = { - injuredPersonInformation: { - email: 'kalli@palli.is', - name: 'Kalli', - }, - } - - const emptyInjuredPersonInformation: FormValue = { - injuredPersonInformation: { - email: '', - name: '', - }, - } - - it('should return an array of length 4 when submitting on behalf of employee', () => { - expect( - getInjuredPersonInformation(injuredPersonInformation)?.email, - ).toEqual('kalli@palli.is') - }) - - it('should return an array of length 5 when not submitting on behalf of employee', () => { - expect(getInjuredPersonInformation(injuredPersonInformation)?.name).toEqual( - 'Kalli', - ) - }) - - it('should return an array of length 5 for empty object', () => { - expect( - getInjuredPersonInformation(emptyInjuredPersonInformation)?.email, - ).toEqual('') - }) - - it('should have work as first option when submitting on behalf of employee', () => { - expect( - getInjuredPersonInformation(emptyInjuredPersonInformation)?.name, - ).toEqual('') - }) -}) diff --git a/libs/application/templates/accident-notification/src/utils/getInjuredPersonInformation.ts b/libs/application/templates/accident-notification/src/utils/getInjuredPersonInformation.ts deleted file mode 100644 index 4a2560a62074..000000000000 --- a/libs/application/templates/accident-notification/src/utils/getInjuredPersonInformation.ts +++ /dev/null @@ -1,19 +0,0 @@ -import { getValueViaPath } from '@island.is/application/core' -import { FormValue } from '@island.is/application/types' - -export const getInjuredPersonInformation = (answers: FormValue) => { - const injuredPersonsEmail = getValueViaPath( - answers, - 'injuredPersonInformation.email', - ) as string - - const injuredPersonsName = getValueViaPath( - answers, - 'injuredPersonInformation.name', - ) as string - const injuredPersonsInformation = { - email: injuredPersonsEmail, - name: injuredPersonsName, - } - return injuredPersonsInformation -} diff --git a/libs/application/templates/accident-notification/src/utils/getAccidentTypeOptions.spec.ts b/libs/application/templates/accident-notification/src/utils/getOptions.spec.ts similarity index 96% rename from libs/application/templates/accident-notification/src/utils/getAccidentTypeOptions.spec.ts rename to libs/application/templates/accident-notification/src/utils/getOptions.spec.ts index 0d252b1e768b..b884f68e3347 100644 --- a/libs/application/templates/accident-notification/src/utils/getAccidentTypeOptions.spec.ts +++ b/libs/application/templates/accident-notification/src/utils/getOptions.spec.ts @@ -1,6 +1,6 @@ import { FormValue } from '@island.is/application/types' import { AccidentTypeEnum, WhoIsTheNotificationForEnum } from '../types' -import { getAccidentTypeOptions } from './getAccidentTypeOptions' +import { getAccidentTypeOptions } from './getOptions' describe('getAccidentTypeOptions', () => { const onBehalfOfEmployee: FormValue = { diff --git a/libs/application/templates/accident-notification/src/utils/getOptions.ts b/libs/application/templates/accident-notification/src/utils/getOptions.ts new file mode 100644 index 000000000000..e2945ae17ad4 --- /dev/null +++ b/libs/application/templates/accident-notification/src/utils/getOptions.ts @@ -0,0 +1,72 @@ +import { WhoIsTheNotificationForEnum } from '../types' +import { whoIsTheNotificationFor } from '../lib/messages' +import { FormValue } from '@island.is/application/types' +import { accidentType } from '../lib/messages' +import { AccidentTypeEnum } from '../types' +import { + isReportingOnBehalfOfChild, + isReportingOnBehalfOfEmployee, +} from './reportingUtils' + +export const getAccidentTypeOptions = (answers: FormValue) => { + const options = [ + { + value: AccidentTypeEnum.WORK, + label: accidentType.labels.work, + }, + { + value: AccidentTypeEnum.RESCUEWORK, + label: accidentType.labels.rescueWork, + }, + { + value: AccidentTypeEnum.STUDIES, + label: accidentType.labels.studies, + }, + { + value: AccidentTypeEnum.SPORTS, + label: accidentType.labels.sports, + }, + ] + + if ( + !isReportingOnBehalfOfEmployee(answers) && + !isReportingOnBehalfOfChild(answers) + ) { + options.unshift({ + value: AccidentTypeEnum.HOMEACTIVITIES, + label: accidentType.labels.homeActivities, + }) + } + + return options +} + +export const whoIsTheNotificationForOptions = [ + { + value: WhoIsTheNotificationForEnum.ME, + label: whoIsTheNotificationFor.labels.me, + }, + { + value: WhoIsTheNotificationForEnum.POWEROFATTORNEY, + label: whoIsTheNotificationFor.labels.powerOfAttorney, + }, + { + value: WhoIsTheNotificationForEnum.JURIDICALPERSON, + label: whoIsTheNotificationFor.labels.juridicalPerson, + }, + { + value: WhoIsTheNotificationForEnum.CHILDINCUSTODY, + label: whoIsTheNotificationFor.labels.childInCustody, + }, +] + +export const whoIsTheNotificationForProcureOptions = [ + { + value: WhoIsTheNotificationForEnum.POWEROFATTORNEY, + label: whoIsTheNotificationFor.labels.powerOfAttorneyProcure, + }, + { + value: WhoIsTheNotificationForEnum.JURIDICALPERSON, + label: whoIsTheNotificationFor.labels.juridicalPerson, + }, +] diff --git a/libs/application/templates/accident-notification/src/utils/getWhoIstheNotificationForOptions.ts b/libs/application/templates/accident-notification/src/utils/getWhoIstheNotificationForOptions.ts deleted file mode 100644 index 28910229cf83..000000000000 --- a/libs/application/templates/accident-notification/src/utils/getWhoIstheNotificationForOptions.ts +++ /dev/null @@ -1,32 +0,0 @@ -import { WhoIsTheNotificationForEnum } from '../types' -import { whoIsTheNotificationFor } from '../lib/messages' - -export const whoIsTheNotificationForOptions = [ - { - value: WhoIsTheNotificationForEnum.ME, - label: whoIsTheNotificationFor.labels.me, - }, - { - value: WhoIsTheNotificationForEnum.POWEROFATTORNEY, - label: whoIsTheNotificationFor.labels.powerOfAttorney, - }, - { - value: WhoIsTheNotificationForEnum.JURIDICALPERSON, - label: whoIsTheNotificationFor.labels.juridicalPerson, - }, - { - value: WhoIsTheNotificationForEnum.CHILDINCUSTODY, - label: whoIsTheNotificationFor.labels.childInCustody, - }, -] - -export const whoIsTheNotificationForProcureOptions = [ - { - value: WhoIsTheNotificationForEnum.POWEROFATTORNEY, - label: whoIsTheNotificationFor.labels.powerOfAttorneyProcure, - }, - { - value: WhoIsTheNotificationForEnum.JURIDICALPERSON, - label: whoIsTheNotificationFor.labels.juridicalPerson, - }, -] diff --git a/libs/application/templates/accident-notification/src/utils/getWorkplaceData.spec.ts b/libs/application/templates/accident-notification/src/utils/getWorkplaceData.spec.ts deleted file mode 100644 index 45a3cb6d6a11..000000000000 --- a/libs/application/templates/accident-notification/src/utils/getWorkplaceData.spec.ts +++ /dev/null @@ -1,79 +0,0 @@ -import { FormValue } from '@island.is/application/types' -import { YES } from './constants' -import { AccidentTypeEnum, WorkAccidentTypeEnum } from '../types' -import { getWorkplaceData } from './getWorkplaceData' - -describe('getWorkplaceData', () => { - const generalWorkplaceAccident: FormValue = { - workAccident: { type: WorkAccidentTypeEnum.GENERAL }, - accidentType: { radioButton: AccidentTypeEnum.WORK }, - companyInfo: {}, - } - - const professionalAthleteAccident: FormValue = { - accidentType: { radioButton: AccidentTypeEnum.SPORTS }, - companyInfo: { onPayRoll: { answer: YES } }, - } - - const rescueWorkAccident: FormValue = { - accidentType: { radioButton: AccidentTypeEnum.RESCUEWORK }, - } - - const studiesAccident: FormValue = { - accidentType: { radioButton: AccidentTypeEnum.STUDIES }, - } - - const fishermanAccident: FormValue = { - workAccident: { type: WorkAccidentTypeEnum.FISHERMAN }, - accidentType: { radioButton: AccidentTypeEnum.WORK }, - } - - const emptyObject = {} - - it('should return general work type data for general work accidents', () => { - expect(getWorkplaceData(generalWorkplaceAccident)?.type).toEqual( - AccidentTypeEnum.WORK, - ) - }) - - it('should return sports type data for professional athlete accidents', () => { - expect(getWorkplaceData(professionalAthleteAccident)?.type).toEqual( - AccidentTypeEnum.SPORTS, - ) - }) - - it('should return employee information for professional athlete accidents', () => { - expect( - getWorkplaceData(professionalAthleteAccident)?.companyInfo.onPayRoll - ?.answer, - ).toBe(YES) - }) - - it('should not return employee information for general workplace accident', () => { - expect( - getWorkplaceData(generalWorkplaceAccident)?.companyInfo.onPayRoll, - ).toBe(undefined) - }) - - it('should return rescue work type data for rescue work accidents', () => { - expect(getWorkplaceData(rescueWorkAccident)?.type).toEqual( - AccidentTypeEnum.RESCUEWORK, - ) - }) - - it('should return studies type data for student accidents', () => { - expect(getWorkplaceData(studiesAccident)?.type).toEqual( - AccidentTypeEnum.STUDIES, - ) - }) - - it('should return fisherman type data for fisherman accidents', () => { - expect(getWorkplaceData(fishermanAccident)?.type).toEqual( - WorkAccidentTypeEnum.FISHERMAN, - ) - }) - - it('should return undefined for empty object', () => { - expect(getWorkplaceData(emptyObject)?.type).toEqual(undefined) - }) -}) diff --git a/libs/application/templates/accident-notification/src/utils/getWorkplaceData.ts b/libs/application/templates/accident-notification/src/utils/getWorkplaceData.ts deleted file mode 100644 index ccabbb5fe7aa..000000000000 --- a/libs/application/templates/accident-notification/src/utils/getWorkplaceData.ts +++ /dev/null @@ -1,93 +0,0 @@ -import { getValueViaPath } from '@island.is/application/core' -import { FormValue } from '@island.is/application/types' -import { - isGeneralWorkplaceAccident, - isStudiesAccident, - isFishermanAccident, - isProfessionalAthleteAccident, - isRescueWorkAccident, -} from './' -import { - companyInfo, - fishingCompanyInfo, - rescueSquadInfo, - schoolInfo, - sportsClubInfo, - representativeInfo, -} from '../lib/messages' -import { - AccidentTypeEnum, - CompanyInfo, - RepresentativeInfo, - WorkAccidentTypeEnum, - YesOrNo, -} from '../types' -import { isHomeActivitiesAccident } from './isHomeActivitiesAccident' - -interface WorkplaceData { - companyInfo: CompanyInfo - representitive: RepresentativeInfo - companyInfoMsg: typeof companyInfo - representitiveMsg: typeof representativeInfo - type: WorkAccidentTypeEnum | AccidentTypeEnum - onPayRoll?: YesOrNo - screenId: string -} - -export const getWorkplaceData = ( - answers: FormValue, -): WorkplaceData | undefined => { - if (isHomeActivitiesAccident(answers)) { - return - } - - const workplaceData = { - companyInfo: getValueViaPath(answers, 'companyInfo') as CompanyInfo, - representitive: getValueViaPath( - answers, - 'representative', - ) as RepresentativeInfo, - representitiveMsg: representativeInfo, - } as WorkplaceData - - if (isGeneralWorkplaceAccident(answers)) - return { - ...workplaceData, - companyInfoMsg: companyInfo, - type: AccidentTypeEnum.WORK, - screenId: 'companyInfo', - } - - if (isStudiesAccident(answers)) - return { - ...workplaceData, - companyInfoMsg: schoolInfo, - type: AccidentTypeEnum.STUDIES, - screenId: 'schoolInfo', - } - - if (isFishermanAccident(answers)) - return { - ...workplaceData, - companyInfoMsg: fishingCompanyInfo, - type: WorkAccidentTypeEnum.FISHERMAN, - screenId: 'fishingCompanyInfo', - } - - if (isProfessionalAthleteAccident(answers)) - return { - ...workplaceData, - onPayRoll: getValueViaPath(answers, 'onPayRoll.answer') as YesOrNo, - companyInfoMsg: sportsClubInfo, - type: AccidentTypeEnum.SPORTS, - screenId: 'sportsClubInfo', - } - - if (isRescueWorkAccident(answers)) - return { - ...workplaceData, - companyInfoMsg: rescueSquadInfo, - type: AccidentTypeEnum.RESCUEWORK, - screenId: 'rescueSquad', - } -} diff --git a/libs/application/templates/accident-notification/src/utils/hasMissingDocuments.spec.ts b/libs/application/templates/accident-notification/src/utils/hasMissingDocuments.spec.ts deleted file mode 100644 index 945c4858ce4f..000000000000 --- a/libs/application/templates/accident-notification/src/utils/hasMissingDocuments.spec.ts +++ /dev/null @@ -1,130 +0,0 @@ -import { - getErrorMessageForMissingDocuments, - hasMissingDocuments, - hasReceivedAllDocuments, -} from './hasMissingDocuments' -import { WhoIsTheNotificationForEnum, AttachmentsEnum } from '../types' -import { NO, YES } from './constants' -import { FormatMessage } from '@island.is/localization' -import { FormValue } from '@island.is/application/types' -import { AccidentNotification } from '../lib/dataSchema' - -describe('hasMissingDocuments', () => { - it('should return true when missing documents', () => { - expect(hasMissingDocuments(getMissingDocuments())).toEqual(true) - }) - - it('should return false when no missing documents', () => { - expect(hasMissingDocuments(getNoMissingDocuments())).toEqual(false) - }) -}) - -describe('getErrorMessageForMissingDocuments', () => { - const formatMessage: FormatMessage = jest.fn().mockReturnValue('test.pdf') - - beforeEach(() => { - jest.clearAllMocks() - }) - - it('should return error message for missing documents', () => { - const result = getErrorMessageForMissingDocuments( - getMissingDocuments(), - formatMessage, - false, - ) - expect(result).toEqual('test.pdf, test.pdf, test.pdf') - expect(formatMessage).toHaveBeenCalledTimes(3) - }) - - it('should return empty string when no documents are missing', () => { - const docs = getNoMissingDocuments() - const result = getErrorMessageForMissingDocuments(docs, formatMessage, true) - expect(result).toBe('') - expect(formatMessage).not.toHaveBeenCalled() - }) -}) - -describe('hasReceivedAllDocuments', () => { - const testCases = [ - { who: WhoIsTheNotificationForEnum.ME, fatal: NO }, - { who: WhoIsTheNotificationForEnum.JURIDICALPERSON, fatal: NO }, - { who: WhoIsTheNotificationForEnum.POWEROFATTORNEY, fatal: YES }, - { who: WhoIsTheNotificationForEnum.POWEROFATTORNEY, fatal: NO }, - ] - it.each(testCases)( - 'should return true when all documents are received', - (data) => { - const answers = getNoMissingDocuments() as AccidentNotification - answers.whoIsTheNotificationFor.answer = data.who - answers.wasTheAccidentFatal = data.fatal as unknown as 'no' | 'yes' - expect(hasReceivedAllDocuments(answers)).toEqual(true) - }, - ) - - it.each(testCases)('should return false when missing documents', (data) => { - const answers = getMissingDocuments() as AccidentNotification - answers.whoIsTheNotificationFor.answer = data.who - answers.wasTheAccidentFatal = data.fatal as unknown as 'no' | 'yes' - expect(hasReceivedAllDocuments(answers)).toEqual(false) - }) -}) - -const EMPTY_FILE: never[] = [] - -const SAMPLE_FILE = { - name: 'test.pdf', - url: 'https://test.pdf', -} as const -const createAttachment = () => ({ file: [SAMPLE_FILE] }) - -const getMissingDocuments = (): FormValue => ({ - whoIsTheNotificationFor: { - answer: WhoIsTheNotificationForEnum.POWEROFATTORNEY, - }, - wasTheAccidentFatal: YES, - injuryCertificate: { - answer: AttachmentsEnum.SENDCERTIFICATELATER, - }, - accidentStatus: { - receivedAttachments: { - InjuryCertificate: false, - PoliceReport: false, - DeathCertificate: false, - ProxyDocument: false, - }, - }, - attachments: { - injuryCertificateFile: { file: EMPTY_FILE }, - deathCertificateFile: { file: EMPTY_FILE }, - powerOfAttorneyFile: { file: EMPTY_FILE }, - }, -}) - -const getNoMissingDocuments = (): FormValue => ({ - whoIsTheNotificationFor: { - answer: WhoIsTheNotificationForEnum.POWEROFATTORNEY, - }, - wasTheAccidentFatal: YES, - injuryCertificate: { - answer: AttachmentsEnum.SENDCERTIFICATELATER, - }, - accidentStatus: { - receivedAttachments: { - InjuryCertificate: true, - PoliceReport: true, - DeathCertificate: true, - ProxyDocument: true, - }, - }, - attachments: { - injuryCertificateFile: { - file: [createAttachment()], - }, - deathCertificateFile: { - file: [createAttachment()], - }, - powerOfAttorneyFile: { - file: [createAttachment()], - }, - }, -}) diff --git a/libs/application/templates/accident-notification/src/utils/hasMissingDocuments.ts b/libs/application/templates/accident-notification/src/utils/hasMissingDocuments.ts deleted file mode 100644 index d262c07b6226..000000000000 --- a/libs/application/templates/accident-notification/src/utils/hasMissingDocuments.ts +++ /dev/null @@ -1,195 +0,0 @@ -import { getValueViaPath } from '@island.is/application/core' -import { FormValue } from '@island.is/application/types' -import { FormatMessage } from '@island.is/localization' -import { AttachmentsEnum, FileType, WhoIsTheNotificationForEnum } from '..' -import { YES } from './constants' -import { attachments } from '../lib/messages' -import { - AccidentNotificationAttachmentStatus, - AccidentNotifTypes, - YesOrNo, -} from '../types' -import { isFatalAccident } from './isFatalAccident' -import { isReportingOnBehalfSelf } from './isReportingBehalfOfSelf' -import { isReportingOnBehalfOfEmployee } from './isReportingOnBehalfOfEmployee' - -const hasAttachment = (attachment: FileType[] | undefined) => - attachment && attachment.length > 0 - -const includesAttachment = ( - answers: FormValue, - attachmentType: AccidentNotifTypes, -): boolean => { - const accidentNotifications = getValueViaPath( - answers, - 'accidentStatus.receivedAttachments', - ) as AccidentNotificationAttachmentStatus - return accidentNotifications?.[attachmentType] || false -} - -export const hasReceivedInjuryCertificate = (answers: FormValue) => { - return includesAttachment(answers, 'InjuryCertificate') -} - -export const hasReceivedProxyDocument = (answers: FormValue) => { - return includesAttachment(answers, 'ProxyDocument') -} - -export const hasReceivedPoliceReport = (answers: FormValue) => { - return includesAttachment(answers, 'PoliceReport') -} - -export const hasReceivedInjuryCertificateOrAddedToAnswers = ( - answers: FormValue, -) => { - const injuryCertificateFile = getValueViaPath( - answers, - 'attachments.injuryCertificateFile.file', - {}, - ) as FileType[] - - return ( - hasReceivedInjuryCertificate(answers) || - hasAttachment(injuryCertificateFile) - ) -} - -export const hasReceivedProxyDocumentOrAddedToAnswers = ( - answers: FormValue, -) => { - const powerOfAttorneyFile = getValueViaPath( - answers, - 'attachments.powerOfAttorneyFile.file', - {}, - ) as FileType[] - - return hasReceivedProxyDocument(answers) || hasAttachment(powerOfAttorneyFile) -} - -export const hasReceivedPoliceReportOrAddedToAnswers = (answers: FormValue) => { - const deathCertificateFile = getValueViaPath( - answers, - 'attachments.deathCertificateFile.file', - {}, - ) as FileType[] - - return hasReceivedPoliceReport(answers) || hasAttachment(deathCertificateFile) -} - -export const hasReceivedAllDocuments = (answers: FormValue) => { - // Reporting for self or as juridicial person only injury certificate relevent - if ( - isReportingOnBehalfSelf(answers) || - isReportingOnBehalfOfEmployee(answers) - ) { - return hasReceivedInjuryCertificate(answers) - } else { - // If fatal and not report for self or as juridicial all documents are relevant - if (isFatalAccident(answers)) { - return ( - hasReceivedPoliceReport(answers) && - hasReceivedProxyDocument(answers) && - hasReceivedInjuryCertificate(answers) - ) - } else { - return ( - hasReceivedProxyDocument(answers) && - hasReceivedInjuryCertificate(answers) - ) - } - } -} - -export const getErrorMessageForMissingDocuments = ( - answers: FormValue, - formatMessage: FormatMessage, - isAssigneeAndUnique: boolean, -) => { - const whoIsTheNotificationFor = getValueViaPath( - answers, - 'whoIsTheNotificationFor.answer', - ) - const wasTheAccidentFatal = getValueViaPath( - answers, - 'wasTheAccidentFatal', - ) as YesOrNo - const missingDocuments = [] - - if (!hasReceivedInjuryCertificateOrAddedToAnswers(answers)) { - missingDocuments.push( - formatMessage(attachments.documentNames.injuryCertificate), - ) - } - - // Only show this to applicant or assignee that is also the applicant - if ( - whoIsTheNotificationFor === WhoIsTheNotificationForEnum.POWEROFATTORNEY && - !hasReceivedProxyDocumentOrAddedToAnswers(answers) && - !isAssigneeAndUnique - ) { - missingDocuments.push( - formatMessage(attachments.documentNames.powerOfAttorneyDocument), - ) - } - - if ( - wasTheAccidentFatal === YES && - !hasReceivedPoliceReportOrAddedToAnswers(answers) - ) { - missingDocuments.push( - formatMessage(attachments.documentNames.deathCertificate), - ) - } - - return missingDocuments.join(', ') -} - -export const hasMissingInjuryCertificate = (answers: FormValue) => { - const injuryCertificate = getValueViaPath( - answers, - 'injuryCertificate.answer', - ) as AttachmentsEnum - return injuryCertificate === AttachmentsEnum.SENDCERTIFICATELATER -} - -export const hasMissingDeathCertificate = (answers: FormValue) => { - const wasTheAccidentFatal = getValueViaPath( - answers, - 'wasTheAccidentFatal', - ) as YesOrNo - return wasTheAccidentFatal === YES -} - -export const hasMissingPowerOfAttorneyFile = (answers: FormValue): boolean => { - const whoIsTheNotificationFor = getValueViaPath( - answers, - 'whoIsTheNotificationFor.answer', - ) as WhoIsTheNotificationForEnum - return whoIsTheNotificationFor === WhoIsTheNotificationForEnum.POWEROFATTORNEY -} - -export const hasMissingDocuments = (answers: FormValue) => { - const injuryCertificateFile = getValueViaPath( - answers, - 'attachments.injuryCertificateFile.file', - ) as FileType[] - - const deathCertificateFile = getValueViaPath( - answers, - 'attachments.deathCertificateFile.file', - ) as FileType[] - - const powerOfAttorneyFile = getValueViaPath( - answers, - 'attachments.powerOfAttorneyFile.file', - ) as FileType[] - - return ( - (hasMissingInjuryCertificate(answers) && - !hasAttachment(injuryCertificateFile)) || - (hasMissingDeathCertificate(answers) && - !hasAttachment(deathCertificateFile)) || - (hasMissingPowerOfAttorneyFile(answers) && - !hasAttachment(powerOfAttorneyFile)) - ) -} diff --git a/libs/application/templates/accident-notification/src/utils/hasReceivedConfirmation.spec.ts b/libs/application/templates/accident-notification/src/utils/hasReceivedConfirmation.spec.ts deleted file mode 100644 index a778beed75ab..000000000000 --- a/libs/application/templates/accident-notification/src/utils/hasReceivedConfirmation.spec.ts +++ /dev/null @@ -1,43 +0,0 @@ -import { FormValue } from '@island.is/application/types' -import { hasReceivedConfirmation } from './hasReceivedConfirmation' -import { WhoIsTheNotificationForEnum } from '../types' -describe('hasReceivedConfirmation', () => { - const confirmedJuridicial: FormValue = { - whoIsTheNotificationFor: { - answer: WhoIsTheNotificationForEnum.JURIDICALPERSON, - }, - accidentStatus: { - receivedConfirmations: { - InjuredOrRepresentativeParty: true, - }, - }, - } - - const confirmedMe: FormValue = { - whoIsTheNotificationFor: { - answer: WhoIsTheNotificationForEnum.ME, - }, - accidentStatus: { - receivedConfirmations: { - CompanyParty: true, - }, - }, - } - - const notConfirmed: FormValue = { - accidentStatus: { - receivedConfirmations: false, - }, - } - - it.each([ - { for: 'juridical person', input: confirmedJuridicial, expected: true }, - { for: 'company', input: confirmedMe, expected: true }, - { for: 'not confirmed', input: notConfirmed, expected: false }, - ])( - 'should return $expected when confirmation is $for', - ({ input, expected }) => { - expect(hasReceivedConfirmation(input)).toEqual(expected) - }, - ) -}) diff --git a/libs/application/templates/accident-notification/src/utils/hasReceivedConfirmation.ts b/libs/application/templates/accident-notification/src/utils/hasReceivedConfirmation.ts deleted file mode 100644 index d3796bbe8ede..000000000000 --- a/libs/application/templates/accident-notification/src/utils/hasReceivedConfirmation.ts +++ /dev/null @@ -1,20 +0,0 @@ -import { AccidentNotificationConfirmation } from '@island.is/api/schema' -import { getValueViaPath } from '@island.is/application/core' -import { FormValue } from '@island.is/application/types' -import { isReportingOnBehalfOfEmployee } from './isReportingOnBehalfOfEmployee' - -export const hasReceivedConfirmation = (answers: FormValue) => { - const accidentConfirmations = getValueViaPath( - answers, - 'accidentStatus.receivedConfirmations', - ) as AccidentNotificationConfirmation - - // if juridical person then the injured or the power of attorney holder has to confirm - if (isReportingOnBehalfOfEmployee(answers)) { - return !!accidentConfirmations.InjuredOrRepresentativeParty - } - - // as there isn't an juridical person reporting, this must be someone reporting for the injured - // or the injured himself and that requires the companies confirmation - return !!accidentConfirmations.CompanyParty -} diff --git a/libs/application/templates/accident-notification/src/utils/hideLocationAndPurpose.spec.ts b/libs/application/templates/accident-notification/src/utils/hideLocationAndPurpose.spec.ts deleted file mode 100644 index e6c00793695b..000000000000 --- a/libs/application/templates/accident-notification/src/utils/hideLocationAndPurpose.spec.ts +++ /dev/null @@ -1,36 +0,0 @@ -import { FormValue } from '@island.is/application/types' -import { - GeneralWorkplaceAccidentLocationEnum, - StudiesAccidentLocationEnum, -} from '../types' -import { hideLocationAndPurpose } from './hideLocationAndPurpose' -describe('hideLocationAndPurpose', () => { - const accidentLocationAtWorkplace: FormValue = { - accidentLocation: { - answer: GeneralWorkplaceAccidentLocationEnum.ATTHEWORKPLACE, - }, - } - - const accidentLocationAtSchoole: FormValue = { - accidentLocation: { answer: StudiesAccidentLocationEnum.ATTHESCHOOL }, - } - - const someOtherLocation: FormValue = { - accidentLocation: { answer: GeneralWorkplaceAccidentLocationEnum.OTHER }, - } - - const emptyObject = {} - - it('should return true for accident location at workplace', () => { - expect(hideLocationAndPurpose(accidentLocationAtWorkplace)).toEqual(true) - }) - it('should return true for accident location at school', () => { - expect(hideLocationAndPurpose(accidentLocationAtSchoole)).toEqual(true) - }) - it('should return false for accident location elsewhere', () => { - expect(hideLocationAndPurpose(someOtherLocation)).toEqual(false) - }) - it('should return false for empty object', () => { - expect(hideLocationAndPurpose(emptyObject)).toEqual(false) - }) -}) diff --git a/libs/application/templates/accident-notification/src/utils/hideLocationAndPurpose.ts b/libs/application/templates/accident-notification/src/utils/hideLocationAndPurpose.ts deleted file mode 100644 index c0d1d5496027..000000000000 --- a/libs/application/templates/accident-notification/src/utils/hideLocationAndPurpose.ts +++ /dev/null @@ -1,26 +0,0 @@ -import { getValueViaPath } from '@island.is/application/core' -import { FormValue } from '@island.is/application/types' -import { - GeneralWorkplaceAccidentLocationEnum, - ProfessionalAthleteAccidentLocationEnum, - StudiesAccidentLocationEnum, -} from '../types' -import { isHomeActivitiesAccident } from './isHomeActivitiesAccident' - -// Location and purpose of accident only relevant in work and studies and never in home -// activities -export const hideLocationAndPurpose = (formValue: FormValue) => { - const answer = getValueViaPath(formValue, 'accidentLocation.answer') as - | GeneralWorkplaceAccidentLocationEnum - | StudiesAccidentLocationEnum - | ProfessionalAthleteAccidentLocationEnum - - if (isHomeActivitiesAccident(formValue)) { - return true - } - return ( - answer === GeneralWorkplaceAccidentLocationEnum.ATTHEWORKPLACE || - answer === StudiesAccidentLocationEnum.ATTHESCHOOL || - answer === ProfessionalAthleteAccidentLocationEnum.SPORTCLUBSFACILITES - ) -} diff --git a/libs/application/templates/accident-notification/src/utils/index.spec.ts b/libs/application/templates/accident-notification/src/utils/index.spec.ts deleted file mode 100644 index 9bde4080715f..000000000000 --- a/libs/application/templates/accident-notification/src/utils/index.spec.ts +++ /dev/null @@ -1,180 +0,0 @@ -import { FormatMessage } from '@island.is/localization' -import { YES } from './constants' -import { AccidentNotification } from '../lib/dataSchema' -import { AttachmentsEnum, WhoIsTheNotificationForEnum } from '../types' -import { - isValid24HFormatTime, - formatPhonenumber, - getAttachmentTitles, - returnMissingDocumentsList, -} from './index' - -describe('isValid24HFormatTime', () => { - it.each(['0000', '2359', '1234'])( - 'should return true for valid time', - (time) => { - const result = isValid24HFormatTime(time) - expect(result).toBeTruthy() - }, - ) - - it.each([ - '2534', - '1265', - '2360', - '2400', - '12:34', - '', - '1', - '12', - '123', - '12345', - ])('should return false for invalid time', (time) => { - const result = isValid24HFormatTime(time) - expect(result).toBeFalsy() - }) -}) - -describe('formatPhonenumber', () => { - it.each([ - { input: '1234567', expected: '123-4567' }, - { input: '1234567891011', expected: '123-4567891011' }, - { input: 'ABCDEF@!()', expected: 'ABC-DEF@!()' }, - { input: '123', expected: '123' }, - ])('should format phone number', ({ input, expected }) => { - const result = formatPhonenumber(input) - expect(result).toBe(expected) - }) -}) - -describe('getAttachmentTitles', () => { - it.each([ - AttachmentsEnum.SENDCERTIFICATELATER, - AttachmentsEnum.HOSPITALSENDSCERTIFICATE, - ])('should return attachment titles', (injuryCertificate) => { - const answers = { - injuryCertificate: { - answer: injuryCertificate, - }, - attachments: { - deathCertificateFile: { - file: [ - { - name: 'test.pdf', - url: 'https://test.pdf', - }, - ], - }, - injuryCertificateFile: { - file: [ - { - name: 'test.pdf', - url: 'https://test.pdf', - }, - ], - }, - powerOfAttorneyFile: { - file: [ - { - name: 'test.pdf', - url: 'https://test.pdf', - }, - ], - }, - additionalFiles: { - file: [ - { - name: 'test.pdf', - url: 'https://test.pdf', - }, - ], - }, - additionalFilesFromReviewer: { - file: [ - { - name: 'test.pdf', - url: 'https://test.pdf', - }, - ], - }, - }, - } - - // Semi annoying push stuff here because order matters for strict equals - const isHospitalSendsCertificate = - injuryCertificate === AttachmentsEnum.HOSPITALSENDSCERTIFICATE - const expectedResults = [] - expectedResults.push({ - id: 'an.application:attachments.documentNames.deathCertificate', - defaultMessage: 'Lögregluskýrsla', - description: 'Name of police report for in review', - }) - if (!isHospitalSendsCertificate) { - expectedResults.push({ - id: 'an.application:attachments.documentNames.injuryCertificate', - defaultMessage: 'Áverkavottorð', - description: 'Name of injury certificate for in review', - }) - } - expectedResults.push({ - id: 'an.application:attachments.documentNames.powerOfAttorney', - defaultMessage: 'Umboð', - description: 'Name of power of attorney document for in review', - }) - if (isHospitalSendsCertificate) { - expectedResults.push({ - id: 'an.application:overview.labels.hospitalSendsCertificate', - defaultMessage: - 'Bráðamóttökuskrá - Ég mun óska eftir því að Landspítalinn sendi bráðamóttökuskrá til Sjúkratrygginga Íslands', - description: 'Label for hospital sends certificate in document list', - }) - } - expectedResults.push({ - id: 'an.application:attachments.documentNames.additionalDocumentsFromApplicant', - defaultMessage: 'Auka fylgiskjöl frá umsækjanda', - description: - 'Name of additional attachments for in review from applicant', - }) - expectedResults.push({ - id: 'an.application:attachments.documentNames.additionalDocumentsFromReviewer', - defaultMessage: 'Auka fylgiskjöl frá forsvarsmanni', - description: 'Name of additional attachments for in review from reviewer', - }) - - const result = getAttachmentTitles( - answers as unknown as AccidentNotification, - ) - expect(result).toStrictEqual(expectedResults) - }) -}) - -describe('returnMissingDocumentsList', () => { - it('should return missing documents list', () => { - const formatMessage: FormatMessage = jest.fn().mockReturnValue('test.pdf') - const missingDocuments = { - whoIsTheNotificationFor: { - answer: WhoIsTheNotificationForEnum.POWEROFATTORNEY, - }, - wasTheAccidentFatal: YES, - injuryCertificate: { - answer: AttachmentsEnum.SENDCERTIFICATELATER, - }, - attachments: { - injuryCertificateFile: { - file: [], - }, - deathCertificateFile: { - file: [], - }, - powerOfAttorneyFile: { - file: [], - }, - }, - } - const result = returnMissingDocumentsList( - missingDocuments as unknown as AccidentNotification, - formatMessage, - ) - expect(result).toEqual('test.pdf, test.pdf, test.pdf') - }) -}) diff --git a/libs/application/templates/accident-notification/src/utils/index.ts b/libs/application/templates/accident-notification/src/utils/index.ts deleted file mode 100644 index 2c1059df92f6..000000000000 --- a/libs/application/templates/accident-notification/src/utils/index.ts +++ /dev/null @@ -1,130 +0,0 @@ -import { AttachmentsEnum, FileType, WhoIsTheNotificationForEnum } from '..' -import { getValueViaPath } from '@island.is/application/core' -import { YES } from './constants' -import { AccidentNotification } from '../lib/dataSchema' -import { attachments, overview } from '../lib/messages' -import { FormatMessage } from '@island.is/localization' - -export const isValid24HFormatTime = (value: string) => { - if (value.length !== 4) return false - const hours = parseInt(value.slice(0, 2)) - const minutes = parseInt(value.slice(2, 4)) - if (hours > 23) return false - if (minutes > 59) return false - return true -} - -export const formatPhonenumber = (value: string) => { - const splitAt = (index: number) => (x: string) => - [x.slice(0, index), x.slice(index)] - if (value.length > 3) return splitAt(3)(value).join('-') - return value -} - -const hasAttachment = (attachment: FileType[] | undefined) => - attachment && attachment.length > 0 - -export const getAttachmentTitles = (answers: AccidentNotification) => { - const deathCertificateFile = - answers.attachments?.deathCertificateFile?.file || undefined - const injuryCertificateFile = - answers.attachments?.injuryCertificateFile?.file || undefined - const powerOfAttorneyFile = - answers.attachments?.powerOfAttorneyFile?.file || undefined - const additionalFiles = - answers.attachments?.additionalFiles?.file || undefined - const additionalFilesFromReviewer = - answers.attachments?.additionalFilesFromReviewer?.file || undefined - - const files = [] - - if (hasAttachment(deathCertificateFile)) - files.push(attachments.documentNames.deathCertificate) - if ( - hasAttachment(injuryCertificateFile) && - getValueViaPath(answers, 'injuryCertificate.answer') !== - AttachmentsEnum.HOSPITALSENDSCERTIFICATE - ) - files.push(attachments.documentNames.injuryCertificate) - if (hasAttachment(powerOfAttorneyFile)) - files.push(attachments.documentNames.powerOfAttorneyDocument) - if ( - answers.injuryCertificate?.answer === - AttachmentsEnum.HOSPITALSENDSCERTIFICATE - ) - files.push(overview.labels.hospitalSendsCertificate) - if (hasAttachment(additionalFiles)) - files.push(attachments.documentNames.additionalDocumentsFromApplicant) - if (hasAttachment(additionalFilesFromReviewer)) - files.push(attachments.documentNames.additionalDocumentsFromReviewer) - - return files -} - -export const returnMissingDocumentsList = ( - answers: AccidentNotification, - formatMessage: FormatMessage, -) => { - const injuryCertificate = answers.injuryCertificate - const whoIsTheNotificationFor = answers.whoIsTheNotificationFor.answer - const wasTheAccidentFatal = answers.wasTheAccidentFatal - const missingDocuments = [] - - if ( - injuryCertificate?.answer === AttachmentsEnum.SENDCERTIFICATELATER && - !hasAttachment(answers.attachments?.injuryCertificateFile?.file) - ) { - missingDocuments.push( - formatMessage(attachments.documentNames.injuryCertificate), - ) - } - - // Only show this to applicant or assignee that is also the applicant - if ( - whoIsTheNotificationFor === WhoIsTheNotificationForEnum.POWEROFATTORNEY && - !hasAttachment(answers.attachments?.powerOfAttorneyFile?.file) - ) { - missingDocuments.push( - formatMessage(attachments.documentNames.powerOfAttorneyDocument), - ) - } - - if ( - wasTheAccidentFatal === YES && - !hasAttachment(answers.attachments?.deathCertificateFile?.file) - ) { - missingDocuments.push( - formatMessage(attachments.documentNames.deathCertificate), - ) - } - - return missingDocuments.join(', ') -} - -export * from './fishermanUtils' -export * from './getAccidentTypeOptions' -export * from './getInjuredPersonInformation' -export * from './getWorkplaceData' -export * from './hasMissingDocuments' -export * from './hideLocationAndPurpose' -export * from './isAgricultureAccident' -export * from './isDateOlderThanAYear' -export * from './isGeneralWorkplaceAccident' -export * from './isHomeActivitiesAccident' -export * from './isInternshipStudiesAccident' -export * from './isMachineRelatedAccident' -export * from './isProfessionalAthleteAccident' -export * from './isReportingOnBehalfOfChild' -export * from './isReportingOnBehalfOfEmployee' -export * from './isReportingOnBehalfOfInjured' -export * from './isRepresentativeOfCompanyOrInstitute' -export * from './isRescueWorkAccident' -export * from './isStudiesAccident' -export * from './isWorkAccident' -export * from './isPowerOfAttorney' -export * from './isRepresentativeOfCompanyOrInstitute' -export * from './isFatalAccident' -export * from './isReportingBehalfOfSelf' -export * from './isOfWorkTypeAccident' -export * from './shouldRequestReview' -export * from './isUniqueAssignee' diff --git a/libs/application/templates/accident-notification/src/utils/isAgricultureAccident.spec.ts b/libs/application/templates/accident-notification/src/utils/isAgricultureAccident.spec.ts deleted file mode 100644 index 8cbb0f338cfc..000000000000 --- a/libs/application/templates/accident-notification/src/utils/isAgricultureAccident.spec.ts +++ /dev/null @@ -1,25 +0,0 @@ -import { FormValue } from '@island.is/application/types' -import { AccidentTypeEnum, WorkAccidentTypeEnum } from '../types' -import { isAgricultureAccident } from './isAgricultureAccident' -describe('isAgricultureAccident', () => { - const agricultureAccident: FormValue = { - workAccident: { type: WorkAccidentTypeEnum.AGRICULTURE }, - accidentType: { radioButton: AccidentTypeEnum.WORK }, - } - - const someOtherAccident: FormValue = { - workAccident: { type: WorkAccidentTypeEnum.PROFESSIONALATHLETE }, - } - - const emptyObject = {} - - it('should return true for agriculture accidents', () => { - expect(isAgricultureAccident(agricultureAccident)).toEqual(true) - }) - it('should return false for workplace accidents other than agriculture', () => { - expect(isAgricultureAccident(someOtherAccident)).toEqual(false) - }) - it('should return false for empty object', () => { - expect(isAgricultureAccident(emptyObject)).toEqual(false) - }) -}) diff --git a/libs/application/templates/accident-notification/src/utils/isAgricultureAccident.ts b/libs/application/templates/accident-notification/src/utils/isAgricultureAccident.ts deleted file mode 100644 index e13dea0a0da9..000000000000 --- a/libs/application/templates/accident-notification/src/utils/isAgricultureAccident.ts +++ /dev/null @@ -1,17 +0,0 @@ -import { getValueViaPath } from '@island.is/application/core' -import { FormValue } from '@island.is/application/types' -import { WorkAccidentTypeEnum } from '../types' -import { isWorkAccident } from './isWorkAccident' - -// As this is a second question the user is asked there is a case where he could go back and select home activities and keep the agriculture type. -// Therefore we need to check also whether this is a work accident -export const isAgricultureAccident = (formValue: FormValue) => { - const workAccidentType = getValueViaPath( - formValue, - 'workAccident.type', - ) as WorkAccidentTypeEnum - return ( - workAccidentType === WorkAccidentTypeEnum.AGRICULTURE && - isWorkAccident(formValue) - ) -} diff --git a/libs/application/templates/accident-notification/src/utils/isFatalAccident.spec.ts b/libs/application/templates/accident-notification/src/utils/isFatalAccident.spec.ts deleted file mode 100644 index 67b9f7bb25ec..000000000000 --- a/libs/application/templates/accident-notification/src/utils/isFatalAccident.spec.ts +++ /dev/null @@ -1,23 +0,0 @@ -import { FormValue } from '@island.is/application/types' -import { isFatalAccident } from './isFatalAccident' -import { NO, YES } from './constants' - -describe('isFatalAccident', () => { - const fatal: FormValue = { - wasTheAccidentFatal: YES, - } - - const notFatal: FormValue = { - wasTheAccidentFatal: NO, - } - - it('should return true for a fatal accident', () => { - expect(isFatalAccident(fatal)).toEqual(true) - }) - it('should return false for a non fatal accident', () => { - expect(isFatalAccident(notFatal)).toEqual(false) - }) - it('should return false for empty object', () => { - expect(isFatalAccident({})).toEqual(false) - }) -}) diff --git a/libs/application/templates/accident-notification/src/utils/isFatalAccident.ts b/libs/application/templates/accident-notification/src/utils/isFatalAccident.ts deleted file mode 100644 index 4094c3efbc99..000000000000 --- a/libs/application/templates/accident-notification/src/utils/isFatalAccident.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { getValueViaPath } from '@island.is/application/core' -import { FormValue } from '@island.is/application/types' -import { YES } from './constants' -import { YesOrNo } from '../types' - -export const isFatalAccident = (formValue: FormValue) => { - const wasTheAccidentFatal = getValueViaPath( - formValue, - 'wasTheAccidentFatal', - ) as YesOrNo - return wasTheAccidentFatal === YES -} diff --git a/libs/application/templates/accident-notification/src/utils/isGeneralWorkplaceAccident.spec.ts b/libs/application/templates/accident-notification/src/utils/isGeneralWorkplaceAccident.spec.ts deleted file mode 100644 index 1949e40394b6..000000000000 --- a/libs/application/templates/accident-notification/src/utils/isGeneralWorkplaceAccident.spec.ts +++ /dev/null @@ -1,25 +0,0 @@ -import { FormValue } from '@island.is/application/types' -import { AccidentTypeEnum, WorkAccidentTypeEnum } from '../types' -import { isGeneralWorkplaceAccident } from './isGeneralWorkplaceAccident' -describe('isGeneralWorkplaceAccident', () => { - const generalWorkplaceAccident: FormValue = { - workAccident: { type: WorkAccidentTypeEnum.GENERAL }, - accidentType: { radioButton: AccidentTypeEnum.WORK }, - } - - const someOtherAccident: FormValue = { - workAccident: { type: WorkAccidentTypeEnum.PROFESSIONALATHLETE }, - } - - const emptyObject = {} - - it('should return true for general workplace accidents', () => { - expect(isGeneralWorkplaceAccident(generalWorkplaceAccident)).toEqual(true) - }) - it('should return false for workplace accidents other than general', () => { - expect(isGeneralWorkplaceAccident(someOtherAccident)).toEqual(false) - }) - it('should return false for empty object', () => { - expect(isGeneralWorkplaceAccident(emptyObject)).toEqual(false) - }) -}) diff --git a/libs/application/templates/accident-notification/src/utils/isGeneralWorkplaceAccident.ts b/libs/application/templates/accident-notification/src/utils/isGeneralWorkplaceAccident.ts deleted file mode 100644 index 7be7ff2e3c8e..000000000000 --- a/libs/application/templates/accident-notification/src/utils/isGeneralWorkplaceAccident.ts +++ /dev/null @@ -1,17 +0,0 @@ -import { getValueViaPath } from '@island.is/application/core' -import { FormValue } from '@island.is/application/types' -import { WorkAccidentTypeEnum } from '../types' -import { isWorkAccident } from './isWorkAccident' - -// As this is a second question the user is asked there is a case where he could go back and select home activities and keep the workaccident type. -// Therefore we need to check also whether this is a work accident -export const isGeneralWorkplaceAccident = (formValue: FormValue) => { - const workAccidentType = getValueViaPath( - formValue, - 'workAccident.type', - ) as string - return ( - workAccidentType === WorkAccidentTypeEnum.GENERAL && - isWorkAccident(formValue) - ) -} diff --git a/libs/application/templates/accident-notification/src/utils/isHealthInsured.spec.ts b/libs/application/templates/accident-notification/src/utils/isHealthInsured.spec.ts deleted file mode 100644 index a5e8d11ce750..000000000000 --- a/libs/application/templates/accident-notification/src/utils/isHealthInsured.spec.ts +++ /dev/null @@ -1,27 +0,0 @@ -import { isHealthInsured } from './isHealthInsured' - -describe('isHealthInsured', () => { - const healthInsured = { - accidentDetails: { - isHealthInsured: 'yes', - }, - } - - const notHealthInsured = { - accidentDetails: { - isHealthInsured: 'no', - }, - } - - it('should return true when health insured is yes', () => { - expect(isHealthInsured(healthInsured)).toEqual(true) - }) - - it('should return false when health insured is no', () => { - expect(isHealthInsured(notHealthInsured)).toEqual(false) - }) - - it('should return true when health insured is undefined', () => { - expect(isHealthInsured({})).toEqual(true) - }) -}) diff --git a/libs/application/templates/accident-notification/src/utils/isHealthInsured.ts b/libs/application/templates/accident-notification/src/utils/isHealthInsured.ts deleted file mode 100644 index e0e6765d67e1..000000000000 --- a/libs/application/templates/accident-notification/src/utils/isHealthInsured.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { getValueViaPath } from '@island.is/application/core' -import { FormValue } from '@island.is/application/types' - -export const isHealthInsured = (formValue: FormValue) => { - const isHealthInsured = getValueViaPath( - formValue, - 'accidentDetails.isHealthInsured', - ) as string - if (isHealthInsured === undefined) return true - return isHealthInsured === 'yes' -} diff --git a/libs/application/templates/accident-notification/src/utils/isHomeActivitiesAccident.spec.ts b/libs/application/templates/accident-notification/src/utils/isHomeActivitiesAccident.spec.ts deleted file mode 100644 index c418a2b87656..000000000000 --- a/libs/application/templates/accident-notification/src/utils/isHomeActivitiesAccident.spec.ts +++ /dev/null @@ -1,24 +0,0 @@ -import { FormValue } from '@island.is/application/types' -import { AccidentTypeEnum } from '../types' -import { isHomeActivitiesAccident } from './isHomeActivitiesAccident' -describe('isHomeActivitiesAccident', () => { - const homeActivitiesAccident: FormValue = { - accidentType: { radioButton: AccidentTypeEnum.HOMEACTIVITIES }, - } - - const someOtherAccident: FormValue = { - accidentType: { radioButton: AccidentTypeEnum.RESCUEWORK }, - } - - const emptyObject = {} - - it('should return true for home activity accidents', () => { - expect(isHomeActivitiesAccident(homeActivitiesAccident)).toEqual(true) - }) - it('should return false for accidents other than home activity accidents', () => { - expect(isHomeActivitiesAccident(someOtherAccident)).toEqual(false) - }) - it('should return false for empty object', () => { - expect(isHomeActivitiesAccident(emptyObject)).toEqual(false) - }) -}) diff --git a/libs/application/templates/accident-notification/src/utils/isHomeActivitiesAccident.ts b/libs/application/templates/accident-notification/src/utils/isHomeActivitiesAccident.ts deleted file mode 100644 index 4aa71f8c1902..000000000000 --- a/libs/application/templates/accident-notification/src/utils/isHomeActivitiesAccident.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { getValueViaPath } from '@island.is/application/core' -import { FormValue } from '@island.is/application/types' -import { AccidentTypeEnum } from '../types' - -export const isHomeActivitiesAccident = (formValue: FormValue) => { - const workAccidentType = getValueViaPath( - formValue, - 'accidentType.radioButton', - ) as AccidentTypeEnum - return workAccidentType === AccidentTypeEnum.HOMEACTIVITIES -} diff --git a/libs/application/templates/accident-notification/src/utils/isInternshipStudiesAccident.spec.ts b/libs/application/templates/accident-notification/src/utils/isInternshipStudiesAccident.spec.ts deleted file mode 100644 index ac468eb6b2bb..000000000000 --- a/libs/application/templates/accident-notification/src/utils/isInternshipStudiesAccident.spec.ts +++ /dev/null @@ -1,24 +0,0 @@ -import { FormValue } from '@island.is/application/types' -import { StudiesAccidentTypeEnum } from '../types' -import { isInternshipStudiesAccident } from './isInternshipStudiesAccident' -describe('isInternshipStudiesAccident', () => { - const studiesAccidentType: FormValue = { - studiesAccident: { type: StudiesAccidentTypeEnum.INTERNSHIP }, - } - - const someOtherAccidentType: FormValue = { - studiesAccident: { type: StudiesAccidentTypeEnum.APPRENTICESHIP }, - } - - const emptyObject = {} - - it('should return true for studies accidents', () => { - expect(isInternshipStudiesAccident(studiesAccidentType)).toEqual(true) - }) - it('should return false for accidents other than studies', () => { - expect(isInternshipStudiesAccident(someOtherAccidentType)).toEqual(false) - }) - it('should return false for empty object', () => { - expect(isInternshipStudiesAccident(emptyObject)).toEqual(false) - }) -}) diff --git a/libs/application/templates/accident-notification/src/utils/isInternshipStudiesAccident.ts b/libs/application/templates/accident-notification/src/utils/isInternshipStudiesAccident.ts deleted file mode 100644 index 07b7a859e87f..000000000000 --- a/libs/application/templates/accident-notification/src/utils/isInternshipStudiesAccident.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { getValueViaPath } from '@island.is/application/core' -import { FormValue } from '@island.is/application/types' -import { StudiesAccidentTypeEnum } from '../types' - -export const isInternshipStudiesAccident = (formValue: FormValue) => { - const studiesAccidentType = getValueViaPath( - formValue, - 'studiesAccident.type', - ) as StudiesAccidentTypeEnum - return studiesAccidentType === StudiesAccidentTypeEnum.INTERNSHIP -} diff --git a/libs/application/templates/accident-notification/src/utils/isMachineRelatedAccident.spec.ts b/libs/application/templates/accident-notification/src/utils/isMachineRelatedAccident.spec.ts deleted file mode 100644 index 017a1e679a26..000000000000 --- a/libs/application/templates/accident-notification/src/utils/isMachineRelatedAccident.spec.ts +++ /dev/null @@ -1,36 +0,0 @@ -import { FormValue } from '@island.is/application/types' -import { NO, YES } from './constants' -import { AccidentTypeEnum, WorkAccidentTypeEnum } from '../types' -import { isMachineRelatedAccident } from './isMachineRelatedAccident' -describe('isMachineRelatedAccident', () => { - const machineRelatedAccident: FormValue = { - workAccident: { type: WorkAccidentTypeEnum.GENERAL }, - accidentType: { radioButton: AccidentTypeEnum.WORK }, - workMachineRadio: YES, - } - - const nonMachineRelatedAccident: FormValue = { - workAccident: { type: WorkAccidentTypeEnum.GENERAL }, - accidentType: { radioButton: AccidentTypeEnum.WORK }, - workMachineRadio: NO, - } - - const someOtherAccident: FormValue = { - workAccident: { type: WorkAccidentTypeEnum.PROFESSIONALATHLETE }, - } - - const emptyObject = {} - - it('should return true for machine related general work accidents', () => { - expect(isMachineRelatedAccident(machineRelatedAccident)).toEqual(true) - }) - it('should return false for non machine related general work accidents', () => { - expect(isMachineRelatedAccident(nonMachineRelatedAccident)).toEqual(false) - }) - it('should return false for workplace accidents other than general', () => { - expect(isMachineRelatedAccident(someOtherAccident)).toEqual(false) - }) - it('should return false for empty object', () => { - expect(isMachineRelatedAccident(emptyObject)).toEqual(false) - }) -}) diff --git a/libs/application/templates/accident-notification/src/utils/isMachineRelatedAccident.ts b/libs/application/templates/accident-notification/src/utils/isMachineRelatedAccident.ts deleted file mode 100644 index fd3cabc5347b..000000000000 --- a/libs/application/templates/accident-notification/src/utils/isMachineRelatedAccident.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { getValueViaPath } from '@island.is/application/core' -import { FormValue } from '@island.is/application/types' -import { YES } from './constants' -import { YesOrNo } from '../types' -import { isGeneralWorkplaceAccident } from './isGeneralWorkplaceAccident' - -export const isMachineRelatedAccident = (formValue: FormValue) => { - const workMachineAnswer = getValueViaPath( - formValue, - 'workMachineRadio', - ) as YesOrNo - return isGeneralWorkplaceAccident(formValue) && workMachineAnswer === YES -} diff --git a/libs/application/templates/accident-notification/src/utils/isOfWorkTypeAccident.ts b/libs/application/templates/accident-notification/src/utils/isOfWorkTypeAccident.ts deleted file mode 100644 index 7ecb4c31b781..000000000000 --- a/libs/application/templates/accident-notification/src/utils/isOfWorkTypeAccident.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { getValueViaPath } from '@island.is/application/core' -import { AccidentNotificationAnswers } from '..' -import { WorkAccidentTypeEnum } from '../types' - -export const isOfWorkAccidentType = ( - answers: Partial, - type: WorkAccidentTypeEnum, -) => { - const workAccidentType = getValueViaPath( - answers, - 'workAccident.type', - ) as WorkAccidentTypeEnum - return workAccidentType === type -} diff --git a/libs/application/templates/accident-notification/src/utils/isPowerOfAttorney.spec.ts b/libs/application/templates/accident-notification/src/utils/isPowerOfAttorney.spec.ts deleted file mode 100644 index 1c5ade01d399..000000000000 --- a/libs/application/templates/accident-notification/src/utils/isPowerOfAttorney.spec.ts +++ /dev/null @@ -1,39 +0,0 @@ -import { FormValue } from '@island.is/application/types' -import { WhoIsTheNotificationForEnum } from '../types' -import { isPowerOfAttorney } from './isPowerOfAttorney' - -describe('isPowerOfAttorney', () => { - const powerOfAttorneyReporter: FormValue = { - whoIsTheNotificationFor: { - answer: WhoIsTheNotificationForEnum.POWEROFATTORNEY, - }, - } - - const juridicialPersonReporter: FormValue = { - whoIsTheNotificationFor: { - answer: WhoIsTheNotificationForEnum.JURIDICALPERSON, - }, - } - - const reportingForSelf: FormValue = { - whoIsTheNotificationFor: { answer: WhoIsTheNotificationForEnum.ME }, - } - - const emptyObject = {} - - it('should return true for power of attorney reporter', () => { - expect(isPowerOfAttorney(powerOfAttorneyReporter)).toEqual(true) - }) - - it('should return false for power of juridical person reporter', () => { - expect(isPowerOfAttorney(juridicialPersonReporter)).toEqual(false) - }) - - it('should return false for reporting for yourself', () => { - expect(isPowerOfAttorney(reportingForSelf)).toEqual(false) - }) - - it('should return false for empty object', () => { - expect(isPowerOfAttorney(emptyObject)).toEqual(false) - }) -}) diff --git a/libs/application/templates/accident-notification/src/utils/isPowerOfAttorney.ts b/libs/application/templates/accident-notification/src/utils/isPowerOfAttorney.ts deleted file mode 100644 index 46b4d177bc5e..000000000000 --- a/libs/application/templates/accident-notification/src/utils/isPowerOfAttorney.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { getValueViaPath } from '@island.is/application/core' -import { FormValue } from '@island.is/application/types' -import { WhoIsTheNotificationForEnum } from '../types' - -export const isPowerOfAttorney = (formValue: FormValue) => { - const reportingOnBehalfType = getValueViaPath( - formValue, - 'whoIsTheNotificationFor.answer', - ) as WhoIsTheNotificationForEnum - return reportingOnBehalfType === WhoIsTheNotificationForEnum.POWEROFATTORNEY -} diff --git a/libs/application/templates/accident-notification/src/utils/isProfessionalAthleteAccident.spec.ts b/libs/application/templates/accident-notification/src/utils/isProfessionalAthleteAccident.spec.ts deleted file mode 100644 index 22c0f49af199..000000000000 --- a/libs/application/templates/accident-notification/src/utils/isProfessionalAthleteAccident.spec.ts +++ /dev/null @@ -1,41 +0,0 @@ -import { FormValue } from '@island.is/application/types' -import { AccidentTypeEnum, WorkAccidentTypeEnum } from '../types' -import { isProfessionalAthleteAccident } from './isProfessionalAthleteAccident' - -describe('isProfessionalAthleteAccident', () => { - const professionalAthleteAccidentRadio: FormValue = { - accidentType: { radioButton: AccidentTypeEnum.SPORTS }, - } - - const professionalAthleteAccidentSecondaryWorkQuestion: FormValue = { - workAccident: { type: WorkAccidentTypeEnum.PROFESSIONALATHLETE }, - accidentType: { radioButton: AccidentTypeEnum.WORK }, - } - - const someOtherAccident: FormValue = { - workAccident: { type: WorkAccidentTypeEnum.FISHERMAN }, - } - - const emptyObject = {} - - it('should return true for professional athlete accidents', () => { - expect( - isProfessionalAthleteAccident(professionalAthleteAccidentRadio), - ).toEqual(true) - }) - - it('should return true for professional athlete accident when user picked work related and then sports related', () => { - expect( - isProfessionalAthleteAccident( - professionalAthleteAccidentSecondaryWorkQuestion, - ), - ).toEqual(true) - }) - - it('should return false for workplace accidents other than professional athlete', () => { - expect(isProfessionalAthleteAccident(someOtherAccident)).toEqual(false) - }) - it('should return false for empty object', () => { - expect(isProfessionalAthleteAccident(emptyObject)).toEqual(false) - }) -}) diff --git a/libs/application/templates/accident-notification/src/utils/isProfessionalAthleteAccident.ts b/libs/application/templates/accident-notification/src/utils/isProfessionalAthleteAccident.ts deleted file mode 100644 index e1b61896a622..000000000000 --- a/libs/application/templates/accident-notification/src/utils/isProfessionalAthleteAccident.ts +++ /dev/null @@ -1,23 +0,0 @@ -import { getValueViaPath } from '@island.is/application/core' -import { FormValue } from '@island.is/application/types' -import { AccidentTypeEnum, WorkAccidentTypeEnum } from '../types' -import { isWorkAccident } from './isWorkAccident' - -// Specific case check here since the accident can be a sports accident if he picks sports in the first question where -// he is asked what the circumstances of the accident were. But that user could also select work and then a sport related -// accident since the question can be missunderstood by the user so we are funneling both cases into the same flow -export const isProfessionalAthleteAccident = (formValue: FormValue) => { - const workAccidentType = getValueViaPath( - formValue, - 'accidentType.radioButton', - ) as AccidentTypeEnum - const workAccidentSecondaryType = getValueViaPath( - formValue, - 'workAccident.type', - ) as WorkAccidentTypeEnum - return ( - workAccidentType === AccidentTypeEnum.SPORTS || - (workAccidentSecondaryType === WorkAccidentTypeEnum.PROFESSIONALATHLETE && - isWorkAccident(formValue)) - ) -} diff --git a/libs/application/templates/accident-notification/src/utils/isReportingBehalfOfSelf.spec.ts b/libs/application/templates/accident-notification/src/utils/isReportingBehalfOfSelf.spec.ts deleted file mode 100644 index 98b80807ac4a..000000000000 --- a/libs/application/templates/accident-notification/src/utils/isReportingBehalfOfSelf.spec.ts +++ /dev/null @@ -1,27 +0,0 @@ -import { FormValue } from '@island.is/application/types' -import { isReportingOnBehalfSelf } from './isReportingBehalfOfSelf' -import { WhoIsTheNotificationForEnum } from '../types' - -describe('isRepresentativeOfCompanyOrInstitute', () => { - const self: FormValue = { - whoIsTheNotificationFor: { - answer: WhoIsTheNotificationForEnum.ME, - }, - } - - const notSelf: FormValue = { - whoIsTheNotificationFor: { - answer: WhoIsTheNotificationForEnum.POWEROFATTORNEY, - }, - } - - it('should return true when someone is reporting on behalf of themselves', () => { - expect(isReportingOnBehalfSelf(self)).toEqual(true) - }) - it('should return false when someone is not reporting on behalf of themselves', () => { - expect(isReportingOnBehalfSelf(notSelf)).toEqual(false) - }) - it('should return false for empty object', () => { - expect(isReportingOnBehalfSelf({})).toEqual(false) - }) -}) diff --git a/libs/application/templates/accident-notification/src/utils/isReportingBehalfOfSelf.ts b/libs/application/templates/accident-notification/src/utils/isReportingBehalfOfSelf.ts deleted file mode 100644 index 90b3784bc058..000000000000 --- a/libs/application/templates/accident-notification/src/utils/isReportingBehalfOfSelf.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { getValueViaPath } from '@island.is/application/core' -import { FormValue } from '@island.is/application/types' -import { WhoIsTheNotificationForEnum } from '../types' - -export const isReportingOnBehalfSelf = (formValue: FormValue) => { - const whoIsTheNotificationFor = getValueViaPath( - formValue, - 'whoIsTheNotificationFor.answer', - ) as WhoIsTheNotificationForEnum - return whoIsTheNotificationFor === WhoIsTheNotificationForEnum.ME -} diff --git a/libs/application/templates/accident-notification/src/utils/isReportingOnBehalfOfChild.spec.ts b/libs/application/templates/accident-notification/src/utils/isReportingOnBehalfOfChild.spec.ts deleted file mode 100644 index f778067b61c1..000000000000 --- a/libs/application/templates/accident-notification/src/utils/isReportingOnBehalfOfChild.spec.ts +++ /dev/null @@ -1,28 +0,0 @@ -import { FormValue } from '@island.is/application/types' -import { WhoIsTheNotificationForEnum } from '../types' -import { isReportingOnBehalfOfChild } from './isReportingOnBehalfOfChild' -describe('isReportingOnBehalfOfChild', () => { - const onBehalfOfChild: FormValue = { - whoIsTheNotificationFor: { - answer: WhoIsTheNotificationForEnum.CHILDINCUSTODY, - }, - } - - const onBehalfOfSomeOtherPerson: FormValue = { - whoIsTheNotificationFor: { - answer: WhoIsTheNotificationForEnum.POWEROFATTORNEY, - }, - } - - const emptyObject = {} - - it('should return true if reporting on behalf of child', () => { - expect(isReportingOnBehalfOfChild(onBehalfOfChild)).toEqual(true) - }) - it('should return false if reporting on behalf of some other person', () => { - expect(isReportingOnBehalfOfChild(onBehalfOfSomeOtherPerson)).toEqual(false) - }) - it('should return false for empty object', () => { - expect(isReportingOnBehalfOfChild(emptyObject)).toEqual(false) - }) -}) diff --git a/libs/application/templates/accident-notification/src/utils/isReportingOnBehalfOfChild.ts b/libs/application/templates/accident-notification/src/utils/isReportingOnBehalfOfChild.ts deleted file mode 100644 index d3193b011c11..000000000000 --- a/libs/application/templates/accident-notification/src/utils/isReportingOnBehalfOfChild.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { getValueViaPath } from '@island.is/application/core' -import { FormValue } from '@island.is/application/types' -import { WhoIsTheNotificationForEnum } from '../types' - -export const isReportingOnBehalfOfChild = (formValue: FormValue) => { - const whoIsTheNotificationFor = getValueViaPath( - formValue, - 'whoIsTheNotificationFor.answer', - ) as WhoIsTheNotificationForEnum - return whoIsTheNotificationFor === WhoIsTheNotificationForEnum.CHILDINCUSTODY -} diff --git a/libs/application/templates/accident-notification/src/utils/isReportingOnBehalfOfEmployee.spec.ts b/libs/application/templates/accident-notification/src/utils/isReportingOnBehalfOfEmployee.spec.ts deleted file mode 100644 index 50c105735b0d..000000000000 --- a/libs/application/templates/accident-notification/src/utils/isReportingOnBehalfOfEmployee.spec.ts +++ /dev/null @@ -1,30 +0,0 @@ -import { FormValue } from '@island.is/application/types' -import { WhoIsTheNotificationForEnum } from '../types' -import { isReportingOnBehalfOfEmployee } from './isReportingOnBehalfOfEmployee' -describe('isReportingOnBehalfOfEmployee', () => { - const onBehalfOfEmployee: FormValue = { - whoIsTheNotificationFor: { - answer: WhoIsTheNotificationForEnum.JURIDICALPERSON, - }, - } - - const onBehalfOfSomeOtherPerson: FormValue = { - whoIsTheNotificationFor: { - answer: WhoIsTheNotificationForEnum.POWEROFATTORNEY, - }, - } - - const emptyObject = {} - - it('should return true if reporting on behalf of employee', () => { - expect(isReportingOnBehalfOfEmployee(onBehalfOfEmployee)).toEqual(true) - }) - it('should return false if reporting on behalf of some other person', () => { - expect(isReportingOnBehalfOfEmployee(onBehalfOfSomeOtherPerson)).toEqual( - false, - ) - }) - it('should return false for empty object', () => { - expect(isReportingOnBehalfOfEmployee(emptyObject)).toEqual(false) - }) -}) diff --git a/libs/application/templates/accident-notification/src/utils/isReportingOnBehalfOfEmployee.ts b/libs/application/templates/accident-notification/src/utils/isReportingOnBehalfOfEmployee.ts deleted file mode 100644 index d00c7ed47f7f..000000000000 --- a/libs/application/templates/accident-notification/src/utils/isReportingOnBehalfOfEmployee.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { getValueViaPath } from '@island.is/application/core' -import { FormValue } from '@island.is/application/types' -import { WhoIsTheNotificationForEnum } from '../types' - -export const isReportingOnBehalfOfEmployee = (formValue: FormValue) => { - const whoIsTheNotificationFor = getValueViaPath( - formValue, - 'whoIsTheNotificationFor.answer', - ) as WhoIsTheNotificationForEnum - return whoIsTheNotificationFor === WhoIsTheNotificationForEnum.JURIDICALPERSON -} diff --git a/libs/application/templates/accident-notification/src/utils/isReportingOnBehalfOfInjured.spec.ts b/libs/application/templates/accident-notification/src/utils/isReportingOnBehalfOfInjured.spec.ts deleted file mode 100644 index efce07880e51..000000000000 --- a/libs/application/templates/accident-notification/src/utils/isReportingOnBehalfOfInjured.spec.ts +++ /dev/null @@ -1,39 +0,0 @@ -import { FormValue } from '@island.is/application/types' -import { WhoIsTheNotificationForEnum } from '../types' -import { isReportingOnBehalfOfInjured } from './isReportingOnBehalfOfInjured' - -describe('isReportingOnBehalfOfInjured', () => { - const powerOfAttorneyReporter: FormValue = { - whoIsTheNotificationFor: { - answer: WhoIsTheNotificationForEnum.POWEROFATTORNEY, - }, - } - - const juridicialPersonReporter: FormValue = { - whoIsTheNotificationFor: { - answer: WhoIsTheNotificationForEnum.JURIDICALPERSON, - }, - } - - const reportingForSelf: FormValue = { - whoIsTheNotificationFor: { answer: WhoIsTheNotificationForEnum.ME }, - } - - const emptyObject = {} - - it('should return true for power of attorney reporter', () => { - expect(isReportingOnBehalfOfInjured(powerOfAttorneyReporter)).toEqual(true) - }) - - it('should return true for power of juridical person reporter', () => { - expect(isReportingOnBehalfOfInjured(juridicialPersonReporter)).toEqual(true) - }) - - it('should return false for reporting for yourself', () => { - expect(isReportingOnBehalfOfInjured(reportingForSelf)).toEqual(false) - }) - - it('should return false for empty object', () => { - expect(isReportingOnBehalfOfInjured(emptyObject)).toEqual(false) - }) -}) diff --git a/libs/application/templates/accident-notification/src/utils/isReportingOnBehalfOfInjured.ts b/libs/application/templates/accident-notification/src/utils/isReportingOnBehalfOfInjured.ts deleted file mode 100644 index d0ac674762ae..000000000000 --- a/libs/application/templates/accident-notification/src/utils/isReportingOnBehalfOfInjured.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { getValueViaPath } from '@island.is/application/core' -import { FormValue } from '@island.is/application/types' -import { WhoIsTheNotificationForEnum } from '../types' - -export const isReportingOnBehalfOfInjured = (formValue: FormValue) => { - const whoIsTheNotificationFor = getValueViaPath( - formValue, - 'whoIsTheNotificationFor.answer', - ) as WhoIsTheNotificationForEnum - return ( - whoIsTheNotificationFor === WhoIsTheNotificationForEnum.JURIDICALPERSON || - whoIsTheNotificationFor === WhoIsTheNotificationForEnum.POWEROFATTORNEY - ) -} diff --git a/libs/application/templates/accident-notification/src/utils/isRepresentativeOfCompanyOrInstitute.spec.ts b/libs/application/templates/accident-notification/src/utils/isRepresentativeOfCompanyOrInstitute.spec.ts deleted file mode 100644 index aeff9475efef..000000000000 --- a/libs/application/templates/accident-notification/src/utils/isRepresentativeOfCompanyOrInstitute.spec.ts +++ /dev/null @@ -1,89 +0,0 @@ -import { FormValue } from '@island.is/application/types' -import { WhoIsTheNotificationForEnum } from '../types' - -import { - isInjuredAndRepresentativeOfCompanyOrInstitute, - isRepresentativeOfCompanyOrInstitute, -} from './isRepresentativeOfCompanyOrInstitute' -import { NO, YES } from './constants' - -const emptyObject = {} - -describe('isRepresentativeOfCompanyOrInstitute', () => { - const representative: FormValue = { - whoIsTheNotificationFor: { - answer: WhoIsTheNotificationForEnum.JURIDICALPERSON, - }, - } - - const notRepresentative: FormValue = { - whoIsTheNotificationFor: { - answer: WhoIsTheNotificationForEnum.ME, - }, - } - - const emptyRepresentative: FormValue = { - whoIsTheNotificationFor: {}, - } - - it('should return true for someone that is a representative of the company or institue', () => { - expect(isRepresentativeOfCompanyOrInstitute(representative)).toEqual(true) - }) - it('should return false for someone that isnt a representative of the company or institue', () => { - expect(isRepresentativeOfCompanyOrInstitute(notRepresentative)).toEqual( - false, - ) - }) - it('should return false for empty object', () => { - expect(isRepresentativeOfCompanyOrInstitute(emptyObject)).toEqual(false) - }) - it('should return false for empty whoIsTheNotificationFor', () => { - expect(isRepresentativeOfCompanyOrInstitute(emptyRepresentative)).toEqual( - false, - ) - }) -}) - -describe('isInjuredAndRepresentativeOfCompanyOrInstitute', () => { - const representative: FormValue = { - isRepresentativeOfCompanyOrInstitute: YES, - } - - const notRepresentative: FormValue = { - isRepresentativeOfCompanyOrInstitute: NO, - } - - it('should return true for someone that is a representative of the company or institute', () => { - expect( - isInjuredAndRepresentativeOfCompanyOrInstitute(representative), - ).toEqual(true) - }) - - it('should return false for someone that isnt a representative of the company or institute', () => { - expect( - isInjuredAndRepresentativeOfCompanyOrInstitute(notRepresentative), - ).toEqual(false) - }) - - it('should return false for empty object', () => { - expect(isInjuredAndRepresentativeOfCompanyOrInstitute(emptyObject)).toEqual( - false, - ) - }) - - it('should return false for garbage string', () => { - expect( - isInjuredAndRepresentativeOfCompanyOrInstitute({ - isRepresentativeOfCompanyOrInstitute: 'garbage', - }), - ).toEqual(false) - }) - - it('should return false for object with non string value', () => { - expect( - isInjuredAndRepresentativeOfCompanyOrInstitute({ - isRepresentativeOfCompanyOrInstitute: true, - }), - ).toEqual(false) - }) -}) diff --git a/libs/application/templates/accident-notification/src/utils/isRepresentativeOfCompanyOrInstitute.ts b/libs/application/templates/accident-notification/src/utils/isRepresentativeOfCompanyOrInstitute.ts deleted file mode 100644 index f8c98b7b61f5..000000000000 --- a/libs/application/templates/accident-notification/src/utils/isRepresentativeOfCompanyOrInstitute.ts +++ /dev/null @@ -1,17 +0,0 @@ -import { getValueViaPath } from '@island.is/application/core' -import { FormValue } from '@island.is/application/types' -import { YES } from './constants' -import { WhoIsTheNotificationForEnum } from '../types' - -export const isRepresentativeOfCompanyOrInstitute = (formValue: FormValue) => { - return ( - getValueViaPath(formValue, 'whoIsTheNotificationFor.answer') === - WhoIsTheNotificationForEnum.JURIDICALPERSON - ) -} - -export const isInjuredAndRepresentativeOfCompanyOrInstitute = ( - formValue: FormValue, -) => { - return formValue.isRepresentativeOfCompanyOrInstitute?.toString() === YES -} diff --git a/libs/application/templates/accident-notification/src/utils/isRescueWorkAccident.spec.ts b/libs/application/templates/accident-notification/src/utils/isRescueWorkAccident.spec.ts deleted file mode 100644 index 1cdf033a88e6..000000000000 --- a/libs/application/templates/accident-notification/src/utils/isRescueWorkAccident.spec.ts +++ /dev/null @@ -1,24 +0,0 @@ -import { FormValue } from '@island.is/application/types' -import { AccidentTypeEnum } from '../types' -import { isRescueWorkAccident } from './isRescueWorkAccident' -describe('isRescueWorkAccident', () => { - const rescueWorkAccident: FormValue = { - accidentType: { radioButton: AccidentTypeEnum.RESCUEWORK }, - } - - const someOtherAccident: FormValue = { - accidentType: { radioButton: AccidentTypeEnum.HOMEACTIVITIES }, - } - - const emptyObject = {} - - it('should return true for rescue work accidents', () => { - expect(isRescueWorkAccident(rescueWorkAccident)).toEqual(true) - }) - it('should return false for accidents other than rescue work', () => { - expect(isRescueWorkAccident(someOtherAccident)).toEqual(false) - }) - it('should return false for empty object', () => { - expect(isRescueWorkAccident(emptyObject)).toEqual(false) - }) -}) diff --git a/libs/application/templates/accident-notification/src/utils/isRescueWorkAccident.ts b/libs/application/templates/accident-notification/src/utils/isRescueWorkAccident.ts deleted file mode 100644 index 2fd410280af8..000000000000 --- a/libs/application/templates/accident-notification/src/utils/isRescueWorkAccident.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { getValueViaPath } from '@island.is/application/core' -import { FormValue } from '@island.is/application/types' -import { AccidentTypeEnum } from '../types' - -export const isRescueWorkAccident = (formValue: FormValue) => { - const accidentType = getValueViaPath( - formValue, - 'accidentType.radioButton', - ) as AccidentTypeEnum - return accidentType === AccidentTypeEnum.RESCUEWORK -} diff --git a/libs/application/templates/accident-notification/src/utils/isSportAccidentAndEmployee.spec.ts b/libs/application/templates/accident-notification/src/utils/isSportAccidentAndEmployee.spec.ts deleted file mode 100644 index a095aa9370ef..000000000000 --- a/libs/application/templates/accident-notification/src/utils/isSportAccidentAndEmployee.spec.ts +++ /dev/null @@ -1,34 +0,0 @@ -import { FormValue } from '@island.is/application/types' -import { AccidentTypeEnum, WorkAccidentTypeEnum } from '../types' -import exp from 'constants' -import { isSportAccidentAndEmployee } from './isSportAccidentAndEmployee' -import { accidentType } from '../lib/messages' - -describe('isSportAccidentAndEmployee', () => { - const sportAccidentRadio: FormValue = { - accidentType: { radioButton: AccidentTypeEnum.SPORTS }, - onPayRoll: { answer: 'yes' }, - } - - const someOtherAccident: FormValue = { - workAccident: { type: AccidentTypeEnum.HOMEACTIVITIES }, - onPayRoll: { answer: 'yes' }, - } - - const notOnPayroll: FormValue = { - accidentType: { radioButton: AccidentTypeEnum.SPORTS }, - onPayRoll: { answer: 'no' }, - } - - it('should return true for sport accidents where the person is also an employee of the sports club', () => { - expect(isSportAccidentAndEmployee(sportAccidentRadio)).toEqual(true) - }) - - it('should return false for other accidents', () => { - expect(isSportAccidentAndEmployee(someOtherAccident)).toEqual(false) - }) - - it('should return false if the person is not on payroll', () => { - expect(isSportAccidentAndEmployee(notOnPayroll)).toEqual(false) - }) -}) diff --git a/libs/application/templates/accident-notification/src/utils/isSportAccidentAndEmployee.ts b/libs/application/templates/accident-notification/src/utils/isSportAccidentAndEmployee.ts deleted file mode 100644 index e214ce3c414f..000000000000 --- a/libs/application/templates/accident-notification/src/utils/isSportAccidentAndEmployee.ts +++ /dev/null @@ -1,19 +0,0 @@ -import { Answer, FormValue } from '@island.is/application/types' -import { AccidentTypeEnum, YesOrNo } from '../types' -import { getValueViaPath } from '@island.is/application/core' - -// When a person is hurt in a sports accident and is an employee of the sport, the accident -// is considered a work accident. This function checks if both conditions are met. -export const isSportAccidentAndEmployee = (formValue: FormValue): boolean => { - const workAccidentType = getValueViaPath( - formValue, - 'accidentType.radioButton', - ) as AccidentTypeEnum - const onPayRoll = getValueViaPath(formValue, 'onPayRoll.answer') as YesOrNo - - if (workAccidentType === AccidentTypeEnum.SPORTS && onPayRoll === 'yes') { - return true - } - - return false -} diff --git a/libs/application/templates/accident-notification/src/utils/isStudiesAccident.spec.ts b/libs/application/templates/accident-notification/src/utils/isStudiesAccident.spec.ts deleted file mode 100644 index b4e40c6e8e4e..000000000000 --- a/libs/application/templates/accident-notification/src/utils/isStudiesAccident.spec.ts +++ /dev/null @@ -1,24 +0,0 @@ -import { FormValue } from '@island.is/application/types' -import { AccidentTypeEnum } from '../types' -import { isStudiesAccident } from './isStudiesAccident' -describe('isStudiesAccident', () => { - const studiesAccident: FormValue = { - accidentType: { radioButton: AccidentTypeEnum.STUDIES }, - } - - const someOtherAccident: FormValue = { - accidentType: { radioButton: AccidentTypeEnum.HOMEACTIVITIES }, - } - - const emptyObject = {} - - it('should return true for studies accidents', () => { - expect(isStudiesAccident(studiesAccident)).toEqual(true) - }) - it('should return false for accidents other than studies', () => { - expect(isStudiesAccident(someOtherAccident)).toEqual(false) - }) - it('should return false for empty object', () => { - expect(isStudiesAccident(emptyObject)).toEqual(false) - }) -}) diff --git a/libs/application/templates/accident-notification/src/utils/isStudiesAccident.ts b/libs/application/templates/accident-notification/src/utils/isStudiesAccident.ts deleted file mode 100644 index 9de0fa5042f3..000000000000 --- a/libs/application/templates/accident-notification/src/utils/isStudiesAccident.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { getValueViaPath } from '@island.is/application/core' -import { FormValue } from '@island.is/application/types' -import { AccidentTypeEnum } from '../types' - -export const isStudiesAccident = (formValue: FormValue) => { - const accidentType = getValueViaPath( - formValue, - 'accidentType.radioButton', - ) as AccidentTypeEnum - return accidentType === AccidentTypeEnum.STUDIES -} diff --git a/libs/application/templates/accident-notification/src/utils/isUniqueAssignee.spec.ts b/libs/application/templates/accident-notification/src/utils/isUniqueAssignee.spec.ts deleted file mode 100644 index 707eeca6673b..000000000000 --- a/libs/application/templates/accident-notification/src/utils/isUniqueAssignee.spec.ts +++ /dev/null @@ -1,43 +0,0 @@ -import { FormValue } from '@island.is/application/types' -import { isUniqueAssignee } from './isUniqueAssignee' -describe('isUniqueAssignee', () => { - // Gervimenn nationalIds: - const applicant = '0101051450' - const assigneeSameAsApplicant = '0101051450' - const uniqueAssignee = '0102491479' - const isAssignee = true - - const applicationSameAsApplicant: FormValue = { - applicant: { - nationalId: applicant, - }, - representative: { - nationalId: assigneeSameAsApplicant, - }, - } - - const applicationUniqueAssignee: FormValue = { - applicant: { - nationalId: applicant, - }, - representative: { - nationalId: uniqueAssignee, - }, - } - - it('should return false for assignee that is the same as applicant', () => { - expect(isUniqueAssignee(applicationSameAsApplicant, isAssignee)).toEqual( - false, - ) - }) - it('should return true for assignee that is unique', () => { - expect(isUniqueAssignee(applicationUniqueAssignee, isAssignee)).toEqual( - true, - ) - }) - it('should return false for not being assignee', () => { - expect(isUniqueAssignee(applicationUniqueAssignee, !isAssignee)).toEqual( - false, - ) - }) -}) diff --git a/libs/application/templates/accident-notification/src/utils/isUniqueAssignee.ts b/libs/application/templates/accident-notification/src/utils/isUniqueAssignee.ts deleted file mode 100644 index b1ba7fe86444..000000000000 --- a/libs/application/templates/accident-notification/src/utils/isUniqueAssignee.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { getValueViaPath } from '@island.is/application/core' -import { FormValue } from '@island.is/application/types' - -export const isUniqueAssignee = ( - formValue: FormValue, - isAssignee: boolean, -): boolean => { - const applicant = getValueViaPath(formValue, 'applicant.nationalId') - const assignee = getValueViaPath(formValue, 'representative.nationalId') - const isSamePerson = applicant === assignee - - return !isSamePerson && isAssignee -} diff --git a/libs/application/templates/accident-notification/src/utils/isUploadNow.spec.ts b/libs/application/templates/accident-notification/src/utils/isUploadNow.spec.ts deleted file mode 100644 index f080cf0092e5..000000000000 --- a/libs/application/templates/accident-notification/src/utils/isUploadNow.spec.ts +++ /dev/null @@ -1,50 +0,0 @@ -import { FormValue } from '@island.is/application/types' -import { - PowerOfAttorneyUploadEnum, - WhoIsTheNotificationForEnum, -} from '../types' -import { isUploadNow } from './isUploadNow' - -describe('isUploadNow', () => { - const powerOfAttorneyReporterWithUploadNow: FormValue = { - whoIsTheNotificationFor: { - answer: WhoIsTheNotificationForEnum.POWEROFATTORNEY, - }, - powerOfAttorney: { - type: PowerOfAttorneyUploadEnum.UPLOADNOW, - }, - } - - const powerOfAttorneyReporterWithUploadLater: FormValue = { - whoIsTheNotificationFor: { - answer: WhoIsTheNotificationForEnum.POWEROFATTORNEY, - }, - powerOfAttorney: { - type: PowerOfAttorneyUploadEnum.UPLOADLATER, - }, - } - - const reportingForSelf: FormValue = { - whoIsTheNotificationFor: { - answer: WhoIsTheNotificationForEnum.ME, - }, - } - - const emptyObject = {} - - it('should return true for power of attorney reporter with upload now', () => { - expect(isUploadNow(powerOfAttorneyReporterWithUploadNow)).toEqual(true) - }) - - it('should return false for power of attorney reporter with upload later', () => { - expect(isUploadNow(powerOfAttorneyReporterWithUploadLater)).toEqual(false) - }) - - it('should return false for reporting for yourself', () => { - expect(isUploadNow(reportingForSelf)).toEqual(false) - }) - - it('should return false for empty object', () => { - expect(isUploadNow(emptyObject)).toEqual(false) - }) -}) diff --git a/libs/application/templates/accident-notification/src/utils/isUploadNow.ts b/libs/application/templates/accident-notification/src/utils/isUploadNow.ts deleted file mode 100644 index 94d87d93940a..000000000000 --- a/libs/application/templates/accident-notification/src/utils/isUploadNow.ts +++ /dev/null @@ -1,21 +0,0 @@ -import { getValueViaPath } from '@island.is/application/core' -import { FormValue } from '@island.is/application/types' -import { - PowerOfAttorneyUploadEnum, - WhoIsTheNotificationForEnum, -} from '../types' - -export const isUploadNow = (formValue: FormValue) => { - const whoIsTheNotificationFor = getValueViaPath( - formValue, - 'whoIsTheNotificationFor.answer', - ) as WhoIsTheNotificationForEnum - const powerOfAttorneyType = getValueViaPath( - formValue, - 'powerOfAttorney.type', - ) as PowerOfAttorneyUploadEnum - return ( - whoIsTheNotificationFor === WhoIsTheNotificationForEnum.POWEROFATTORNEY && - powerOfAttorneyType === PowerOfAttorneyUploadEnum.UPLOADNOW - ) -} diff --git a/libs/application/templates/accident-notification/src/utils/isWorkAccident.spec.ts b/libs/application/templates/accident-notification/src/utils/isWorkAccident.spec.ts deleted file mode 100644 index a3aaae308e53..000000000000 --- a/libs/application/templates/accident-notification/src/utils/isWorkAccident.spec.ts +++ /dev/null @@ -1,24 +0,0 @@ -import { FormValue } from '@island.is/application/types' -import { AccidentTypeEnum } from '../types' -import { isWorkAccident } from './isWorkAccident' -describe('isWorkAccident', () => { - const workAccident: FormValue = { - accidentType: { radioButton: AccidentTypeEnum.WORK }, - } - - const someOtherAccident: FormValue = { - accidentType: { radioButton: AccidentTypeEnum.HOMEACTIVITIES }, - } - - const emptyObject = {} - - it('should return true for work accidents', () => { - expect(isWorkAccident(workAccident)).toEqual(true) - }) - it('should return false for accidents other than work', () => { - expect(isWorkAccident(someOtherAccident)).toEqual(false) - }) - it('should return false for empty object', () => { - expect(isWorkAccident(emptyObject)).toEqual(false) - }) -}) diff --git a/libs/application/templates/accident-notification/src/utils/isWorkAccident.ts b/libs/application/templates/accident-notification/src/utils/isWorkAccident.ts deleted file mode 100644 index d88e055641be..000000000000 --- a/libs/application/templates/accident-notification/src/utils/isWorkAccident.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { getValueViaPath } from '@island.is/application/core' -import { FormValue } from '@island.is/application/types' -import { AccidentTypeEnum } from '../types' - -export const isWorkAccident = (formValue: FormValue) => { - const accidentType = getValueViaPath( - formValue, - 'accidentType.radioButton', - ) as AccidentTypeEnum - return accidentType === AccidentTypeEnum.WORK -} diff --git a/libs/application/templates/accident-notification/src/utils/miscUtils.spec.ts b/libs/application/templates/accident-notification/src/utils/miscUtils.spec.ts new file mode 100644 index 000000000000..a415c9b0cc91 --- /dev/null +++ b/libs/application/templates/accident-notification/src/utils/miscUtils.spec.ts @@ -0,0 +1,313 @@ +import { + formatPhonenumber, + hasReceivedConfirmation, + hideLocationAndPurpose, + isHealthInsured, + isInjuredAndRepresentativeOfCompanyOrInstitute, + isPowerOfAttorney, + isRepresentativeOfCompanyOrInstitute, + isUniqueAssignee, + shouldRequestReview, +} from './miscUtils' +import { FormValue, NO, YES } from '@island.is/application/types' +import { + AccidentTypeEnum, + GeneralWorkplaceAccidentLocationEnum, + StudiesAccidentLocationEnum, + WhoIsTheNotificationForEnum, + WorkAccidentTypeEnum, +} from '../types' +import { AccidentNotificationAnswers } from '..' + +describe('formatPhonenumber', () => { + it.each([ + { input: '1234567', expected: '123-4567' }, + { input: '1234567891011', expected: '123-4567891011' }, + { input: 'ABCDEF@!()', expected: 'ABC-DEF@!()' }, + { input: '123', expected: '123' }, + ])('should format phone number', ({ input, expected }) => { + const result = formatPhonenumber(input) + expect(result).toBe(expected) + }) +}) + +describe('hasReceivedConfirmation', () => { + const confirmedJuridicial: FormValue = { + whoIsTheNotificationFor: { + answer: WhoIsTheNotificationForEnum.JURIDICALPERSON, + }, + accidentStatus: { + receivedConfirmations: { + InjuredOrRepresentativeParty: true, + }, + }, + } + + const confirmedMe: FormValue = { + whoIsTheNotificationFor: { + answer: WhoIsTheNotificationForEnum.ME, + }, + accidentStatus: { + receivedConfirmations: { + CompanyParty: true, + }, + }, + } + + const notConfirmed: FormValue = { + accidentStatus: { + receivedConfirmations: false, + }, + } + + it.each([ + { for: 'juridical person', input: confirmedJuridicial, expected: true }, + { for: 'company', input: confirmedMe, expected: true }, + { for: 'not confirmed', input: notConfirmed, expected: false }, + ])( + 'should return $expected when confirmation is $for', + ({ input, expected }) => { + expect(hasReceivedConfirmation(input)).toEqual(expected) + }, + ) +}) + +describe('hideLocationAndPurpose', () => { + const accidentLocationAtWorkplace: FormValue = { + accidentLocation: { + answer: GeneralWorkplaceAccidentLocationEnum.ATTHEWORKPLACE, + }, + } + + const accidentLocationAtSchoole: FormValue = { + accidentLocation: { answer: StudiesAccidentLocationEnum.ATTHESCHOOL }, + } + + const someOtherLocation: FormValue = { + accidentLocation: { answer: GeneralWorkplaceAccidentLocationEnum.OTHER }, + } + + const emptyObject = {} + + it('should return true for accident location at workplace', () => { + expect(hideLocationAndPurpose(accidentLocationAtWorkplace)).toEqual(true) + }) + it('should return true for accident location at school', () => { + expect(hideLocationAndPurpose(accidentLocationAtSchoole)).toEqual(true) + }) + it('should return false for accident location elsewhere', () => { + expect(hideLocationAndPurpose(someOtherLocation)).toEqual(false) + }) + it('should return false for empty object', () => { + expect(hideLocationAndPurpose(emptyObject)).toEqual(false) + }) +}) + +describe('isHealthInsured', () => { + const healthInsured = { + accidentDetails: { + isHealthInsured: 'yes', + }, + } + + const notHealthInsured = { + accidentDetails: { + isHealthInsured: 'no', + }, + } + + it('should return true when health insured is yes', () => { + expect(isHealthInsured(healthInsured)).toEqual(true) + }) + + it('should return false when health insured is no', () => { + expect(isHealthInsured(notHealthInsured)).toEqual(false) + }) + + it('should return true when health insured is undefined', () => { + expect(isHealthInsured({})).toEqual(true) + }) +}) + +describe('isPowerOfAttorney', () => { + const powerOfAttorneyReporter: FormValue = { + whoIsTheNotificationFor: { + answer: WhoIsTheNotificationForEnum.POWEROFATTORNEY, + }, + } + + const juridicialPersonReporter: FormValue = { + whoIsTheNotificationFor: { + answer: WhoIsTheNotificationForEnum.JURIDICALPERSON, + }, + } + + const reportingForSelf: FormValue = { + whoIsTheNotificationFor: { answer: WhoIsTheNotificationForEnum.ME }, + } + + const emptyObject = {} + + it('should return true for power of attorney reporter', () => { + expect(isPowerOfAttorney(powerOfAttorneyReporter)).toEqual(true) + }) + + it('should return false for power of juridical person reporter', () => { + expect(isPowerOfAttorney(juridicialPersonReporter)).toEqual(false) + }) + + it('should return false for reporting for yourself', () => { + expect(isPowerOfAttorney(reportingForSelf)).toEqual(false) + }) + + it('should return false for empty object', () => { + expect(isPowerOfAttorney(emptyObject)).toEqual(false) + }) +}) + +describe('isRepresentativeOfCompanyOrInstitute', () => { + const representative: FormValue = { + whoIsTheNotificationFor: { + answer: WhoIsTheNotificationForEnum.JURIDICALPERSON, + }, + } + + const notRepresentative: FormValue = { + whoIsTheNotificationFor: { + answer: WhoIsTheNotificationForEnum.ME, + }, + } + + const emptyRepresentative: FormValue = { + whoIsTheNotificationFor: {}, + } + + it('should return true for someone that is a representative of the company or institue', () => { + expect(isRepresentativeOfCompanyOrInstitute(representative)).toEqual(true) + }) + it('should return false for someone that isnt a representative of the company or institue', () => { + expect(isRepresentativeOfCompanyOrInstitute(notRepresentative)).toEqual( + false, + ) + }) + it('should return false for empty object', () => { + expect(isRepresentativeOfCompanyOrInstitute(emptyObject)).toEqual(false) + }) + it('should return false for empty whoIsTheNotificationFor', () => { + expect(isRepresentativeOfCompanyOrInstitute(emptyRepresentative)).toEqual( + false, + ) + }) +}) + +const emptyObject = {} + +describe('isInjuredAndRepresentativeOfCompanyOrInstitute', () => { + const representative: FormValue = { + isRepresentativeOfCompanyOrInstitute: YES, + } + + const notRepresentative: FormValue = { + isRepresentativeOfCompanyOrInstitute: NO, + } + + it('should return true for someone that is a representative of the company or institute', () => { + expect( + isInjuredAndRepresentativeOfCompanyOrInstitute(representative), + ).toEqual(true) + }) + + it('should return false for someone that isnt a representative of the company or institute', () => { + expect( + isInjuredAndRepresentativeOfCompanyOrInstitute(notRepresentative), + ).toEqual(false) + }) + + it('should return false for empty object', () => { + expect(isInjuredAndRepresentativeOfCompanyOrInstitute(emptyObject)).toEqual( + false, + ) + }) + + it('should return false for garbage string', () => { + expect( + isInjuredAndRepresentativeOfCompanyOrInstitute({ + isRepresentativeOfCompanyOrInstitute: 'garbage', + }), + ).toEqual(false) + }) + + it('should return false for object with non string value', () => { + expect( + isInjuredAndRepresentativeOfCompanyOrInstitute({ + isRepresentativeOfCompanyOrInstitute: true, + }), + ).toEqual(false) + }) +}) + +describe('isUniqueAssignee', () => { + // Gervimenn nationalIds: + const applicant = '0101051450' + const assigneeSameAsApplicant = '0101051450' + const uniqueAssignee = '0102491479' + const isAssignee = true + + const applicationSameAsApplicant: FormValue = { + applicant: { + nationalId: applicant, + }, + representative: { + nationalId: assigneeSameAsApplicant, + }, + } + + const applicationUniqueAssignee: FormValue = { + applicant: { + nationalId: applicant, + }, + representative: { + nationalId: uniqueAssignee, + }, + } + + it('should return false for assignee that is the same as applicant', () => { + expect(isUniqueAssignee(applicationSameAsApplicant, isAssignee)).toEqual( + false, + ) + }) + it('should return true for assignee that is unique', () => { + expect(isUniqueAssignee(applicationUniqueAssignee, isAssignee)).toEqual( + true, + ) + }) + it('should return false for not being assignee', () => { + expect(isUniqueAssignee(applicationUniqueAssignee, !isAssignee)).toEqual( + false, + ) + }) +}) + +describe('shouldRequestReview', () => { + const agricultureAccident: Partial = { + workAccident: { type: WorkAccidentTypeEnum.AGRICULTURE }, + } + + const accidentAtHome: Partial = { + accidentType: { radioButton: AccidentTypeEnum.HOMEACTIVITIES }, + } + + const normalWorkAccident: Partial = { + workAccident: { type: WorkAccidentTypeEnum.GENERAL }, + } + + it('should return false for work accidents', () => { + expect(shouldRequestReview(agricultureAccident)).toEqual(false) + }) + it('should return true for general work accident', () => { + expect(shouldRequestReview(normalWorkAccident)).toEqual(true) + }) + it('should return false for home accident', () => { + expect(shouldRequestReview(accidentAtHome)).toEqual(false) + }) +}) diff --git a/libs/application/templates/accident-notification/src/utils/miscUtils.ts b/libs/application/templates/accident-notification/src/utils/miscUtils.ts new file mode 100644 index 000000000000..bee5dd87bf40 --- /dev/null +++ b/libs/application/templates/accident-notification/src/utils/miscUtils.ts @@ -0,0 +1,134 @@ +import { AccidentNotificationConfirmation } from '@island.is/api/schema' +import { getValueViaPath } from '@island.is/application/core' +import { FormValue, YES } from '@island.is/application/types' +import { isReportingOnBehalfOfEmployee as isReportingOnBehalfOfEmployeeOrginal } from './reportingUtils' +import { + GeneralWorkplaceAccidentLocationEnum, + ProfessionalAthleteAccidentLocationEnum, + StudiesAccidentLocationEnum, + WhoIsTheNotificationForEnum, + WorkAccidentTypeEnum, + YesOrNo, +} from '../types' +import { + getInjuredPersonInformation as getInjuredPersonInformationOrginal, + isHomeActivitiesAccident, +} from './accidentUtils' +import { AccidentNotificationAnswers } from '..' +import { + getWorkplaceData as getWorkplaceDataOrginal, + isOfWorkAccidentType, +} from './occupationUtils' + +export const formatPhonenumber = (value: string) => { + const splitAt = (index: number) => (x: string) => + [x.slice(0, index), x.slice(index)] + if (value.length > 3) return splitAt(3)(value).join('-') + return value +} + +export const hasReceivedConfirmation = (answers: FormValue) => { + const accidentConfirmations = getValueViaPath( + answers, + 'accidentStatus.receivedConfirmations', + ) as AccidentNotificationConfirmation + + // if juridical person then the injured or the power of attorney holder has to confirm + if (isReportingOnBehalfOfEmployee(answers)) { + return !!accidentConfirmations.InjuredOrRepresentativeParty + } + + // as there isn't an juridical person reporting, this must be someone reporting for the injured + // or the injured himself and that requires the companies confirmation + return !!accidentConfirmations.CompanyParty +} + +// Location and purpose of accident only relevant in work and studies and never in home +// activities +export const hideLocationAndPurpose = (formValue: FormValue) => { + const answer = getValueViaPath(formValue, 'accidentLocation.answer') as + | GeneralWorkplaceAccidentLocationEnum + | StudiesAccidentLocationEnum + | ProfessionalAthleteAccidentLocationEnum + + if (isHomeActivitiesAccident(formValue)) { + return true + } + return ( + answer === GeneralWorkplaceAccidentLocationEnum.ATTHEWORKPLACE || + answer === StudiesAccidentLocationEnum.ATTHESCHOOL || + answer === ProfessionalAthleteAccidentLocationEnum.SPORTCLUBSFACILITES + ) +} + +export const isHealthInsured = (formValue: FormValue) => { + const isHealthInsured = getValueViaPath( + formValue, + 'accidentDetails.isHealthInsured', + ) + if (isHealthInsured === undefined) return true + return isHealthInsured === 'yes' +} + +export const isPowerOfAttorney = (formValue: FormValue) => { + const reportingOnBehalfType = getValueViaPath( + formValue, + 'whoIsTheNotificationFor.answer', + ) + return reportingOnBehalfType === WhoIsTheNotificationForEnum.POWEROFATTORNEY +} + +export const isRepresentativeOfCompanyOrInstitute = (formValue: FormValue) => { + return ( + getValueViaPath( + formValue, + 'whoIsTheNotificationFor.answer', + ) === WhoIsTheNotificationForEnum.JURIDICALPERSON + ) +} + +export const isInjuredAndRepresentativeOfCompanyOrInstitute = ( + formValue: FormValue, +) => { + return formValue.isRepresentativeOfCompanyOrInstitute?.toString() === YES +} + +export const isUniqueAssignee = ( + formValue: FormValue, + isAssignee: boolean, +): boolean => { + const applicant = getValueViaPath(formValue, 'applicant.nationalId') + const assignee = getValueViaPath( + formValue, + 'representative.nationalId', + ) + const isSamePerson = applicant === assignee + + return !isSamePerson && isAssignee +} + +export const shouldRequestReview = ( + answers: Partial, +): boolean => { + const ishome = isHomeActivitiesAccident(answers) + const isAgriculture = isOfWorkAccidentType( + answers, + WorkAccidentTypeEnum.AGRICULTURE, + ) + + const isEitherHomeOrAgriculture = ishome || isAgriculture + + return !isEitherHomeOrAgriculture +} + +export const isReportingOnBehalfOfEmployee = (answers: FormValue) => { + return isReportingOnBehalfOfEmployeeOrginal(answers) +} + +export const getWorkplaceData = (answers: FormValue) => { + return getWorkplaceDataOrginal(answers) +} + +export const getInjuredPersonInformation = (answers: FormValue) => { + return getInjuredPersonInformationOrginal(answers) +} diff --git a/libs/application/templates/accident-notification/src/utils/occupationUtils.spec.ts b/libs/application/templates/accident-notification/src/utils/occupationUtils.spec.ts new file mode 100644 index 000000000000..4a76aafb7521 --- /dev/null +++ b/libs/application/templates/accident-notification/src/utils/occupationUtils.spec.ts @@ -0,0 +1,312 @@ +import { FormValue, NO, YES } from '@island.is/application/types' +import { + AccidentTypeEnum, + FishermanWorkplaceAccidentLocationEnum, + StudiesAccidentTypeEnum, + WorkAccidentTypeEnum, +} from '../types' +import { + getWorkplaceData, + isAboardShip, + isAgricultureAccident, + isFishermanAccident, + isGeneralWorkplaceAccident, + isInternshipStudiesAccident, + isMachineRelatedAccident, + isProfessionalAthleteAccident, + isSportAccidentAndEmployee, +} from './occupationUtils' + +describe('isAboardShip', () => { + const onTheShipLocation: FormValue = { + accidentLocation: { + answer: FishermanWorkplaceAccidentLocationEnum.ONTHESHIP, + }, + workAccident: { type: WorkAccidentTypeEnum.FISHERMAN }, + accidentType: { radioButton: AccidentTypeEnum.WORK }, + } + + const someOtherLocation: FormValue = { + accidentLocation: { answer: FishermanWorkplaceAccidentLocationEnum.OTHER }, + workAccident: { type: WorkAccidentTypeEnum.FISHERMAN }, + accidentType: { radioButton: AccidentTypeEnum.WORK }, + } + + const emptyObject = {} + + it('should return true for fisherman work accident that happens on a ship', () => { + expect(isAboardShip(onTheShipLocation)).toEqual(true) + }) + it('should return false for fisherman work accident that happens else where', () => { + expect(isAboardShip(someOtherLocation)).toEqual(false) + }) + it('should return false for empty object', () => { + expect(isAboardShip(emptyObject)).toEqual(false) + }) +}) + +describe('getWorkplaceData', () => { + const generalWorkplaceAccident: FormValue = { + workAccident: { type: WorkAccidentTypeEnum.GENERAL }, + accidentType: { radioButton: AccidentTypeEnum.WORK }, + companyInfo: {}, + } + + const professionalAthleteAccident: FormValue = { + accidentType: { radioButton: AccidentTypeEnum.SPORTS }, + companyInfo: { onPayRoll: { answer: YES } }, + } + + const rescueWorkAccident: FormValue = { + accidentType: { radioButton: AccidentTypeEnum.RESCUEWORK }, + } + + const studiesAccident: FormValue = { + accidentType: { radioButton: AccidentTypeEnum.STUDIES }, + } + + const fishermanAccident: FormValue = { + workAccident: { type: WorkAccidentTypeEnum.FISHERMAN }, + accidentType: { radioButton: AccidentTypeEnum.WORK }, + } + + const emptyObject = {} + + it('should return general work type data for general work accidents', () => { + expect(getWorkplaceData(generalWorkplaceAccident)?.type).toEqual( + AccidentTypeEnum.WORK, + ) + }) + + it('should return sports type data for professional athlete accidents', () => { + expect(getWorkplaceData(professionalAthleteAccident)?.type).toEqual( + AccidentTypeEnum.SPORTS, + ) + }) + + it('should return employee information for professional athlete accidents', () => { + expect( + getWorkplaceData(professionalAthleteAccident)?.companyInfo.onPayRoll + ?.answer, + ).toBe(YES) + }) + + it('should not return employee information for general workplace accident', () => { + expect( + getWorkplaceData(generalWorkplaceAccident)?.companyInfo.onPayRoll, + ).toBe(undefined) + }) + + it('should return rescue work type data for rescue work accidents', () => { + expect(getWorkplaceData(rescueWorkAccident)?.type).toEqual( + AccidentTypeEnum.RESCUEWORK, + ) + }) + + it('should return studies type data for student accidents', () => { + expect(getWorkplaceData(studiesAccident)?.type).toEqual( + AccidentTypeEnum.STUDIES, + ) + }) + + it('should return fisherman type data for fisherman accidents', () => { + expect(getWorkplaceData(fishermanAccident)?.type).toEqual( + WorkAccidentTypeEnum.FISHERMAN, + ) + }) + + it('should return undefined for empty object', () => { + expect(getWorkplaceData(emptyObject)?.type).toEqual(undefined) + }) +}) + +describe('isInternshipStudiesAccident', () => { + const studiesAccidentType: FormValue = { + studiesAccident: { type: StudiesAccidentTypeEnum.INTERNSHIP }, + } + + const someOtherAccidentType: FormValue = { + studiesAccident: { type: StudiesAccidentTypeEnum.APPRENTICESHIP }, + } + + const emptyObject = {} + + it('should return true for studies accidents', () => { + expect(isInternshipStudiesAccident(studiesAccidentType)).toEqual(true) + }) + it('should return false for accidents other than studies', () => { + expect(isInternshipStudiesAccident(someOtherAccidentType)).toEqual(false) + }) + it('should return false for empty object', () => { + expect(isInternshipStudiesAccident(emptyObject)).toEqual(false) + }) +}) + +describe('isMachineRelatedAccident', () => { + const machineRelatedAccident: FormValue = { + workAccident: { type: WorkAccidentTypeEnum.GENERAL }, + accidentType: { radioButton: AccidentTypeEnum.WORK }, + workMachineRadio: YES, + } + + const nonMachineRelatedAccident: FormValue = { + workAccident: { type: WorkAccidentTypeEnum.GENERAL }, + accidentType: { radioButton: AccidentTypeEnum.WORK }, + workMachineRadio: NO, + } + + const someOtherAccident: FormValue = { + workAccident: { type: WorkAccidentTypeEnum.PROFESSIONALATHLETE }, + } + + const emptyObject = {} + + it('should return true for machine related general work accidents', () => { + expect(isMachineRelatedAccident(machineRelatedAccident)).toEqual(true) + }) + it('should return false for non machine related general work accidents', () => { + expect(isMachineRelatedAccident(nonMachineRelatedAccident)).toEqual(false) + }) + it('should return false for workplace accidents other than general', () => { + expect(isMachineRelatedAccident(someOtherAccident)).toEqual(false) + }) + it('should return false for empty object', () => { + expect(isMachineRelatedAccident(emptyObject)).toEqual(false) + }) +}) + +describe('isSportAccidentAndEmployee', () => { + const sportAccidentRadio: FormValue = { + accidentType: { radioButton: AccidentTypeEnum.SPORTS }, + onPayRoll: { answer: 'yes' }, + } + + const someOtherAccident: FormValue = { + workAccident: { type: AccidentTypeEnum.HOMEACTIVITIES }, + onPayRoll: { answer: 'yes' }, + } + + const notOnPayroll: FormValue = { + accidentType: { radioButton: AccidentTypeEnum.SPORTS }, + onPayRoll: { answer: 'no' }, + } + + it('should return true for sport accidents where the person is also an employee of the sports club', () => { + expect(isSportAccidentAndEmployee(sportAccidentRadio)).toEqual(true) + }) + + it('should return false for other accidents', () => { + expect(isSportAccidentAndEmployee(someOtherAccident)).toEqual(false) + }) + + it('should return false if the person is not on payroll', () => { + expect(isSportAccidentAndEmployee(notOnPayroll)).toEqual(false) + }) +}) + +describe('isFishermanAccident', () => { + const fishermanAccident: FormValue = { + workAccident: { type: WorkAccidentTypeEnum.FISHERMAN }, + accidentType: { radioButton: AccidentTypeEnum.WORK }, + } + + const someOtherAccident: FormValue = { + workAccident: { type: WorkAccidentTypeEnum.PROFESSIONALATHLETE }, + } + + const emptyObject = {} + + it('should return true for fisherman accidents', () => { + expect(isFishermanAccident(fishermanAccident)).toEqual(true) + }) + it('should return false for workplace accidents other than fisherman', () => { + expect(isFishermanAccident(someOtherAccident)).toEqual(false) + }) + it('should return false for empty object', () => { + expect(isFishermanAccident(emptyObject)).toEqual(false) + }) +}) + +describe('isAgricultureAccident', () => { + const agricultureAccident: FormValue = { + workAccident: { type: WorkAccidentTypeEnum.AGRICULTURE }, + accidentType: { radioButton: AccidentTypeEnum.WORK }, + } + + const someOtherAccident: FormValue = { + workAccident: { type: WorkAccidentTypeEnum.PROFESSIONALATHLETE }, + } + + const emptyObject = {} + + it('should return true for agriculture accidents', () => { + expect(isAgricultureAccident(agricultureAccident)).toEqual(true) + }) + it('should return false for workplace accidents other than agriculture', () => { + expect(isAgricultureAccident(someOtherAccident)).toEqual(false) + }) + it('should return false for empty object', () => { + expect(isAgricultureAccident(emptyObject)).toEqual(false) + }) +}) + +describe('isProfessionalAthleteAccident', () => { + const professionalAthleteAccidentRadio: FormValue = { + accidentType: { radioButton: AccidentTypeEnum.SPORTS }, + } + + const professionalAthleteAccidentSecondaryWorkQuestion: FormValue = { + workAccident: { type: WorkAccidentTypeEnum.PROFESSIONALATHLETE }, + accidentType: { radioButton: AccidentTypeEnum.WORK }, + } + + const someOtherAccident: FormValue = { + workAccident: { type: WorkAccidentTypeEnum.FISHERMAN }, + } + + const emptyObject = {} + + it('should return true for professional athlete accidents', () => { + expect( + isProfessionalAthleteAccident(professionalAthleteAccidentRadio), + ).toEqual(true) + }) + + it('should return true for professional athlete accident when user picked work related and then sports related', () => { + expect( + isProfessionalAthleteAccident( + professionalAthleteAccidentSecondaryWorkQuestion, + ), + ).toEqual(true) + }) + + it('should return false for workplace accidents other than professional athlete', () => { + expect(isProfessionalAthleteAccident(someOtherAccident)).toEqual(false) + }) + it('should return false for empty object', () => { + expect(isProfessionalAthleteAccident(emptyObject)).toEqual(false) + }) +}) + +describe('isGeneralWorkplaceAccident', () => { + const generalWorkplaceAccident: FormValue = { + workAccident: { type: WorkAccidentTypeEnum.GENERAL }, + accidentType: { radioButton: AccidentTypeEnum.WORK }, + } + + const someOtherAccident: FormValue = { + workAccident: { type: WorkAccidentTypeEnum.PROFESSIONALATHLETE }, + } + + const emptyObject = {} + + it('should return true for general workplace accidents', () => { + expect(isGeneralWorkplaceAccident(generalWorkplaceAccident)).toEqual(true) + }) + it('should return false for workplace accidents other than general', () => { + expect(isGeneralWorkplaceAccident(someOtherAccident)).toEqual(false) + }) + it('should return false for empty object', () => { + expect(isGeneralWorkplaceAccident(emptyObject)).toEqual(false) + }) +}) diff --git a/libs/application/templates/accident-notification/src/utils/occupationUtils.ts b/libs/application/templates/accident-notification/src/utils/occupationUtils.ts new file mode 100644 index 000000000000..79351222b877 --- /dev/null +++ b/libs/application/templates/accident-notification/src/utils/occupationUtils.ts @@ -0,0 +1,203 @@ +import { getValueViaPath, YES } from '@island.is/application/core' +import { FormValue } from '@island.is/application/types' +import { + AccidentTypeEnum, + CompanyInfo, + FishermanWorkplaceAccidentLocationEnum, + RepresentativeInfo, + StudiesAccidentTypeEnum, + WorkAccidentTypeEnum, + WorkplaceData, + YesOrNo, +} from '../types' +import { + isHomeActivitiesAccident, + isRescueWorkAccident, + isStudiesAccident, + isWorkAccident, +} from './accidentUtils' +import { + companyInfo, + fishingCompanyInfo, + representativeInfo, + rescueSquadInfo, + schoolInfo, + sportsClubInfo, +} from '../lib/messages' +import { AccidentNotificationAnswers } from '..' + +// As this is a third question the user is asked there is a case where he could go back +// and select home activities and keep the workaccident type or go back and change where the +// accident happened. +// Therefore we need to check ifFishermanAccident function again +export const isAboardShip = (formValue: FormValue) => { + const fishermanWorkplaceAccidentLocationAnswer = + getValueViaPath( + formValue, + 'accidentLocation.answer', + ) + return ( + isFishermanAccident(formValue) && + fishermanWorkplaceAccidentLocationAnswer === + FishermanWorkplaceAccidentLocationEnum.ONTHESHIP + ) +} + +export const getWorkplaceData = ( + answers: FormValue, +): WorkplaceData | undefined => { + if (isHomeActivitiesAccident(answers)) { + return + } + + const workplaceData = { + companyInfo: getValueViaPath(answers, 'companyInfo'), + representitive: getValueViaPath( + answers, + 'representative', + ), + representitiveMsg: representativeInfo, + } as WorkplaceData + + if (isGeneralWorkplaceAccident(answers)) + return { + ...workplaceData, + companyInfoMsg: companyInfo, + type: AccidentTypeEnum.WORK, + screenId: 'companyInfo', + } + + if (isStudiesAccident(answers)) + return { + ...workplaceData, + companyInfoMsg: schoolInfo, + type: AccidentTypeEnum.STUDIES, + screenId: 'schoolInfo', + } + + if (isFishermanAccident(answers)) + return { + ...workplaceData, + companyInfoMsg: fishingCompanyInfo, + type: WorkAccidentTypeEnum.FISHERMAN, + screenId: 'fishingCompanyInfo', + } + + if (isProfessionalAthleteAccident(answers)) + return { + ...workplaceData, + onPayRoll: getValueViaPath(answers, 'onPayRoll.answer'), + companyInfoMsg: sportsClubInfo, + type: AccidentTypeEnum.SPORTS, + screenId: 'sportsClubInfo', + } + + if (isRescueWorkAccident(answers)) + return { + ...workplaceData, + companyInfoMsg: rescueSquadInfo, + type: AccidentTypeEnum.RESCUEWORK, + screenId: 'rescueSquad', + } +} + +export const isInternshipStudiesAccident = (formValue: FormValue) => { + const studiesAccidentType = getValueViaPath( + formValue, + 'studiesAccident.type', + ) + return studiesAccidentType === StudiesAccidentTypeEnum.INTERNSHIP +} + +export const isMachineRelatedAccident = (formValue: FormValue) => { + const workMachineAnswer = getValueViaPath( + formValue, + 'workMachineRadio', + ) + return isGeneralWorkplaceAccident(formValue) && workMachineAnswer === YES +} + +// When a person is hurt in a sports accident and is an employee of the sport, the accident +// is considered a work accident. This function checks if both conditions are met. +export const isSportAccidentAndEmployee = (formValue: FormValue): boolean => { + const workAccidentType = getValueViaPath( + formValue, + 'accidentType.radioButton', + ) as AccidentTypeEnum + const onPayRoll = getValueViaPath(formValue, 'onPayRoll.answer') as YesOrNo + + if (workAccidentType === AccidentTypeEnum.SPORTS && onPayRoll === 'yes') { + return true + } + + return false +} + +// As this is a second question the user is asked there is a case where he could go back and select home activities and keep the workaccident type. +// Therefore we need to check also whether this is a work accident +export const isFishermanAccident = (formValue: FormValue) => { + const workAccidentType = getValueViaPath( + formValue, + 'workAccident.type', + ) + return ( + workAccidentType === WorkAccidentTypeEnum.FISHERMAN && + isWorkAccident(formValue) + ) +} + +// As this is a second question the user is asked there is a case where he could go back and select home activities and keep the agriculture type. +// Therefore we need to check also whether this is a work accident +export const isAgricultureAccident = (formValue: FormValue) => { + const workAccidentType = getValueViaPath( + formValue, + 'workAccident.type', + ) + return ( + workAccidentType === WorkAccidentTypeEnum.AGRICULTURE && + isWorkAccident(formValue) + ) +} + +// Specific case check here since the accident can be a sports accident if he picks sports in the first question where +// he is asked what the circumstances of the accident were. But that user could also select work and then a sport related +// accident since the question can be missunderstood by the user so we are funneling both cases into the same flow +export const isProfessionalAthleteAccident = (formValue: FormValue) => { + const workAccidentType = getValueViaPath( + formValue, + 'accidentType.radioButton', + ) + const workAccidentSecondaryType = getValueViaPath( + formValue, + 'workAccident.type', + ) + return ( + workAccidentType === AccidentTypeEnum.SPORTS || + (workAccidentSecondaryType === WorkAccidentTypeEnum.PROFESSIONALATHLETE && + isWorkAccident(formValue)) + ) +} + +// As this is a second question the user is asked there is a case where he could go back and select home activities and keep the workaccident type. +// Therefore we need to check also whether this is a work accident +export const isGeneralWorkplaceAccident = (formValue: FormValue) => { + const workAccidentType = getValueViaPath( + formValue, + 'workAccident.type', + ) + return ( + workAccidentType === WorkAccidentTypeEnum.GENERAL && + isWorkAccident(formValue) + ) +} + +export const isOfWorkAccidentType = ( + answers: Partial, + type: WorkAccidentTypeEnum, +) => { + const workAccidentType = getValueViaPath( + answers, + 'workAccident.type', + ) + return workAccidentType === type +} diff --git a/libs/application/templates/accident-notification/src/utils/reportingUtils.spec.ts b/libs/application/templates/accident-notification/src/utils/reportingUtils.spec.ts new file mode 100644 index 000000000000..1cad36fc260c --- /dev/null +++ b/libs/application/templates/accident-notification/src/utils/reportingUtils.spec.ts @@ -0,0 +1,122 @@ +import { FormValue } from '@island.is/application/types' +import { WhoIsTheNotificationForEnum } from '../types' +import { + isReportingOnBehalfOfChild, + isReportingOnBehalfOfEmployee, + isReportingOnBehalfOfInjured, + isReportingOnBehalfSelf, +} from './reportingUtils' + +describe('isReportingOnBehalfOfInjured', () => { + const powerOfAttorneyReporter: FormValue = { + whoIsTheNotificationFor: { + answer: WhoIsTheNotificationForEnum.POWEROFATTORNEY, + }, + } + + const juridicialPersonReporter: FormValue = { + whoIsTheNotificationFor: { + answer: WhoIsTheNotificationForEnum.JURIDICALPERSON, + }, + } + + const reportingForSelf: FormValue = { + whoIsTheNotificationFor: { answer: WhoIsTheNotificationForEnum.ME }, + } + + const emptyObject = {} + + it('should return true for power of attorney reporter', () => { + expect(isReportingOnBehalfOfInjured(powerOfAttorneyReporter)).toEqual(true) + }) + + it('should return true for power of juridical person reporter', () => { + expect(isReportingOnBehalfOfInjured(juridicialPersonReporter)).toEqual(true) + }) + + it('should return false for reporting for yourself', () => { + expect(isReportingOnBehalfOfInjured(reportingForSelf)).toEqual(false) + }) + + it('should return false for empty object', () => { + expect(isReportingOnBehalfOfInjured(emptyObject)).toEqual(false) + }) +}) + +describe('isReportingOnBehalfOfEmployee', () => { + const onBehalfOfEmployee: FormValue = { + whoIsTheNotificationFor: { + answer: WhoIsTheNotificationForEnum.JURIDICALPERSON, + }, + } + + const onBehalfOfSomeOtherPerson: FormValue = { + whoIsTheNotificationFor: { + answer: WhoIsTheNotificationForEnum.POWEROFATTORNEY, + }, + } + + const emptyObject = {} + + it('should return true if reporting on behalf of employee', () => { + expect(isReportingOnBehalfOfEmployee(onBehalfOfEmployee)).toEqual(true) + }) + it('should return false if reporting on behalf of some other person', () => { + expect(isReportingOnBehalfOfEmployee(onBehalfOfSomeOtherPerson)).toEqual( + false, + ) + }) + it('should return false for empty object', () => { + expect(isReportingOnBehalfOfEmployee(emptyObject)).toEqual(false) + }) +}) + +describe('isReportingOnBehalfOfChild', () => { + const onBehalfOfChild: FormValue = { + whoIsTheNotificationFor: { + answer: WhoIsTheNotificationForEnum.CHILDINCUSTODY, + }, + } + + const onBehalfOfSomeOtherPerson: FormValue = { + whoIsTheNotificationFor: { + answer: WhoIsTheNotificationForEnum.POWEROFATTORNEY, + }, + } + + const emptyObject = {} + + it('should return true if reporting on behalf of child', () => { + expect(isReportingOnBehalfOfChild(onBehalfOfChild)).toEqual(true) + }) + it('should return false if reporting on behalf of some other person', () => { + expect(isReportingOnBehalfOfChild(onBehalfOfSomeOtherPerson)).toEqual(false) + }) + it('should return false for empty object', () => { + expect(isReportingOnBehalfOfChild(emptyObject)).toEqual(false) + }) +}) + +describe('isRepresentativeOfCompanyOrInstitute', () => { + const self: FormValue = { + whoIsTheNotificationFor: { + answer: WhoIsTheNotificationForEnum.ME, + }, + } + + const notSelf: FormValue = { + whoIsTheNotificationFor: { + answer: WhoIsTheNotificationForEnum.POWEROFATTORNEY, + }, + } + + it('should return true when someone is reporting on behalf of themselves', () => { + expect(isReportingOnBehalfSelf(self)).toEqual(true) + }) + it('should return false when someone is not reporting on behalf of themselves', () => { + expect(isReportingOnBehalfSelf(notSelf)).toEqual(false) + }) + it('should return false for empty object', () => { + expect(isReportingOnBehalfSelf({})).toEqual(false) + }) +}) diff --git a/libs/application/templates/accident-notification/src/utils/reportingUtils.ts b/libs/application/templates/accident-notification/src/utils/reportingUtils.ts new file mode 100644 index 000000000000..ecba491760ad --- /dev/null +++ b/libs/application/templates/accident-notification/src/utils/reportingUtils.ts @@ -0,0 +1,38 @@ +import { getValueViaPath } from '@island.is/application/core' +import { FormValue } from '@island.is/application/types' +import { WhoIsTheNotificationForEnum } from '../types' + +export const isReportingOnBehalfOfInjured = (formValue: FormValue) => { + const whoIsTheNotificationFor = getValueViaPath( + formValue, + 'whoIsTheNotificationFor.answer', + ) + return ( + whoIsTheNotificationFor === WhoIsTheNotificationForEnum.JURIDICALPERSON || + whoIsTheNotificationFor === WhoIsTheNotificationForEnum.POWEROFATTORNEY + ) +} + +export const isReportingOnBehalfOfEmployee = (formValue: FormValue) => { + const whoIsTheNotificationFor = getValueViaPath( + formValue, + 'whoIsTheNotificationFor.answer', + ) + return whoIsTheNotificationFor === WhoIsTheNotificationForEnum.JURIDICALPERSON +} + +export const isReportingOnBehalfOfChild = (formValue: FormValue) => { + const whoIsTheNotificationFor = getValueViaPath( + formValue, + 'whoIsTheNotificationFor.answer', + ) + return whoIsTheNotificationFor === WhoIsTheNotificationForEnum.CHILDINCUSTODY +} + +export const isReportingOnBehalfSelf = (formValue: FormValue) => { + const whoIsTheNotificationFor = getValueViaPath( + formValue, + 'whoIsTheNotificationFor.answer', + ) + return whoIsTheNotificationFor === WhoIsTheNotificationForEnum.ME +} diff --git a/libs/application/templates/accident-notification/src/utils/shouldRequestReview.spec.ts b/libs/application/templates/accident-notification/src/utils/shouldRequestReview.spec.ts deleted file mode 100644 index cef1aa791e08..000000000000 --- a/libs/application/templates/accident-notification/src/utils/shouldRequestReview.spec.ts +++ /dev/null @@ -1,26 +0,0 @@ -import { AccidentNotificationAnswers } from '..' -import { AccidentTypeEnum, WorkAccidentTypeEnum } from '../types' -import { shouldRequestReview } from './shouldRequestReview' -describe('shouldRequestReview', () => { - const agricultureAccident: Partial = { - workAccident: { type: WorkAccidentTypeEnum.AGRICULTURE }, - } - - const accidentAtHome: Partial = { - accidentType: { radioButton: AccidentTypeEnum.HOMEACTIVITIES }, - } - - const normalWorkAccident: Partial = { - workAccident: { type: WorkAccidentTypeEnum.GENERAL }, - } - - it('should return false for work accidents', () => { - expect(shouldRequestReview(agricultureAccident)).toEqual(false) - }) - it('should return true for general work accident', () => { - expect(shouldRequestReview(normalWorkAccident)).toEqual(true) - }) - it('should return false for home accident', () => { - expect(shouldRequestReview(accidentAtHome)).toEqual(false) - }) -}) diff --git a/libs/application/templates/accident-notification/src/utils/shouldRequestReview.ts b/libs/application/templates/accident-notification/src/utils/shouldRequestReview.ts deleted file mode 100644 index f4773098dc74..000000000000 --- a/libs/application/templates/accident-notification/src/utils/shouldRequestReview.ts +++ /dev/null @@ -1,15 +0,0 @@ -import { AccidentNotificationAnswers, utils, WorkAccidentTypeEnum } from '..' - -export const shouldRequestReview = ( - answers: Partial, -): boolean => { - const ishome = utils.isHomeActivitiesAccident(answers) - const isAgriculture = utils.isOfWorkAccidentType( - answers, - WorkAccidentTypeEnum.AGRICULTURE, - ) - - const isEitherHomeOrAgriculture = ishome || isAgriculture - - return !isEitherHomeOrAgriculture -}