-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(external): add ResultExternalPage and related routing
- Loading branch information
Showing
49 changed files
with
949 additions
and
199 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
118 changes: 118 additions & 0 deletions
118
apps/hcdc-access-service/src/app/print-form/print-template/reminder.ejs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
<!DOCTYPE html> | ||
<html lang="vi"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<script src="https://cdn.tailwindcss.com"></script> | ||
<style> | ||
* { | ||
font-family: 'Times New Roman', monospace; | ||
} | ||
html { | ||
font-size: 15px; | ||
} | ||
@page { | ||
margin-top: 5mm; | ||
margin-bottom: 5mm; | ||
margin-left: 18mm; | ||
margin-right: 10mm; | ||
} | ||
p { | ||
page-break-inside: avoid; | ||
} | ||
.print-footer { | ||
position: fixed; | ||
bottom: 0; | ||
font-size: 10px; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<!-- <div class="print-footer"> | ||
BM.TTXN.04/3 | ||
| ||
| ||
| ||
| ||
Phiên bản: 1.0 | ||
| ||
| ||
| ||
| ||
Ngày áp dụng: 18/09/2019 | ||
</div> --> | ||
<div class="flex flex-row justify-between"> | ||
<div class="flex flex-row"> | ||
<img | ||
src=<%= `https://raw.githubusercontent.com/wermarter/diut/refs/heads/main/apps/hcdc-access-service/assets/logo.png` %> | ||
style="width: 90px; object-fit: contain" | ||
/> | ||
<div class="text-center ml-1"> | ||
<p>SỞ Y TẾ TP.HỒ CHÍ MINH</p> | ||
<p class="font-bold">TRUNG TÂM KIỂM SOÁT BỆNH TẬT TP.HCM</p> | ||
<p><%= meta.branch.address %></p> | ||
<p>Website: www.hcdc.gov.vn</p> | ||
</div> | ||
</div> | ||
<div class="text-center"> | ||
<p class="text-xl font-bold my-1">PHIẾU HẸN KẾT QUẢ XÉT NGHIỆM</p> | ||
<div class="ml-10 text-left"> | ||
<p class="text-base"> | ||
Ngày lấy mẫu: | ||
<span><%= data.sample.sampledAt.toLocaleDateString('vi') %></span> | ||
</p> | ||
<p>Nơi chỉ định: Phòng khám</p> | ||
<p>Nơi lấy mẫu: Phòng xét nghiệm</p> | ||
</div> | ||
</div> | ||
</div> | ||
<div class="m-4"> | ||
<div class="flex flex-row justify-between"> | ||
<div class="flex flex-col"> | ||
<p class="text-lg"> | ||
Họ và tên: | ||
<span class="font-bold" | ||
><%= data.sample.patient.name.toLocaleUpperCase() %></span | ||
> | ||
</p> | ||
<p class="text-lg"> | ||
ID XN: <span class="font-bold"><%= data.sample.sampleId %></span> | ||
</p> | ||
</div> | ||
<div class="flex flex-col"> | ||
<p class="text-lg">Năm sinh: <span><%= data.sample.patient.birthYear %></span></p> | ||
<p class="text-lg">Loại bệnh phẩm: Máu</p> | ||
</div> | ||
<div class="flex flex-col"> | ||
<p class="text-lg"> | ||
Giới tính: | ||
<span><%= data.sample.patient.gender === "Male" ? "Nam" : "Nữ" %></span> | ||
</p> | ||
<p class="text-lg"> | ||
CCCD (nếu có): | ||
<span><%= data.sample.patient.SSN %></span> | ||
</p> | ||
</div> | ||
</div> | ||
<p class="text-lg">Địa chỉ: <span><%= data.sample.patient.address %></span></p> | ||
|
||
</div> | ||
<div class="flex flex-row justify-between mt-6"> | ||
<div | ||
class="flex flex-col text-center mr-8" | ||
style="page-break-inside: avoid" | ||
> | ||
<p> | ||
Ngày <%= new Date().getDate() %> tháng <%= new Date().getMonth() + 1 | ||
%> năm <%= new Date().getFullYear() %> | ||
</p> | ||
<p class="font-bold">Nhân viên xét nghiệm</p> | ||
<p style="margin-top: 20mm" class="font-bold"><%= meta.authorName %></p> | ||
</div> | ||
</div> | ||
<img | ||
src=<%= `https://quickchart.io/qr?size=300&text=${data.url}` %> | ||
/> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
134 changes: 134 additions & 0 deletions
134
apps/hcdc-access-service/src/app/sample/use-case/print-reminder.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
import { NodeEnv } from '@diut/common' | ||
import { AuthSubject, ExternalRoutePath, SampleAction } from '@diut/hcdc' | ||
import { PageFormat, PageOrientation } from '@diut/services' | ||
import { Inject, Injectable } from '@nestjs/common' | ||
import { render } from 'ejs' | ||
import { readFile } from 'fs/promises' | ||
import { join } from 'path' | ||
import { of } from 'rxjs' | ||
import { assertPermission } from 'src/app/auth/common' | ||
import { AuthAuthorizeExternalRouteUseCase } from 'src/app/auth/use-case/authorize-external-route' | ||
import { AppConfig, loadAppConfig } from 'src/config' | ||
import { | ||
AUTH_CONTEXT_TOKEN, | ||
BROWSER_SERVICE_TOKEN, | ||
EEntityNotFound, | ||
IAuthContext, | ||
IBrowserService, | ||
IStorageBucket, | ||
IStorageService, | ||
STORAGE_BUCKET_TOKEN, | ||
STORAGE_SERVICE_TOKEN, | ||
StorageBucket, | ||
StorageKeyFactory, | ||
} from 'src/domain' | ||
import { SampleFindOneUseCase } from './find-one' | ||
|
||
const TEMPLATE_PATH = 'reminder.ejs' | ||
|
||
@Injectable() | ||
export class SamplePrintReminderUseCase { | ||
constructor( | ||
private readonly sampleFindOneUseCase: SampleFindOneUseCase, | ||
private readonly authorizeExternalRouteUseCase: AuthAuthorizeExternalRouteUseCase, | ||
@Inject(AUTH_CONTEXT_TOKEN) | ||
private readonly authContext: IAuthContext, | ||
@Inject(BROWSER_SERVICE_TOKEN) | ||
private readonly browserService: IBrowserService, | ||
@Inject(loadAppConfig.KEY) | ||
private readonly appConfig: AppConfig, | ||
@Inject(STORAGE_SERVICE_TOKEN) | ||
private readonly storageService: IStorageService, | ||
@Inject(STORAGE_BUCKET_TOKEN) | ||
private readonly storageBucket: IStorageBucket, | ||
) {} | ||
|
||
async execute(sampleId: string, date: Date) { | ||
const htmlContent = await this.getHtmlContent(sampleId, date) | ||
|
||
const { mergedPdf } = await this.browserService.printMultiplePage( | ||
of({ | ||
htmlContent, | ||
pageFormat: PageFormat.A5, | ||
pageOrientation: PageOrientation.Landscape, | ||
}), | ||
) | ||
|
||
return mergedPdf | ||
} | ||
|
||
private async getHtmlContent(sampleId: string, date: Date) { | ||
const { jwt, sample, meta } = await this.getPrintData(sampleId) | ||
const printTemplate = await this.getPrintTemplate() | ||
const url = this.appConfig.REMINDER_URL_PREFIX + jwt | ||
|
||
return render( | ||
printTemplate, | ||
{ data: { url, sample, date }, meta }, | ||
{ async: true }, | ||
) | ||
} | ||
|
||
private async getPrintTemplate() { | ||
const isDevelopment = this.appConfig.NODE_ENV === NodeEnv.Development | ||
if (isDevelopment) { | ||
const buffer = await readFile( | ||
join( | ||
__dirname, | ||
'..', | ||
'..', | ||
`print-form/print-template/${TEMPLATE_PATH}`, | ||
), | ||
) | ||
|
||
return buffer.toString() | ||
} | ||
|
||
const { buffer } = await this.storageService.readToBuffer({ | ||
key: StorageKeyFactory[StorageBucket.APP].printFormTemplate({ | ||
templatePath: TEMPLATE_PATH, | ||
}), | ||
bucket: this.storageBucket.get(StorageBucket.APP), | ||
}) | ||
return buffer.toString() | ||
} | ||
|
||
private async getPrintData(sampleId: string) { | ||
const { ability, user } = this.authContext.getDataInternal() | ||
|
||
const sample = await this.sampleFindOneUseCase.execute({ | ||
filter: { sampleId }, | ||
populates: [ | ||
{ | ||
path: 'patient', | ||
}, | ||
{ | ||
path: 'branch', | ||
}, | ||
], | ||
}) | ||
if (!sample) { | ||
throw new EEntityNotFound(`Sample id=${sampleId}`) | ||
} | ||
|
||
assertPermission( | ||
ability, | ||
AuthSubject.Sample, | ||
SampleAction.ReadResult, | ||
sample, | ||
) | ||
|
||
const { jwt } = await this.authorizeExternalRouteUseCase.execute( | ||
this.constructor.name, | ||
ExternalRoutePath.GetSampleResult, | ||
{ sampleId: sample._id }, | ||
[sample.branchId], | ||
) | ||
|
||
return { | ||
jwt, | ||
sample, | ||
meta: { branch: sample.branch, authorName: user.name }, | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
apps/hcdc-access-service/src/controller/http/external/auth/common.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { ApiQuery } from '@nestjs/swagger' | ||
|
||
export type ExternalAuthQuery = { | ||
jwt: string | ||
} | ||
|
||
export const AuthQuery = () => | ||
ApiQuery({ | ||
name: 'jwt', | ||
required: true, | ||
type: 'string', | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
apps/hcdc-access-service/src/controller/http/external/auth/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export * from './service' | ||
export * from './common' | ||
export * from './guard' | ||
export * from './service' |
Oops, something went wrong.