From 7c916d805356e6e03a3315e8a67ba4d9fb72e372 Mon Sep 17 00:00:00 2001 From: Your Name Date: Fri, 27 Nov 2026 18:27:13 +0800 Subject: [PATCH] =?UTF-8?q?=E7=AD=BE=E7=BD=B2=E5=8E=9F=E6=96=87=E4=B8=AD?= =?UTF-8?q?=E9=87=91=E9=A2=9D=E4=B8=BA=200=E3=80=81=E8=BE=85=E6=96=B9?= =?UTF-8?q?=E4=B8=8D=E4=BB=A3=E7=85=8E=E6=97=B6=E4=B8=8D=E5=86=8D=E5=86=99?= =?UTF-8?q?=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 金额(元)为 0 / 0.00 时省略,非 0 照常写入 - 辅方代煎为 0 时省略;代煎时显示「是」(与主方代煎一致),不再显示 0/1 Co-Authored-By: Claude Opus 5 (1M context) <[EMAIL]> --- server/app/common/service/esign/PrescriptionPdf.php | 12 +++++++++++- server/tests/PrescriptionEsignFlowTest.php | 11 +++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/server/app/common/service/esign/PrescriptionPdf.php b/server/app/common/service/esign/PrescriptionPdf.php index d910d3c85..698c40f88 100644 --- a/server/app/common/service/esign/PrescriptionPdf.php +++ b/server/app/common/service/esign/PrescriptionPdf.php @@ -65,7 +65,10 @@ final class PrescriptionPdf $add($label, $row[$key]); } $add('代煎', $row['need_decoction'] === '1' ? '是' : '否'); - $add('金额(元)', $row['amount']); + // 金额为 0(含 0.00)时不写入签署原文。 + if (is_numeric($row['amount']) && (float) $row['amount'] != 0.0) { + $add('金额(元)', $row['amount']); + } // 开方表单总会带一份默认辅方用法;只有药品里确有辅方(与笺面 formula_type 判定一致)才写入。 $hasAux = array_filter((array) $row['herbs'], static fn ($herb): bool => is_array($herb) && ($herb['formula_type'] ?? '') === '辅方') !== []; @@ -76,6 +79,13 @@ final class PrescriptionPdf $label = ['dosage_amount' => '单次用量', 'dosage_bag_count' => '单次袋数', 'need_decoction' => '代煎', 'times_per_day' => '每日次数', 'usage_days' => '服用天数', 'prescription_name' => '方名'][$key] ?? $key; + if ($key === 'need_decoction') { + // 辅方不代煎(0)时不写;代煎时与主方一样显示「是」。 + if ((int) $value === 0) { + continue; + } + $value = '是'; + } $add('辅方' . $label, $value); } $pages = array_chunk($lines, 33); diff --git a/server/tests/PrescriptionEsignFlowTest.php b/server/tests/PrescriptionEsignFlowTest.php index a5d00b022..2c0c39f56 100644 --- a/server/tests/PrescriptionEsignFlowTest.php +++ b/server/tests/PrescriptionEsignFlowTest.php @@ -1204,6 +1204,17 @@ namespace { $mainOnly = PrescriptionPdf::render(array_replace($sample, ['aux_usage' => $auxUsage, 'herbs' => array_map(static fn (array $herb): array => $herb + ['formula_type' => '主方'], $sampleHerbs)]), 'sandbox'); $assert(!str_contains($mainOnly, $pdfText('辅方')), 'a prescription without auxiliary herbs omits the default auxiliary usage'); + $auxHerbs = array_merge($sampleHerbs, [['name' => '虚构辅方药', 'dosage' => 6, 'unit' => 'g', 'formula_type' => '辅方']]); + foreach (['0', '0.00', 0] as $zero) { + $zeroPdf = PrescriptionPdf::render(array_replace($sample, ['amount' => $zero, 'herbs' => $auxHerbs, + 'aux_usage' => ['need_decoction' => 0, 'usage_days' => 7]]), 'sandbox'); + $assert(!str_contains($zeroPdf, $pdfText('金额(元)')) && !str_contains($zeroPdf, $pdfText('辅方代煎')) + && str_contains($zeroPdf, $pdfText('辅方服用天数:7')), 'zero amount and no auxiliary decoction are omitted: ' . var_export($zero, true)); + } + $paidPdf = PrescriptionPdf::render(array_replace($sample, ['amount' => '18.50', 'herbs' => $auxHerbs, + 'aux_usage' => ['need_decoction' => 1]]), 'sandbox'); + $assert(str_contains($paidPdf, $pdfText('金额(元):18.5')) && str_contains($paidPdf, $pdfText('辅方代煎:是')), + 'a non-zero amount and auxiliary decoction are still disclosed'); $manyHerbs = []; for ($i = 1; $i <= 65; ++$i) { $manyHerbs[] = ['name' => '虚构药品' . $i, 'dosage' => $i, 'unit' => 'g']; } $largePdf = PrescriptionPdf::render(array_replace($sample, ['herbs' => $manyHerbs, 'amount' => '18.50']), 'sandbox');