From 5f53aa0bbd288f2dff1834dda4999d8b18c7ed85 Mon Sep 17 00:00:00 2001 From: Your Name Date: Mon, 17 Aug 2026 14:06:41 +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 --- .../validate/tcm/DiagnosisValidate.php | 176 +++++++++--------- 1 file changed, 91 insertions(+), 85 deletions(-) diff --git a/server/app/adminapi/validate/tcm/DiagnosisValidate.php b/server/app/adminapi/validate/tcm/DiagnosisValidate.php index cec66a3a4..ef36db8be 100755 --- a/server/app/adminapi/validate/tcm/DiagnosisValidate.php +++ b/server/app/adminapi/validate/tcm/DiagnosisValidate.php @@ -47,10 +47,10 @@ class DiagnosisValidate extends BaseValidate 'revisit_slot_start_offset' => 'integer|between:0,20', 'report_id' => 'number|gt:0', 'content' => 'max:12000', - 'task' => 'require|in:summary,tcm_pattern,prescription_review,medication_review,exam_review,complication_risk,guideline_review,custom', - 'prompt' => 'max:500', - 'model' => 'in:qwen,openai', - 'patient_id' => 'integer|gt:0', + 'task' => 'require|in:summary,tcm_pattern,prescription_review,medication_review,exam_review,complication_risk,guideline_review,custom', + 'prompt' => 'max:500', + 'model' => 'in:qwen,openai', + 'patient_id' => 'integer|gt:0', ]; protected $message = [ @@ -83,21 +83,27 @@ class DiagnosisValidate extends BaseValidate 'report_id.gt' => '报告ID必须大于0', 'content.require' => '报告内容不能为空', 'content.max' => '报告内容最多12000个字符', - 'task.require' => '请选择 AI 助手任务', - 'task.in' => 'AI 助手任务不受支持', - 'prompt.max' => '问题最多500个字符', - 'model.in' => 'AI模型仅支持qwen或openai', - 'patient_id.require' => '患者ID不能为空', - 'patient_id.integer' => '患者ID必须为整数', - 'patient_id.gt' => '患者ID必须大于0', + 'task.require' => '请选择 AI 助手任务', + 'task.in' => 'AI 助手任务不受支持', + 'prompt.max' => '问题最多500个字符', + 'model.in' => 'AI模型仅支持qwen或openai', + 'patient_id.require' => '患者ID不能为空', + 'patient_id.integer' => '患者ID必须为整数', + 'patient_id.gt' => '患者ID必须大于0', ]; public function sceneAdd() { - // 全局规则中含 tracking 相关字段,新增诊单不应校验诊单 ID + // 全局规则里混有跟踪备注、AI 助手字段;新增诊单只去掉这些无关校验。 + // 不要改成 only([...]):add 还会写入现病史等多选字段,only 会把它们从请求里丢掉。 return $this->remove('id', true) ->remove('diagnosis_id', true) - ->remove('tracking_content', true); + ->remove('tracking_content', true) + ->remove('task', true) + ->remove('prompt', true) + ->remove('model', true) + ->remove('report_id', true) + ->remove('content', true); } public function sceneEdit() @@ -178,25 +184,25 @@ class DiagnosisValidate extends BaseValidate return $this->only(['id', 'task', 'prompt']); } - public function sceneAiAnalysis() - { - return $this->only(['id', 'model']) - ->remove('id', 'checkDiagnosis') - ->append('id', 'integer|gt:0|checkAiAnalysisPayload'); - } - - public function scenePatientAiReports() - { - return $this->only(['patient_id']) - ->append('patient_id', 'require|integer|gt:0|checkPatientAiReportsPayload'); - } - - public function sceneGeneratePatientAiReport() - { - return $this->only(['patient_id', 'model']) - ->append('patient_id', 'require|integer|gt:0|checkGeneratePatientAiReportPayload') - ->append('model', 'require|in:qwen,openai'); - } + public function sceneAiAnalysis() + { + return $this->only(['id', 'model']) + ->remove('id', 'checkDiagnosis') + ->append('id', 'integer|gt:0|checkAiAnalysisPayload'); + } + + public function scenePatientAiReports() + { + return $this->only(['patient_id']) + ->append('patient_id', 'require|integer|gt:0|checkPatientAiReportsPayload'); + } + + public function sceneGeneratePatientAiReport() + { + return $this->only(['patient_id', 'model']) + ->append('patient_id', 'require|integer|gt:0|checkGeneratePatientAiReportPayload') + ->append('model', 'require|in:qwen,openai'); + } public function sceneGenerateAiReports() { @@ -252,62 +258,62 @@ class DiagnosisValidate extends BaseValidate } /** - * AI 智能分析仅接受诊单 ID 和可选的固定模型键。客户端不得提供 - * provider、凭据、上游地址、提示词等服务端配置或控制字段。 + * AI 智能分析仅接受诊单 ID 和可选的固定模型键。客户端不得提供 + * provider、凭据、上游地址、提示词等服务端配置或控制字段。 * * @param mixed $value * @param mixed $rule * @param array $data * @return bool|string */ - protected function checkAiAnalysisPayload($value, $rule, array $data = []) - { - if (!array_key_exists('id', $data)) { - return 'AI智能分析请求缺少id参数'; - } - - $extraFields = array_diff(array_keys($data), ['id', 'model']); - if ($extraFields !== []) { - return 'AI智能分析请求仅允许id及可选model参数'; - } - - if (array_key_exists('model', $data)) { - $model = $data['model']; - if (!is_string($model) || !in_array($model, ['qwen', 'openai'], true)) { - return 'AI模型仅支持qwen或openai'; - } - } - return true; - } - - /** @param array $data */ - protected function checkPatientAiReportsPayload($value, $rule, array $data = []) - { - if (!array_key_exists('patient_id', $data)) { - return '请求缺少patient_id参数'; - } - $extraFields = array_diff(array_keys($data), ['patient_id']); - return $extraFields === [] ? true : '请求仅允许patient_id参数'; - } - - /** - * 患者报告生成端点只接受稳定患者ID与服务端模型白名单键。 - * provider、凭据、BASE_URL、提示词和任意来源正文均不得由客户端注入。 - * - * @param array $data - */ - protected function checkGeneratePatientAiReportPayload($value, $rule, array $data = []) - { - if (!array_key_exists('patient_id', $data) || !array_key_exists('model', $data)) { - return '请求缺少patient_id或model参数'; - } - $extraFields = array_diff(array_keys($data), ['patient_id', 'model']); - if ($extraFields !== []) { - return '请求仅允许patient_id和model参数'; - } - if (!is_string($data['model']) || !in_array($data['model'], ['qwen', 'openai'], true)) { - return 'AI模型仅支持qwen或openai'; - } - return true; - } -} + protected function checkAiAnalysisPayload($value, $rule, array $data = []) + { + if (!array_key_exists('id', $data)) { + return 'AI智能分析请求缺少id参数'; + } + + $extraFields = array_diff(array_keys($data), ['id', 'model']); + if ($extraFields !== []) { + return 'AI智能分析请求仅允许id及可选model参数'; + } + + if (array_key_exists('model', $data)) { + $model = $data['model']; + if (!is_string($model) || !in_array($model, ['qwen', 'openai'], true)) { + return 'AI模型仅支持qwen或openai'; + } + } + return true; + } + + /** @param array $data */ + protected function checkPatientAiReportsPayload($value, $rule, array $data = []) + { + if (!array_key_exists('patient_id', $data)) { + return '请求缺少patient_id参数'; + } + $extraFields = array_diff(array_keys($data), ['patient_id']); + return $extraFields === [] ? true : '请求仅允许patient_id参数'; + } + + /** + * 患者报告生成端点只接受稳定患者ID与服务端模型白名单键。 + * provider、凭据、BASE_URL、提示词和任意来源正文均不得由客户端注入。 + * + * @param array $data + */ + protected function checkGeneratePatientAiReportPayload($value, $rule, array $data = []) + { + if (!array_key_exists('patient_id', $data) || !array_key_exists('model', $data)) { + return '请求缺少patient_id或model参数'; + } + $extraFields = array_diff(array_keys($data), ['patient_id', 'model']); + if ($extraFields !== []) { + return '请求仅允许patient_id和model参数'; + } + if (!is_string($data['model']) || !in_array($data['model'], ['qwen', 'openai'], true)) { + return 'AI模型仅支持qwen或openai'; + } + return true; + } +}