Clinical Trial Emulator
Emulate published clinical trials against real-world EHR data using a structured pipeline — from protocol parsing through cohort assembly, effect estimation, and discrepancy diagnosis.
Target trial emulation takes months of manual work — parsing protocols, mapping concepts to your EHR schema, assembling cohorts, and running survival models. One study takes a research team weeks; you have a dozen to validate.
Who it's for: clinical researchers doing real-world evidence studies, epidemiologists validating trial findings, pharmacoepi teams at pharma companies, health data scientists working with OMOP databases, academic medical centers scaling trial emulation
Example
"Emulate the ROCKET-AF anticoagulation trial against our OMOP database" → Protocol parsed, concepts mapped to your EHR codes, cohort assembled with propensity-score adjustment, survival analysis run, and results compared to the published trial with discrepancy diagnosis
CLAUDE.md Template
New here? 3-minute setup guide → | Already set up? Copy the template below.
npx ccplaybooks add clinical-trial-emulator# Clinical Trial Emulator
## Role
You help me emulate published randomized clinical trials against real-world electronic health record (EHR) data. You follow a structured pipeline from protocol interpretation through effect estimation, running each phase methodically and documenting decisions at every step.
## Directory Structure
- `protocols/` — Source trial protocols (PDFs, text summaries, extracted criteria)
- `concept-sets/` — OMOP concept set definitions (JSON or CSV mappings)
- `cohorts/` — Assembled cohort files with inclusion/exclusion logs
- `analysis/` — Scripts, model outputs, propensity scores, survival curves
- `literature/` — Comparison priors and literature synthesis
- `reports/` — Final emulation reports with diagnosticsGet new playbooks like this one
One email a week with new Claude Code workflows. Free, like everything here.
No spam. Unsubscribe anytime.
What This Does
Turns the labor-intensive process of target trial emulation into a repeatable, multi-phase pipeline. You feed in a published trial protocol and point Claude at your EHR database, and it walks through protocol parsing, concept mapping, cohort assembly, propensity-score adjustment, survival modeling, and result comparison — flagging quality issues and refining along the way.
Inspired by work at Mount Sinai using autonomous agents to scale trial emulation across multiple anticoagulation studies against OMOP-mapped EHR data.
Prerequisites
- Claude Code installed
- Access to an EHR database (ideally OMOP CDM-mapped)
- Published trial protocol(s) to emulate (PDF or structured text)
- Python environment with
pandas,lifelines,scikit-learn, and a database connector (e.g.,sqlalchemy,pyodbc) - Basic familiarity with observational study design
Step-by-Step Setup
Step 1: Create the project structure
mkdir -p ~/trial-emulation/{protocols,concept-sets,cohorts,analysis,literature,reports,logs}
cd ~/trial-emulation
Step 2: Add your trial protocol
Place the published trial protocol PDF or extracted text into protocols/. For example, a summary of the ARISTOTLE trial comparing apixaban to warfarin for atrial fibrillation.
Step 3: Configure database access
Create a config.env file (add to .gitignore) with your EHR database connection:
DB_HOST=your-ehr-host
DB_NAME=your-omop-database
DB_SCHEMA=cdm
Step 4: Save CLAUDE.md and start
cd ~/trial-emulation
claude
Try: "/parse protocols/aristotle-protocol.pdf" to start Phase 1.
Example Usage
Parse a trial protocol:
"/parse protocols/aristotle-protocol.pdf — Extract eligibility criteria, treatment definitions, and primary endpoint for the ARISTOTLE trial"
Build concept sets:
"/concepts aristotle — Map apixaban, warfarin, atrial fibrillation, stroke, and major bleeding to OMOP codes"
Assemble cohorts:
"/cohort aristotle — Build treatment and control cohorts. Apply all eligibility criteria and log the exclusion flow"
Estimate treatment effect:
"/estimate aristotle — Fit propensity score model, check balance, and estimate the HR for stroke/systemic embolism"
Compare with published results:
"/diagnose aristotle — The published HR was 0.79 (95% CI 0.66–0.95). Compare our emulated result and diagnose any discrepancies"
Run multiple times for robustness:
"/multi-run aristotle — Execute the full pipeline 3 times with independent analytic decisions and report the range of estimates"
Tips
- Start with a well-known trial: Pick a landmark trial with clear eligibility criteria and a simple primary endpoint. Anticoagulation trials for atrial fibrillation are a good starting point because the drug definitions and outcomes are relatively clean in EHR data.
- OMOP mapping is the hardest part: Concept set construction (Phase 2) typically requires the most iteration. Expect to refine your mappings after seeing cohort sizes.
- Check the exclusion flow: If your cohort is dramatically smaller or larger than the original trial, your eligibility criteria are probably too strict or too loose. The consort flow diagram helps diagnose this.
- Covariate balance matters more than sample size: A well-balanced cohort of 2,000 patients is more trustworthy than a poorly balanced cohort of 20,000.
- The multi-run strategy is powerful: Running the same emulation 3 times with independent decisions reveals how much of the result depends on analytic choices vs. the actual data.
- Document everything: The decision log is your most valuable artifact. It lets you (and others) understand exactly why results came out the way they did.
Troubleshooting
Problem: Concept set returns zero patients
Solution: Your OMOP codes may be too specific. Try including descendant concepts, or check whether your institution uses a different vocabulary version. Run a frequency check on the concept codes before building cohorts.
Problem: Severe covariate imbalance after propensity score adjustment
Solution: Check for positivity violations — if some covariate combinations only exist in one treatment arm, no adjustment method will fix it. Consider trimming the propensity score distribution (e.g., exclude patients with PS < 0.05 or > 0.95) or relaxing eligibility criteria.
Problem: Emulated result points in the opposite direction from the published trial
Solution: This is where Phase 6 earns its keep. Common causes: immortal time bias (check index date definition), informative censoring (check loss-to-follow-up patterns), or eligibility criteria that selected a fundamentally different population. Run /diagnose to systematically check each.
Problem: Too few outcome events for reliable estimation
Solution: Consider using a composite endpoint (e.g., stroke + systemic embolism + death) or extending the follow-up window. If the event rate is below 2–3% in either arm, the confidence intervals will be too wide to be informative.