72 lines
2.0 KiB
PHP
72 lines
2.0 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
require dirname(__DIR__) . '/vendor/autoload.php';
|
|
|
|
use app\adminapi\logic\tcm\PrescriptionLibraryAiLogic;
|
|
|
|
$method = (new ReflectionClass(PrescriptionLibraryAiLogic::class))->getMethod('parseReport');
|
|
$method->setAccessible(true);
|
|
|
|
$legacyText = <<<'TEXT'
|
|
核心判断
|
|
脾胃虚弱,兼有湿滞倾向
|
|
|
|
可能症状与证候
|
|
- 食少腹胀
|
|
• 神疲乏力
|
|
|
|
主治方向
|
|
健脾益气,兼顾化湿
|
|
|
|
主要功效
|
|
健脾
|
|
益气
|
|
|
|
可能适用人群
|
|
- 需经辨证确认的脾虚人群
|
|
|
|
配伍分析
|
|
补益药与理气化湿药配合,
|
|
兼顾扶正与运化。
|
|
|
|
用药与复核提醒
|
|
• 特殊人群需由医师复核
|
|
- 合并用药时咨询药师
|
|
|
|
免责声明
|
|
仅供专业人员辅助审方,不替代辨证、诊断和处方审核。
|
|
TEXT;
|
|
|
|
$report = $method->invoke(null, $legacyText);
|
|
$expected = [
|
|
'summary' => '脾胃虚弱,兼有湿滞倾向',
|
|
'possible_symptoms' => ['食少腹胀', '神疲乏力'],
|
|
'main_indications' => '健脾益气,兼顾化湿',
|
|
'efficacy' => ['健脾', '益气'],
|
|
'suitable_people' => ['需经辨证确认的脾虚人群'],
|
|
'compatibility_analysis' => '补益药与理气化湿药配合, 兼顾扶正与运化。',
|
|
'cautions' => ['特殊人群需由医师复核', '合并用药时咨询药师'],
|
|
'disclaimer' => '仅供专业人员辅助审方,不替代辨证、诊断和处方审核。',
|
|
];
|
|
|
|
if ($report !== $expected) {
|
|
fwrite(STDERR, "Legacy structured-text report was not parsed as expected.\n");
|
|
fwrite(STDERR, var_export($report, true) . "\n");
|
|
exit(1);
|
|
}
|
|
|
|
$json = json_encode($expected, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
|
|
if (!is_string($json) || $method->invoke(null, $json) !== $expected) {
|
|
fwrite(STDERR, "Existing JSON report parsing must remain unchanged.\n");
|
|
exit(1);
|
|
}
|
|
|
|
if ($method->invoke(null, '这是一段没有固定章节的普通文本') !== null) {
|
|
fwrite(STDERR, "Unrecognized free text must not be treated as a structured report.\n");
|
|
exit(1);
|
|
}
|
|
|
|
fwrite(STDOUT, "PrescriptionLibraryAiReportParserTest OK\n");
|