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(accident-notification): connect new api for accident-notification #15420

Merged
merged 28 commits into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
8541e4c
feat: connect new api for accident-notification
jonnigs Jun 28, 2024
f972698
feat: map and send attachments to new api
jonnigs Jul 2, 2024
ff47133
chore: remove unused code
jonnigs Jul 2, 2024
7494f1e
feat: codegen for api changes and fix dataSchema
jonnigs Sep 26, 2024
508c5d8
Merge branch 'main' into feat/new-accident-notification-client
jonnigs Oct 1, 2024
55939e2
chore: nx format:write update dirty files
andes-it Oct 1, 2024
237adec
fix: remove test
jonnigs Oct 1, 2024
e027617
chore: nx format:write update dirty files
andes-it Oct 1, 2024
8f213d1
fix: add null test to pass build
jonnigs Oct 1, 2024
bf8deed
chore: lint
jonnigs Oct 1, 2024
36cac5e
fix: Coderabbit comments
jonnigs Oct 2, 2024
6c8fdb9
Merge branch 'main' into feat/new-accident-notification-client
jonnigs Oct 2, 2024
4705a3f
feat: connect review application and addAditionalAttachment
jonnigs Oct 3, 2024
c1f68af
fix: pr comments and add test back in
jonnigs Oct 3, 2024
ed9016d
chore: use switch instead of if
jonnigs Oct 3, 2024
9b9a6a7
fix: getReportId
jonnigs Oct 3, 2024
00e3116
fix: codegen backend schema
jonnigs Oct 3, 2024
86d95a6
chore: consistent early return
jonnigs Oct 3, 2024
edc5cec
chore: simplify accidentTypeDTO
jonnigs Oct 3, 2024
019e133
fix: lint
jonnigs Oct 3, 2024
1438de9
feat: connect getAccidentReportStatus
jonnigs Oct 7, 2024
97886bc
feat: add auth to getAccidentNotificationStatus
jonnigs Oct 7, 2024
203d0eb
fix: import
jonnigs Oct 7, 2024
dd1f66b
chore: add test back in
jonnigs Oct 7, 2024
07221d7
fix: test
jonnigs Oct 8, 2024
9c62f14
chore: remove console.log
jonnigs Oct 8, 2024
eceb7b4
Merge branch 'main' into feat/new-accident-notification-client
kodiakhq[bot] Oct 9, 2024
0cc442c
Merge branch 'main' into feat/new-accident-notification-client
kodiakhq[bot] Oct 9, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Expand Up @@ -3,11 +3,11 @@ import { SharedTemplateAPIModule } from '../../shared'
import { BaseTemplateAPIModuleConfig } from '../../../types'
import { ACCIDENT_NOTIFICATION_CONFIG } from './config'
import { AccidentNotificationService } from './accident-notification.service'
import { HealthInsuranceV2ClientModule } from '@island.is/clients/icelandic-health-insurance/health-insurance'
import { ApplicationAttachmentService } from './attachments/applicationAttachment.service'
import { AccidentNotificationAttachmentProvider } from './attachments/applicationAttachmentProvider'
import { S3 } from 'aws-sdk'
import { S3Service } from './attachments/s3.service'
import { RightsPortalClientModule } from '@island.is/clients/icelandic-health-insurance/rights-portal'

const applicationRecipientName =
process.env.ACCIDENT_NOTIFICATION_APPLICATION_RECIPIENT_NAME ?? ''
Expand All @@ -26,7 +26,7 @@ export class AccidentNotificationModule {
module: AccidentNotificationModule,
imports: [
SharedTemplateAPIModule.register(config),
HealthInsuranceV2ClientModule,
RightsPortalClientModule,
],
providers: [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@ import {
ReviewApprovalEnum,
utils,
} from '@island.is/application/templates/accident-notification'
import { DocumentApi } from '@island.is/clients/icelandic-health-insurance/health-insurance'
import { LOGGER_PROVIDER } from '@island.is/logging'
import type { Logger } from '@island.is/logging'
import { Inject, Injectable } from '@nestjs/common'
import { TemplateApiModuleActionProps } from '../../../types'
import { SharedTemplateApiService } from '../../shared'
import {
applictionAnswersToXml,
getApplicationDocumentId,
whiteListedErrorCodes,
} from './accident-notification.utils'
Expand All @@ -28,9 +26,11 @@ import {
getAddAttachmentSentDocumentHashList,
getApplicationAttachmentStatus,
} from './attachments/attachment.utils'
import { AccidentNotificationAttachment } from './types/attachments'
import { BaseTemplateApiService } from '../../base-template-api.service'
import { ApplicationTypes } from '@island.is/application/types'
import { applicationToAccidentReport } from './accodent-notification-v2.utils'
jonnigs marked this conversation as resolved.
Show resolved Hide resolved
import { AccidentreportsApi } from '@island.is/clients/icelandic-health-insurance/rights-portal'
import { Auth, AuthMiddleware } from '@island.is/auth-nest-tools'

const SIX_MONTHS_IN_SECONDS_EXPIRES = 6 * 30 * 24 * 60 * 60

Expand All @@ -42,36 +42,41 @@ export class AccidentNotificationService extends BaseTemplateApiService {
private accidentConfig: AccidentNotificationConfig,
private readonly sharedTemplateAPIService: SharedTemplateApiService,
private readonly attachmentProvider: AccidentNotificationAttachmentProvider,
private readonly documentApi: DocumentApi,
private readonly accidentReportsApi: AccidentreportsApi,
) {
super(ApplicationTypes.ACCIDENT_NOTIFICATION)
}

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

async submitApplication({ application, auth }: TemplateApiModuleActionProps) {
jonnigs marked this conversation as resolved.
Show resolved Hide resolved
try {
const requests = attachmentStatusToAttachmentRequests()

const attachments = await this.attachmentProvider.getFiles(
requests,
application,
)

const fileHashList = attachments.map((attachment) => attachment.hash)

const answers = application.answers as AccidentNotificationAnswers
const xml = applictionAnswersToXml(answers, attachments)
const accidentReport = applicationToAccidentReport(answers, attachments)

const { ihiDocumentID } = await this.documentApi.documentPost({
document: { doc: xml, documentType: 801 },
const res = await this.accidentsReportsApiWithAuth(
auth,
).submitAccidentReport({
minarsidurAPIModelsAccidentReportsAccidentReportDTO: accidentReport,
})
const reportId = res.reportId

await this.sharedTemplateAPIService.sendEmail(
(props) =>
generateConfirmationEmail(
props,
this.accidentConfig.applicationSenderName,
this.accidentConfig.applicationSenderEmail,
ihiDocumentID,
reportId ?? undefined,
),
application,
)
Expand All @@ -85,13 +90,17 @@ export class AccidentNotificationService extends BaseTemplateApiService {

await this.sharedTemplateAPIService.assignApplicationThroughEmail(
(props, assignLink) =>
generateAssignReviewerEmail(props, assignLink, ihiDocumentID),
generateAssignReviewerEmail(
props,
assignLink,
reportId ?? undefined,
),
application,
token,
)
}
return {
documentId: ihiDocumentID,
documentId: reportId,
sentDocuments: fileHashList,
}
jonnigs marked this conversation as resolved.
Show resolved Hide resolved
} catch (e) {
Expand Down Expand Up @@ -131,18 +140,18 @@ export class AccidentNotificationService extends BaseTemplateApiService {

const documentId = getApplicationDocumentId(application)

const promises = newAttachments.map((attachment) =>
this.sendAttachment(attachment, documentId),
)
// const promises = newAttachments.map((attachment) =>
// this.sendAttachment(attachment, documentId),
// )
jonnigs marked this conversation as resolved.
Show resolved Hide resolved

const successfulAttachments = (await Promise.all(promises)).filter(
(x) => x !== null,
)
// const successfulAttachments = (await Promise.all(promises)).filter(
// (x) => x !== null,
// )

return {
sentDocuments: [
...getAddAttachmentSentDocumentHashList(application),
...successfulAttachments,
// ...successfulAttachments,
jonnigs marked this conversation as resolved.
Show resolved Hide resolved
],
}
}
Expand All @@ -151,25 +160,25 @@ export class AccidentNotificationService extends BaseTemplateApiService {
* Sends the attachment to SÍ and returns the document hash on success and null on failure
* @param attachment attachment to send
*/
private async sendAttachment(
attachment: AccidentNotificationAttachment,
documentId: number,
): Promise<string | null> {
try {
await this.documentApi.documentDocumentAttachment({
documentAttachment: {
attachmentBody: attachment.content,
attachmentType: attachment.attachmentType,
title: attachment.name,
},
ihiDocumentID: documentId,
})
return attachment.hash
} catch (e) {
this.logger.error('Error sending document to SÍ', e)
return null
}
}
// private async sendAttachment(
// attachment: AccidentNotificationAttachment,
// documentId: number,
// ): Promise<string | null> {
// try {
// // await this.documentApi.documentDocumentAttachment({
// // documentAttachment: {
// // attachmentBody: attachment.content,
// // attachmentType: attachment.attachmentType,
// // title: attachment.name,
// // },
// // ihiDocumentID: documentId,
// // })
// return attachment.hash
// } catch (e) {
// this.logger.error('Error sending document to SÍ', e)
// return null
// }
// }

async reviewApplication({ application }: TemplateApiModuleActionProps) {
const documentId = getApplicationDocumentId(application)
Expand All @@ -182,14 +191,14 @@ export class AccidentNotificationService extends BaseTemplateApiService {
) as ReviewApprovalEnum
const reviewComment =
getValueViaPath(application.answers, 'reviewComment') || ''
await this.documentApi.documentSendConfirmation({
ihiDocumentID: documentId,
confirmationIN: {
confirmationType:
reviewApproval === ReviewApprovalEnum.APPROVED ? 1 : 2,
confirmationParty: isRepresentativeOfCompanyOrInstitue ? 1 : 2,
objection: reviewComment as string,
},
})
// await this.documentApi.documentSendConfirmation({
// ihiDocumentID: documentId,
// confirmationIN: {
// confirmationType:
// reviewApproval === ReviewApprovalEnum.APPROVED ? 1 : 2,
// confirmationParty: isRepresentativeOfCompanyOrInstitue ? 1 : 2,
// objection: reviewComment as string,
// },
// })
jonnigs marked this conversation as resolved.
Show resolved Hide resolved
}
}
Loading
Loading