igengx
This commit is contained in:
@@ -178,6 +178,34 @@ test('opening a pending enrollment performs a GET and requires an explicit resum
|
||||
settings.unmount()
|
||||
})
|
||||
|
||||
test('certificate recheck reads a fresh result without leaving the dialog or writing enrollment', async () => {
|
||||
let result = grant({ certificate_state: 'valid' })
|
||||
const settings = createDialog({ read: () => result })
|
||||
await flush()
|
||||
assert.equal(settings.certificateLabel.value, '有效')
|
||||
assert.match(dialogScript.template, /重新校验证书/)
|
||||
assert.doesNotMatch(dialogScript.template, /切换签署账号/)
|
||||
|
||||
result = status({ status: 'renewal_required', certificate_state: 'unconfirmed' })
|
||||
await settings.checkStatus()
|
||||
assert.equal(settings.certificateLabel.value, '暂无法确认')
|
||||
assert.match(settings.guidance.value, /重新校验/)
|
||||
assert.equal(settings.statusNotice.value, '')
|
||||
assert.deepEqual(settings.writeCalls(), [])
|
||||
|
||||
result = status({ status: 'renewal_required', certificate_state: 'renewal_required' })
|
||||
await settings.checkStatus()
|
||||
assert.equal(settings.certificateLabel.value, '需要续期')
|
||||
assert.equal(settings.startLabel.value, '开始续期认证')
|
||||
|
||||
result = grant({ certificate_state: 'valid', quicksign_unavailable_reason: 'expired', quicksign_expires_at: 0 })
|
||||
await settings.checkStatus()
|
||||
assert.equal(settings.statusNotice.value, '证书校验通过。')
|
||||
assert.equal(settings.certificateLabel.value, '有效')
|
||||
assert.match(settings.guidance.value, /快捷签授权已过期/)
|
||||
assert.deepEqual(settings.calls.map(([method]) => method), ['read', 'read', 'read', 'read'])
|
||||
})
|
||||
|
||||
test('certificate renewal uses the explicitly entered mobile and clears it after starting', async () => {
|
||||
const settings = createDialog({ read: () => status({ status: 'renewal_required' }) })
|
||||
await flush()
|
||||
|
||||
@@ -51,6 +51,19 @@ test('signing mutations allow 180 seconds and explicitly disable transport repla
|
||||
}
|
||||
})
|
||||
|
||||
test('the detail and audit status requests use independent cancellation signals', async () => {
|
||||
const calls = []
|
||||
const api = loadModule('api/tcm.ts', {
|
||||
'@/utils/request': { default: { get: async (config, options) => { calls.push({ config, options }); return status() } } }
|
||||
})
|
||||
const detail = new AbortController()
|
||||
const audit = new AbortController()
|
||||
await Promise.all([api.prescriptionEsignStatus({ id: 17 }, detail.signal), api.prescriptionEsignStatus({ id: 17 }, audit.signal)])
|
||||
assert.equal(calls[0].config.signal, detail.signal)
|
||||
assert.equal(calls[1].config.signal, audit.signal)
|
||||
assert.ok(calls.every((call) => call.options.ignoreCancelToken === true))
|
||||
})
|
||||
|
||||
test('authentication links accept only absolute HTTPS URLs without credentials', () => {
|
||||
const utils = loadModule('utils/prescription-esign.ts', { '@/api/tcm': {} })
|
||||
for (const value of ['javascript:alert(1)', 'http://example.test', '//example.test', 'https://user:secret@example.test', '', null]) {
|
||||
@@ -217,9 +230,11 @@ function panel(initial = status(), api = {}) {
|
||||
clearTimeout: (id) => timers.delete(id),
|
||||
Date: { now: () => now }, document,
|
||||
props, emit: (_, value) => events.push(value),
|
||||
useUserStore: () => ({ serverTimeOffsetMs: 0 }),
|
||||
safeEsignAuthUrl: utils.safeEsignAuthUrl,
|
||||
canApprovePrescriptionEsign: utils.canApprovePrescriptionEsign,
|
||||
canCheckEsignIdentity: utils.canCheckEsignIdentity,
|
||||
formatSigningTime: utils.formatSigningTime,
|
||||
prescriptionEsignTiming: utils.prescriptionEsignTiming,
|
||||
validateEsignStatus: utils.validateEsignStatus,
|
||||
validateEsignIdentityStatus: utils.validateEsignIdentityStatus,
|
||||
@@ -227,13 +242,14 @@ function panel(initial = status(), api = {}) {
|
||||
calls.push(['download', { id }]); return api.download?.(isCurrent)
|
||||
},
|
||||
prescriptionEsignStatus: async (p) => { calls.push(['status', p]); return api.refresh ? api.refresh() : initial },
|
||||
prescriptionSubmitForReview: async (p) => { calls.push(['upload', p]); return api.upload(p) },
|
||||
prescriptionEsignDoctorStatus: async (signal) => { calls.push(['profile']); return api.profile(signal) },
|
||||
prescriptionEsignStart: async (p) => { calls.push(['start', p]); return api.start ? api.start(p) : identity() },
|
||||
prescriptionEsignIdentityStatus: async (p, signal) => { calls.push(['identity', p]); return api.identity ? api.identity(signal) : identity() },
|
||||
prescriptionEsignVerifyWillingness: async (p) => { calls.push(['verify-sms', p]); return api.verifySms(p) },
|
||||
prescriptionEsignComplete: async (p) => { calls.push(['complete', p]); return api.complete ? api.complete(p) : status({ status: 'signed', can_sign: false, can_download: true }) }
|
||||
}
|
||||
const value = new Function(...Object.keys(globals), `${compiledPanel}\nreturn { state, busy, work, confirmed, showControls, signingTime, error, authUrl, start, refresh, dialogVisible, readiness, action, message, activeStep, identityNumber, identityDetailsRequired, confirmSign, closeAuthentication, authenticationUnavailable, onVisibilityChange, smsCode, smsCodeEntry, smsSendCoolingDown, sendSms, verifySms }`)(...Object.values(globals))
|
||||
const value = new Function(...Object.keys(globals), `${compiledPanel}\nreturn { state, busy, work, confirmed, showControls, signingTime, signingLog, showSigningLog, error, authUrl, start, refresh, dialogVisible, readiness, action, message, activeStep, identityNumber, identityDetailsRequired, confirmSign, closeAuthentication, authenticationUnavailable, onVisibilityChange, smsCode, smsCodeEntry, smsSendCoolingDown, sendSms, verifySms, showSteps, reviewRequired, reviewSigning, updateReview, runAction, statusNotice }`)(...Object.values(globals))
|
||||
value.confirmed.value = true // The existing-state tests begin after a successful initial query.
|
||||
async function advance(ms) {
|
||||
now += ms
|
||||
@@ -260,6 +276,43 @@ function accountBasedIdentity(method, changes = {}) {
|
||||
})
|
||||
}
|
||||
|
||||
test('a saved draft must upload before quick-sign preparation, with retry and explicit confirmation', async () => {
|
||||
const draft = status({
|
||||
review_required: true, awaiting_upload: true, review_submitted_at: 0,
|
||||
can_submit_for_review: true, can_review_prescription: false, can_sign: false
|
||||
})
|
||||
const submitted = accountBasedStatus('quick', {
|
||||
review_required: true, awaiting_upload: false, review_submitted_at: 1760000000,
|
||||
can_submit_for_review: false, can_review_prescription: false
|
||||
})
|
||||
let attempts = 0
|
||||
const p = panel(draft, {
|
||||
refresh: async () => attempts === 2 ? submitted : draft,
|
||||
upload: async () => {
|
||||
if (++attempts === 1) throw new Error('temporary network error')
|
||||
return { review_submitted_at: 1760000000, can_submit_for_review: false }
|
||||
},
|
||||
start: async () => ({ ...submitted, status: 'authenticating', can_resume_identity: true }),
|
||||
identity: async () => accountBasedIdentity('quick', {
|
||||
...submitted, status: 'authenticating', can_resume_identity: true
|
||||
})
|
||||
})
|
||||
p.watchers[0]()
|
||||
await flush()
|
||||
assert.equal(p.action.value.label, '上传处方')
|
||||
assert.equal(p.activeStep.value, 1)
|
||||
assert.deepEqual(p.calls.map(([name]) => name), ['status'])
|
||||
await p.runAction()
|
||||
assert.match(p.error.value, /重试/)
|
||||
assert.equal(p.action.value.label, '上传处方')
|
||||
await p.runAction()
|
||||
assert.deepEqual(p.calls.map(([name]) => name), ['status', 'upload', 'upload', 'status', 'start', 'identity'])
|
||||
assert.equal(p.action.value.label, '确认签名')
|
||||
assert.equal(p.activeStep.value, 2)
|
||||
await p.runAction()
|
||||
assert.equal(p.calls.at(-1)[0], 'complete')
|
||||
})
|
||||
|
||||
test('quick signing prepares once on open and waits for the prescriber to confirm', async () => {
|
||||
const prepared = accountBasedStatus('quick', { status: 'authenticating', can_resume_identity: true })
|
||||
const p = panel(accountBasedStatus('quick'), {
|
||||
@@ -307,7 +360,7 @@ test('quick signing routes missing identity and unusable grants to account setti
|
||||
await blocked.refresh()
|
||||
await blocked.confirmSign()
|
||||
assert.deepEqual(blocked.calls.map(([method]) => method), ['status'])
|
||||
assert.match(blocked.message.value, /身份认证.*医生电子签署身份/)
|
||||
assert.match(blocked.message.value, /身份认证.*签署身份与证书/)
|
||||
|
||||
for (const [reason, copy] of [['missing', /待完成/], ['expired', /已到期/], ['exhausted', /次数已用完/], ['invalid', /已失效/]]) {
|
||||
let authorized = false
|
||||
@@ -322,7 +375,7 @@ test('quick signing routes missing identity and unusable grants to account setti
|
||||
assert.deepEqual(p.calls.map(([method]) => method), ['status', 'start'])
|
||||
assert.equal(p.action.value.label, '查询签署状态')
|
||||
assert.match(p.message.value, copy)
|
||||
assert.match(p.message.value, /医生电子签署身份.*查询签署状态/)
|
||||
assert.match(p.message.value, /签署身份与证书/)
|
||||
authorized = true
|
||||
await p.action.value.run()
|
||||
assert.equal(p.action.value.label, '确认签名')
|
||||
@@ -451,7 +504,7 @@ test('SMS checks the repaired account profile before allowing another manual sen
|
||||
identity: async () => accountBasedIdentity('sms', { identity_status: 'ING', can_complete: false })
|
||||
})
|
||||
await p.refresh()
|
||||
assert.match(p.message.value, /医生电子签署身份/)
|
||||
assert.match(p.message.value, /签署身份与证书/)
|
||||
await p.sendSms()
|
||||
assert.deepEqual(p.calls.map(([method]) => method), ['status', 'profile'])
|
||||
|
||||
@@ -512,6 +565,53 @@ test('audit panel retains signing evidence when signing actions are hidden', asy
|
||||
assert.equal(p.signingTime.value.signatureTime, '2026/11/18 00:03:04')
|
||||
})
|
||||
|
||||
test('audit progress waits for a verified pharmacist signature and shows its trusted time', async () => {
|
||||
const doctor = status({ status: 'signed', can_sign: false, can_download: true, review_required: true })
|
||||
const p = panel(doctor)
|
||||
p.props.audit = true
|
||||
await p.refresh()
|
||||
assert.equal(p.showControls.value, false)
|
||||
assert.equal(p.showSteps.value, true)
|
||||
assert.equal(p.activeStep.value, 3)
|
||||
assert.match(p.message.value, /等待药师审核签署/)
|
||||
|
||||
const time = Date.parse('2026-11-17T16:03:04Z') / 1000
|
||||
p.updateReview({ required: true, state: 'verifying', signature_time: time, signer_name: '测试药师' })
|
||||
assert.equal(p.reviewSigning.value, null)
|
||||
assert.equal(p.activeStep.value, 3)
|
||||
p.updateReview({ required: true, state: 'signed', signature_time: 0, signer_name: '测试药师' })
|
||||
assert.equal(p.activeStep.value, 3)
|
||||
p.updateReview({ required: true, state: 'signed', signature_time: time, signer_name: '测试药师' })
|
||||
assert.equal(p.activeStep.value, 4)
|
||||
assert.deepEqual(p.reviewSigning.value, { time: '2026/11/18 00:03:04', name: '测试药师' })
|
||||
})
|
||||
|
||||
test('single-signed records retain three steps and archived pharmacist timestamps show a completed fourth step', async () => {
|
||||
const signed = status({ status: 'signed', can_sign: false, can_download: true })
|
||||
const single = panel(signed)
|
||||
assert.equal(single.showSteps.value, true)
|
||||
assert.equal(single.reviewRequired.value, false)
|
||||
assert.equal(single.activeStep.value, 3)
|
||||
const audit = panel(signed)
|
||||
audit.props.audit = true
|
||||
await audit.refresh()
|
||||
assert.equal(audit.showSteps.value, false)
|
||||
audit.updateReview({ required: true, state: 'pending' })
|
||||
assert.equal(audit.showSteps.value, true)
|
||||
assert.equal(audit.activeStep.value, 3)
|
||||
|
||||
const time = Date.parse('2026-11-17T16:03:04Z') / 1000
|
||||
for (const status of ['signed', 'voided']) {
|
||||
const response = { ...signed, status, review_signature_time: time, review_signer_name: '测试药师' }
|
||||
const dual = panel(signed, { refresh: async () => response })
|
||||
await dual.refresh()
|
||||
assert.equal(dual.showSteps.value, true)
|
||||
assert.equal(dual.reviewRequired.value, true)
|
||||
assert.equal(dual.activeStep.value, 4)
|
||||
assert.deepEqual(dual.reviewSigning.value, { time: '2026/11/18 00:03:04', name: '测试药师' })
|
||||
}
|
||||
})
|
||||
|
||||
test('audit signing panel directs unsigned work to the prescriber', async () => {
|
||||
let response = status()
|
||||
const p = panel(status(), { refresh: async () => response })
|
||||
@@ -1045,12 +1145,28 @@ test('supplementary identity is a masked input with explicit action and no persi
|
||||
const { descriptor } = parse(source)
|
||||
assert.match(descriptor.template.content, /v-model="identityNumber"\s+type="password"/)
|
||||
assert.match(descriptor.template.content, /autocomplete="off"/)
|
||||
assert.match(descriptor.template.content, /@click="action.run"/)
|
||||
assert.match(descriptor.template.content, /@click="runAction"/)
|
||||
assert.match(source, /const run = action\.value\.run\s+const current = operation\s+await run\(\)/)
|
||||
assert.match(source, /label: '确认签名', run: confirmSign/)
|
||||
assert.match(descriptor.template.content, /v-if="authUrl && dialogVisible/)
|
||||
assert.doesNotMatch(source, /show-password|localStorage|sessionStorage|console\.|window\.open|window\.location/)
|
||||
})
|
||||
|
||||
test('status checks and exiting authentication retain a visible notice without submitting a signature', async () => {
|
||||
const p = panel(status())
|
||||
p.confirmed.value = false
|
||||
await p.runAction()
|
||||
assert.match(p.statusNotice.value, /签署状态已更新/)
|
||||
p.dialogVisible.value = true
|
||||
p.identityNumber.value = 'private-input'
|
||||
p.closeAuthentication()
|
||||
assert.equal(p.dialogVisible.value, false)
|
||||
assert.equal(p.identityNumber.value, '')
|
||||
assert.match(p.statusNotice.value, /已退出本次签署/)
|
||||
assert.equal(p.action.value.label, '查询签署状态')
|
||||
assert.deepEqual(p.calls.map(([method]) => method), ['status'])
|
||||
})
|
||||
|
||||
function pageDeclarations(filename, selected, globals) {
|
||||
const fullPath = path.join(__dirname, '../src', filename)
|
||||
const source = parse(fs.readFileSync(fullPath, 'utf8'), { filename: fullPath }).descriptor.scriptSetup.content
|
||||
@@ -1069,6 +1185,146 @@ function pageDeclarations(filename, selected, globals) {
|
||||
return new Function(...Object.keys(globals), `${compiled}\nreturn { ${selected.join(', ')} }`)(...Object.values(globals))
|
||||
}
|
||||
|
||||
test('audit preview loads only its current prescription and refreshes after a signing change', async () => {
|
||||
const filename = 'PrescriptionAuditLayout.vue'
|
||||
const source = fs.readFileSync(path.join(__dirname, '../src/components', filename), 'utf8')
|
||||
const { descriptor } = parse(source, { filename })
|
||||
const script = compileScript(descriptor, { id: 'audit-preview-test' }).content
|
||||
const js = ts.transpileModule(script, {
|
||||
compilerOptions: { target: ts.ScriptTarget.ES2022, module: ts.ModuleKind.CommonJS }
|
||||
}).outputText
|
||||
const calls = []
|
||||
const imports = {
|
||||
vue,
|
||||
'@/api/tcm': { prescriptionDetail: ({ id }, signal) => new Promise((resolve) => calls.push({ id, signal, resolve })) },
|
||||
'@/components/prescription-slip/index.vue': { default: {} }
|
||||
}
|
||||
const exports = {}
|
||||
new Function('require', 'exports', js)((id) => imports[id], exports)
|
||||
const props = vue.reactive({ prescriptionId: null })
|
||||
const scope = vue.effectScope()
|
||||
const preview = scope.run(() => exports.default.setup(props, { expose() {} }))
|
||||
try {
|
||||
assert.equal(calls.length, 0)
|
||||
props.prescriptionId = 51
|
||||
await vue.nextTick()
|
||||
props.prescriptionId = 52
|
||||
await vue.nextTick()
|
||||
assert.equal(calls[0].signal.aborted, true)
|
||||
assert.deepEqual(calls.map((call) => call.id), [51, 52])
|
||||
calls[0].resolve({ id: 51 })
|
||||
calls[1].resolve({ id: 51 })
|
||||
await Promise.resolve()
|
||||
assert.equal(preview.detail.value, null)
|
||||
assert.match(preview.error.value, /重试/)
|
||||
|
||||
preview.retry.value++
|
||||
await vue.nextTick()
|
||||
calls[2].resolve({ id: 52, esign: { signature_time: 10 } })
|
||||
await Promise.resolve()
|
||||
assert.equal(preview.detail.value.id, 52)
|
||||
assert.equal(preview.error.value, '')
|
||||
|
||||
props.doctorSignedAt = 10
|
||||
await vue.nextTick()
|
||||
assert.equal(calls.length, 3)
|
||||
props.pharmacistSignedAt = 15
|
||||
await vue.nextTick()
|
||||
assert.equal(calls[3].id, 52)
|
||||
calls[3].resolve({ id: 52, esign: { signature_time: 10, review_signature_time: 15 } })
|
||||
await Promise.resolve()
|
||||
assert.equal(preview.detail.value.esign.review_signature_time, 15)
|
||||
} finally {
|
||||
scope.stop()
|
||||
}
|
||||
})
|
||||
|
||||
test('signing log orders actual events and preserves the time source and empty states', () => {
|
||||
const time = Date.parse('2026-11-17T16:03:04Z') / 1000
|
||||
const entries = [
|
||||
{ event: 'archived', label: '系统归档完成', time: time + 3, source: 'system' },
|
||||
{ event: 'signed', label: '医师签署', time, source: 'tsa', actor_name: '测试医师', message: '签署完成' },
|
||||
{ event: 'draft', label: '草稿已保存', time: time - 2, source: 'local' },
|
||||
{ event: 'invalid', label: '无效时间', time: 0, source: 'tsa' },
|
||||
{ event: 'unknown', label: '未知来源', time, source: 'unknown' }
|
||||
]
|
||||
const withEvents = panel(status({ signing_log: entries }))
|
||||
assert.deepEqual(withEvents.signingLog.value.map((entry) => [entry.event, entry.sourceLabel]), [
|
||||
['draft', '签名记录时间'], ['signed', '可信时间戳'], ['archived', '系统记录']
|
||||
])
|
||||
assert.equal(withEvents.signingLog.value[1].actor_name, '测试医师')
|
||||
assert.equal(withEvents.signingLog.value[1].message, '签署完成')
|
||||
assert.equal(withEvents.signingLog.value[1].timeText, '2026/11/18 00:03:04')
|
||||
assert.equal(entries[0].event, 'archived')
|
||||
assert.equal(withEvents.showSigningLog.value, true)
|
||||
|
||||
const pending = panel(status())
|
||||
assert.deepEqual(pending.signingLog.value, [])
|
||||
assert.equal(pending.showSigningLog.value, true)
|
||||
const audit = panel(status())
|
||||
audit.props.audit = true
|
||||
assert.equal(audit.showSigningLog.value, false)
|
||||
assert.equal(panel(status({ required: false, status: 'legacy' })).showSigningLog.value, false)
|
||||
})
|
||||
|
||||
test('both slips use verified physician and pharmacist PNGs and fall back to the signer names', () => {
|
||||
const png = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/x8AAwMCAO+jN9sAAAAASUVORK5CYII='
|
||||
const props = vue.reactive({ variant: 'internal', data: { doctor_name: '开方人', doctor_signature: png, esign: status({
|
||||
status: 'signed', doctor_signer_name: ' 测试医生 ',
|
||||
review_signature_time: 1794931384, review_signer_name: ' 测试药师 ', review_signature: png
|
||||
}) } })
|
||||
const component = 'components/prescription-slip/index.vue'
|
||||
const { doctorName, doctorSignature, failedDoctorSignature, reviewerName, reviewerSignature, failedReviewerSignature } = pageDeclarations(component,
|
||||
['verifiedDoctor', 'doctorName', 'failedDoctorSignature', 'doctorSignature',
|
||||
'reviewerName', 'failedReviewerSignature', 'reviewerSignature', 'isVerifiedSignaturePng'],
|
||||
{ computed: vue.computed, ref: vue.ref, props })
|
||||
for (const variant of ['internal', 'user']) {
|
||||
props.variant = variant
|
||||
assert.equal(doctorName.value, '测试医生')
|
||||
assert.equal(doctorSignature.value, png)
|
||||
assert.equal(reviewerName.value, '测试药师')
|
||||
assert.equal(reviewerSignature.value, png)
|
||||
failedDoctorSignature.value = png
|
||||
failedReviewerSignature.value = png
|
||||
assert.equal(doctorSignature.value, '')
|
||||
assert.equal(reviewerSignature.value, '')
|
||||
assert.equal(doctorName.value, '测试医生')
|
||||
assert.equal(reviewerName.value, '测试药师')
|
||||
failedDoctorSignature.value = ''
|
||||
failedReviewerSignature.value = ''
|
||||
}
|
||||
|
||||
props.data.esign.status = 'pending'
|
||||
assert.equal(doctorSignature.value, '')
|
||||
assert.equal(doctorName.value, '开方人')
|
||||
assert.equal(reviewerName.value, '')
|
||||
assert.equal(reviewerSignature.value, '')
|
||||
props.data.esign.status = 'signed'
|
||||
props.data.esign.review_signature = 'data:image/svg+xml;base64,PHN2Zz4='
|
||||
assert.equal(reviewerSignature.value, '')
|
||||
assert.equal(reviewerName.value, '测试药师')
|
||||
})
|
||||
|
||||
test('the slip reloads a newly verified physician seal once from prescription detail', async () => {
|
||||
const requests = []
|
||||
const { updatePrescriptionSlipEsign } = loadModule('utils/prescription-esign.ts', { '@/api/tcm': {
|
||||
prescriptionDetail: async ({ id }) => {
|
||||
requests.push(id)
|
||||
return { id, doctor_signature: 'verified seal' }
|
||||
}
|
||||
} })
|
||||
const signed = status({ status: 'signed', can_sign: false, can_download: true })
|
||||
const slip = { id: 17, esign: status(), doctor_signature: 'old signature' }
|
||||
|
||||
const refreshed = updatePrescriptionSlipEsign(slip, signed)
|
||||
assert.equal(slip.esign, signed)
|
||||
assert.equal(slip.doctor_signature, '')
|
||||
await refreshed
|
||||
assert.equal(slip.doctor_signature, 'verified seal')
|
||||
await updatePrescriptionSlipEsign(slip, signed)
|
||||
assert.deepEqual(requests, [17])
|
||||
})
|
||||
|
||||
test('shared editor permits an unsigned save only in enabled mode and retains the saved id after detail failure', async () => {
|
||||
for (const enabled of [false, true]) {
|
||||
const requests = []
|
||||
@@ -1105,7 +1361,7 @@ test('consumer editor keeps the saved prescription open for signing instead of r
|
||||
formRef: vue.ref({ validate: async () => {} }), submitLoading: vue.ref(false),
|
||||
esignReady: vue.ref(true), esignEnabled: vue.ref(true), loadEsignConfig: async () => true,
|
||||
editForm: { herbs: [{ name: 'test herb', dosage: 1 }], doctor_signature: '' },
|
||||
editMode: vue.ref('add'), showEdit: vue.ref(true), herbValidationLabel: () => 'test herb',
|
||||
editMode: vue.ref('add'), showEdit: vue.ref(true), reissueContext: vue.ref(null), herbValidationLabel: () => 'test herb',
|
||||
prescriptionAdd: async () => ({ id: 17, esign: status() }),
|
||||
prescriptionEdit: async () => { throw new Error('wrong API') },
|
||||
handleView: async (row) => viewed.push(row), getLists: () => {},
|
||||
@@ -1119,7 +1375,177 @@ test('consumer editor keeps the saved prescription open for signing instead of r
|
||||
assert.match(messages[0], /处方草稿已保存/)
|
||||
})
|
||||
|
||||
test('opening a consumer audit clears previous evidence and allows rejection while signing is pending', async () => {
|
||||
test('list upload can retry and opens signing without exposing audit to the pharmacist', async () => {
|
||||
const requests = []
|
||||
const messages = []
|
||||
const opened = []
|
||||
const row = {
|
||||
id: 17, audit_status: 0, review_submitted_at: 0, can_submit_for_review: true, can_review_prescription: false,
|
||||
esign: status({ awaiting_upload: true, can_sign: false })
|
||||
}
|
||||
const drawer = { ...row }
|
||||
const { pendingPrescriptionReviewLabel } = loadModule('utils/prescription-esign.ts', { '@/api/tcm': {} })
|
||||
const globals = {
|
||||
pager: { lists: [row] }, slipView: vue.ref(drawer), uploadingPrescriptionId: vue.ref(0),
|
||||
getLists: async () => {},
|
||||
handleView: async (rx) => { opened.push(rx.id) },
|
||||
prescriptionSubmitForReview: async (params) => {
|
||||
requests.push(params)
|
||||
if (requests.length === 1) throw new Error('temporary network error')
|
||||
return { review_submitted_at: 1760000000, can_submit_for_review: false }
|
||||
},
|
||||
feedback: { msgSuccess: (message) => messages.push(message) }
|
||||
}
|
||||
const { submitPrescriptionForReview, canOpenPrescriptionAudit } = pageDeclarations(
|
||||
'views/consumer/prescription/index.vue',
|
||||
['isPendingPrescriptionAudit', 'canOpenPrescriptionAudit', 'submitPrescriptionForReview'], globals
|
||||
)
|
||||
assert.equal(canOpenPrescriptionAudit(row), false)
|
||||
assert.equal(pendingPrescriptionReviewLabel(row), '待上传')
|
||||
await submitPrescriptionForReview({ ...row, can_submit_for_review: false })
|
||||
assert.equal(requests.length, 0)
|
||||
await submitPrescriptionForReview(row)
|
||||
assert.equal(canOpenPrescriptionAudit(row), false)
|
||||
assert.equal(globals.uploadingPrescriptionId.value, 0)
|
||||
await submitPrescriptionForReview(row)
|
||||
assert.deepEqual(requests, [{ id: 17 }, { id: 17 }])
|
||||
assert.equal(canOpenPrescriptionAudit(row), false)
|
||||
assert.equal(canOpenPrescriptionAudit(globals.slipView.value), false)
|
||||
assert.equal(pendingPrescriptionReviewLabel(row), '待医师签署')
|
||||
const verified = {
|
||||
...row, can_review_prescription: true,
|
||||
esign: { ...row.esign, status: 'signed', can_review_prescription: true }
|
||||
}
|
||||
assert.equal(canOpenPrescriptionAudit(verified), true)
|
||||
assert.equal(pendingPrescriptionReviewLabel(verified), '待审核')
|
||||
assert.equal(canOpenPrescriptionAudit({ ...verified, void_status: 1 }), false)
|
||||
assert.equal(row.can_submit_for_review, false)
|
||||
assert.equal(globals.slipView.value.esign.review_submitted_at, 1760000000)
|
||||
assert.deepEqual(opened, [17])
|
||||
assert.match(messages[0], /请完成医师签署/)
|
||||
})
|
||||
|
||||
test('issued prescriptions can void pending drafts with permission and keep the record', async () => {
|
||||
const calls = []
|
||||
const messages = []
|
||||
let cancel = true
|
||||
let refreshes = 0
|
||||
const row = { id: 17, audit_status: '0', can_void: true, can_submit_for_review: true }
|
||||
const globals = {
|
||||
voidingPrescriptionId: vue.ref(0),
|
||||
prescriptionVoid: async (params) => {
|
||||
calls.push(params)
|
||||
if (calls.length === 1) throw new Error('temporary failure')
|
||||
},
|
||||
getLists: async () => { refreshes++ },
|
||||
feedback: {
|
||||
confirm: async () => { if (cancel) throw new Error('cancel') },
|
||||
msgSuccess: (message) => messages.push(message)
|
||||
}
|
||||
}
|
||||
const { canVoidPendingPrescription, voidPendingPrescription } = pageDeclarations(
|
||||
'views/consumer/prescription/index.vue',
|
||||
['isPendingPrescriptionAudit', 'canVoidPendingPrescription', 'voidPendingPrescription'], globals
|
||||
)
|
||||
assert.equal(canVoidPendingPrescription(row), true)
|
||||
for (const other of [{ audit_status: 1 }, { audit_status: 2 }, { void_status: 1 }, { can_void: false }]) {
|
||||
await voidPendingPrescription({ ...row, ...other })
|
||||
}
|
||||
await voidPendingPrescription(row)
|
||||
assert.deepEqual(calls, [])
|
||||
cancel = false
|
||||
await voidPendingPrescription(row)
|
||||
assert.equal(canVoidPendingPrescription(row), true)
|
||||
await Promise.all([voidPendingPrescription(row), voidPendingPrescription(row)])
|
||||
assert.deepEqual(calls, [{ id: 17, pending_only: true }, { id: 17, pending_only: true }])
|
||||
assert.equal(row.void_status, 1)
|
||||
assert.equal(row.can_submit_for_review, false)
|
||||
assert.equal(canVoidPendingPrescription(row), false)
|
||||
assert.equal(refreshes, 1)
|
||||
assert.deepEqual(messages, ['处方已作废'])
|
||||
})
|
||||
|
||||
test('issued prescriptions reopen a voided record as a new prescription with fresh signature and review', async () => {
|
||||
const source = {
|
||||
id: 17, sn: 'RX0017', visit_no: 'RX0017', void_status: '1', creator_id: '8',
|
||||
prescription_date: '2025-01-01', prescription_type: '饮片', dosage_amount: '120',
|
||||
diagnosis_id: 18, appointment_id: 19, patient_id: 20, phone: 'test', patient_name: '虚构测试',
|
||||
clinical_diagnosis: '虚构诊断', herbs: [{ name: '测试药材', dosage: 1, formula_type: '辅方' }],
|
||||
dietary_taboo: ['测试项目'], prescription_name: '测试处方', case_record: { archive: true },
|
||||
audit_status: 2, doctor_signature: 'data:image/png;base64,old', esign: status({ status: 'voided' }),
|
||||
prescription_order_id: 21, is_shared: 1, visible_role_ids: [22]
|
||||
}
|
||||
const newEsign = status({ status: 'pending', awaiting_upload: true })
|
||||
const view = []
|
||||
const saves = []
|
||||
const reads = []
|
||||
const warnings = []
|
||||
const form = { aux_usage: {} }
|
||||
let permitted = true
|
||||
let detail = { ...source, void_status: 0 }
|
||||
const globals = {
|
||||
userStore: { userInfo: { id: 8, name: '虚构医师' } }, hasPermission: () => permitted,
|
||||
showEdit: vue.ref(false), editMode: vue.ref('view'), slipView: vue.ref(null), editForm: form,
|
||||
reissueContext: vue.ref(null), reissuingPrescriptionId: vue.ref(0), isLoadingData: vue.ref(false),
|
||||
editingWasVoid: vue.ref(true), editingWasRejected: vue.ref(true),
|
||||
nextTick: vue.nextTick, formRef: vue.ref({ clearValidate() {}, validate: async () => true }),
|
||||
loadEsignConfig: async () => true, scheduleEditSignatureInit() {}, clearRxLinkedOrderHint() {},
|
||||
dayRangeStrings: () => ({ start: '2026-11-23 00:00:00' }), defaultAuxUsage: () => ({}),
|
||||
normalizeAuxUsageForm: () => ({}), normalizeSlipHerbs: (herbs) => herbs.map((herb) => ({ ...herb })),
|
||||
submitLoading: vue.ref(false), esignReady: vue.ref(true), esignEnabled: vue.ref(true),
|
||||
herbValidationLabel: () => '药材', prescriptionDetail: async (params) => { reads.push(params); return detail },
|
||||
prescriptionAdd: async (params) => { saves.push(params); return { id: 23, esign: newEsign } },
|
||||
prescriptionEdit: async () => assert.fail('reissue edited original prescription'),
|
||||
handleView: async (row) => view.push(row), getLists() {},
|
||||
feedback: { msgSuccess() {}, msgWarning: (message) => warnings.push(message), msgError: assert.fail }
|
||||
}
|
||||
const { canReissuePrescription, handleReissue, handleSubmit, handleAdd } = pageDeclarations(
|
||||
'views/consumer/prescription/index.vue',
|
||||
['resetForm', 'fillPrescriptionContents', 'openNewPrescription', 'handleAdd', 'canReissuePrescription', 'handleReissue', 'handleSubmit'], globals
|
||||
)
|
||||
assert.equal(canReissuePrescription(source), true)
|
||||
await handleReissue({ ...source, void_status: 0 })
|
||||
await handleReissue({ ...source, creator_id: 9 })
|
||||
permitted = false
|
||||
await handleReissue(source)
|
||||
assert.deepEqual(reads, [])
|
||||
permitted = true
|
||||
await handleReissue(source)
|
||||
assert.equal(globals.showEdit.value, false)
|
||||
assert.equal(warnings.length, 1)
|
||||
detail = source
|
||||
await Promise.all([handleReissue(source), handleReissue(source)])
|
||||
assert.deepEqual(reads, [{ id: 17 }, { id: 17 }])
|
||||
assert.equal(globals.showEdit.value, true)
|
||||
assert.equal(globals.editMode.value, 'add')
|
||||
assert.equal(form.id, 0)
|
||||
assert.equal(form.doctor_signature, '')
|
||||
assert.equal(form.prescription_date, '2026-11-23')
|
||||
assert.equal(form.dosage_amount, 120)
|
||||
assert.deepEqual(form.herbs, source.herbs)
|
||||
form.dietary_taboo.push('本次新增')
|
||||
assert.deepEqual(source.dietary_taboo, ['测试项目'])
|
||||
await handleSubmit()
|
||||
const [saved] = saves
|
||||
assert.equal(saved.audit_status, 0)
|
||||
assert.equal(saved.diagnosis_id, 18)
|
||||
assert.equal(saved.appointment_id, 19)
|
||||
assert.equal(saved.patient_id, 20)
|
||||
assert.equal(saved.phone, 'test')
|
||||
assert.equal(saved.prescription_name, '测试处方')
|
||||
assert.equal(saved.case_record, undefined)
|
||||
assert.equal(saved.doctor_signature, '')
|
||||
assert.deepEqual(saved.visible_role_ids, [])
|
||||
for (const field of ['sn', 'visit_no', 'void_status', 'esign', 'prescription_order_id']) {
|
||||
assert.equal(Object.hasOwn(saved, field), false)
|
||||
}
|
||||
assert.equal(view[0].id, 23)
|
||||
assert.deepEqual(view[0].esign, newEsign)
|
||||
handleAdd()
|
||||
assert.equal(globals.reissueContext.value, null)
|
||||
})
|
||||
|
||||
test('opening a submitted consumer audit clears previous evidence and still needs pharmacist signature for approval', async () => {
|
||||
const requests = []
|
||||
const { canApprovePrescriptionEsign } = loadModule('utils/prescription-esign.ts', { '@/api/tcm': {} })
|
||||
const signed = status({ status: 'signed', can_download: true, can_sign: false })
|
||||
@@ -1133,10 +1559,14 @@ test('opening a consumer audit clears previous evidence and allows rejection whi
|
||||
}
|
||||
const { openAuditDialog, onAuditEsignStatusChange, submitAudit } = pageDeclarations(
|
||||
'views/consumer/prescription/index.vue',
|
||||
['canApproveAudit', 'openAuditDialog', 'onAuditEsignStatusChange', 'submitAudit'], globals
|
||||
['canApproveAudit', 'isPendingPrescriptionAudit', 'canOpenPrescriptionAudit', 'openAuditDialog', 'onAuditEsignStatusChange', 'submitAudit'], globals
|
||||
)
|
||||
|
||||
openAuditDialog(17)
|
||||
openAuditDialog({ id: 17, audit_status: 0, review_submitted_at: 0 })
|
||||
assert.equal(globals.auditDialogVisible.value, false)
|
||||
openAuditDialog({ id: 17, audit_status: 0, review_submitted_at: 1760000000, can_review_prescription: false })
|
||||
assert.equal(globals.auditDialogVisible.value, false)
|
||||
openAuditDialog({ id: 17, audit_status: 0, review_submitted_at: 1760000000, can_review_prescription: true })
|
||||
assert.equal(globals.auditEsign.value, null)
|
||||
assert.equal(globals.auditReview.value, null)
|
||||
await submitAudit('approve')
|
||||
@@ -1146,7 +1576,7 @@ test('opening a consumer audit clears previous evidence and allows rejection whi
|
||||
globals.auditRemark.value = '处方需修正'
|
||||
await submitAudit('reject')
|
||||
|
||||
openAuditDialog(18)
|
||||
openAuditDialog({ id: 18, audit_status: 0, review_submitted_at: 1760000000, can_review_prescription: true })
|
||||
onAuditEsignStatusChange(signed)
|
||||
await submitAudit('approve')
|
||||
assert.equal(requests.length, 1, 'a single verified doctor signature cannot approve')
|
||||
@@ -1181,8 +1611,13 @@ for (const filename of [
|
||||
}
|
||||
const isFirstVisit = filename.includes('OrderActionHost')
|
||||
const open = isFirstVisit ? 'openAction' : 'openAudit'
|
||||
const handlers = pageDeclarations(filename, ['canApproveAudit', open, 'submitAudit'], globals)
|
||||
handlers[open]({ id: 17, prescription_id: 51 }, isFirstVisit ? 'audit_prescription' : 'prescription')
|
||||
const helpers = isFirstVisit ? [] : ['canRxAudit']
|
||||
const handlers = pageDeclarations(filename, ['canApproveAudit', ...helpers, open, 'submitAudit'], globals)
|
||||
const row = { id: 17, prescription_id: 51, prescription_audit_status: 0, fulfillment_status: 1 }
|
||||
const prescriptionAction = isFirstVisit ? 'audit_prescription' : 'prescription'
|
||||
handlers[open]({ ...row, can_review_prescription: false }, prescriptionAction)
|
||||
assert.equal(globals.auditVisible.value, false)
|
||||
handlers[open]({ ...row, can_review_prescription: true }, prescriptionAction)
|
||||
await handlers.submitAudit('approve')
|
||||
assert.deepEqual(requests, [])
|
||||
|
||||
@@ -1204,6 +1639,7 @@ for (const filename of [
|
||||
for (const filename of [
|
||||
'components/EsignPrescriptionPanel.vue',
|
||||
'components/EsignReviewPanel.vue',
|
||||
'components/prescription-slip/index.vue',
|
||||
'components/tcm-prescription/index.vue',
|
||||
'views/consumer/prescription/index.vue',
|
||||
'views/consumer/prescription/order_list.vue',
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
const assert = require('node:assert/strict')
|
||||
const fs = require('node:fs')
|
||||
const path = require('node:path')
|
||||
const test = require('node:test')
|
||||
const ts = require('typescript')
|
||||
const { parse, compileScript, compileTemplate } = require('@vue/compiler-sfc')
|
||||
|
||||
const viewDir = path.join(__dirname, '../src/views/consumer/prescription')
|
||||
const source = fs.readFileSync(path.join(viewDir, 'components/prescription-list-signing-status.ts'), 'utf8')
|
||||
const { outputText } = ts.transpileModule(source, {
|
||||
compilerOptions: { module: ts.ModuleKind.CommonJS, target: ts.ScriptTarget.ES2022 }
|
||||
})
|
||||
const moduleExports = {}
|
||||
new Function('exports', outputText)(moduleExports)
|
||||
const { prescriptionListSigningStatus } = moduleExports
|
||||
|
||||
test('list separates prescriber and pharmacist signing from audit outcome', () => {
|
||||
const cases = [
|
||||
[{ status: 'pending', required: true, awaiting_upload: true }, '上传后签署', 'info'],
|
||||
[{ status: 'pending' }, '待医师签署', 'warning'],
|
||||
[{ status: 'authenticating' }, '待医师确认签署', 'warning'],
|
||||
[{ status: 'signing' }, '医师签署中', 'primary'],
|
||||
[{ status: 'failed' }, '医师签署未完成', 'danger'],
|
||||
[{ status: 'uncertain' }, '医师签署待核实', 'warning'],
|
||||
[{ status: 'signed', can_download: false }, '医师签署待核实', 'warning'],
|
||||
[{ status: 'signed', can_download: true }, '医师已签署', 'success'],
|
||||
[{ status: 'signed', can_download: true, awaiting_upload: true, review_required: true }, '医师已签署', 'success'],
|
||||
[{ status: 'signed', can_download: true, review_required: true }, '待药师签署', 'warning'],
|
||||
[{ status: 'signed', can_download: true, review_required: true, review_state: 'pending' }, '待药师签署', 'warning'],
|
||||
[{ status: 'signed', can_download: true, review_required: true, review_state: 'signing' }, '药师签署中', 'primary'],
|
||||
[{ status: 'signed', can_download: true, review_required: true, review_state: 'verifying' }, '药师验签中', 'primary'],
|
||||
[{ status: 'signed', can_download: true, review_required: true, review_state: 'failed' }, '药师签署未完成', 'danger'],
|
||||
[{ status: 'signed', can_download: true, review_required: true, review_state: 'uncertain' }, '药师签署待核实', 'warning'],
|
||||
[{ status: 'signed', can_download: true, review_required: true, review_state: 'signed' }, '已完成双签', 'success'],
|
||||
[{ status: 'signed', can_download: true, review_signature_time: 1712345678 }, '已完成双签', 'success'],
|
||||
[{ status: 'legacy' }, '历史处方', 'info'],
|
||||
[{ status: 'voided' }, '已作废', 'danger'],
|
||||
[{ status: 'unavailable' }, '签署状态待核实', 'warning'],
|
||||
[undefined, '签署状态待核实', 'warning']
|
||||
]
|
||||
for (const [esign, label, type] of cases) {
|
||||
for (const audit_status of [0, 1, 2]) {
|
||||
assert.deepEqual(prescriptionListSigningStatus({ esign, audit_status }), { label, type })
|
||||
}
|
||||
}
|
||||
assert.deepEqual(prescriptionListSigningStatus({ esign: { status: 'legacy' }, void_status: '1' }),
|
||||
{ label: '已作废', type: 'danger' })
|
||||
})
|
||||
|
||||
test('issued prescription template renders signing in a dedicated table column', () => {
|
||||
const filename = path.join(viewDir, 'index.vue')
|
||||
const { descriptor, errors } = parse(fs.readFileSync(filename, 'utf8'), { filename })
|
||||
assert.deepEqual(errors, [])
|
||||
const template = descriptor.template.content
|
||||
assert.match(template, /label="审核状态"[\s\S]+?listAuditStatusLabel\(row\)[\s\S]+?<\/el-table-column>/)
|
||||
assert.match(template, /label="签署状态"[\s\S]+?prescriptionListSigningStatus\(row\)\.label[\s\S]+?<\/el-table-column>/)
|
||||
const script = compileScript(descriptor, { id: 'prescription-list' })
|
||||
const compiled = compileTemplate({ filename, source: template, id: 'prescription-list', compilerOptions: { bindingMetadata: script.bindings } })
|
||||
assert.deepEqual(compiled.errors, [])
|
||||
})
|
||||
Reference in New Issue
Block a user