AI-Powered Clinical Trial Patient Matching with Amazon Bedrock (Mistral Large 2)
Live Demo β’ Frontend Repo β’ AWS Hackathon
- Overview
- Architecture
- Key Features
- Technology Stack
- FHIR Resource Support
- Quick Start
- Project Structure
- Testing
- API Endpoints
- Demo Video
- Live Deployment
- AWS Hackathon Compliance
- Impact & Value
- Compliance & Security
- Roadmap
- Use Cases
- Contributing
- License
- Documentation
- Acknowledgments
- Contact
Samyama's Clinical Trial Enrollment Agent is an autonomous AI agent that revolutionizes clinical trial enrollment by automating patient-trial matching. Built for the AWS AI Agent Global Hackathon 2025, this system reduces enrollment time from weeks to minutes using intelligent automation powered by Amazon Bedrock with Mistral Large 2.
85% of clinical trials fail due to slow patient enrollment. Traditional manual screening is:
- Time-consuming (weeks of coordinator effort)
- Error-prone (manual criteria interpretation)
- Expensive (millions in delayed drug development)
- Inconsistent (subjective eligibility decisions)
An intelligent AI agent that:
- π Parses clinical trial protocols using AWS Textract and Mistral Large 2
- π Analyzes patient health records from AWS HealthLake (FHIR R4)
- π§ Matches patients to trials with explainable AI reasoning
- π Generates confidence-scored eligibility reports
- User Personas Layer: CRC, StudyAdmin, PI with role-based access
- Frontend Layer: CloudFront CDN β S3 β React Application
- Authentication & API Layer: Cognito (3 user groups) β API Gateway β Lambda Authorizer
- AI Agent Layer: 10 Lambda functions orchestrating the AI pipeline
- AI Services Layer: Bedrock (Mistral Large 2), Textract, Comprehend Medical, HealthLake
- Data Persistence Layer: 3 DynamoDB tables, S3, CloudWatch
6-Phase Automated Protocol Processing:
- Document Upload - Secure upload to S3
- Text Extraction - AWS Textract OCR from PDF
- Medical Analysis - AWS Comprehend Medical entity extraction
- Criteria Classification - Organize inclusion/exclusion criteria
- Data Structuring - Amazon Bedrock (Mistral Large 2) parsing
- Finalization - Save to DynamoDB cache
AI-Powered Patient Matching with:
- Mistral Large 2 reasoning for complex medical criteria
- Confidence scores (0-100%) for each criterion
- Criterion-by-criterion explanations with evidence
- FHIR resource integration (11 resource types)
- Transparent decision-making with audit trails
- Patient screening and eligibility checking
- View match confidence scores
- Track success rates (78% in demo)
- Protocol upload and management
- Monitor processing pipeline
- Track protocol status distribution
- Enrollment oversight across trials
- Review pending matches
- Approve/reject enrollments
- Export professional reports
| Service | Purpose | Usage |
|---|---|---|
| Amazon Bedrock | LLM Reasoning | Mistral Large 2 (mistral.mistral-large-2402-v1:0) for criteria parsing and eligibility decisions |
| AWS Lambda | Serverless Compute | 10 functions for agent execution |
| AWS HealthLake | FHIR R4 Datastore | Patient health records (11 resource types) |
| AWS Textract | Document OCR | Extract text from protocol PDFs |
| Amazon Comprehend Medical | Medical NLP | Entity extraction and NER |
| Amazon DynamoDB | NoSQL Database | 3 tables: criteria cache, evaluation results, matches |
| Amazon Cognito | Authentication | User pools with 3 groups (CRC, StudyAdmin, PI) |
| Amazon API Gateway | REST API | API endpoints for frontend integration |
| Amazon S3 | Object Storage | Protocol documents and static website hosting |
| Amazon CloudFront | CDN | Global content delivery |
| Amazon CloudWatch | Observability | Logging, monitoring, tracing |
- Infrastructure as Code: AWS CDK (Python)
- Backend: Python 3.11+ with AWS Lambda Powertools
- Frontend: React + TypeScript + Tailwind CSS
- FHIR Compliance: FHIR R4 standard (11 resource types)
- Testing: pytest with 93% pass rate
Supports 11 FHIR R4 resource types for comprehensive patient data:
- Patient - Demographics, birthDate, gender
- Condition - Diagnoses, ICD-10 codes
- Observation - Lab values, vital signs
- MedicationStatement - Current medications
- AllergyIntolerance - Allergies and intolerances
- Procedure - Surgical history
- Immunization - Vaccination records
- DiagnosticReport - Lab reports
- Encounter - Healthcare visits
- CarePlan - Treatment plans
- FamilyMemberHistory - Family medical history
- AWS Account with:
- Amazon Bedrock access (Mistral Large 2 enabled in us-east-1)
- HealthLake permissions
- Lambda, API Gateway, and DynamoDB permissions
- Python 3.11+
- AWS CLI configured
- Node.js 18+ (for AWS CDK)
# 1. Clone the repository
git clone https://github.com/VaidhyaMegha/samyama-trial-enrollment-agent.git
cd samyama-trial-enrollment-agent
# 2. Create virtual environment
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# 3. Install dependencies
pip install -r requirements.txt
# 4. Configure AWS credentials
aws configure
# Set region to us-east-1 for Bedrock access
# 5. Deploy infrastructure
cd infrastructure
npm install -g aws-cdk
pip install -r requirements.txt
cdk deploy --require-approval never
# 6. Load synthetic patient data
cd ../scripts
python3 upload_to_healthlake.py- Go to AWS Console β Bedrock β Model access
- Enable Mistral Large 2 (
mistral.mistral-large-2402-v1:0) - Wait for approval (usually instant)
samyama-trial-enrollment-agent/
βββ docs/ # Documentation
β βββ PROTOCOL_PROCESSING_GUIDE.md # Protocol processing guide
β βββ screenshots/ # 15 demo screenshots
β βββ AWS Hackathon Idea _ v1.md # Original concept
βββ src/ # Source code
β βββ lambda/ # Lambda functions
β β βββ criteria_parser/ # Mistral Large 2 parsing (core AI)
β β βββ fhir_search/ # HealthLake FHIR queries
β β βββ textract_processor/ # PDF text extraction
β β βββ section_classifier/ # Comprehend Medical classification
β β βββ protocol_orchestrator/ # Pipeline orchestration
β β βββ protocol_manager/ # Protocol CRUD operations
β β βββ patient_manager/ # Patient data management
β β βββ match_manager/ # Patient-protocol matching
β β βββ admin_manager/ # System administration
β β βββ authorizer/ # JWT authentication
β βββ agent/ # Agent configuration
β βββ utils/ # Shared utilities
βββ infrastructure/ # AWS CDK Infrastructure
β βββ app.py # CDK stack definition
βββ scripts/ # Utility scripts
β βββ process_protocol_pdf.py # End-to-end protocol processor
β βββ load_synthea_data.py # Generate synthetic FHIR data
β βββ upload_to_healthlake.py # Upload patients to HealthLake
β βββ end_to_end_demo.py # Complete workflow demo
βββ tests/ # Test suites (pytest)
β βββ test_criteria_parser.py # Criteria parser tests
β βββ test_fhir_search.py # FHIR search tests
βββ protocol-docs/ # Sample protocol PDFs
βββ requirements.txt # Python dependencies
βββ README.md # This file
# Set environment variables
export POWERTOOLS_TRACE_DISABLED=1
export AWS_XRAY_CONTEXT_MISSING=LOG_ERROR
# Run all tests
pytest tests/ -v --tb=short
# Run with coverage
pytest tests/ --cov=src --cov-report=html
# Run end-to-end demo
python scripts/end_to_end_demo.pyTest Results: 14/15 tests passing (93% pass rate)
Parse eligibility criteria using Mistral Large 2.
Request:
{
"criteria_text": "Patients must be between 18 and 65 years old",
"trial_id": "trial-001"
}Response:
{
"criteria": [{
"type": "inclusion",
"category": "demographics",
"description": "Age between 18 and 65 years",
"attribute": "age",
"operator": "between",
"value": [18, 65],
"unit": "years",
"fhir_resource": "Patient",
"fhir_path": "Patient.birthDate"
}],
"trial_id": "trial-001"
}Check patient eligibility with AI reasoning.
Request:
{
"patient_id": "patient-001",
"criteria": [...]
}Response:
{
"patient_id": "patient-001",
"eligible": true,
"confidence": 92,
"results": [{
"met": true,
"confidence": 95,
"reason": "Patient age is 46 years (within range 18-65)",
"evidence": {
"birthDate": "1979-05-15",
"calculated_age": 46
}
}]
}Watch our 3-minute demo showcasing the complete workflow:
Video Highlights:
- All three user personas (CRC, StudyAdmin, PI)
- Protocol upload and AI processing pipeline
- Patient eligibility checking with Mistral Large 2 reasoning
- Real-time match results with confidence scores
- Complete end-to-end workflow demonstration
Production URL: https://enrollment.samyama.care
Deployed Infrastructure (us-east-1):
- API Gateway:
https://gt7dlyqj78.execute-api.us-east-1.amazonaws.com/prod/ - CloudFront Distribution:
https://d25df0kqd06e10.cloudfront.net - HealthLake Datastore:
8640ed6b344b85e4729ac42df1c7d00e
β οΈ Demo Environment NoticeThis is a demonstration deployment for the AWS AI Agent Hackathon 2025:
- All patient data is synthetic (generated via Synthea - no real PHI)
- Demo accounts are isolated with no production data access
- Test credentials are for demonstration purposes only
- For hackathon evaluation and testing only
To run your own instance, follow the Quick Start guide or contact project maintainers for setup assistance.
- Amazon Bedrock: Mistral Large 2 (
mistral.mistral-large-2402-v1:0) for AI reasoning - AWS Lambda: 10 serverless functions for agent execution
- Multiple AWS Services: DynamoDB, HealthLake, Textract, Comprehend Medical, Cognito, API Gateway, S3, CloudFront
a) Reasoning Capabilities:
- Analyzes complex medical eligibility criteria
- Makes intelligent decisions with confidence scores
- Provides explainable AI reasoning
- Handles edge cases and ambiguous criteria
b) Autonomous Execution:
- Automatically processes protocol PDF uploads via S3 triggers
- Self-initiates eligibility evaluations through orchestration
- Manages state across multi-step workflows
- Error handling and recovery without human intervention
c) External Integration:
- AWS HealthLake FHIR API (11 resource types)
- Amazon Bedrock API (Mistral Large 2)
- AWS Textract API (document processing)
- Amazon Comprehend Medical API (medical NER)
- DynamoDB for state management
- β±οΈ Time Savings: Reduces enrollment screening from weeks to minutes
- π° Cost Reduction: Saves millions in trial delays
- π― Improved Accuracy: AI-powered consistent eligibility decisions
- π Better Insights: Confidence scores and explainable reasoning
- π HIPAA-Eligible: All AWS services are HIPAA-eligible
- π Scalable: Serverless architecture for global deployment
- 247 patients screened (demo data)
- 78% success rate
- 92% average confidence score for matches
- <90 seconds to process 26-page protocol
- 11 FHIR resource types supported
- HIPAA-Eligible Services: AWS HealthLake with encryption
- No Real PHI: All testing uses Synthea-generated synthetic data
- Audit Logging: Complete trail via CloudWatch
- IAM Least Privilege: Minimal permissions for Lambda roles
- Encryption: DynamoDB and HealthLake encryption enabled
- Human Review Required: System assists; final decisions by clinicians
- Core AI agent with Mistral Large 2
- FHIR R4 integration with HealthLake
- Multi-persona frontend (CRC, StudyAdmin, PI)
- Production deployment with custom domain
- Batch patient screening
- Advanced lab value criteria (complex ranges)
- Multi-site enrollment coordination
- Real-time HealthLake event triggers
- IRB submission automation
- Clinical Research Sites: Screen patients for active trials
- Pharmaceutical Companies: Accelerate Phase II/III enrollment
- Academic Medical Centers: Match patients across trial portfolios
- Contract Research Organizations: Multi-site enrollment management
- Patient Recruitment Services: Targeted outreach campaigns
This project was built for the AWS AI Agent Global Hackathon 2025. Contributions are welcome!
- Fork the repository
- Create a feature branch (
git checkout -b feature/AmazingFeature) - Commit changes (
git commit -m 'Add AmazingFeature') - Push to branch (
git push origin feature/AmazingFeature) - Open a Pull Request
MIT License - See LICENSE file for details.
For commercial use or questions about licensing, please contact the project maintainers.
- AWS AI Agent Global Hackathon 2025 for the opportunity
- Amazon Bedrock team for Mistral Large 2 integration
- AWS HealthLake team for FHIR R4 support
- Synthea for synthetic patient data generation
- Samyama.ai for project sponsorship
Organization: Samyama.ai
GitHub:
- Backend: samyama-trial-enrollment-agent
- Frontend: samyama-trial-enrollment-app
Live Demo: enrollment.samyama.care
Built with β€οΈ for AWS AI Agent Global Hackathon 2025





