// ============================================================ // CHART REVIEW — /api/generate-chart-review // ============================================================ import { useState } from 'react'; import { useMutation } from '@tanstack/react-query'; import { api, ApiError } from '@/lib/api'; import type { ChartReviewOk } from '@/shared/types'; type ReviewType = 'outpatient' | 'subspecialty' | 'ed'; interface VisitInput { date: string; content: string; labs: string } function emptyVisit(): VisitInput { return { date: '', content: '', labs: '' }; } export default function ChartReview() { const [type, setType] = useState('outpatient'); const [patientAge, setPatientAge] = useState(''); const [patientGender, setPatientGender] = useState(''); const [pmh, setPmh] = useState(''); const [visits, setVisits] = useState([emptyVisit()]); const [additionalInstructions, setAdditionalInstructions] = useState(''); const [result, setResult] = useState(null); const generate = useMutation({ mutationFn: (body) => api.post('/api/generate-chart-review', body), onSuccess: (data) => setResult(data.review), }); function updateVisit(i: number, patch: Partial) { setVisits((vs) => vs.map((v, idx) => (idx === i ? { ...v, ...patch } : v))); } function submit(e: React.FormEvent) { e.preventDefault(); setResult(null); const filled = visits.filter((v) => v.content.trim()); generate.mutate({ type, patientAge, patientGender, pmh, visits: type === 'outpatient' ? filled : undefined, subspecialty: type === 'subspecialty' ? filled : undefined, edVisits: type === 'ed' ? filled : undefined, additionalInstructions: additionalInstructions || undefined, }); } const input = 'w-full rounded-md border border-input bg-background px-3 py-2 text-sm'; return (

Chart Review

Past visits → summary for pre-charting.

Visits
{visits.map((v, i) => (
updateVisit(i, { date: e.target.value })} /> {visits.length > 1 && ( )}