已签署处方在业务订单中可修改服用参数(只改订单页面与药房下单,不改 CA 签署原件);查看处方可下载 CA 原件或当前样式的药房联/处方联

- 处方已电子签署(内容冻结)时,「修改服用参数」改写为订单级覆盖值 usage_override(次数/天数/袋数,含辅方),
  签署原文、快照哈希与 CA PDF 不变;订单详情、处方笺、甘草/洛阳下单按本订单生效值;未签署处方仍直接修改处方
- 已发货锁定天数按生效值比较;重新开方改关联时清除旧覆盖值
- 迁移 2026_11_30_prescription_order_usage_override.sql
- 业务订单「查看处方」下载改为下拉:CA 签署处方 PDF、药房联 PDF、处方联 PDF(当前页面样式,A4);PC 与 H5 一致
- 重新构建管理后台

Co-Authored-By: Claude Opus 5 <[EMAIL]>
This commit is contained in:
Your Name
2026-11-30 14:49:34 +08:00
co-authored by Claude Opus 5
parent 562f8d6ce4
commit dc18098566
392 changed files with 566 additions and 397 deletions
@@ -327,6 +327,40 @@ function computeAuxOutPellet(data: Record<string, any>): string {
return days > 0 && times > 0 && doseG > 0 ? formatNum(days * times * doseG * bags) : ''
}
/**
* 合并业务订单的服用参数覆盖:已签署(CA 冻结)处方在订单中修改的次数/天数/袋数记在订单 usage_override,
* 只作用于该订单的页面与药房下单,签署原文不变。与服务端 PrescriptionOrderLogic::applyUsageOverride 一致。
*/
export function applyOrderUsageOverride<T extends Record<string, any>>(rx: T, rawOverride: unknown): T {
let override: unknown = rawOverride
if (typeof override === 'string') {
try {
override = JSON.parse(override)
} catch {
override = null
}
}
if (!override || typeof override !== 'object' || Array.isArray(override)) return rx
const o = override as Record<string, any>
const out: Record<string, any> = { ...rx }
for (const key of ['times_per_day', 'usage_days', 'dosage_bag_count']) {
if (o[key] != null && Number.isFinite(Number(o[key]))) out[key] = Number(o[key])
}
if (o.aux_usage && typeof o.aux_usage === 'object') {
let aux = out.aux_usage
if (typeof aux === 'string') {
try {
aux = JSON.parse(aux)
} catch {
aux = null
}
}
out.aux_usage = { ...(aux && typeof aux === 'object' ? aux : {}), ...o.aux_usage }
}
out.usage_overridden = 1
return out as T
}
export function rxOutPelletText(data: Record<string, any> | null | undefined): string {
if (!data) return ''
const out = computeOutPellet(data)
@@ -964,6 +964,14 @@
:rules="patchUsageRules"
label-width="108px"
>
<el-alert
v-if="usageFrozenBySignature"
type="warning"
:closable="false"
show-icon
class="mb-3"
title="处方已电子签署:此处修改只作用于本订单的页面与药房下单,CA 签署的处方原件不变。"
/>
<el-alert
v-if="daysLocked"
type="info"
@@ -1366,7 +1374,12 @@ const detailRxHerbs = computed(() => normalizeSlipHerbs(detailPrescription.value
const detailHasAuxHerbs = computed(() => prescriptionHasAuxFormula(detailPrescription.value as any))
/** 已发货的订单服用天数锁定(服务端 days_locked,同样拦截保存) */
const daysLocked = computed(() => detailData.value?.days_locked === true)
const daysLocked = computed(() => detailData.value?.days_locked === true)
/** 处方已进入电子签署(内容冻结),服用参数改写为订单级覆盖值 */
const usageFrozenBySignature = computed(() => {
const esign = (detailPrescription.value as any)?.esign
return esign?.required === true && esign?.status !== 'pending'
})
/** 详情:辅方用法(aux_usage JSON 经规范化后的对象,与处方类型一致) */
const detailAuxUsage = computed(() => {
@@ -1810,14 +1810,24 @@
>
下载图片
</el-button>
<el-button
size="small"
:loading="prescriptionSlipExporting"
:disabled="requiresOriginalEsignPdf(prescriptionViewData.esign) && !prescriptionViewData.esign?.can_download"
@click="downloadPrescriptionSlipPdf"
<el-dropdown
trigger="click"
:disabled="prescriptionSlipExporting"
@command="downloadPrescriptionSlipPdf"
>
{{ requiresOriginalEsignPdf(prescriptionViewData.esign) ? '下载已签原始 PDF' : '下载PDF' }}
</el-button>
<el-button size="small" type="primary" :loading="prescriptionSlipExporting">下载 PDF (A4)</el-button>
<template #dropdown>
<el-dropdown-menu>
<el-dropdown-item
v-if="requiresOriginalEsignPdf(prescriptionViewData.esign)"
command="esign"
:disabled="!prescriptionViewData.esign?.can_download"
>CA 签署处方 PDF</el-dropdown-item>
<el-dropdown-item command="internal">药房联 PDF(当前页面样式)</el-dropdown-item>
<el-dropdown-item command="user">处方联 PDF(当前页面样式)</el-dropdown-item>
</el-dropdown-menu>
</template>
</el-dropdown>
</div>
</div>
</template>
@@ -2156,11 +2166,12 @@ import {
getDoctors,
getAssistants
} from '@/api/tcm'
import PrescriptionSlip from '@/components/prescription-slip/index.vue'
import PrescriptionSlip from '@/components/prescription-slip/index.vue'
import { applyOrderUsageOverride } from '@/components/prescription-slip/utils'
import EsignPrescriptionPanel from '@/components/EsignPrescriptionPanel.vue'
import PrescriptionAuditLayout from '@/components/PrescriptionAuditLayout.vue'
import type { PrescriptionEsignStatus } from '@/api/tcm'
import { canApprovePrescriptionEsign, downloadPrescriptionPdfIfRequired, requiresOriginalEsignPdf, updatePrescriptionSlipEsign } from '@/utils/prescription-esign'
import { canApprovePrescriptionEsign, downloadOriginalEsignPdf, requiresOriginalEsignPdf, updatePrescriptionSlipEsign } from '@/utils/prescription-esign'
import html2canvas from 'html2canvas'
import { jsPDF } from 'jspdf'
import { getDictData } from '@/api/app'
@@ -5002,7 +5013,8 @@ async function openPrescriptionView(row: any) {
const base = res?.data ?? res ?? null
if (base) {
const md = row.medication_days
const merged: Record<string, unknown> = { ...base }
// 已签署处方在本订单修改过的服用参数(订单 usage_override),笺面按本订单生效值显示;CA 签署原件不变。
const merged: Record<string, unknown> = applyOrderUsageOverride({ ...base }, row.usage_override)
if (md != null && String(md).trim() !== '') {
merged.medication_days = md
}
@@ -5135,7 +5147,8 @@ async function capturePrescriptionSlipCanvas(): Promise<HTMLCanvasElement> {
function slipDownloadBaseName() {
const name = prescriptionViewData.value?.patient_name
const safe = typeof name === 'string' && name.trim() ? name.trim().replace(/[\\/:*?"<>|]/g, '_') : '未命名'
return `处方_${safe}_${Date.now()}`
const copy = prescriptionTabType.value === 'internal' ? '药房联' : '处方联'
return `${copy}_${safe}_${Date.now()}`
}
async function downloadPrescriptionSlipImage() {
@@ -5155,11 +5168,19 @@ async function downloadPrescriptionSlipImage() {
}
}
async function downloadPrescriptionSlipPdf() {
/** 下载 PDF:CA 签署原件,或按当前页面样式导出药房联 / 处方联(含本订单生效的服用参数与签章) */
async function downloadPrescriptionSlipPdf(command: 'esign' | 'internal' | 'user' = 'internal') {
if (!prescriptionViewData.value) return
prescriptionSlipExporting.value = true
try {
if (await downloadPrescriptionPdfIfRequired(Number(prescriptionViewData.value.id))) return
if (command === 'esign') {
await downloadOriginalEsignPdf(Number(prescriptionViewData.value.id))
return
}
if (prescriptionTabType.value !== command) {
prescriptionTabType.value = command
await nextTick()
}
const canvas = await capturePrescriptionSlipCanvas()
const imgData = canvas.toDataURL('image/jpeg', 0.95)
/**
@@ -2413,14 +2413,24 @@
>
下载图片
</el-button>
<el-button
size="small"
:loading="prescriptionSlipExporting"
:disabled="requiresOriginalEsignPdf(prescriptionViewData.esign) && !prescriptionViewData.esign?.can_download"
@click="downloadPrescriptionSlipPdf"
<el-dropdown
trigger="click"
:disabled="prescriptionSlipExporting"
@command="downloadPrescriptionSlipPdf"
>
{{ requiresOriginalEsignPdf(prescriptionViewData.esign) ? '下载已签原始 PDF' : '下载PDF' }}
</el-button>
<el-button size="small" type="primary" :loading="prescriptionSlipExporting">下载 PDF (A4)</el-button>
<template #dropdown>
<el-dropdown-menu>
<el-dropdown-item
v-if="requiresOriginalEsignPdf(prescriptionViewData.esign)"
command="esign"
:disabled="!prescriptionViewData.esign?.can_download"
>CA 签署处方 PDF</el-dropdown-item>
<el-dropdown-item command="internal">药房联 PDF(当前页面样式)</el-dropdown-item>
<el-dropdown-item command="user">处方联 PDF(当前页面样式)</el-dropdown-item>
</el-dropdown-menu>
</template>
</el-dropdown>
</div>
</div>
</template>
@@ -2723,11 +2733,12 @@ import {
supplyModeLabel,
supplyModeTagType
} from './components/prescription-order-utils'
import PrescriptionSlip from '@/components/prescription-slip/index.vue'
import PrescriptionSlip from '@/components/prescription-slip/index.vue'
import { applyOrderUsageOverride } from '@/components/prescription-slip/utils'
import EsignPrescriptionPanel from '@/components/EsignPrescriptionPanel.vue'
import PrescriptionAuditLayout from '@/components/PrescriptionAuditLayout.vue'
import type { PrescriptionEsignStatus } from '@/api/tcm'
import { canApprovePrescriptionEsign, downloadPrescriptionPdfIfRequired, requiresOriginalEsignPdf, updatePrescriptionSlipEsign } from '@/utils/prescription-esign'
import { canApprovePrescriptionEsign, downloadOriginalEsignPdf, requiresOriginalEsignPdf, updatePrescriptionSlipEsign } from '@/utils/prescription-esign'
import html2canvas from 'html2canvas'
import { jsPDF } from 'jspdf'
import { getDictData } from '@/api/app'
@@ -5760,7 +5771,8 @@ async function openPrescriptionView(row: any) {
const base = res?.data ?? res ?? null
if (base) {
const md = row.medication_days
const merged: Record<string, unknown> = { ...base }
// 已签署处方在本订单修改过的服用参数(订单 usage_override),笺面按本订单生效值显示;CA 签署原件不变。
const merged: Record<string, unknown> = applyOrderUsageOverride({ ...base }, row.usage_override)
if (md != null && String(md).trim() !== '') {
merged.medication_days = md
}
@@ -5890,7 +5902,8 @@ async function capturePrescriptionSlipCanvas(): Promise<HTMLCanvasElement> {
function slipDownloadBaseName() {
const name = prescriptionViewData.value?.patient_name
const safe = typeof name === 'string' && name.trim() ? name.trim().replace(/[\\/:*?"<>|]/g, '_') : '未命名'
return `处方_${safe}_${Date.now()}`
const copy = prescriptionTabType.value === 'internal' ? '药房联' : '处方联'
return `${copy}_${safe}_${Date.now()}`
}
async function downloadPrescriptionSlipImage() {
@@ -5910,11 +5923,19 @@ async function downloadPrescriptionSlipImage() {
}
}
async function downloadPrescriptionSlipPdf() {
/** 下载 PDF:CA 签署原件,或按当前页面样式导出药房联 / 处方联(含本订单生效的服用参数与签章) */
async function downloadPrescriptionSlipPdf(command: 'esign' | 'internal' | 'user' = 'internal') {
if (!prescriptionViewData.value) return
prescriptionSlipExporting.value = true
try {
if (await downloadPrescriptionPdfIfRequired(Number(prescriptionViewData.value.id))) return
if (command === 'esign') {
await downloadOriginalEsignPdf(Number(prescriptionViewData.value.id))
return
}
if (prescriptionTabType.value !== command) {
prescriptionTabType.value = command
await nextTick()
}
const canvas = await capturePrescriptionSlipCanvas()
const imgData = canvas.toDataURL('image/jpeg', 0.95)
/**