import { Section } from '@/components/ui/section'; import { EmptyState } from '@/components/ui/empty-state'; import { Freshness } from '@/components/ui/freshness'; import { ClaimBadge } from '@/components/ui/badge'; import { SourceBadge, TableProvenance } from '@/components/ui/source-badge'; import { Pager } from '@/components/ui/pager'; import { PublicationList } from '@/components/data/publication-list'; import { literatureCountsFor, recentPublicationsFor, recentPublicationsForCount, PUBLICATION_PAGE_SIZE } from '@/lib/queries/publications'; import { loadProvenance, toInfo } from '@/lib/queries/provenance'; import { fmtInt, isoDate } from '@/lib/format'; import { pageInfo } from '@/lib/pagination'; import type { CancerBundle } from '../load'; const WINDOW_LABEL: Record = { all: 'All time', '10y': 'Last 10 years', '5y': 'Last 5 years', '5y_prior': 'Preceding 5-year window', '12m': 'Last 12 months' }; export async function ResearchTab({ b, pPage = 1 }: { b: CancerBundle; pPage?: number }) { const [counts, pubTotal] = await Promise.all([literatureCountsFor(b.cancer.id), recentPublicationsForCount('cancer', b.descendants)]); const info = pageInfo(pPage, PUBLICATION_PAGE_SIZE, pubTotal); const [pubs, prov] = await Promise.all([pubTotal > 0 ? recentPublicationsFor('cancer', b.descendants, { page: info.page, pageSize: info.pageSize }) : Promise.resolve([]), loadProvenance(counts.map((c) => c.provenance_id))]); const countsProv = counts[0] ? toInfo(prov.get(counts[0].provenance_id), 'derived') : null; const hrefFor = (p: number) => `/cancer/${b.cancer.slug}/research${p > 1 ? `?pPage=${p}` : ''}#recent-publications`; return (
{counts.length ? ( <> }> {counts.length} window{counts.length === 1 ? '' : 's'} · counts computed by CancerIndex from PubMed E-utilities; the exact query is stored with each count.
{counts.map((c) => ( ))}
Window Period Records (count) Exact query Computed Source
{WINDOW_LABEL[c.window_key] ?? c.window_key} {c.window_start || c.window_end ? `${c.window_start ?? '…'} → ${c.window_end ?? '…'}` : '—'} {fmtInt(c.count)} {c.query} {isoDate(c.updated_at)}
) : ( No PubMed query has been run for this entity. Counts require a MeSH-anchored query built from the entity's terminology mappings; the query string is stored with each count so it can be reproduced. )}
{pubs.length ? ( <> Showing {fmtInt(info.from)}–{fmtInt(info.to)} of {fmtInt(pubTotal)} publications } /> ) : ( No publication is linked to this entity yet. )}
); }