Protocol Compiler

Role: Solo Developer Timeline: Ongoing (2025–Present) Platform: Web

A production-grade system that decompiles clinical trial protocol PDFs into the structured data needed to build E-Source systems, CDISC-compliant study configurations, eSource forms, and annotated CRF exports. It combines AI-driven extraction with deterministic validation, rule-based mapping, and human-review gating.

The Problem

Building an electronic data-capture system for a clinical study starts with a protocol PDF — often hundreds of pages containing visits, procedures, eligibility criteria, and complex edit checks. Manually translating that document into study-build artifacts is slow, error-prone, and inconsistent:

Solution Overview

PDF Ingestion & Parsing

  • Magic-bytes validation rejects non-PDFs, corrupted files, and password-protected uploads
  • PyMuPDF + pdfplumber extract plain text, tables, and visit-schedule matrices
  • Page classification (text / image / mixed) with optional OCR fallback for scanned protocols
  • Raw text and tables persisted for transparent debugging and provenance

AI-Driven Extraction

  • Multi-pass focused prompting: visits, forms, item groups, fields, code lists, edit checks
  • Provider-agnostic LLM backend: OpenAI, Groq, Gemini, Ollama, or mock for testing
  • Per-entity confidence scores with source grounding (span, chunk, page reference)
  • Centralized rate limiting, daily quotas, retries, and provider failover
  • Deterministic response cache for quota-free reruns

Generalized Constraint Extraction

  • Deterministic scan for numeric ranges, thresholds, and temporal windows
  • Allowed categorical values and sample/storage/dosing constraints
  • Constraints linked to matching entities; unmatched ones surfaced for review
  • Not hardcoded to vital signs or labs — works across any item or section

Reference Enrichment & Mapping

  • Static CDISC/CDASH library for canonical domains and SAS field names
  • Dynamic Annotated CRF library learned from uploaded reference PDFs
  • Versioned LearnedTemplates with provenance tracking and rollback
  • Priority resolution when static templates, CRFs, and LLM output conflict

Validation, Review & Export

  • Rule-based validation engine with ERROR / WARNING / INFO findings
  • Export gated by validation status, unresolved review, and confidence thresholds
  • Multi-format export: JSON, CSV, Excel, ODM XML, Annotated CRF HTML
  • Immutable study revisions with snapshot creation, comparison, and revert

Collaboration & Access Control

  • Study-level collaborator roles: viewer, reviewer, editor, admin, owner
  • Centralized permission enforcement via reusable access-control helpers
  • 404-not-403 pattern prevents leaking existence of unshared studies
  • Full audit trail of uploads, extractions, reviews, and exports

Architecture

The backend is an async FastAPI application with SQLAlchemy 2.0 + Alembic on PostgreSQL, orchestrated by Celery for long-running extraction jobs. The React + TypeScript frontend uses Vite, TailwindCSS, and Zustand, with shared UI primitives across every view.

Tech Stack

Python 3.12 FastAPI SQLAlchemy 2.0 Alembic PostgreSQL Celery Redis React 18 TypeScript 5.4 Vite 5.3 TailwindCSS 3.4 Zustand OpenAI / Groq / Gemini / Ollama PyMuPDF pdfplumber

Screenshots

Challenges & Solutions

Outcomes & Impact

Lessons Learned

Future Improvements