Skip to content

Commit

Permalink
feat(accident-notification): connect new api for accident-notification (
Browse files Browse the repository at this point in the history
#15420)

* feat: connect new api for accident-notification

* feat: map and send attachments to new api

* chore: remove unused code

* feat: codegen for api changes and fix dataSchema

* chore: nx format:write update dirty files

* fix: remove test

* chore: nx format:write update dirty files

* fix: add null test to pass build

* chore: lint

* fix: Coderabbit comments

* feat: connect review application and addAditionalAttachment

* fix: pr comments and add test back in

* chore: use switch instead of if

* fix: getReportId

* fix: codegen backend schema

* chore: consistent early return

* chore: simplify accidentTypeDTO

* fix: lint

* feat: connect getAccidentReportStatus

* feat: add auth to getAccidentNotificationStatus

* fix: import

* chore: add test back in

* fix: test

* chore: remove console.log

---------

Co-authored-by: andes-it <[email protected]>
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored and busla committed Oct 10, 2024
1 parent 3784e4f commit 2988a6c
Show file tree
Hide file tree
Showing 24 changed files with 1,194 additions and 1,270 deletions.
2 changes: 2 additions & 0 deletions apps/application-system/api/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ import { DataProtectionComplaintClientConfig } from '@island.is/clients/data-pro
import { CriminalRecordClientConfig } from '@island.is/clients/criminal-record'
import { HealthInsuranceV2ClientConfig } from '@island.is/clients/icelandic-health-insurance/health-insurance'
import { VmstClientConfig } from '@island.is/clients/vmst'
import { RightsPortalClientConfig } from '@island.is/clients/icelandic-health-insurance/rights-portal'
import { FriggClientConfig } from '@island.is/clients/mms/frigg'
import { smsModuleConfig } from '@island.is/nova-sms'
import { emailModuleConfig } from '@island.is/email-service'
Expand Down Expand Up @@ -112,6 +113,7 @@ import { emailModuleConfig } from '@island.is/email-service'
CriminalRecordClientConfig,
HealthInsuranceV2ClientConfig,
VmstClientConfig,
RightsPortalClientConfig,
FriggClientConfig,
smsModuleConfig,
emailModuleConfig,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ export class ApplicationService {
to: input.to,
})
}

async create(input: CreateApplicationInput, auth: Auth) {
return this.applicationApiWithAuth(auth).applicationControllerCreate({
createApplicationDto: input,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Inject, Injectable } from '@nestjs/common'
import { LOGGER_PROVIDER } from '@island.is/logging'
import type { Logger } from '@island.is/logging'
import { DocumentApi } from '@island.is/clients/icelandic-health-insurance/health-insurance'
import {
HealthInsuranceAccidentNotificationAttachmentTypes as AttachmentTypes,
HealthInsuranceAccidentNotificationConfirmationTypes as ConfirmationTypes,
Expand All @@ -12,6 +11,8 @@ import {
AccidentNotificationConfirmation,
AccidentNotificationStatus,
} from './graphql/models'
import { AccidentreportsApi } from '@island.is/clients/icelandic-health-insurance/rights-portal'
import { Auth, AuthMiddleware } from '@island.is/auth-nest-tools'

const mapStatus = (statusId: number) => {
switch (statusId) {
Expand Down Expand Up @@ -55,34 +56,42 @@ const mapConfirmationType = (confirmationTypeId: number | undefined) => {
@Injectable()
export class AccidentNotificationService {
constructor(
private readonly accidentNotificationApi: DocumentApi,
private readonly accidentReportsApi: AccidentreportsApi,
@Inject(LOGGER_PROVIDER)
private logger: Logger,
) {}

private accidentsReportsApiWithAuth(auth: Auth) {
return this.accidentReportsApi.withMiddleware(new AuthMiddleware(auth))
}

async getAccidentNotificationStatus(
auth: Auth,
ihiDocumentID: number,
): Promise<AccidentNotificationStatus | null> {
this.logger.log('starting call to get accident', ihiDocumentID)
const accidentStatus =
await this.accidentNotificationApi.documentGetAccidentStatus({
ihiDocumentID: ihiDocumentID,
})

const accidentStatus = await this.accidentsReportsApiWithAuth(
auth,
).getAccidentReportStatus({
reportId: ihiDocumentID,
})

if (!accidentStatus) return null
return {
numberIHI: accidentStatus.numberIHI,
numberIHI: accidentStatus.requestId,
status: accidentStatus.status ? mapStatus(accidentStatus.status) : '',
receivedAttachments: accidentStatus.attachments
?.map((x) => ({
[mapAttachmentType(x.attachmentType)]: !!x.isReceived,
[mapAttachmentType(x.type)]: !!x.received,
}))
.reduce(
(prev, curr) => ({ ...prev, ...curr }),
{},
) as AccidentNotificationAttachment,
receivedConfirmations: accidentStatus.confirmations
?.map((x) => ({
[mapConfirmationType(x.confirmationType)]: !!x.isReceived,
[mapConfirmationType(x.party)]: !!x.received,
}))
.reduce(
(prev, curr) => ({ ...prev, ...curr }),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@ import { Inject, UseGuards } from '@nestjs/common'
import { Args, Query, Resolver } from '@nestjs/graphql'
import { Audit } from '@island.is/nest/audit'
import { ApiScope } from '@island.is/auth/scopes'
import { IdsUserGuard, Scopes, ScopesGuard } from '@island.is/auth-nest-tools'
import {
CurrentUser,
IdsUserGuard,
Scopes,
ScopesGuard,
} from '@island.is/auth-nest-tools'
import type { User as AuthUser } from '@island.is/auth-nest-tools'
import { LOGGER_PROVIDER } from '@island.is/logging'
import type { Logger } from '@island.is/logging'
import { HealthInsuranceAccidentStatusInput } from './dto/accidentStatus.input'
Expand All @@ -27,10 +33,12 @@ export class HealthInsuranceAccidentNotificationResolver {
async accidentStatus(
@Args('input', { type: () => HealthInsuranceAccidentStatusInput })
input: HealthInsuranceAccidentStatusInput,
@CurrentUser() user: AuthUser,
): Promise<AccidentNotificationStatus | null> {
this.logger.debug(`Getting company information`)
const accidentStatus =
await this.accidentNotificationService.getAccidentNotificationStatus(
user,
input.ihiDocumentID,
)
this.logger.debug(`Getting accident status for id ${input.ihiDocumentID}`)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,13 @@ import {
import { HealthInsuranceService } from './healthInsurance.service'
import { HealthInsuranceV2ClientModule } from '@island.is/clients/icelandic-health-insurance/health-insurance'
import { AccidentNotificationService } from './accident-notification.service'
import {
AccidentreportsApi,
RightsPortalClientModule,
} from '@island.is/clients/icelandic-health-insurance/rights-portal'

@Module({
imports: [HealthInsuranceV2ClientModule],
imports: [HealthInsuranceV2ClientModule, RightsPortalClientModule],
providers: [
HealthInsuranceService,
AccidentNotificationService,
Expand Down
Loading

0 comments on commit 2988a6c

Please sign in to comment.