spb/cancerindex
Public
TypeScript 97.2%
SQL 1.5%
CSS 0.6%
JavaScript 0.5%
1import 'server-only';2import { cache } from 'react';3import { getCancerBySlug, getCounters, getCodes, getAliases, getParents, getChildren, getBreadcrumbPath, getDescendantIds, getAnatomy, getCancerById, type CancerCore } from '@/lib/queries/cancers';45/** Everything the header and every tab need, loaded once per request (React cache). */6export const loadCancer = cache(async (slug: string) => {7 let cancer = await getCancerBySlug(slug);8 let redirectedFrom: CancerCore | null = null;9 if (cancer && cancer.status === 'merged' && cancer.merged_into) {10 const target = await getCancerById(cancer.merged_into);11 if (target) {12 redirectedFrom = cancer;13 cancer = target;14 }15 }16 if (!cancer) return null;17 const [counters, codes, aliases, parents, children, path, descendants, anatomy] = await Promise.all([18 getCounters(cancer.id),19 getCodes(cancer.id),20 getAliases(cancer.id),21 getParents(cancer.id),22 getChildren(cancer.id),23 getBreadcrumbPath(cancer.id),24 getDescendantIds(cancer.id),25 getAnatomy(cancer.id),26 ]);27 return { cancer, redirectedFrom, counters, codes, aliases, parents, children, path, descendants, anatomy };28});2930export type CancerBundle = NonNullable<Awaited<ReturnType<typeof loadCancer>>>;3132export const TABS = [33 { key: 'overview', label: 'Overview' },34 { key: 'statistics', label: 'Statistics' },35 { key: 'survival', label: 'Survival' },36 { key: 'genomics', label: 'Genomics' },37 { key: 'evidence', label: 'Variants & evidence' },38 { key: 'drugs', label: 'Drugs' },39 { key: 'trials', label: 'Trials' },40 { key: 'research', label: 'Research' },41 { key: 'rankings', label: 'Rankings' },42 { key: 'sources', label: 'Sources & provenance' },43] as const;44export type TabKey = (typeof TABS)[number]['key'];45