import { pgTable, text, integer, bigserial, index, uniqueIndex, boolean, jsonb } from 'drizzle-orm/pg-core'; import { ciId, createdAt, updatedAt } from './_common.js'; /** Drugs (CLAUDE.md §7, §344): brand names are aliases, never separate molecules. */ export const drugs = pgTable( 'drugs', { id: ciId().primaryKey(), // CI-DRUG-… slug: text('slug').notNull(), name: text('name').notNull(), // generic / INN preferred kind: text('kind'), // small_molecule | monoclonal_antibody | adc | bispecific | car_t | cell_therapy | gene_therapy | vaccine | radiopharmaceutical | chemotherapy | hormonal | immunotherapy | targeted | other ncitCode: text('ncit_code'), chemblId: text('chembl_id'), civicTherapyId: integer('civic_therapy_id'), drugbankId: text('drugbank_id'), pubchemCid: text('pubchem_cid'), unii: text('unii'), mechanism: text('mechanism'), targetGeneIds: text('target_gene_ids').array().notNull().default([]), developmentStatus: text('development_status'), description: text('description'), createdAt: createdAt(), updatedAt: updatedAt(), }, (t) => [uniqueIndex('drugs_slug_uq').on(t.slug), index('drugs_ncit_idx').on(t.ncitCode), index('drugs_civic_idx').on(t.civicTherapyId), index('drugs_chembl_idx').on(t.chemblId)], ); export const drugAliases = pgTable( 'drug_aliases', { id: bigserial('id', { mode: 'number' }).primaryKey(), drugId: ciId('drug_id').notNull(), alias: text('alias').notNull(), normalized: text('normalized').notNull(), aliasType: text('alias_type').notNull().default('synonym'), // generic | brand | development_code | salt | synonym sourceId: ciId('source_id'), }, (t) => [uniqueIndex('drug_aliases_uq').on(t.drugId, t.normalized, t.aliasType), index('drug_aliases_norm_idx').on(t.normalized)], ); /** Regimens / combinations (CLAUDE.md §53). */ export const treatmentRegimens = pgTable( 'treatment_regimens', { id: ciId().primaryKey(), // CI-TRT-… slug: text('slug').notNull(), name: text('name').notNull(), componentDrugIds: text('component_drug_ids').array().notNull().default([]), modality: text('modality').notNull().default('drug_combination'), // drug | drug_combination | surgery | radiotherapy | transplantation | cell_therapy | surveillance description: text('description'), createdAt: createdAt(), }, (t) => [uniqueIndex('treatment_regimens_slug_uq').on(t.slug)], ); /** Country-aware regulatory status (CLAUDE.md §13). Never a bare approved=true. */ export const drugApprovals = pgTable( 'drug_approvals', { id: bigserial('id', { mode: 'number' }).primaryKey(), drugId: ciId('drug_id').notNull(), cancerId: ciId('cancer_id'), biomarkerIds: text('biomarker_ids').array().notNull().default([]), tumorAgnostic: boolean('tumor_agnostic').notNull().default(false), jurisdiction: text('jurisdiction').notNull(), // US | CA | EU | UK | AU | JP | CH | OTHER authority: text('authority').notNull(), // FDA | Health Canada | EMA | MHRA | TGA | PMDA | Swissmedic indication: text('indication').notNull(), lineOfTherapy: text('line_of_therapy'), diseaseStage: text('disease_stage'), approvalType: text('approval_type'), accelerated: boolean('accelerated'), conditional: boolean('conditional'), approvalDate: text('approval_date'), withdrawalDate: text('withdrawal_date'), status: text('status').notNull(), // approved | conditional | accelerated | withdrawn | superseded applicationNumber: text('application_number'), sourceId: ciId('source_id').notNull(), provenanceId: integer('provenance_id').notNull(), raw: jsonb('raw'), createdAt: createdAt(), updatedAt: updatedAt(), }, (t) => [index('drug_approvals_drug_idx').on(t.drugId), index('drug_approvals_cancer_idx').on(t.cancerId)], );