| use axum::{response::Json, http::StatusCode}; |
| use serde::{Deserialize, Serialize}; |
| use tracing::instrument; |
| use crate::orchestrator; |
|
|
| #[derive(Debug, Deserialize)] |
| pub struct TriageRequest { |
| pub patient_note: String, |
| pub consent_hash: String, |
| } |
|
|
| #[derive(Debug, Serialize)] |
| pub struct TriageResponse { |
| pub triage_result: String, |
| pub model_used: String, |
| pub device_info: String, |
| pub transaction_hash: String, |
| pub redacted_prompt: String, |
| pub pii_map: Vec<crate::shield::redact::PiiMatch>, |
| pub cid: String, |
| pub redaction_proof: String, |
| pub agent_steps: Vec<orchestrator::AgentStep>, |
| } |
|
|
| #[instrument(skip_all)] |
| pub async fn handle( |
| Json(payload): Json<TriageRequest>, |
| ) -> Result<Json<TriageResponse>, (StatusCode, String)> { |
| tracing::info!("Received triage request (consent_hash: {})", payload.consent_hash); |
|
|
| let output = orchestrator::run_triage(&payload.patient_note) |
| .await |
| .map_err(|e| { |
| tracing::error!("Triage pipeline error: {:?}", e); |
| (StatusCode::INTERNAL_SERVER_ERROR, "Triage pipeline error".into()) |
| })?; |
|
|
| Ok(Json(TriageResponse { |
| triage_result: output.triage_result, |
| model_used: output.model_used, |
| device_info: output.device_info, |
| transaction_hash: output.transaction_hash, |
| redacted_prompt: output.redacted_prompt, |
| pii_map: output.pii_map, |
| cid: output.cid, |
| redaction_proof: output.redaction_proof, |
| agent_steps: output.agent_steps, |
| })) |
| } |
|
|