'use client'; import React, { useState } from 'react'; import { SoapNote, Patient, Provider, SpinalAdjustmentEntry, CptCodeItem, Icd10CodeItem, ClinicalDiscipline, } from '@/types/clinical'; import { SpineVisualizer } from '@/components/ui/SpineVisualizer'; import { AmbientAudioRecorder } from '@/components/ui/AmbientAudioRecorder'; import { PatientClinicalHud } from '@/components/ui/PatientClinicalHud'; import { clinicalAudio } from '@/lib/clinical-audio'; import { STANDARD_CPT_CODES, STANDARD_ICD10_CODES, DISCIPLINE_PRESETS } from '@/lib/mock-data'; import { CheckCircle, Copy, DollarSign, ChevronLeft, Tag, ShieldCheck, Video, Layers, Lock, } from 'lucide-react'; interface SoapChartEditorProps { patient: Patient; provider: Provider; initialSoapNote?: SoapNote; onSaveSoapNote: (note: SoapNote) => void; onGenerateSuperbill: (note: SoapNote) => void; onLaunchTelehealth: () => void; onBackToCalendar: () => void; } export const SoapChartEditor: React.FC = ({ patient, provider, initialSoapNote, onSaveSoapNote, onGenerateSuperbill, onLaunchTelehealth, onBackToCalendar, }) => { const [discipline, setDiscipline] = useState( initialSoapNote?.discipline || 'chiropractic' ); const [subjective, setSubjective] = useState( initialSoapNote?.subjective || `Patient presents for scheduled visit ${patient.carePlan.completedVisits + 1} of ${ patient.carePlan.totalVisits }. Chief complaint: ${patient.chiefComplaint}. VAS pain reported at 4/10.` ); const [objective, setObjective] = useState( initialSoapNote?.objective || 'Postural examination reveals mild anterior head carriage and unleveling of right iliac crest. Motion palpation identifies segmental hypomobility with paraspinal guarding.' ); const [assessment, setAssessment] = useState( initialSoapNote?.assessment || 'Segmental and somatic dysfunction of lumbar and cervical spine. Patient progressing steadily toward functional goals outlined in care plan.' ); const [plan, setPlan] = useState( initialSoapNote?.plan || '1. High velocity low amplitude (HVLA) manipulative therapy delivered to listed subluxations.\n2. Prescribed postural home stabilization exercises.\n3. Return in 3 days for scheduled care plan visit.' ); const [adjustments, setAdjustments] = useState( initialSoapNote?.spinalAdjustments || [ { vertebra: 'L4', region: 'Lumbar', listing: 'Right Posterior (RP)', technique: 'Diversified' }, { vertebra: 'Sacrum', region: 'Pelvis/Sacrum', listing: 'Right Sacral Base Anterior', technique: 'Thompson Drop' }, ] ); const [selectedIcd10, setSelectedIcd10] = useState( initialSoapNote?.icd10Codes || [STANDARD_ICD10_CODES[2], STANDARD_ICD10_CODES[5]] ); const [selectedCpt, setSelectedCpt] = useState( initialSoapNote?.cptCodes || [STANDARD_CPT_CODES[0], STANDARD_CPT_CODES[3]] ); const [vasScore, setVasScore] = useState(initialSoapNote?.vasScore || 3); const [isSigned, setIsSigned] = useState(initialSoapNote?.status === 'signed'); const [signedTimestamp, setSignedTimestamp] = useState(initialSoapNote?.signedAt); const handleApplyExtractedSoap = (data: { vasScore: number; subjective: string; objective: string; assessment: string; plan: string; spinalAdjustments: SpinalAdjustmentEntry[]; icd10: string[]; cpt: string[]; }) => { setVasScore(data.vasScore); setSubjective(data.subjective); setObjective(data.objective); setAssessment(data.assessment); setPlan(data.plan); if (data.spinalAdjustments && data.spinalAdjustments.length > 0) { setAdjustments(data.spinalAdjustments); } const matchedIcds = STANDARD_ICD10_CODES.filter((icd) => data.icd10.includes(icd.code)); if (matchedIcds.length > 0) setSelectedIcd10(matchedIcds); const matchedCpts = STANDARD_CPT_CODES.filter((cpt) => data.cpt.includes(cpt.code)); if (matchedCpts.length > 0) setSelectedCpt(matchedCpts); }; const handleSwitchDiscipline = (newDiscipline: ClinicalDiscipline) => { clinicalAudio.playClick(); setDiscipline(newDiscipline); const preset = DISCIPLINE_PRESETS[newDiscipline]; if (preset) { setSubjective(preset.sampleSubjective); setObjective(preset.sampleObjective); setAssessment(preset.sampleAssessment); setPlan(preset.samplePlan); const matchedIcds = STANDARD_ICD10_CODES.filter((icd) => preset.icd10Codes.includes(icd.code)); if (matchedIcds.length > 0) setSelectedIcd10(matchedIcds); const matchedCpts = STANDARD_CPT_CODES.filter((cpt) => preset.cptCodes.includes(cpt.code)); if (matchedCpts.length > 0) setSelectedCpt(matchedCpts); } }; const handleToggleAdjustment = (entry: SpinalAdjustmentEntry) => { clinicalAudio.playClick(); setAdjustments((prev) => { const exists = prev.some((a) => a.vertebra === entry.vertebra); if (exists) { return prev.filter((a) => a.vertebra !== entry.vertebra); } else { return [...prev, entry]; } }); }; const handleCloneLastNote = () => { clinicalAudio.playClick(); setSubjective('Patient reports continued symptom improvement following last spinal adjustment. Morning stiffness resolved within 10 minutes. Current pain rated 3/10.'); setObjective('Palpation reveals decreased tone in lumbar paraspinals. Persistent fixation noted at L4-L5 with right sacral torsion.'); setAssessment('Care plan compliance high. Significant restoration of active range of motion noted.'); setPlan('1. Diversified adjustment delivered to indicated segments.\n2. Manual myofascial release 10 minutes.\n3. Continue active home rehabilitation.'); }; const handleSignChart = () => { clinicalAudio.playSuccess(); const now = new Date().toISOString(); setIsSigned(true); setSignedTimestamp(now); const savedNote: SoapNote = { id: initialSoapNote?.id || `soap-${Date.now()}`, tenantId: patient.tenantId, patientId: patient.id, patientName: `${patient.firstName} ${patient.lastName}`, providerId: provider.id, providerName: provider.name, date: '2026-09-05', status: 'signed', discipline, vasScore, subjective, objective, assessment, plan, spinalAdjustments: adjustments, icd10Codes: selectedIcd10, cptCodes: selectedCpt, signedAt: now, signedBy: `${provider.name}, ${provider.credentials} (NPI ${provider.npi})`, }; onSaveSoapNote(savedNote); }; const handleCreateSuperbillClick = () => { clinicalAudio.playSuccess(); const savedNote: SoapNote = { id: initialSoapNote?.id || `soap-${Date.now()}`, tenantId: patient.tenantId, patientId: patient.id, patientName: `${patient.firstName} ${patient.lastName}`, providerId: provider.id, providerName: provider.name, date: '2026-09-05', status: isSigned ? 'signed' : 'draft', discipline, vasScore, subjective, objective, assessment, plan, spinalAdjustments: adjustments, icd10Codes: selectedIcd10, cptCodes: selectedCpt, signedAt: signedTimestamp, signedBy: isSigned ? `${provider.name}, ${provider.credentials}` : undefined, }; onSaveSoapNote(savedNote); onGenerateSuperbill(savedNote); }; return (
{/* Patient Clinical HUD Ribbon */} {/* Top Patient Header Bar */}

{patient.firstName} {patient.lastName}

HIPAA Vault Sync
{isSigned ? ( Signed & Locked ) : ( In Progress (Draft) )}
DOB: {patient.dob} Insurance: {patient.insuranceName} Attending: {provider.name}
{/* Action buttons */}
{/* Multi-Discipline Template Presets Bar */}
Clinical Discipline Template:
{[ { id: 'chiropractic', label: '🦴 Chiropractic (Spine CMT)' }, { id: 'physical_therapy', label: '🏃 Physical Therapy & Rehab' }, { id: 'acupuncture', label: '🪡 Acupuncture Meridian' }, { id: 'massage_therapy', label: '💆 Medical Massage' }, ].map((d) => ( ))}
{/* Ambient AI Scribe */} {/* Spine Subluxation Visualizer (shown prominently for chiropractic & physical therapy) */} {/* Structured SOAP Fields */}
{/* S */}
S Subjective History & Complaint VAS: {vasScore}/10