import Link from 'next/link'; import { Section } from '@/components/ui/section'; import { EmptyState } from '@/components/ui/empty-state'; import { Freshness } from '@/components/ui/freshness'; import { Pager } from '@/components/ui/pager'; import { TrialTable } from '@/components/data/trial-list'; import { ClaimBadge } from '@/components/ui/badge'; import { SourceBadge } from '@/components/ui/source-badge'; import { listTrialRows, trialFacets, TRIAL_PAGE_SIZE } from '@/lib/queries/trials'; import { trialIntelligenceFor, type TrialIntelRow } from '@/lib/queries/trial-intelligence'; import { fmtInt, fmtNum, fmtPct, humanize, phaseLabel } from '@/lib/format'; import { fmtGrowth } from '@/lib/trial-intel'; import { pageInfo } from '@/lib/pagination'; import { withParams } from '@/lib/search-params'; import type { CancerBundle } from '../load'; /** * Intelligence strip on top of the trials tab: figures from `trial_intelligence` (level "all" for this * entity, falling back to "top"). Rendered only when a row exists — never a fake zero. */ function IntelStrip({ r, slug }: { r: TrialIntelRow; slug: string }) { const th = (r.inputs.thresholds ?? {}) as Record; const burden = r.inputs.burden as { deaths?: number } | undefined; const items: Array<{ k: string; v: React.ReactNode; title: string }> = [ { k: 'Active', v: fmtInt(r.active_trials), title: `Interventional studies with status ${(r.inputs.activeStatuses as string[] | undefined)?.join(', ') ?? 'active'} mapped to this entity or a descendant` }, { k: 'Recruiting', v: fmtInt(r.recruiting_trials), title: 'Interventional studies with overall status RECRUITING' }, { k: 'Ph III recruiting', v: fmtInt(r.phase3_recruiting), title: `Recruiting interventional studies with PHASE3 among their phases (${fmtInt(r.phase3_active)} active Phase III)` }, { k: 'Growth YoY', v: fmtGrowth(r.trial_growth_yoy), title: `(${fmtInt(r.new_trials_12m)} first posted in the last 12 months − ${fmtInt(r.new_trials_prior_12m)} in the preceding 12 months) / ${fmtInt(r.new_trials_prior_12m)}${r.trial_growth_yoy == null ? ` — not computed under ${String(th.growthMinPriorTrials ?? 20)} studies in the preceding window` : ''}` }, { k: 'Industry share', v: fmtPct(r.industry_share, 0), title: 'Share of active interventional studies whose lead sponsor class is INDUSTRY' }, { k: 'Top sponsor', v: r.top_sponsor ? {r.top_sponsor} : '—', title: r.top_sponsor ? `${r.top_sponsor} leads ${fmtPct(r.top_sponsor_share, 1)} of active studies · ${fmtInt(r.distinct_sponsors)} distinct lead sponsors · sponsor HHI ${fmtNum(r.sponsor_hhi, 3)}` : 'No active study with a lead sponsor' }, { k: 'Termination share', v: fmtPct(r.termination_share, 1), title: `(terminated + withdrawn) / (completed + terminated + withdrawn), interventional studies first posted since ${String(th.terminationSince ?? '2010-01-01')}${r.termination_share == null ? ` — not computed under ${String(th.terminationMinTerminalTrials ?? 30)} terminal studies` : ''}` }, ]; if (r.trials_per_1000_deaths != null) { items.push({ k: 'Trials / 1,000 deaths', v: <>{fmtNum(r.trials_per_1000_deaths, 1)} {r.burden_geography} {r.burden_year} {r.burden_source_slug ? : null}, title: `${fmtInt(r.active_trials)} active interventional studies / (${fmtInt(burden?.deaths)} annual deaths / 1,000) · also ${fmtNum(r.trials_per_100k_cases, 1)} per 100,000 new cases` }); } return (
{items.map((i) => (
{i.k}
{i.v}
))}

formula {r.formula_version} · interventional studies · entity + NCIt descendants · hover a figure for its formula Compare cancers Terminated studies ({fmtInt(r.terminated_trials + r.withdrawn_trials + r.suspended_trials)})

); } export async function TrialsTab({ b, status, phase, page }: { b: CancerBundle; status: string; phase: string; page: number }) { const [facets, { rows, total }, intel] = await Promise.all([trialFacets(b.descendants), listTrialRows({ q: '', status, phase, country: '', cancerIds: b.descendants, page, pageSize: TRIAL_PAGE_SIZE }), trialIntelligenceFor(b.cancer.id)]); const info = pageInfo(page, TRIAL_PAGE_SIZE, total); const base = `/cancer/${b.cancer.slug}/trials`; const href = (o: Record) => `${base}${withParams({ status, phase }, o)}`; const anyTrials = facets.statuses.reduce((s, x) => s + x.n, 0); if (anyTrials === 0) { return (
No ClinicalTrials.gov study has a condition mapped to this entity or its descendants yet. Conditions are free text at the source; they are reconciled to the taxonomy by identifier, curated alias, then normalized string — unmatched labels are queued for review, never dropped.
); } const chip = (isCurrent: boolean) => ({ className: 'ci-chip', 'aria-current': isCurrent ? ('page' as const) : undefined }); return (
{intel.primary ? : null}
{rows.length ? ( <> Showing {fmtInt(info.from)}–{fmtInt(info.to)} of {fmtInt(total)} studies{status || phase ? ' matching the filters' : ''} } /> href({ page: p === 1 ? '' : p })} label="Trial pages" noun="studies" /> ((m, t) => (m == null || String(t.updated_at) > String(m) ? t.updated_at : m), null)} sourceUpdatedAt={rows[0]?.last_update_posted_date ?? null} extra="source: clinicaltrials" /> ) : ( )}
); }