igengx
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import {
|
||||
prescriptionDetail,
|
||||
prescriptionEsignDownload,
|
||||
prescriptionEsignStatus,
|
||||
type PrescriptionEsignFile,
|
||||
@@ -55,7 +56,9 @@ export function validateEsignStatus(value: unknown): PrescriptionEsignStatus {
|
||||
|| ['enabled', 'required', 'can_sign', 'can_download'].some((key) => typeof (state as any)[key] !== 'boolean')
|
||||
|| (state.verification_method !== undefined && !['quick', 'sms'].includes(state.verification_method))
|
||||
|| [state.can_resume_identity, state.can_retry_verify, state.doctor_identity_required,
|
||||
state.signing_authorization_required, state.sms_sent].some((flag) => flag !== undefined && typeof flag !== 'boolean')) {
|
||||
state.signing_authorization_required, state.sms_sent, state.awaiting_upload,
|
||||
state.can_submit_for_review, state.can_review_prescription]
|
||||
.some((flag) => flag !== undefined && typeof flag !== 'boolean')) {
|
||||
throw new Error('无法核对处方签署状态,请刷新后重试')
|
||||
}
|
||||
return state
|
||||
@@ -104,6 +107,39 @@ export function canApprovePrescriptionEsign(status: unknown): boolean {
|
||||
}
|
||||
}
|
||||
|
||||
export function pendingPrescriptionReviewLabel(row: {
|
||||
review_submitted_at?: number | string
|
||||
can_review_prescription?: boolean
|
||||
esign?: PrescriptionEsignStatus
|
||||
}): string {
|
||||
const submittedAt = row.esign?.review_submitted_at ?? row.review_submitted_at
|
||||
if (!(Number(submittedAt) > 0)) return '待上传'
|
||||
if ((row.esign?.can_review_prescription ?? row.can_review_prescription) === true) return '待审核'
|
||||
return row.esign?.status === 'signed' ? '签署待核实' : '待医师签署'
|
||||
}
|
||||
|
||||
export async function updatePrescriptionSlipEsign(data: Record<string, unknown> | null, state: PrescriptionEsignStatus): Promise<void> {
|
||||
if (!data) return
|
||||
const previous = data.esign as PrescriptionEsignStatus | undefined
|
||||
data.esign = state
|
||||
if (state.status !== 'signed' || previous?.status === 'signed') return
|
||||
|
||||
// The verified physician seal is stored on the prescription detail after signing.
|
||||
data.doctor_signature = ''
|
||||
const id = Number(data.id)
|
||||
if (!Number.isInteger(id) || id <= 0) return
|
||||
try {
|
||||
const response = await prescriptionDetail({ id })
|
||||
const detail = response?.data ?? response
|
||||
if (Number(detail?.id) === id && (data.esign as PrescriptionEsignStatus).status === 'signed'
|
||||
&& typeof detail?.doctor_signature === 'string') {
|
||||
data.doctor_signature = detail.doctor_signature
|
||||
}
|
||||
} catch {
|
||||
// The slip falls back to the verified name when the seal cannot be loaded.
|
||||
}
|
||||
}
|
||||
|
||||
/** Verify the received bytes before creating a download; never render or alter the signed PDF. */
|
||||
export async function verifyEsignPdf(file: PrescriptionEsignFile): Promise<Uint8Array> {
|
||||
if (!/^[a-f\d]{64}$/i.test(file.sha256 || '')) throw new Error('签署文件缺少有效校验信息')
|
||||
|
||||
Reference in New Issue
Block a user