File size: 20,326 Bytes
1c68fe6 bab7e89 1c68fe6 bab7e89 1c68fe6 bab7e89 1c68fe6 bab7e89 1c68fe6 bab7e89 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 | 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<HTMLTextAreaElement>) => {
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 <div className={`bg-white rounded-xl shadow-sm border border-gray-100 overflow-hidden ${layout === 'vertical' ? 'h-full flex flex-col' : ''}`}>
<div className="bg-teal-50/50 p-3 md:p-4 border-b border-teal-100 flex items-center gap-2 md:gap-3">
<div className="w-8 h-8 md:w-10 md:h-10 rounded-full bg-teal-100 text-teal-700 flex items-center justify-center flex-shrink-0">
<CheckSquare className="w-4 h-4 md:w-5 md:h-5" />
</div>
<h3 className="font-bold text-sm md:text-base text-[#0A2540]">Visual Observations</h3>
</div>
<div className={`p-4 md:p-6 ${layout === 'horizontal' ? 'space-y-6 flex-1 overflow-y-auto' : 'space-y-4 md:space-y-6 flex-1 overflow-y-auto'}`}>
{layout === 'horizontal' && (
<div className="space-y-6">
{/* Row: Cervix fully visible */}
<div className="pb-4 border-b border-gray-100">
<div className="flex flex-col md:flex-row md:items-center gap-3 md:gap-6">
<label className="text-sm md:text-base font-semibold text-gray-900 min-w-fit">Cervix fully visible?</label>
<div className="flex items-center gap-2">
{['Yes', 'No'].map(opt => (
<label key={opt} className={`px-4 py-2 rounded-lg border cursor-pointer transition-all text-xs md:text-sm font-medium ${observations.cervixFullyVisible === opt ? 'border-teal-300 bg-teal-50 text-teal-700' : 'border-gray-200 bg-gray-50 text-gray-600'}`}>
<input type="radio" name="cervixVisible" checked={observations.cervixFullyVisible === opt} onChange={() => handleFieldChange('cervixFullyVisible', opt)} className="mr-2" />
{opt}
</label>
))}
</div>
</div>
</div>
{/* Row: Obscured by */}
<div className="pb-4 border-b border-gray-100">
<label className="block text-sm md:text-base font-semibold text-gray-900 mb-3">Obscured by:</label>
<div className="flex flex-wrap gap-2">
{['blood', 'inflammation', 'discharge', 'scarring'].map(k => <label key={k} className="flex items-center gap-2 px-4 py-2 rounded-lg border bg-gray-50 border-gray-200 cursor-pointer hover:border-teal-200 transition-all">
<input type="checkbox" checked={observations.obscuredBy[k as keyof typeof observations.obscuredBy]} onChange={() => handleObscuredChange(k)} className="w-4 h-4" />
<span className="text-sm capitalize">{k}</span>
</label>)}
</div>
</div>
{/* Row: Adequacy notes */}
<div className="pb-4 border-b border-gray-100">
<label className="block text-sm font-semibold text-gray-900 mb-2">Adequacy Notes</label>
<textarea value={observations.adequacyNotes} onChange={e => handleFieldChange('adequacyNotes', e.target.value)} rows={2} className="w-full px-3 py-2 bg-gray-50 border-2 border-gray-200 rounded-lg text-sm focus:border-teal-300 focus:ring-2 focus:ring-teal-100 outline-none transition-all" placeholder="Notes about adequacy..." />
</div>
{/* Row: SCJ Visibility */}
<div className="pb-4 border-b border-gray-100">
<label className="block text-sm md:text-base font-semibold text-gray-900 mb-3">SCJ Visibility</label>
<div className="flex flex-wrap items-center gap-2">
{['Completely visible', 'Partially visible', 'Not visible'].map(opt => <label key={opt} className={`px-4 py-2 rounded-lg border cursor-pointer transition-all text-xs md:text-sm font-medium ${observations.scjVisibility === opt ? 'border-teal-300 bg-teal-50 text-teal-700' : 'border-gray-200 bg-gray-50 text-gray-600'}`}>
<input type="radio" name="scj" checked={observations.scjVisibility === opt} onChange={() => handleFieldChange('scjVisibility', opt)} className="mr-2" />
{opt}
</label>)}
</div>
<div className="mt-3">
<textarea value={observations.scjNotes} onChange={e => handleFieldChange('scjNotes', e.target.value)} rows={2} className="w-full px-3 py-2 bg-gray-50 border-2 border-gray-200 rounded-lg text-sm focus:border-teal-300 focus:ring-2 focus:ring-teal-100 outline-none transition-all" placeholder="SCJ notes..." />
</div>
</div>
{/* Row: Transformation Zone Type */}
<div className="pb-4 border-b border-gray-100">
<label className="block text-sm md:text-base font-semibold text-gray-900 mb-3">Transformation Zone (TZ) Type</label>
<div className="flex items-center gap-2">
{['TZ 1', 'TZ 2', 'TZ 3'].map(tz => (
<label key={tz} className={`px-4 py-2 rounded-lg border cursor-pointer transition-all text-xs md:text-sm font-medium ${observations.tzType === tz ? 'border-teal-300 bg-teal-50 text-teal-700' : 'border-gray-200 bg-gray-50 text-gray-600'}`}>
<input type="radio" name="tzType" checked={observations.tzType === tz} onChange={() => handleFieldChange('tzType', tz)} className="mr-2" />
{tz}
</label>
))}
</div>
</div>
{/* Row: Native (Untreated) Examination */}
<div className="pb-4 border-b border-gray-100">
<label className="block text-sm md:text-base font-semibold text-gray-900 mb-3">Native (Untreated) Examination</label>
<label className="flex items-center gap-3 cursor-pointer">
<input type="checkbox" checked={observations.suspiciousAtNativeView} onChange={() => {
const next = !observations.suspiciousAtNativeView;
const updated = {
...observations,
suspiciousAtNativeView: next,
skipStainInterpretation: next
};
setObservations(updated);
if (onObservationsChange) onObservationsChange(updated);
}} className="w-5 h-5 rounded text-teal-600 border-gray-300" />
<span className="text-sm font-medium text-gray-900">Suspicious at Native View</span>
</label>
{observations.suspiciousAtNativeView && <div className="mt-3">
<textarea value={observations.adequacyNotes} onChange={e => handleFieldChange('adequacyNotes', e.target.value)} rows={2} className="w-full px-3 py-2 bg-gray-50 border-2 border-gray-200 rounded-lg text-sm focus:border-teal-300 focus:ring-2 focus:ring-teal-100 outline-none transition-all" placeholder="Additional notes..." />
</div>}
</div>
</div>
)}
{layout !== 'horizontal' && (
<>
{/* Default Vertical Layout - kept for non-native pages */}
<div>
<label className="block text-xs font-semibold text-gray-500 uppercase mb-2 md:mb-3">
Examination Adequacy Checklist
</label>
<div className="space-y-2 md:space-y-3">
<div className="flex flex-col md:flex-row md:items-center gap-2 md:gap-4">
<label className="text-xs md:text-sm font-medium whitespace-nowrap">Cervix fully visible?</label>
<div className="flex items-center gap-2">
{['Yes', 'No'].map(opt => (
<label key={opt} className={`px-3 py-1 rounded-lg border cursor-pointer text-xs md:text-sm ${observations.cervixFullyVisible === opt ? 'bg-teal-50 border-teal-200' : 'bg-gray-50 border-gray-200'}`}>
<input type="radio" name="cervixVisibleVertical" checked={observations.cervixFullyVisible === opt} onChange={() => handleFieldChange('cervixFullyVisible', opt)} className="mr-2" />
{opt}
</label>
))}
</div>
</div>
<div>
<span className="block text-sm font-semibold text-gray-900">Obscured by:</span>
<div className="mt-2 grid grid-cols-2 gap-2">
{['blood', 'inflammation', 'discharge', 'scarring'].map(k => <label key={k} className="flex items-center gap-2 p-3 rounded-lg border bg-gray-50 border-gray-200 cursor-pointer">
<input type="checkbox" checked={observations.obscuredBy[k as keyof typeof observations.obscuredBy]} onChange={() => handleObscuredChange(k)} className="w-4 h-4" />
<span className="text-sm capitalize">{k}</span>
</label>)}
</div>
</div>
<div className="pt-2">
<label className="block text-xs font-semibold text-gray-500 uppercase mb-2">Additional notes</label>
<textarea value={observations.adequacyNotes} onChange={e => handleFieldChange('adequacyNotes', e.target.value)} rows={3} className="w-full px-3 py-2 bg-gray-50 border-2 border-gray-200 rounded-lg text-sm" placeholder="Notes about adequacy..." />
</div>
</div>
</div>
{/* SCJ Visibility and TZ */}
<div className="pt-4 border-t border-gray-100">
<label className="block text-xs font-semibold text-gray-500 uppercase mb-3">SCJ Visibility</label>
<div className="flex items-center gap-3">
{['Completely visible', 'Partially visible', 'Not visible'].map(opt => <label key={opt} className={`p-3 rounded-lg border ${observations.scjVisibility === opt ? 'border-teal-200 bg-teal-50' : 'border-gray-200 bg-gray-50'} cursor-pointer`}>
<input type="radio" name="scj" checked={observations.scjVisibility === opt} onChange={() => handleFieldChange('scjVisibility', opt)} className="mr-2" />
<span className="text-sm">{opt}</span>
</label>)}
</div>
<div className="mt-3">
<textarea value={observations.scjNotes} onChange={e => handleFieldChange('scjNotes', e.target.value)} rows={2} className="w-full px-3 py-2 bg-gray-50 border-2 border-gray-200 rounded-lg text-sm" placeholder="SCJ notes..." />
</div>
<div className="mt-4">
<label className="block text-xs font-semibold text-gray-500 uppercase mb-2">Transformation Zone (TZ) Type</label>
<div className="flex items-center gap-2">
{['TZ 1', 'TZ 2', 'TZ 3'].map(tz => (
<label key={tz} className={`px-3 py-2 rounded-lg border cursor-pointer text-sm ${observations.tzType === tz ? 'border-teal-200 bg-teal-50' : 'border-gray-200 bg-gray-50'}`}>
<input type="radio" name="tzTypeVertical" checked={observations.tzType === tz} onChange={() => handleFieldChange('tzType', tz)} className="mr-2" />
{tz}
</label>
))}
</div>
</div>
</div>
{/* Native (Untreated) Examination */}
<div className="pt-4 border-t border-gray-100">
<label className="block text-xs font-semibold text-gray-500 uppercase mb-3">Native (Untreated) Examination (STEP 2)</label>
<div className="flex items-center gap-3">
<label className="flex items-center gap-2">
<input type="checkbox" checked={observations.suspiciousAtNativeView} onChange={() => {
const next = !observations.suspiciousAtNativeView;
const updated = {
...observations,
suspiciousAtNativeView: next,
skipStainInterpretation: next
};
setObservations(updated);
if (onObservationsChange) onObservationsChange(updated);
}} className="w-4 h-4" />
<span className="text-sm font-medium">Suspicious at Native View</span>
</label>
</div>
{observations.suspiciousAtNativeView && <div className="mt-3">
<textarea value={observations.adequacyNotes} onChange={e => handleFieldChange('adequacyNotes', e.target.value)} rows={2} className="w-full px-3 py-2 bg-gray-50 border-2 border-gray-200 rounded-lg text-sm" placeholder="Additional notes..." />
</div>}
</div>
</>
)}
<div>
<label className="block text-xs font-semibold text-gray-500 uppercase mb-3">
Clinical Findings
</label>
<div className="space-y-3">
<label className="flex items-start p-4 rounded-lg border-2 border-gray-200 hover:border-[#05998c]/50 cursor-pointer transition-all bg-gray-50/50 group">
<input type="checkbox" checked={observations.obviousGrowths} onChange={() => handleCheckboxChange('obviousGrowths')} className="w-5 h-5 rounded text-[#05998c] focus:ring-[#05998c] border-gray-300 mt-0.5" />
<div className="ml-3">
<span className="block text-sm font-semibold text-gray-900 group-hover:text-[#0A2540]">
Obvious growths / ulcers
</span>
<span className="block text-xs text-gray-500 mt-0.5">
Visible abnormal tissue growth or ulceration
</span>
</div>
</label>
<label className="flex items-start p-4 rounded-lg border-2 border-gray-200 hover:border-[#05998c]/50 cursor-pointer transition-all bg-gray-50/50 group">
<input type="checkbox" checked={observations.contactBleeding} onChange={() => handleCheckboxChange('contactBleeding')} className="w-5 h-5 rounded text-[#05998c] focus:ring-[#05998c] border-gray-300 mt-0.5" />
<div className="ml-3">
<span className="block text-sm font-semibold text-gray-900 group-hover:text-[#0A2540]">
Contact bleeding
</span>
<span className="block text-xs text-gray-500 mt-0.5">
Bleeding upon contact with instrument
</span>
</div>
</label>
<label className="flex items-start p-4 rounded-lg border-2 border-gray-200 hover:border-[#05998c]/50 cursor-pointer transition-all bg-gray-50/50 group">
<input type="checkbox" checked={observations.irregularSurface} onChange={() => handleCheckboxChange('irregularSurface')} className="w-5 h-5 rounded text-[#05998c] focus:ring-[#05998c] border-gray-300 mt-0.5" />
<div className="ml-3">
<span className="block text-sm font-semibold text-gray-900 group-hover:text-[#0A2540]">
Irregular surface
</span>
<span className="block text-xs text-gray-500 mt-0.5">
Uneven or abnormal surface texture
</span>
</div>
</label>
<label className="flex items-start p-4 rounded-lg border-2 border-gray-200 hover:border-[#05998c]/50 cursor-pointer transition-all bg-gray-50/50 group">
<input type="checkbox" checked={observations.other} onChange={() => handleCheckboxChange('other')} className="w-5 h-5 rounded text-[#05998c] focus:ring-[#05998c] border-gray-300 mt-0.5" />
<div className="ml-3">
<span className="block text-sm font-semibold text-gray-900 group-hover:text-[#0A2540]">
Other findings
</span>
<span className="block text-xs text-gray-500 mt-0.5">
Additional observations not listed above
</span>
</div>
</label>
</div>
</div>
<div className="pt-6 border-t border-gray-100">
<label className="block text-xs font-semibold text-gray-500 uppercase mb-3 flex items-center gap-2">
<FileText className="w-4 h-4" />
Additional Notes
</label>
<textarea value={observations.additionalNotes} onChange={handleNotesChange} rows={6} className="w-full px-4 py-3 bg-gray-50 border-2 border-gray-200 rounded-lg focus:ring-2 focus:ring-[#05998c] focus:border-[#05998c] outline-none transition-all resize-none text-sm" placeholder="Document any additional observations, measurements, or clinical notes..." />
</div>
<div className="bg-blue-50 rounded-lg p-4 border border-blue-100">
<p className="text-xs text-blue-800 leading-relaxed">
<strong>Tip:</strong> Use the annotation tool to mark specific areas
of concern on the image, then document your findings here.
</p>
</div>
</div>
</div>;
} |