import React, { useState, useEffect } from 'react'; import { CheckSquare, FileText } from 'lucide-react'; import { sessionStore } from '../store/sessionStore'; interface ImagingObservationsProps { onObservationsChange?: (observations: any) => void; layout?: 'vertical' | 'horizontal'; stepId?: 'native' | 'acetowhite' | 'greenFilter' | 'lugol' | 'biopsyMarking'; } export function ImagingObservations({ onObservationsChange, layout = 'vertical', stepId }: ImagingObservationsProps) { const [observations, setObservations] = useState({ obviousGrowths: false, contactBleeding: false, irregularSurface: false, other: false, additionalNotes: '', // Examination Adequacy cervixFullyVisible: null as null | 'Yes' | 'No', obscuredBy: { blood: false, inflammation: false, discharge: false, scarring: false }, adequacyNotes: '', // SCJ & TZ scjVisibility: 'Completely visible', scjNotes: '', tzType: 'TZ 1', // Native exam suspiciousAtNativeView: false, skipStainInterpretation: false }); const handleCheckboxChange = (field: string) => { const updated = { ...observations, [field]: !observations[field as keyof typeof observations] }; setObservations(updated); if (onObservationsChange) { onObservationsChange(updated); } }; const handleFieldChange = (field: string, value: any) => { const updated = { ...observations, [field]: value }; setObservations(updated); if (onObservationsChange) { onObservationsChange(updated); } }; const handleObscuredChange = (key: string) => { const updatedObscured = { ...observations.obscuredBy, [key]: !observations.obscuredBy[key as keyof typeof observations.obscuredBy] }; const updated = { ...observations, obscuredBy: updatedObscured }; setObservations(updated); if (onObservationsChange) onObservationsChange(updated); }; const handleNotesChange = (e: React.ChangeEvent) => { const updated = { ...observations, additionalNotes: e.target.value }; setObservations(updated); if (onObservationsChange) { onObservationsChange(updated); } }; // Load previously saved findings for this step from sessionStore on mount useEffect(() => { if (!stepId) return; const session = sessionStore.get(); if (session.stepFindings?.[stepId]) { setObservations(prev => ({ ...prev, ...session.stepFindings[stepId] })); console.log(`[ImagingObservations] Loaded saved findings for step: ${stepId}`, session.stepFindings[stepId]); } }, [stepId]); // Save observations to sessionStore for this step on every change with debouncing useEffect(() => { if (!stepId) return; // Debounce: save after 500ms of inactivity const timer = setTimeout(() => { const session = sessionStore.get(); const newStepFindings = { ...(session.stepFindings || {}), [stepId]: observations }; sessionStore.merge({ stepFindings: newStepFindings }); console.log(`[ImagingObservations] Saved observations for step: ${stepId}`, observations); }, 500); return () => clearTimeout(timer); }, [stepId, JSON.stringify(observations)]); return

Visual Observations

{layout === 'horizontal' && (
{/* Row: Cervix fully visible */}
{['Yes', 'No'].map(opt => ( ))}
{/* Row: Obscured by */}
{['blood', 'inflammation', 'discharge', 'scarring'].map(k => )}
{/* Row: Adequacy notes */}