import { useState } from 'react'; import { X, FileText, Loader2, AlertCircle, CheckCircle } from 'lucide-react'; import { api } from '../api'; /** * Modal that generates and displays an AI clinical report for a single prediction. * Opens when the user clicks "Generate AI Report" after a prediction + SHAP explain. * * Props: * disease — disease key (e.g. 'heart_disease') * probability — prediction probability (0–1) * label — prediction label string (e.g. 'Positive') * confidenceBand — string (e.g. 'HIGH', 'MODERATE', 'LOW') * shapValues — array of { feature, shap_value } * features — original patient feature dict * onClose — () => void */ export default function ClinicalReportModal({ disease, probability, label, confidenceBand, shapValues = [], features = {}, onClose, }) { const [report, setReport] = useState(''); const [source, setSource] = useState(''); const [loading, setLoading] = useState(false); const [error, setError] = useState(''); async function handleGenerate() { setLoading(true); setError(''); setReport(''); try { const res = await api.generateReport({ disease, probability, label, confidence_band: confidenceBand, shap_values: shapValues, features, }); setReport(res.report); setSource(res.source); } catch (err) { setError(err.message || 'Failed to generate report'); } finally { setLoading(false); } } return (
{/* Header */}

AI Clinical Report

{source && ( {source === 'llm' ? 'AI Generated' : 'Rule-Based'} )}
{/* Body */}
{/* Prediction summary */}

Disease

{disease.replace(/_/g, ' ')}

Probability

{(probability * 100).toFixed(1)}%

Risk Band

{confidenceBand}

{/* Error */} {error && (
{error}
)} {/* Report output */} {report && (
Report generated successfully
{report}
)} {!report && !loading && !error && (

Click "Generate Report" to create a structured clinical narrative from this prediction.

)}
{/* Footer */}
); }