// ============================================================ // HOSPITAL COURSE — /api/generate-hospital-course // ============================================================ import { useState } from 'react'; import { useMutation } from '@tanstack/react-query'; import { api, ApiError } from '@/lib/api'; import type { HospitalCourseOk } from '@/shared/types'; type SettingKind = 'floor' | 'picu' | 'nicu' | 'psych'; type FormatKind = 'auto' | 'prose' | 'dayByDay' | 'organSystem'; interface NoteEntry { date: string; type: string; content: string } export default function HospitalCourse() { const [patientAge, setPatientAge] = useState(''); const [patientGender, setPatientGender] = useState(''); const [pmh, setPmh] = useState(''); const [setting, setSetting] = useState('floor'); const [los, setLos] = useState(''); const [format, setFormat] = useState('auto'); const [hAndPContent, setHAndPContent] = useState(''); const [notesText, setNotesText] = useState(''); const [additionalInstructions, setAdditionalInstructions] = useState(''); const [result, setResult] = useState<{ hospitalCourse: string; format: string } | null>(null); const generate = useMutation({ mutationFn: (body) => api.post('/api/generate-hospital-course', body), onSuccess: (data) => setResult({ hospitalCourse: data.hospitalCourse, format: data.format || 'auto' }), }); function submit(e: React.FormEvent) { e.preventDefault(); setResult(null); // Notes textarea: one blank-line-separated note per block. First // line of each block is used as the date if it looks like one, // rest becomes content. const notes: NoteEntry[] = notesText .split(/\n\s*\n/) .map((block) => block.trim()) .filter(Boolean) .map((block, i) => ({ date: `Day ${i + 1}`, type: 'Progress Note', content: block })); generate.mutate({ notes, hAndP: hAndPContent ? { date: 'Admission', content: hAndPContent } : undefined, patientAge, patientGender, pmh, setting, los: los ? parseInt(los) : undefined, formatPreference: format, additionalInstructions: additionalInstructions || undefined, }); } const input = 'w-full rounded-md border border-input bg-background px-3 py-2 text-sm'; return (

Hospital Course

Progress notes + H&P → hospital course summary (prose, day-by-day, or organ-system format).