From 582c7cf0c6b4889dcc5c5fa21633aac83c553497 Mon Sep 17 00:00:00 2001 From: Your Name Date: Mon, 3 Aug 2026 11:27:15 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../logic/tcm/PrescriptionOrderLogic.php | 8 +- ...scription_order_export_name_regression.php | 88 +++++++++++++++++++ 2 files changed, 95 insertions(+), 1 deletion(-) create mode 100644 server/tests/pharmacy/prescription_order_export_name_regression.php diff --git a/server/app/adminapi/logic/tcm/PrescriptionOrderLogic.php b/server/app/adminapi/logic/tcm/PrescriptionOrderLogic.php index b9cad68ce..d05427595 100755 --- a/server/app/adminapi/logic/tcm/PrescriptionOrderLogic.php +++ b/server/app/adminapi/logic/tcm/PrescriptionOrderLogic.php @@ -4374,7 +4374,8 @@ class PrescriptionOrderLogic /** * 反查单张处方的主方 / 辅方名称(与处方笺展示一致): * - 主方:主方药材集合匹配开方医师/公开处方库(formula_type=主方);兜底取处方 prescription_name。 - * - 辅方:优先 aux_usage.prescription_name / library_name,否则辅方药材集合匹配(formula_type=辅方)。 + * - 辅方:仅在实际存在辅方药材时,优先 aux_usage.prescription_name / library_name, + * 否则按辅方药材集合匹配(formula_type=辅方)。 * * @param array $rx 处方行(含 herbs / creator_id / prescription_name / aux_usage) * @param array>> $libByDoctor @@ -4413,6 +4414,11 @@ class PrescriptionOrderLogic $mainName = trim((string) ($rx['prescription_name'] ?? '')); } + // 是否存在辅方以 herbs[].formula_type 为准;忽略删除辅方后遗留的 aux_usage 名称。 + if ($auxHerbs === []) { + return [$mainName, '']; + } + // 辅方:先读持久化字段 $auxName = ''; $auxUsage = $rx['aux_usage'] ?? null; diff --git a/server/tests/pharmacy/prescription_order_export_name_regression.php b/server/tests/pharmacy/prescription_order_export_name_regression.php new file mode 100644 index 000000000..cc0eafc27 --- /dev/null +++ b/server/tests/pharmacy/prescription_order_export_name_regression.php @@ -0,0 +1,88 @@ + '黄芪', 'dosage' => 10, 'formula_type' => '主方']; +$auxHerb = ['name' => '龙骨', 'dosage' => 15, 'formula_type' => '辅方']; + +$assertSame( + ['主方名', ''], + $resolveNames->invoke(null, [ + 'prescription_name' => '主方名', + 'herbs' => [$mainHerb], + 'aux_usage' => ['prescription_name' => '已删除的辅方名'], + ], [], []), + 'export must ignore a stale auxiliary prescription name when no auxiliary herbs exist' +); + +$assertSame( + ['主方名', ''], + $resolveNames->invoke(null, [ + 'prescription_name' => '主方名', + 'herbs' => json_encode([$mainHerb], JSON_UNESCAPED_UNICODE), + 'aux_usage' => json_encode(['library_name' => '已删除的处方库辅方名'], JSON_UNESCAPED_UNICODE), + ], [], []), + 'JSON-backed export data must ignore a stale auxiliary library name when no auxiliary herbs exist' +); + +$assertSame( + ['主方名', ''], + $resolveNames->invoke(null, [ + 'prescription_name' => '主方名', + 'creator_id' => 7, + 'herbs' => [$mainHerb], + 'aux_usage' => ['prescription_name' => '残留名称', 'usage_days' => 7], + ], [ + 7 => [ + '辅方' => ['龙骨:15' => '不应命中的处方库辅方名'], + ], + ], [ + '辅方' => ['龙骨:15' => '不应命中的公开辅方名'], + ]), + 'stale auxiliary usage and library indexes must not imply that an auxiliary formula exists' +); + +$assertSame( + ['主方名', '持久化辅方名'], + $resolveNames->invoke(null, [ + 'prescription_name' => '主方名', + 'herbs' => [$mainHerb, $auxHerb], + 'aux_usage' => json_encode(['prescription_name' => '持久化辅方名'], JSON_UNESCAPED_UNICODE), + ], [], []), + 'export must keep the persisted auxiliary prescription name when auxiliary herbs exist' +); + +$assertSame( + ['主方名', '处方库辅方名'], + $resolveNames->invoke(null, [ + 'prescription_name' => '主方名', + 'creator_id' => 7, + 'herbs' => [$mainHerb, $auxHerb], + ], [ + 7 => [ + '辅方' => ['龙骨:15' => '处方库辅方名'], + ], + ], []), + 'export must still resolve an auxiliary prescription name from the library when auxiliary herbs exist' +); + +fwrite(STDOUT, sprintf("Prescription order export name regression tests passed: %d\n", $passed));