use async_trait::async_trait; use crate::agent::tool::{AgentTool, ToolContext, ToolResult}; /// 查询患者预约记录 pub struct QueryAppointmentsTool; #[async_trait] impl AgentTool for QueryAppointmentsTool { fn name(&self) -> &str { "query_patient_appointments" } fn description(&self) -> &str { "查询患者的即将到来的预约记录,包括科室、医生、时间和状态。" } fn parameters_schema(&self) -> serde_json::Value { serde_json::json!({ "type": "object", "properties": {} }) } async fn execute(&self, ctx: &ToolContext, _params: serde_json::Value) -> ToolResult { let patient_id = match ctx.patient_id { Some(id) => id, None => { return ToolResult { output: "未关联患者档案,无法查询预约记录".to_string(), display_hint: None, }; } }; match ctx .health_provider .get_upcoming_appointments(ctx.tenant_id, patient_id) .await { Ok(appointments) => { if appointments.is_empty() { return ToolResult { output: "该患者暂无即将到来的预约".to_string(), display_hint: None, }; } let mut output = String::from("即将到来的预约:\n"); for a in &appointments { output.push_str(&format!( "- {} | {} | {} | 状态: {}\n", a.scheduled_at, a.department, a.doctor_name, a.status )); } ToolResult { output, display_hint: None, } } Err(e) => ToolResult { output: format!("查询预约记录失败: {}", e), display_hint: None, }, } } }