// ============================================================ // SOAP — transcript → SOAP note via /api/generate-soap // ============================================================ import { useState } from 'react'; import { useMutation } from '@tanstack/react-query'; import { api, ApiError } from '@/lib/api'; import type { SoapOk } from '@/shared/types'; import { SoapRequestSchema, type SoapRequest } from '@/shared/schemas'; type SoapType = 'full' | 'subjective'; export default function Soap() { const [patientAge, setPatientAge] = useState(''); const [patientGender, setPatientGender] = useState(''); const [type, setType] = useState('full'); const [transcript, setTranscript] = useState(''); const [additionalInstructions, setAdditionalInstructions] = useState(''); const [result, setResult] = useState(null); const [validationError, setValidationError] = useState(null); const generate = useMutation({ mutationFn: (body) => api.post('/api/generate-soap', body), onSuccess: (data) => setResult(data.soap), }); function submit(e: React.FormEvent) { e.preventDefault(); setValidationError(null); const body: SoapRequest = { transcript, patientAge, patientGender, type, additionalInstructions }; const parsed = SoapRequestSchema.safeParse(body); if (!parsed.success) { setValidationError(parsed.error.issues.map((i: { message: string }) => i.message).join(', ')); return; } setResult(null); generate.mutate(parsed.data); } const input = 'w-full rounded-md border border-input bg-background px-3 py-2 text-sm'; return (

SOAP Note

Encounter transcript → full SOAP or subjective-only narrative.