import type { Metadata } from 'next'; import Link from 'next/link'; import { TOP_LEVEL_CANCERS } from '@cancerindex/ontology'; import { PageHeader, Section } from '@/components/ui/section'; import { EmptyState } from '@/components/ui/empty-state'; import { Badge } from '@/components/ui/badge'; import { Tree } from '@/components/data/tree'; import { hierarchyTypes, rootsOf, orphanCount, anatomicalView } from '@/lib/queries/taxonomy'; import { resolveTopLevel } from '@/lib/queries/cancers'; import { fmtInt, humanize } from '@/lib/format'; import { str, type SP } from '@/lib/search-params'; export const metadata: Metadata = { title: 'Taxonomy', description: 'Browse the cancer taxonomy by NCIt hierarchy, OncoTree hierarchy or anatomical site.' }; export const revalidate = 3600; export default async function TaxonomyPage({ searchParams }: { searchParams: Promise }) { const sp = await searchParams; const types = await hierarchyTypes(); const available = types.map((t) => t.hierarchy_type); const requested = str(sp, 'view', ''); const view = requested === 'anatomy' ? 'anatomy' : available.includes(requested) ? requested : available.includes('ncit') ? 'ncit' : (available[0] ?? 'ncit'); const topLevel = await resolveTopLevel(TOP_LEVEL_CANCERS.map((t) => t.ncit)); const [roots, orphans, sites] = await Promise.all([view === 'anatomy' ? Promise.resolve([]) : rootsOf(view), view === 'anatomy' ? Promise.resolve(0) : orphanCount(view), view === 'anatomy' ? anatomicalView() : Promise.resolve([])]); const views = [...available.map((t) => ({ key: t, label: t === 'ncit' ? 'NCIt hierarchy' : t === 'oncotree' ? 'OncoTree hierarchy' : `${humanize(t)} hierarchy`, n: types.find((x) => x.hierarchy_type === t)?.n ?? 0 })), { key: 'anatomy', label: 'Anatomical view', n: null as number | null }]; if (!available.includes('ncit')) views.unshift({ key: 'ncit', label: 'NCIt hierarchy', n: 0 }); return (
{view === 'anatomy' ? ( sites.length ? (
{sites.map((s) => (
{s.cancers.length ? (
    {s.cancers.map((c) => (
  • {c.canonical_name} {c.relation !== 'primary' ? {c.relation} : null}
  • ))}
) : ( No entity linked to this site yet. )}
))}
) : ( Anatomical sites are populated by the terminology connectors (OncoTree tissues, NCIt anatomy). ) ) : roots.length ? ( <>

{fmtInt(roots.length)} root {roots.length === 1 ? 'node' : 'nodes'} {orphans > 0 ? ( <> {' '} · {fmtInt(orphans)} entities have no edge in this hierarchy and are listed in the{' '} explorer ) : null}

) : ( v.key !== view && (v.n == null || v.n > 0)).map((v) => ({ label: v.label, href: `/taxonomy?view=${v.key}` }))}> {view === 'ncit' ? 'The NCIt connector has not run on this environment yet. NCIt is the primary disease hierarchy; OncoTree edges are available meanwhile.' : 'No edges of this type have been ingested.'} )}
); }