papertrail/lib/bio/ddi.schemas.ts
caelum0x 174222bcaa feat: Builder-Track named-user tools, bio + evidence-intelligence platform, Apache-2.0
Builds PaperTrail from the base skeleton into a full evidence-verification platform
for the "Built with Claude: Life Sciences" hackathon (Builder Track).

New named-user features (Build Beyond the Bench):
- Lab Notebook Companion — rough bench notes -> structured, searchable, grounded
  experiment records (lib/labNotebook, /console/lab-notebook, migration 0059)
- Clinical Trial Matcher — de-identified patient notes -> ranked eligible
  ClinicalTrials.gov trials with per-criterion inclusion/exclusion reasoning
  (lib/trialMatcher, /console/trial-matcher, migrations 0060)

Platform:
- Deterministic verification moat (biostats recompute, exact-span grounding)
- 11 biomedical evidence engines (FAERS, GWAS, Open Targets, ChEMBL, ClinVar,
  PharmGKB, PubTator, DDI, repurposing, biomarker, unified verifier)
- Evidence Intelligence (KG, dossier, provenance/export, RWE) + enterprise
  governance (RBAC, /api/v1 gateway, metering, audit chain, retention)
- 17 OSS projects assimilated into native TypeScript on our stack (backend/engines
  retained + credited in NOTICE)
- Multi-format upload (PDF/DOCX/XLSX/CSV/MD/TXT), logo, marketing site
- Next.js 16 upgrade, benchmark harness (honest smoke-test caveat)

Licensing: Apache-2.0 (LICENSE + NOTICE).
2026-07-10 16:23:13 +03:00

77 lines
3.3 KiB
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { z } from "zod";
// Zod schemas for the open DRUG–DRUG-INTERACTION (DDI) signal layer.
//
// This layer derives an interaction signal purely from FAERS (openFDA, CC0)
// spontaneous-report counts. It deliberately AVOIDS DrugBank / DDInter and any
// other paid or non-commercial interaction knowledge base — everything here is
// computed from open report counts with the same disproportionality math the
// pharmacovigilance layer uses. NO LLM is anywhere in the numeric path.
//
// Two roles for these schemas:
// 1. Validate the public POST body for /api/bio/drug-interaction.
// 2. Describe (and bound-check) the shape of the deterministic result the
// engine returns, so a malformed value can never masquerade as a signal.
// A single disproportionality block (PRR / ROR / chi² / IC) for one 2x2 table.
// These are the exact fields lib/bio/pharmacovigilance.ts computes; we re-declare
// the shape here (rather than import a value) so the schema stays self-contained
// and the numbers can be bound-checked at the trust boundary.
export const DisproportionalitySchema = z.object({
a: z.number(),
b: z.number(),
c: z.number(),
d: z.number(),
n: z.number(),
prr: z.number(),
prrCiLower: z.number(),
prrCiUpper: z.number(),
ror: z.number(),
rorCiLower: z.number(),
rorCiUpper: z.number(),
chiSquared: z.number(),
chiSquaredYates: z.number(),
pValue: z.number(),
informationComponent: z.number(),
ic025: z.number(),
signal: z.boolean(),
});
export type DisproportionalityBlock = z.infer<typeof DisproportionalitySchema>;
// The interaction verdict. DETERMINISTIC, from documented thresholds only:
// synergistic_signal — the co-reported (BOTH drugs) signal is materially higher
// than EITHER drug alone (possible interaction / synergy).
// no_excess — a valid combined signal exists but it does NOT exceed the
// single-drug signals materially (the co-report is explained
// by each drug's own event profile, not their combination).
// insufficient_data — too few co-reports to compute a trustworthy contrast.
export const InteractionVerdictSchema = z.enum([
"synergistic_signal",
"no_excess",
"insufficient_data",
]);
export type InteractionVerdict = z.infer<typeof InteractionVerdictSchema>;
// The full DDI signal result. `combined` is the disproportionality of the event
// among reports listing BOTH drugs; `aAlone` / `bAlone` are the single-drug
// signals used for the interaction contrast. Any block can be null when its 2x2
// couldn't be assembled — an HONEST empty, never a fabricated table.
export const InteractionSignalSchema = z.object({
drugA: z.string(),
drugB: z.string(),
event: z.string(),
combined: DisproportionalitySchema.nullable(),
aAlone: DisproportionalitySchema.nullable(),
bAlone: DisproportionalitySchema.nullable(),
interaction: InteractionVerdictSchema,
});
export type InteractionSignalResult = z.infer<typeof InteractionSignalSchema>;
// The public POST body for /api/bio/drug-interaction.
export const InteractionRequestSchema = z.object({
drugA: z.string().trim().min(1, "drugA is required").max(200),
drugB: z.string().trim().min(1, "drugB is required").max(200),
event: z.string().trim().min(1, "event is required").max(200),
});
export type InteractionRequest = z.infer<typeof InteractionRequestSchema>;