更新
This commit is contained in:
@@ -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<int, array<string, array<string, string>>> $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;
|
||||
|
||||
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
require dirname(__DIR__, 2) . '/vendor/autoload.php';
|
||||
|
||||
use app\adminapi\logic\tcm\PrescriptionOrderLogic;
|
||||
|
||||
$passed = 0;
|
||||
$assertSame = static function (mixed $expected, mixed $actual, string $message) use (&$passed): void {
|
||||
if ($expected !== $actual) {
|
||||
throw new RuntimeException(sprintf(
|
||||
"%s\nExpected: %s\nActual: %s",
|
||||
$message,
|
||||
var_export($expected, true),
|
||||
var_export($actual, true)
|
||||
));
|
||||
}
|
||||
++$passed;
|
||||
};
|
||||
|
||||
$resolveNames = new ReflectionMethod(PrescriptionOrderLogic::class, 'resolvePrescriptionNamesForExport');
|
||||
|
||||
$mainHerb = ['name' => '黄芪', '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));
|
||||
Reference in New Issue
Block a user