Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

feat(driving-license): check if 65+ renewal is possible #16292

Merged
merged 13 commits into from
Oct 7, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -355,8 +355,15 @@ export class DrivingLicenseService {
}
}

async canApplyFor(type: 'B-full' | 'B-temp' | 'BE', token: string) {
if (type === 'B-full') {
async canApplyFor(
type: 'B-full' | 'B-temp' | 'BE' | 'B-full-renewal-65',
stjanilofts marked this conversation as resolved.
Show resolved Hide resolved
token: string,
) {
if (type === 'B-full-renewal-65') {
return this.drivingLicenseApi.getCanApplyForRenewal65({
token,
})
} else if (type === 'B-full') {
return this.drivingLicenseApi.getCanApplyForCategoryFull({
category: 'B',
token,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ const getDeniedByServiceMessageDescription = (
case RequirementKey.HasDeprivation:
case RequirementKey.HasPoints:
return requirementsMessages.hasPointsOrDeprivation
case RequirementKey.NoExtendedDrivingLicense:
return requirementsMessages.noExtendedDrivingLicenseTitle
default:
return requirementsMessages.rlsDefaultDeniedDescription
}
Expand Down Expand Up @@ -85,6 +87,11 @@ const requirementKeyToStep = (
title: requirementsMessages.beLicenseQualityPhotoTitle,
description: requirementsMessages.beLicenseQualityPhotoDescription,
}
case RequirementKey.NoExtendedDrivingLicense:
return {
title: requirementsMessages.noExtendedDrivingLicenseTitle,
description: requirementsMessages.noExtendedDrivingLicenseDescription,
}
default:
throw new Error('Unknown requirement reason - should not happen')
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
import { getValueViaPath } from '@island.is/application/core'
import { Application } from '@island.is/application/types'
import { ApplicationEligibility, RequirementKey } from '../../types/schema'
import {
ApplicationEligibility,
ApplicationEligibilityRequirement,
RequirementKey,
} from '../../types/schema'
import { useQuery, gql } from '@apollo/client'
import {
B_FULL,
B_FULL_RENEWAL_65,
BE,
codesExtendedLicenseCategories,
codesRequiringHealthCertificate,
DrivingLicenseApplicationFor,
DrivingLicenseFakeData,
otherLicenseCategories,
remarksCannotRenew65,
YES,
} from '../../lib/constants'
import { fakeEligibility } from './fakeEligibility'
Expand Down Expand Up @@ -90,6 +97,23 @@ export const useEligibility = (
)
}

const hasExtendedDrivingLicense = (
currentLicense: DrivingLicense | undefined,
drivingLicenseIssued: string | undefined,
): boolean => {
if (!drivingLicenseIssued) return false

const relevantCategories = currentLicense?.categories?.filter((x) =>
codesExtendedLicenseCategories.includes(x.nr),
)

if (!relevantCategories?.length) return false

// Check if any category was issued on a different date than the 'B' license
// (indicating an extended license)
return relevantCategories.some((x) => x.issued !== drivingLicenseIssued)
}

if (usingFakeData) {
return {
loading: false,
Expand All @@ -111,13 +135,11 @@ export const useEligibility = (
}
}

const eligibility: ApplicationEligibilityRequirement[] =
data.drivingLicenseApplicationEligibility?.requirements ?? []

//TODO: Remove when RLS/SGS supports health certificate in BE license
if (application.answers.applicationFor === BE) {
const eligibility =
data.drivingLicenseApplicationEligibility === undefined
? []
: (data.drivingLicenseApplicationEligibility as ApplicationEligibility)
.requirements
return {
loading: loading,
eligibility: {
Expand All @@ -143,6 +165,52 @@ export const useEligibility = (
}
}

if (application.answers.applicationFor === B_FULL_RENEWAL_65) {
const licenseB = currentLicense?.categories?.find(
(license) => license.nr === 'B',
)
const drivingLicenseIssued = licenseB?.issued

const hasExtendedLicense = hasExtendedDrivingLicense(
currentLicense,
drivingLicenseIssued,
)

const hasAnyInvalidRemarks =
currentLicense?.remarks?.some((remark) =>
remarksCannotRenew65.includes(remark.code),
) ?? false

const requirements = [
...eligibility,
{
key: RequirementKey.HasNoPhoto,
requirementMet: hasQualityPhoto,
},
...(hasExtendedLicense
? [
{
key: RequirementKey.NoExtendedDrivingLicense,
requirementMet: false,
},
]
: []),
]

return {
loading: loading,
eligibility: {
isEligible: loading
? undefined
: (data.drivingLicenseApplicationEligibility?.isEligible ?? false) &&
hasQualityPhoto &&
!hasExtendedDrivingLicense &&
!hasAnyInvalidRemarks,
requirements,
},
}
stjanilofts marked this conversation as resolved.
Show resolved Hide resolved
}

return {
loading,
eligibility: data.drivingLicenseApplicationEligibility,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export const sectionApplicationFor = (
'currentLicense.data',
) ?? { categories: null }

const age =
let age =
getValueViaPath<number>(
app.externalData,
'nationalRegistry.data.age',
Expand All @@ -53,6 +53,7 @@ export const sectionApplicationFor = (
app.answers,
'fakeData',
)

if (fakeData?.useFakeData === 'yes') {
currentLicense = fakeData.currentLicense ?? null
categories =
Expand All @@ -66,6 +67,8 @@ export const sectionApplicationFor = (
{ nr: 'BE', validToCode: 9 },
]
: []

age = fakeData?.age
}

let options = [
Expand All @@ -91,9 +94,7 @@ export const sectionApplicationFor = (
subLabel:
m.applicationForRenewalLicenseDescription.defaultMessage,
value: B_FULL_RENEWAL_65,
disabled:
!currentLicense ||
(fakeData && fakeData.age ? fakeData.age < 65 : age < 65),
disabled: !currentLicense || age < 65,
})
}

Expand Down
14 changes: 14 additions & 0 deletions libs/application/templates/driving-license/src/lib/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,20 @@ export const CHARGE_ITEM_CODES: Record<string, string> = {

export const otherLicenseCategories = ['C', 'C1', 'CE', 'D', 'D1', 'DE']
export const codesRequiringHealthCertificate = ['400', '01.06']
export const codesExtendedLicenseCategories = [
'C1',
'C1E',
'C',
'CE',
'D1',
'D1E',
'D',
'DE',
'Bfar',
'Far',
'FAR',
]
export const remarksCannotRenew65 = ['400', '450', '95']

export type DrivingLicenseApplicationFor =
| typeof B_FULL
Expand Down
10 changes: 10 additions & 0 deletions libs/application/templates/driving-license/src/lib/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -980,4 +980,14 @@ export const requirementsMessages = defineMessages({
description:
'requirement unmet api returned false for an unspecified reason',
},
noExtendedDrivingLicenseTitle: {
id: 'dl.application:requirementunmet.noExtendedDrivingLicenseTitle',
defaultMessage: 'Ekki hægt að sækja um endurnýjun á 65+ ökuskírteini.',
description: 'requirement unmet 65 plus renewal',
},
noExtendedDrivingLicenseDescription: {
id: 'dl.application:requirementunmet.noExtendedDrivingLicenseDescription#markdown',
defaultMessage: 'Ekki hægt að sækja um endurnýjun á 65+ ökuskírteini.',
description: 'requirement unmet 65 plus renewal',
},
})
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export type ConditionFn = (answer: FormValue) => boolean
export type DrivingLicenseCategory = {
nr: string
validToCode: number
issued?: string
}

export interface Remark {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,23 @@ export class DrivingLicenseApi {
}
}

public async getCanApplyForRenewal65(params: {
token: string
}): Promise<CanApplyForCategoryResult<CanApplyErrorCodeBFull>> {
const response = await this.v5.apiDrivinglicenseV5CanapplyforRenewal65Get({
apiVersion: v5.DRIVING_LICENSE_API_VERSION_V5,
apiVersion2: v5.DRIVING_LICENSE_API_VERSION_V5,
jwttoken: params.token,
})

return {
result: !!response.result,
errorCode: response.errorCode
? (response.errorCode as CanApplyErrorCodeBFull)
: undefined,
}
}

public async getCanApplyForCategoryTemporary(params: {
token: string
}): Promise<CanApplyForCategoryResult<CanApplyErrorCodeBTemporary>> {
Expand Down
Loading
Loading