From c22be5d586a4060c175169185fbb1a43dc383be6 Mon Sep 17 00:00:00 2001 From: Your Name Date: Fri, 27 Nov 2026 18:14:10 +0800 Subject: [PATCH] =?UTF-8?q?=E7=AD=BE=E7=BD=B2=E5=8E=9F=E6=96=87=E4=BB=85?= =?UTF-8?q?=E5=9C=A8=E5=A4=84=E6=96=B9=E7=A1=AE=E6=9C=89=E8=BE=85=E6=96=B9?= =?UTF-8?q?=E8=8D=AF=E5=93=81=E6=97=B6=E5=86=99=E5=85=A5=E8=BE=85=E6=96=B9?= =?UTF-8?q?=E7=94=A8=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 开方表单始终携带一份默认辅方用法(如服用天数 7、每日 3 次),之前签署 PDF 不论有无辅方都写入「辅方…」, 导致只有主方的处方(如 RX202611279326)提交 e签宝 的原文出现辅方。现与笺面一致:药品中存在 formula_type 为「辅方」的药材时才写入辅方用法。已签处方不受影响,未签处方签署时按新规则重新生成原文。 Co-Authored-By: Claude Opus 5 (1M context) <[EMAIL]> --- artifacts/esign-prescription-test.pdf | 17 +++++++++-------- .../common/service/esign/PrescriptionPdf.php | 5 ++++- server/tests/PrescriptionEsignFlowTest.php | 10 ++++++++-- 3 files changed, 21 insertions(+), 11 deletions(-) diff --git a/artifacts/esign-prescription-test.pdf b/artifacts/esign-prescription-test.pdf index aded0a03e..3c970ecdf 100644 --- a/artifacts/esign-prescription-test.pdf +++ b/artifacts/esign-prescription-test.pdf @@ -19,7 +19,7 @@ endobj << /Type /Page /Parent 2 0 R /MediaBox [0 0 595 842] /Resources << /Font << /F1 3 0 R >> >> /Contents 7 0 R >> endobj 7 0 obj -<< /Length 1789>> +<< /Length 1969>> stream BT /F1 20 Tf 1 0 0 1 235 795 Tm <4e2d533b590465b97b3a> Tj ET BT /F1 12 Tf 1 0 0 1 170 770 Tm <6c997bb16d4b8bd565874ef6002000b700204e0d75284e8e6b635f0f53d1836f> Tj ET @@ -29,16 +29,17 @@ BT /F1 11 Tf 1 0 0 1 45 702 Tm <60a38005ff1a865a67846d4b8bd560a38005002000200020 BT /F1 11 Tf 1 0 0 1 45 684 Tm <80547cfb75358bddff1a00310033003800300030003000300030003000300030> Tj ET BT /F1 11 Tf 1 0 0 1 45 666 Tm <4e345e8a8bca65adff1a4ec575284e8e8f6f4ef66d4b8bd5> Tj ET BT /F1 11 Tf 1 0 0 1 45 648 Tm <836f54c100200031ff1a752891cf0020003100300020002f0020836f540d00206d4b8bd5836f67500020002f002053554f4d00200067> Tj ET -BT /F1 11 Tf 1 0 0 1 45 630 Tm <53556b21888b6570ff1a0033> Tj ET -BT /F1 11 Tf 1 0 0 1 45 612 Tm <4ee3714eff1a5426> Tj ET -BT /F1 11 Tf 1 0 0 1 45 594 Tm <8f8565b953556b21888b6570ff1a0034> Tj ET -BT /F1 11 Tf 1 0 0 1 45 576 Tm <8f8565b965b9540dff1a8f8552a965b96a21677f> Tj ET -BT /F1 11 Tf 1 0 0 1 45 558 Tm <8f8565b9670d752859296570ff1a0038> Tj ET +BT /F1 11 Tf 1 0 0 1 45 630 Tm <836f54c100200032ff1a752891cf002000360020002f002065b9522b00208f8565b90020002f0020836f540d0020865a67848f8565b9836f0020002f002053554f4d00200067> Tj ET +BT /F1 11 Tf 1 0 0 1 45 612 Tm <53556b21888b6570ff1a0033> Tj ET +BT /F1 11 Tf 1 0 0 1 45 594 Tm <4ee3714eff1a5426> Tj ET +BT /F1 11 Tf 1 0 0 1 45 576 Tm <8f8565b953556b21888b6570ff1a0034> Tj ET +BT /F1 11 Tf 1 0 0 1 45 558 Tm <8f8565b965b9540dff1a8f8552a965b96a21677f> Tj ET +BT /F1 11 Tf 1 0 0 1 45 540 Tm <8f8565b9670d752859296570ff1a0038> Tj ET 0.7 w 45 133 m 550 133 l S BT /F1 12 Tf 1 0 0 1 45 110 Tm <5f0065b9533b5e08ff1a6d4b8bd5533b5e08> Tj ET BT /F1 11 Tf 1 0 0 1 420 104 Tm <533b5e0875355b507b7e7ae0> Tj ET BT /F1 8 Tf 1 0 0 1 45 58 Tm <590465b95feb71670020005300480041002d003200350036> Tj ET -BT /F1 7 Tf 1 0 0 1 45 44 Tm <0064003500380037003800330063003400360032006300650034006100610037003800610031006300620064006100620066006100300034003200650062003400340061006300310066003700650037006200360063006500360066006300630062003800390066006600650066003700380066003900620038003500330037> Tj ET +BT /F1 7 Tf 1 0 0 1 45 44 Tm <0031003300350032003700660032003200640065003500340037003900320037003400370033003900660034003100300030003300620061003400300034003300370064006300360032006400630036006500610061003800650037003700380033003500300039006100340032003000380037006600350031003400320063> Tj ET BT /F1 9 Tf 1 0 0 1 515 30 Tm <00310020002f00200031> Tj ET endstream endobj @@ -54,5 +55,5 @@ xref 0000000735 00000 n trailer << /Size 8 /Root 1 0 R >> startxref -2574 +2754 %%EOF diff --git a/server/app/common/service/esign/PrescriptionPdf.php b/server/app/common/service/esign/PrescriptionPdf.php index adbe0472d..d910d3c85 100644 --- a/server/app/common/service/esign/PrescriptionPdf.php +++ b/server/app/common/service/esign/PrescriptionPdf.php @@ -66,7 +66,10 @@ final class PrescriptionPdf } $add('代煎', $row['need_decoction'] === '1' ? '是' : '否'); $add('金额(元)', $row['amount']); - foreach ((array) $row['aux_usage'] as $key => $value) { + // 开方表单总会带一份默认辅方用法;只有药品里确有辅方(与笺面 formula_type 判定一致)才写入。 + $hasAux = array_filter((array) $row['herbs'], static fn ($herb): bool => + is_array($herb) && ($herb['formula_type'] ?? '') === '辅方') !== []; + foreach ($hasAux ? (array) $row['aux_usage'] : [] as $key => $value) { if ($key === 'bags_per_dose') { continue; } diff --git a/server/tests/PrescriptionEsignFlowTest.php b/server/tests/PrescriptionEsignFlowTest.php index e253c196c..a5d00b022 100644 --- a/server/tests/PrescriptionEsignFlowTest.php +++ b/server/tests/PrescriptionEsignFlowTest.php @@ -1186,10 +1186,12 @@ namespace { $assert(Policy::hash(Policy::snapshot($decimalRow)) === Policy::hash($decimalRow), 'snapshot hashing is idempotent'); $pdf = PrescriptionPdf::render($sample, 'sandbox'); $assert($pdf === PrescriptionPdf::render($sample, 'sandbox'), 'deterministic PDF'); + $auxUsage = ['bags_per_dose' => 763, 'dosage_bag_count' => 4, 'usage_days' => 8, 'prescription_name' => '辅助方模板']; + $sampleHerbs = is_string($sample['herbs']) ? json_decode($sample['herbs'], true) : $sample['herbs']; $pdf = PrescriptionPdf::render(array_replace($sample, [ 'prescription_name' => '仅内部查看方名', 'dose_count' => 761, 'dose_unit' => '仅内部剂数单位', - 'bags_per_dose' => 762, 'dosage_bag_count' => 3, - 'aux_usage' => ['bags_per_dose' => 763, 'dosage_bag_count' => 4, 'usage_days' => 8, 'prescription_name' => '辅助方模板'], + 'bags_per_dose' => 762, 'dosage_bag_count' => 3, 'aux_usage' => $auxUsage, + 'herbs' => array_merge($sampleHerbs, [['name' => '虚构辅方药', 'dosage' => 6, 'unit' => 'g', 'formula_type' => '辅方']]), ]), 'sandbox'); foreach (['方名:仅内部查看方名', '总剂数:761', '剂数单位:仅内部剂数单位', '每剂袋数:762', '辅方每剂袋数:763', '辅方bags_per_dose:763'] as $excluded) { @@ -1198,6 +1200,10 @@ namespace { foreach (['单次袋数:3', '辅方单次袋数:4', '辅方服用天数:8', '辅方方名:辅助方模板'] as $disclosed) { $assert(str_contains($pdf, $pdfText($disclosed)), 'signing PDF retains distinct field: ' . $disclosed); } + // RX202611279326:药品全是主方,但开方表单带了默认辅方用法,不能把辅方写进签署原文。 + $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'); $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');