feat: add inline preview for Wochenübersicht reports

- Backend stores per-KW summary in report_data (count, ICD status, FG split)
- WochenuebersichtViewer component shows expandable KW table with totals
- Expand/collapse pattern matching ReportsPage (ChevronRight/Down, useReportData)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
CCS Admin 2026-02-27 15:26:20 +00:00
parent efeb619b06
commit 27b3810250
2 changed files with 181 additions and 33 deletions

View file

@ -360,11 +360,29 @@ def generate_wochenuebersicht(
)
.first()
)
# Build per-KW summary for frontend preview
fg1, fg2 = fallgruppen
fg1_label, fg2_label = type_cfg["fg_labels"]
weeks_summary = []
for kw in sorted(cases_by_kw.keys(), reverse=True):
kw_cases = cases_by_kw[kw]
weeks_summary.append({
"kw": kw,
"count": len(kw_cases),
"with_icd": sum(1 for c in kw_cases if c.icd),
"fg1_count": sum(1 for c in kw_cases if c.fallgruppe == fg1),
"fg2_count": sum(1 for c in kw_cases if c.fallgruppe == fg2),
"gutachten": sum(1 for c in kw_cases if c.gutachten),
})
report_data = {
"export_type": export_type,
"kw_von": kw_von,
"kw_bis": kw_bis,
"case_count": len(cases),
"fg1_label": fg1_label,
"fg2_label": fg2_label,
"weeks": weeks_summary,
}
if report:
report.report_date = date.today()

View file

@ -1,9 +1,10 @@
import { useCallback, useState } from 'react'
import { Download, FileSpreadsheet, Loader2, Plus, Upload } from 'lucide-react'
import { Fragment, useCallback, useState } from 'react'
import { ChevronDown, ChevronRight, Download, FileSpreadsheet, Loader2, Plus, Upload } from 'lucide-react'
import api from '@/services/api'
import { useAuth } from '@/context/AuthContext'
import {
useReports,
useReportData,
useGenerateWochenuebersicht,
useDeleteReports,
useUploadWochenuebersichtIcd,
@ -16,7 +17,7 @@ import {
Select, SelectContent, SelectItem, SelectTrigger, SelectValue,
} from '@/components/ui/select'
import {
Table, TableBody, TableCell, TableHead, TableHeader, TableRow,
Table, TableBody, TableCell, TableFooter, TableHead, TableHeader, TableRow,
} from '@/components/ui/table'
import { Skeleton } from '@/components/ui/skeleton'
import { Alert, AlertDescription } from '@/components/ui/alert'
@ -86,6 +87,10 @@ export function WochenuebersichtPage() {
const [uploadSuccess, setUploadSuccess] = useState('')
const uploadMutation = useUploadWochenuebersichtIcd()
// Inline expansion state
const [expandedId, setExpandedId] = useState<number | null>(null)
const { data: reportData, isLoading: reportDataLoading } = useReportData(expandedId)
// Drag state
const [isDragOver, setIsDragOver] = useState(false)
@ -296,14 +301,27 @@ export function WochenuebersichtPage() {
</TableRow>
</TableHeader>
<TableBody>
{reports.map((r) => (
<TableRow key={r.id}>
<TableCell>{formatDate(r.report_date)}</TableCell>
{reports.map((r) => {
const isExpanded = expandedId === r.id
return (
<Fragment key={r.id}>
<TableRow
className="cursor-pointer hover:bg-muted/50"
onClick={() => setExpandedId(isExpanded ? null : r.id)}
>
<TableCell>
<span className="inline-flex items-center gap-1.5">
{isExpanded
? <ChevronDown className="size-4 text-muted-foreground" />
: <ChevronRight className="size-4 text-muted-foreground" />}
{formatDate(r.report_date)}
</span>
</TableCell>
<TableCell>{r.jahr}</TableCell>
<TableCell>KW {r.kw}</TableCell>
<TableCell>{REPORT_TYPE_LABELS[r.report_type] ?? r.report_type}</TableCell>
<TableCell>{formatDateTime(r.generated_at)}</TableCell>
<TableCell className="text-right">
<TableCell className="text-right" onClick={(e) => e.stopPropagation()}>
<Button
variant="outline"
size="sm"
@ -327,7 +345,28 @@ export function WochenuebersichtPage() {
)}
</TableCell>
</TableRow>
))}
{isExpanded && (
<TableRow>
<TableCell colSpan={6} className="p-0">
{reportDataLoading ? (
<div className="p-6">
<Skeleton className="h-48 w-full" />
</div>
) : reportData ? (
<div className="p-4 border-t bg-muted/20">
<WochenuebersichtViewer data={reportData} />
</div>
) : (
<div className="p-6 text-center text-muted-foreground">
Keine Vorschaudaten verfügbar.
</div>
)}
</TableCell>
</TableRow>
)}
</Fragment>
)
})}
</TableBody>
</Table>
) : (
@ -445,3 +484,94 @@ export function WochenuebersichtPage() {
</div>
)
}
// ---------------------------------------------------------------------------
// Wochenübersicht Viewer (inline preview)
// ---------------------------------------------------------------------------
interface WeekSummary {
kw: number
count: number
with_icd: number
fg1_count: number
fg2_count: number
gutachten: number
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
function WochenuebersichtViewer({ data }: { data: Record<string, any> }) {
const weeks: WeekSummary[] = data?.weeks ?? []
const fg1Label: string = data?.fg1_label ?? 'FG1'
const fg2Label: string = data?.fg2_label ?? 'FG2'
const kwVon: number = data?.kw_von ?? '?'
const kwBis: number = data?.kw_bis ?? '?'
const totalCases: number = data?.case_count ?? 0
if (!weeks.length) {
return (
<p className="py-4 text-center text-muted-foreground">
Keine Vorschaudaten verfügbar.
</p>
)
}
const totals = weeks.reduce(
(acc, w) => ({
count: acc.count + w.count,
with_icd: acc.with_icd + w.with_icd,
fg1: acc.fg1 + w.fg1_count,
fg2: acc.fg2 + w.fg2_count,
gutachten: acc.gutachten + w.gutachten,
}),
{ count: 0, with_icd: 0, fg1: 0, fg2: 0, gutachten: 0 },
)
return (
<div className="space-y-3">
<div className="flex items-center gap-4 text-sm text-muted-foreground">
<span>KW {kwVon}{kwBis}</span>
<span>{totalCases} Fälle gesamt</span>
<span>{totals.with_icd} mit ICD</span>
</div>
<Table>
<TableHeader>
<TableRow>
<TableHead>KW</TableHead>
<TableHead className="text-right">Fälle</TableHead>
<TableHead className="text-right">{fg1Label}</TableHead>
<TableHead className="text-right">{fg2Label}</TableHead>
<TableHead className="text-right">Gutachten</TableHead>
<TableHead className="text-right">mit ICD</TableHead>
</TableRow>
</TableHeader>
<TableBody>
{weeks.map((w) => (
<TableRow key={w.kw}>
<TableCell>KW {w.kw}</TableCell>
<TableCell className="text-right">{w.count}</TableCell>
<TableCell className="text-right">{w.fg1_count}</TableCell>
<TableCell className="text-right">{w.fg2_count}</TableCell>
<TableCell className="text-right">{w.gutachten}</TableCell>
<TableCell className="text-right">
{w.with_icd}/{w.count}
</TableCell>
</TableRow>
))}
</TableBody>
<TableFooter>
<TableRow>
<TableCell className="font-bold">Gesamt</TableCell>
<TableCell className="text-right font-bold">{totals.count}</TableCell>
<TableCell className="text-right font-bold">{totals.fg1}</TableCell>
<TableCell className="text-right font-bold">{totals.fg2}</TableCell>
<TableCell className="text-right font-bold">{totals.gutachten}</TableCell>
<TableCell className="text-right font-bold">
{totals.with_icd}/{totals.count}
</TableCell>
</TableRow>
</TableFooter>
</Table>
</div>
)
}