"use client" import React, { useRef, useMemo } from "react" import { Canvas, useFrame } from "@react-three/fiber" import { OrbitControls, Sphere, Html, Stars, Float } from "@react-three/drei" import * as THREE from "three" interface PredictionOutput { sepsis: number respiration: number coagulation: number liver: number cardiovascular: number cns: number renal: number hours_beforesepsis: number fod: number hours_beforedeath: number } interface OrganProps { position: [number, number, number] baseColor: string riskScore?: number // 0-4 SOFA score or 0-1 probability label: string size?: number } function getColorByRisk(baseColor: string, riskScore: number = 0, maxScore: number = 4): string { const normalizedRisk = Math.min(riskScore / maxScore, 1) if (normalizedRisk >= 0.75) return "#ef4444" // Critical - Red if (normalizedRisk >= 0.5) return "#f59e0b" // Warning - Orange if (normalizedRisk >= 0.25) return "#eab308" // Elevated - Yellow return baseColor // Normal - Original color } function Organ({ position, baseColor, riskScore = 0, label, size = 0.3 }: OrganProps) { const meshRef = useRef(null) const color = getColorByRisk(baseColor, riskScore) const isHighRisk = riskScore >= 2 useFrame((state) => { if (meshRef.current) { const t = state.clock.getElapsedTime() // More intense pulse for high-risk organs const pulseIntensity = isHighRisk ? 0.15 : 0.05 const pulseSpeed = isHighRisk ? 3 : 2 meshRef.current.scale.setScalar(1 + Math.sin(t * pulseSpeed) * pulseIntensity) } }) return (
{label} {riskScore > 0 && ( ({riskScore.toFixed(1)}) )}
) } interface BodyProps { prediction: PredictionOutput | null } function RotatingBody({ prediction }: BodyProps) { const groupRef = useRef(null) useFrame((state, delta) => { if (groupRef.current) { groupRef.current.rotation.y += delta * 0.15 } }) // Calculate overall risk for body wireframe color const overallRisk = useMemo(() => { if (!prediction) return 0 return prediction.sepsis }, [prediction]) const bodyColor = overallRisk >= 0.7 ? "#ef4444" : overallRisk >= 0.4 ? "#f59e0b" : "#64748b" return ( {/* Human Body Outline - Capsule torso */} = 0.4 ? 0.2 : 0} /> {/* Head */} {/* Organ Highlights with prediction data */} ) } interface BodyVisualizerProps { prediction?: PredictionOutput | null } export default function BodyVisualizer({ prediction = null }: BodyVisualizerProps) { return (
{/* Lighting */} {/* Star field background */} {/* Controls */} {/* Body Visualization */}
) }