Create an application to fetch patient charts for encounters with >1 unsigned notes from Comprehensive Medical Clinic's Azalea Health EHR, process them with AWS Bedrock AI, and update the EHR with recommendations for provider review.
- Organization: Comprehensive Medical Clinic LLC (ID: 142219)
- API: Azalea Health FHIR R4 API
- Auth: OAuth 2.0 Client Credentials
- Base URL (Sandbox): https://app.azaleahealth.com/fhir/R4/sandbox
- Base URL (Production): https://app.azaleahealth.com/fhir/R4/142219
- Environment: Currently set to SANDBOX for safe testing
- ✅ OAuth 2.0 client credentials implementation
- ✅ Environment switching (sandbox/production)
- ✅ Token management with system/. scope
- ✅ Comprehensive error handling
- ✅ Fetch recent encounters (status=in-progress or finished)
- ✅ Check for Encounter Signature Extension
- ✅ Get DocumentReferences for each encounter
- ✅ Filter encounters with >1 unsigned/preliminary documents
- ✅ Pagination support for large datasets
- ✅ Detailed logging of discovery process
For each qualifying encounter, collect:
- ✅ Patient demographics
- ✅ Encounter details
- ✅ Clinical notes (all types)
- ✅ Diagnoses (Conditions)
- ✅ Allergies
- ✅ Medications
- ✅ Vital signs
- ✅ Problem list
- ✅ AWS Bedrock integration for AI processing
- ✅ Clinical context building for accurate AI recommendations
- ✅ SQL Server database for tracking processed notes
- ✅ Structured prompt engineering for medical documentation
- ✅ Error handling and fallback mechanisms
- ✅ Update DocumentReference with AI recommendations
- ✅ Comparison format for provider review
- ✅ Preserve original content with AI suggestions
- ✅ Clear labeling of AI-generated content
-
DatabaseManager Class
- SQL Server connection management
- Table initialization
- CRUD operations for processed notes
- Error handling and logging
-
BedrockAIProcessor Class
- AWS Bedrock client initialization
- Clinical context extraction
- Prompt engineering for medical notes
- Response parsing and formatting
-
Document Update System
- FHIR DocumentReference updates
- Base64 encoding for content
- Comparison format generation
- PUT operation implementation
-
Comprehensive Logging
- File and console output
- Multiple log levels (INFO, ERROR, DEBUG)
- Detailed operation tracking
- Audit trail for compliance
/Encounter- Find encounters/DocumentReference- Get clinical notes and update them/Patient- Demographics/Condition- Diagnoses & problems/AllergyIntolerance- Allergies/MedicationRequest- Medications/Observation- Vital signs
- Encounters:
?status=in-progress,finished&date=ge[date]&_sort=-date - Documents:
?encounter=[id]&category=clinical-note - Conditions:
?patient=[id]&category=encounter-diagnosis,problem-list-item - Observations:
?patient=[id]&category=vital-signs
# SQL Server (optional)
SQL_CONNECTION_STRING=<your-connection-string>
# AWS Bedrock
AWS_ACCESS_KEY_ID=<your-key>
AWS_SECRET_ACCESS_KEY=<your-secret>
AWS_DEFAULT_REGION=us-east-1
# Optional
BEDROCK_MODEL_ID=anthropic.claude-v2CREATE TABLE processed_notes (
id INT IDENTITY(1,1) PRIMARY KEY,
encounter_id VARCHAR(255) NOT NULL,
patient_id VARCHAR(255) NOT NULL,
document_id VARCHAR(255),
original_text NVARCHAR(MAX),
ai_enhanced_text NVARCHAR(MAX),
recommendations NVARCHAR(MAX),
processed_at DATETIME NOT NULL,
status VARCHAR(50) DEFAULT 'pending',
created_at DATETIME DEFAULT GETDATE(),
updated_at DATETIME DEFAULT GETDATE()
)Documents are updated with:
[Original Note Content]
========== AI ENHANCED VERSION (For Review) ==========
[AI Enhanced Version]
========== AI RECOMMENDATIONS ==========
[Specific Recommendations]
========== END AI SUGGESTIONS ==========
Note: Please review the AI suggestions above and edit as needed before signing.
- ✅ Environment-based configuration
- ✅ Secure credential storage via environment variables
- ✅ HTTPS-only communication
- ✅ Comprehensive error handling without exposing sensitive data
- ✅ Audit logging for all operations
- ✅ Sandbox testing before production
- ✅ Core functionality complete
- ✅ AWS Bedrock integration implemented
- ✅ SQL Server tracking implemented
- ✅ Document update capability added
- ✅ Comprehensive logging throughout
- ✅ Sandbox testing environment configured
- ✅ Production-ready architecture
- Set environment to sandbox in config.json
- Configure environment variables (.env file)
- Run
python main.py - Monitor logs for progress
- Review updated documents in EHR
- Check SQL Server for tracking data
- Switch to production when ready
- ⏳ Automated scheduling (cron/Windows Task Scheduler)
- ⏳ Web dashboard for monitoring progress
- ⏳ Bulk approval interface for providers
- ⏳ Analytics on AI recommendation acceptance rates
- ⏳ Support for different note types (SOAP, H&P, etc.)
- ⏳ Multi-organization support
- ⏳ Real-time processing via webhooks