Base Path
Authentication
All endpoints require theicsr:read permission via the require_permission dependency.
MedDRA Hierarchy Levels
MedDRA organizes adverse events in a 5-level hierarchy:| Level | Code | Description | Example |
|---|---|---|---|
| SOC | System Organ Class | Highest level categorization | ”Trastornos cardíacos” |
| HLGT | High Level Group Term | Organ/physiology grouping | ”Arritmias cardiacas” |
| HLT | High Level Term | Medical condition grouping | ”Taquiarritmias” |
| PT | Preferred Term | Standard medical terminology | ”Taquicardia” |
| LLT | Lowest Level Term | Clinical/laymen terms | ”Palpitaciones”, “Latidos rápidos” |
Endpoints
AI-Powered Adverse Event Extraction
POST /meddra/extract_ai
Extract adverse events from clinical narratives using OpenAI GPT models.
- Extract only terms explicitly or near-literally mentioned in the text
- Avoid inventing diagnoses or adding qualifiers not present in the narrative
- Return short, literal terms (1-4 words)
- Deduplicate similar events (e.g., “picar” and “picazón” → return only one)
narrative(required): Clinical narrative textproduct(optional): Suspected product namelang(optional, default: “es”): Language code
200 OK
- Model: Controlled by
OPENAI_MEDDRA_MODELenv var (default:gpt-4o-mini) - Requires:
OPENAI_API_KEYenvironment variable
- Normalizes text (removes accents, lowercases, collapses whitespace)
- Checks if term exists as substring or word boundary match
- Rejects AI hallucinations that don’t appear in source text
- Compresses verbose phrases to shortest literal form (“picar todo el cuerpo” → “picar”)
Get MedDRA Options for Terms
POST /meddra/options
For each extracted term, generate AI synonyms and search MedDRA database to provide coding options.
- Generates clinical synonyms using AI (e.g., “picar” → [“picar”, “picazón”, “prurito”, “picor”])
- Searches MedDRA database with each synonym
- Ranks and deduplicates results
- Returns top coding options for each term
terms(required): Array of adverse event terms to codenarrative(optional): Original narrative for contextlimit(optional, default: 15): Max options per termscope(optional, default: “all”): MedDRA level scope (all,llt,pt,hlt,hlgt,soc)version_id(optional): Specific MedDRA version to search
200 OK
- First Fallback: Search using the first word of the term
- Second Fallback: Return a manual entry option:
Direct MedDRA Search (Manual)
GET /meddra/suggest
Direct search endpoint for manual MedDRA term lookup.
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
q | string | Yes | - | Search query |
limit | integer | No | 15 | Max results (1-100) |
scope | string | No | ”all” | Level scope (all, llt, pt, hlt, hlgt, soc) |
version_id | integer | No | null | MedDRA version ID |
200 OK
Search Algorithm
The MedDRA search implements intelligent ranking and filtering:1. Database Query
- Uses PostgreSQL
ILIKEwithunaccentextension for accent-insensitive search - Searches across term names at the specified hierarchy level(s)
2. Anti-Substring Filtering
Prevents false positives from substring matches (e.g., “picar” matching “epiCARdio”):- Exact Match: Normalized query equals normalized term
- Whole Word Match: Query appears as complete word (word boundary check)
- Prefix Match: For queries ≥4 chars, allows token prefix match (“pruri” → “prurito”)
- Rejected: Substring within another word (“picar” within “epicardio”)
3. Ranking
Results are ranked by match quality:| Rank | Type | Example |
|---|---|---|
| 0 | Exact match | ”prurito” = “Prurito” |
| 1 | Whole word present | ”prurito” in “Prurito generalizado” |
| 2 | Prefix match (≥4 chars) | “pruri” → “Prurito” |
| 3 | Substring fallback | ”pru” in “Prurito” |
AI Synonym Expansion
When using/meddra/options, the API generates clinical synonyms to improve search coverage:
Synonym Rules:
- Maximum 6 variants per term
- Same semantic meaning (no new events)
- Verb-to-noun transformations allowed (“picar” → “picazón”, “prurito”)
- No invented diagnoses
- No added qualifiers (no “generalizado” unless in base term)
- Short variants (1-4 words)
- “picar” → [“picar”, “picazón”, “prurito”, “picor”]
- “vómito” → [“vómito”, “vómitos”, “emesis”]
- “dolor de cabeza” → [“dolor de cabeza”, “cefalea”, “cefalalgia”]
Environment Variables
| Variable | Required | Default | Description |
|---|---|---|---|
OPENAI_API_KEY | Yes | - | OpenAI API key for GPT models |
OPENAI_MEDDRA_MODEL | No | gpt-4o-mini | GPT model for MedDRA operations |
Error Handling
500 Internal Server Error - MissingOPENAI_API_KEY: