# Project export: MedCall

This document was generated by HackStack to give an AI agent context about a hackathon project. Sections are labeled with their provenance; content marked as truncated was cut to keep this document small.

## Project metadata

- Hackathon: TreeHacks 2026
- Tagline: AI powered clinical call monitoring agent that detects emergencies, adverse events, scheduling risks, and emotional distress in real time so no critical signal goes unnoticed.
- Devpost: https://devpost.com/software/medcall
- GitHub: https://github.com/joshitaarora/MedCall
- Video: https://www.youtube.com/embed/dlufohNkNMA?enablejsapi=1&hl=en_US&rel=0&start=&version=3&wmode=transparent
- Team: 1 GitHub contributor(s) — Mansi Patel (2 commits)

## Devpost submission (written by the team)

### Inspiration

Healthcare conversations often happen at the most vulnerable moments in a patient's life. Post surgery recovery calls, medication follow ups, or mental health check ins are charged with anxiety. In those moments, critical signals get lost. A patient might casually mention chest discomfort that is actually ischemic pain. A caregiver might describe confusion that could indicate neurological decline. A provider may overlook a potential adverse event that legally must be reported within 24 hours. We asked ourselves a simple question: "What if AI could act as a real time clinical co listener, surfacing high risk signals while the conversation is happening?" MedCall is born from the idea that AI should not replace clinicians but augment their vigilance when cognitive load is highest.

### What it does

MedCall is a real time AI powered patient call monitoring system. It listens to live clinical conversations, transcribes them, and runs four specialized agents in parallel: Emergency Detection Agent\ Identifies high acuity phrases such as chest pain, sudden weakness, slurred speech, or respiratory distress.\ If detected, the system recommends immediate escalation such as calling emergency services. Adverse Event Detection Agent\ Extracts and flags potential adverse drug events in compliance with pharmacovigilance requirements.\ Ensures time sensitive AE reporting within the regulatory 24 hour window. Appointment and Adherence Agent\ Detects missed medications, scheduling conflicts, or follow up non compliance and suggests actionable next steps. The result is structured, actionable intelligence generated from unstructured conversation.

### How we built it

MedCall is a full stack system built with React and Flask. Audio Pipeline: The browser captures microphone input using the MediaRecorder API. Audio is chunked into 3 second windows and streamed to the backend via WebSockets using Socket.IO. Transcription Layer: Each audio chunk is transcribed using the OpenAI Whisper API. This produces near real time text transcripts. Parallel Agent Architecture: The transcript is dispatched to four concurrent AI agents powered by OpenAI GPT models. Each agent operates independently on the same transcript segment, allowing specialized reasoning per task. Conceptually, for a transcript segment (T), we compute: [ A_i = f_i(T), \quad i \in {\text{emergency}, \text{AE}, \text{scheduling}} ] where each (f_i) represents a domain specific reasoning function implemented via structured prompting. Real Time Feedback: Results are streamed back to the frontend over WebSockets, enabling immediate clinician facing alerts and structured summaries. The backend uses Flask for REST endpoints, Flask SocketIO for bidirectional streaming, Eventlet for concurrency, python threading for parallel agent execution. All configuration is managed securely using environment variables.

### Challenges we ran into

Speech Emotion Recognition Limitations\ We explored SER models to detect vocal stress markers such as tremor or stutter. However, production ready APIs with reliable clinical accuracy were limited. Integrating emotion recognition in a medically meaningful way remains a challenge. Latency vs. Safety Tradeoff\ We optimized chunk size to balance responsiveness and transcription accuracy. Smaller chunks reduce latency but increase context fragmentation. Regulatory Sensitivity\ Adverse event detection must prioritize recall without overwhelming clinicians with false positives. Designing prompts that balance sensitivity and precision required iterative refinement. Resource Constraints\ Advanced features such as automatic emergency dialing or direct AE submission to pharmaceutical safety portals require deeper integration and compliance review.

### Accomplishments we're proud of

Successfully built a real time, multi agent clinical monitoring system within hackathon constraints Designed a parallel AI architecture instead of a single monolithic model Integrated live transcription with concurrent reasoning pipelines Addressed a real pharmacovigilance compliance use case rather than a generic chatbot scenario Created a system that feels clinically aware, not just conversational

### What we learned

How to architect real time AI pipelines using streaming audio and WebSockets Practical integration of Whisper for incremental transcription Prompt engineering for domain constrained reasoning The operational realities of adverse event reporting in healthcare The limitations and promise of speech emotion recognition systems We also learned that building AI for healthcare requires thinking about safety, latency, compliance, and human trust simultaneously.

### What's next

Integrate a clinically validated speech emotion recognition model Add structured adverse event auto reporting workflows Develop clinician configurable alert thresholds Deploy to a secure HIPAA compliant cloud environment Explore reinforcement learning for adaptive agent sensitivity Long term, MedCall aims to become an AI clinical co pilot that ensures no critical signal in patient communication is ever missed again.

## README (from the GitHub repository)

# MedCall - AI-Powered Post-Surgery Call Monitoring 🏥

[![TreeHacks 2026](https://img.shields.io/badge/TreeHacks-2026-blue)](https://treehacks.com)
[![License](https://img.shields.io/badge/license-MIT-green)](LICENSE)

**MedCall** is a clinical AI system that monitors post-surgery patient phone calls in real-time using parallel AI agents. Built for TreeHacks 2026, it detects adverse events, scheduling conflicts, emergencies, and hidden danger signals through audio-sentiment mismatch analysis.

## 🎯 The Problem

After surgery, patients call with symptoms and concerns. Nurses manually take notes during these calls, and **critical information gets lost, delayed, or misunderstood:**

- 🔴 Infection symptoms dismissed as "normal healing"
- 🔴 Severe pain (8/10) documented but urgency missed
- 🔴 Medication side effects buried in 10-minute conversations
- 🔴 Scheduling conflicts delay critical follow-ups

**Result:** Preventable ER visits, complications, and poor patient outcomes.

## 💡 The Solution

MedCall AI analyzes post-surgery calls in real-time with **4 specialized clinical agents** running in parallel:

### 1️⃣ **Adverse Event (AE) Detector** ⚠️
Identifies post-surgery complications with medical precision:
- **Infection symptoms:** Fever >100.4°F, redness, drainage, swelling
- **Severe pain:** Pain level 7+/10, sudden pain increase
- **Medication issues:** Side effects, allergic reactions, non-response
- **Bleeding/circulation:** Excessive bleeding, DVT risk
- **Respiratory/cardiac:** Breathing difficulty, chest pain

**Clinical accuracy:** Detects pain levels, days post-surgery, specific symptoms

### 2️⃣ **Emergency Detector** 🚨
Triages sudden health concerns requiring immediate action:
- **CRITICAL:** PE risk, stroke symptoms, severe bleeding → Call 911
- **URGENT:** High fever, wound dehiscence, uncontrolled pain → Contact surgeon within 1 hour
- **MODERATE:** Low-grade fever, mild drainage → Contact doctor within 24 hours

**Time-sensitive escalation** based on complication type and severity

### 3️⃣ **Appointment Agent** 📅
Manages post-surgery follow-up scheduling:
- Missed wound checks, PT sessions, suture removal
- Scheduling conflicts affecting recovery timeline
- Urgent rescheduling due to complications
- Follow-up needs (specialist referrals, additional visits)

**Tracks clinical impact** on patient recovery

### 4️⃣ **Sentiment Mismatch Analyzer** 🎭 *(Ambitious Feature)*
Detects hidden danger through audio-content discrepancies:
- **Coercion/abuse:** Patient minimizing pain under pressure
- **Hidden complications:** Says "fine" but describes concerning symptoms
- **Mental health crisis:** Depression/suicidal ideation masked
- **Access barriers:** Can't afford care but claiming recovery is good

**Identifies patterns:** Coached responses, third-party influence, financial barriers

---

## 🚀 How It Works

### **Parallel AI Architecture**
```
Microphone → Audio Capture → Whisper Transcription
                                      ↓
                         ┌────────────┴──────────────┐
                         │   Parallel Processing     │
           ┌─────────────┼─────────────┼─────────────┼──────────────┐
           ↓             ↓             ↓             ↓              ↓
    AE Detector   Appointment   Emergency    Sentiment        Clinical
   (Infections,     (Missed      (Critical    (Hidden        Note Gen
    Pain 7+/10,    Follow-ups,   PE/DVT,     Distress,       (Future)
    Med Issues)    Scheduling)   Sepsis)     Coercion)
           │             │             │             │              │
           └─────────────┴─────────────┴─────────────┴──────────────┘
                                      ↓
                     Real-time Alerts + Live Transcript
```

**All 4 agents run simultaneously** - no blocking, instant analysis.

---

## 🌟 Key Features

✅ **Clinical Precision**
- Detects pain levels (0-10 scale)
- Tracks days post-surgery
- Identifies specific complication types (PE, DVT, infection, dehiscence)

✅ **Real-Time Processing**
- Live audio transcription with OpenAI Whisper
- Parallel agent execution (Python threading)
- WebSocket updates to dashboard

✅ **Structured Clinical Output**
- Severity classification (mild/moderate/severe)
- Urgency levels (immediate/1hr/24hr)
- Actionable recommendations (Call 911, Contact surgeon, Schedule follow-up)

✅ **Comprehensive Monitoring**
- Post-surgery adverse events
- Missed appointments affecting recovery
- Life-threatening emergencies
- Hidden danger signals (coercion, mental health, access barriers)

---

## 🛠️ Tech Stack

### Backend
- **Python 3.8+** with Flask
- **OpenAI API** (GPT-4 + Whisper)
- **Flask-SocketIO** for real-time communication
- **Threading** for parallel agent execution

### Frontend
- **React 18**
- **Socket.io Client** for WebSocket
- **Web Audio API** for microphone
- **Responsive design**

---

## 📦 Quick Start

### Prerequisites
- Python 3.8+
- Node.js 16+
- OpenAI API key

### 1️⃣ **Run Setup Script (Windows)**
```powershell
.\setup.ps1
```

### 2️⃣ **Add Your OpenAI API Key**
Edit `backend/.env`:
```
OPENAI_API_KEY=your-actual-api-key-here
```

### 3️⃣ **Start Backend**
```powershell
cd backend
.\venv\Scripts\Activate.ps1
python app.py
```

### 4️⃣ **Start Frontend** (New Terminal)
```powershell
cd frontend
npm start
```

Access at: `http://localhost:3000`

---

## 🧪 Testing with Clinical Scenarios

### **Test 1: Post-Surgery Infection**
**Say:** *"I had my appendectomy 3 days ago, and now I have a fever of 101 degrees. The incision site is red and there's some yellowish drainage coming out."*

**Expected Alerts:**
- ⚠️ **AE Detector:** Infection symptoms (fever, drainage, redness)
- 🔴 **Emergency Detector:** Urgent - Contact surgeon within 1 hour
- **Pain Level:** Extracted if mentioned
- **Days Post-Op:** 3 days

---

### **Test 2: Severe Pain Crisis**
**Say:** *"The pain is unbearable - I'd rate it 9 out of 10. The pain medication isn't helping at all, and it's getting worse."*

**Expected Alerts:**
- 🚨 **AE Detector:** Severe pain (9/10), medication non-response
- 🚨 **Emergency Detector:** Urgent - Uncontrolled pain
- **Action:** Immediate surgical consultation

---

### **Test 3: Missed Follow-up Appointment**
**Say:** *"Oh no, I completely forgot about my wound check appointment yesterday. I've been having some drainage but thought it was normal."*

**Expected Alerts:**
- 📅 **Appointment Agent:** Missed wound check
- ⚠️ **Clinical Impact:** Yes (drainage present, needs evaluation)
- **Action:** Urgent rescheduling + wound assessment

---

### **Test 4: Sentiment Mismatch (Ambitious)**
**Say (in distressed tone):** *"Everything is fine, I'm managing okay. My husband says I'm doing great and I shouldn't bother the doctor..."*

**Expected Alerts:**
- 🎭 **Sentiment Analyzer:** Potential coercion/hidden distress
- **Red Flags:** Third-party influence, minimizing symptoms
- **Action:** Private follow-up call, welfare check

---

### **Test 5: Critical Emergency**
**Say:** *"I'm having severe chest pain and I can't catch my breath. My left leg is also really swollen and painful."*

**Expected Alerts:**
- 🚨🚨 **Emergency Detector:** CRITICAL - Possible PE/DVT
- **Action:** Call 911 immediately
- **Symptoms:** Chest pain, dyspnea, leg swelling (classic PE presentation)

---

## 📊 Clinical Accuracy

- ✅ **Pain Level Detection:** Extracts numeric scale (0-10)
- ✅ **Timeline Tracking:** Days post-surgery calculation
- ✅ **Symptom Classification:** Maps to clinical categories
- ✅ **Urgency Triage:** Follows post-op emergency protocols
- ✅ **Conservative Flagging:** Better false positive than missed emergency

---

## 🎨 Dashboard Features

### Real-Time Alert Panel
- Color-coded severity (🚨 Critical, 🔴 High, ⚠️ Medium)
- Alert statistics (Critical/High/Medium counts)
- Recommended actions for each alert
- Timestamp tracking

### Live Transcript View
- Auto-scrolling conversation
- Speaker identification
- Searchable history
- Times

[README truncated for size]

## Detected evidence (automated analysis)

Indexed codebase: 27 recognized source files, 88 KB.
- CSS (language) — detected in the code
- Flask (technology) — detected in the code
- HTML (language) — detected in the code
- JavaScript (language) — detected in the code
- OpenAI (technology) — detected in the code
- Python (language) — detected in the code
- React (technology) — detected in the code

## Codebase structure (from repository index)

### Files (34 of 34)

```
backend/.env.example
backend/.gitignore
backend/agents/__init__.py
backend/agents/ae_detector.py
backend/agents/appointment_agent.py
backend/agents/emergency_detector.py
backend/agents/sentiment_analyzer.py
backend/app.py
backend/audio/__init__.py
backend/audio/processor.py
backend/requirements.txt
backend/test_setup.py
frontend/.env.example
frontend/.gitignore
frontend/package.json
frontend/public/index.html
frontend/src/App.css
frontend/src/App.js
frontend/src/components/AlertDashboard.css
frontend/src/components/AlertDashboard.js
frontend/src/components/AudioFileUpload.css
frontend/src/components/AudioFileUpload.js
frontend/src/components/CallMonitor.css
frontend/src/components/CallMonitor.js
frontend/src/components/SessionControl.css
frontend/src/components/SessionControl.js
frontend/src/components/TranscriptView.css
frontend/src/components/TranscriptView.js
frontend/src/index.css
frontend/src/index.js
QUICKSTART.md
README.md
setup.ps1
setup.sh
```

### Dependencies

- backend/requirements.txt: eventlet@==0.35.1, flask@==3.0.0, flask-cors@==4.0.0, flask-socketio@==5.3.5, openai@==1.12.0, python-dotenv@==1.0.0, python-socketio@==5.11.0
- frontend/package.json: axios@^1.6.5, lucide-react@^0.303.0, react@^18.2.0, react-dom@^18.2.0, react-scripts@5.0.1, recharts@^2.10.3, socket.io-client@^4.6.1

### Recent commits (newest first)

- Final Modifications to improve the features
- debugging
- some minor changes
- Added some more features
- Initial commit of MedCall project, including backend and frontend code, documentation, and setup scripts.
- Initial commit

## Key source files (fetched from GitHub, selected and truncated for size)

### QUICKSTART.md

```markdown
# MedCall Project - Quick Reference Guide

## 🚀 Quick Start

### 1. Run Setup Script (Windows)
```powershell
.\setup.ps1
```

### 2. Add Your API Key
Edit `backend\.env` and replace:
```
OPENAI_API_KEY=your-openai-api-key-here
```

### 3. Start Backend
```powershell
cd backend
.\venv\Scripts\Activate.ps1
python app.py
```

### 4. Start Frontend (New Terminal)
```powershell
cd frontend
npm start
```

## 🎯 How It Works

### Architecture Flow
```
Microphone → Audio Capture → Whisper (Transcription)
                                      ↓
                              Parallel AI Agents
              ┌─────────────────┬────────┴────────┬──────────────────┐
              ↓                 ↓                 ↓                  ↓
      AE Detector    Appointment Agent   Emergency Detector  Sentiment Analyzer
              │                 │                 │                  │
              └─────────────────┴────────┬────────┴──────────────────┘
                                         ↓
                                Alert Dashboard + Transcript
```

### Parallel Processing
- All 4 agents run simultaneously using Python threading
- No blocking - instant analysis
- Real-time WebSocket updates to frontend

## 🔧 Troubleshooting

### Backend Issues

**Port already in use:**
```powershell
# Change port in backend/.env
PORT=5001
```

**OpenAI API errors:**
- Check your API key is correct
- Ensure you have credits in your OpenAI account
- Verify internet connection

### Frontend Issues

**Cannot connect to backend:**
- Ensure backend is running on port 5001
- Check `REACT_APP_API_URL` in frontend/.env

**Microphone access denied:**
- Allow microphone permissions in browser
- Use HTTPS in production (required for mic access)

## 📊 Testing the Application

### Test Scenarios

**1. Test AE Detection:**
Say: "I've been having severe side effects from the medication - nausea and dizziness."

**2. Test Appointment:**
Say: "I missed my appointment yesterday and need to reschedule."

**3. Test Emergency:**
Say: "I'm having severe chest pain and difficulty breathing."

**4. Test Sentiment Mismatch:**
Say: "Everything is fine..." (in a distressed tone)
Context: The AI will analyze the conversation pattern for inconsistencies

## 🎨 Customization

### Adding New Agents

1. Create new agent in `backend/agents/your_agent.py`:
```python
class YourAgent:
    def __init__(self, api_key):
        self.client = OpenAI(api_key=api_key)
    
    def analyze(self, text, history):
        # Your logic here
        return result
```

2. Import in `backend/app.py`:
```python
from agents.your_agent import YourAgent
your_agent = YourAgent(OPENAI_API_KEY)
```

3. Add to parallel processing:
```python
def run_your_analysis():
    results['your_feature'] = your_agent.analyze(text, history)

threads.append(threading.Thread(target=run_your_analysis))
```

### Modifying Agent Behavior

Edit the prompts in each agent file:
- `agents/ae_detector.py` - Line ~25
- `agents/appointment_agen
[truncated — 2545 more characters]
```

### backend/requirements.txt

```
flask==3.0.0
flask-cors==4.0.0
flask-socketio==5.3.5
openai==1.12.0
python-socketio==5.11.0
python-dotenv==1.0.0
eventlet==0.35.1

```

### frontend/package.json

```
{
  "name": "medcall-frontend",
  "version": "1.0.0",
  "private": true,
  "dependencies": {
    "react": "^18.2.0",
    "react-dom": "^18.2.0",
    "react-scripts": "5.0.1",
    "socket.io-client": "^4.6.1",
    "axios": "^1.6.5",
    "recharts": "^2.10.3",
    "lucide-react": "^0.303.0"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
  "eslintConfig": {
    "extends": [
      "react-app"
    ]
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  }
}

```

### backend/app.py

```python
"""
MedCall Backend - Live Call Monitoring with Parallel AI Agents
Hackathon Project for Healthcare Call Analysis
"""

from flask import Flask, request, jsonify
from flask_cors import CORS
from flask_socketio import SocketIO, emit
import os
from dotenv import load_dotenv
import json
from datetime import datetime
from concurrent.futures import ThreadPoolExecutor, as_completed
from agents.ae_detector import AdverseEventDetector
from agents.appointment_agent import AppointmentAgent
from agents.emergency_detector import EmergencyDetector
from agents.sentiment_analyzer import SentimentMismatchAnalyzer
from audio.processor import AudioProcessor

load_dotenv() 

app = Flask(__name__)
CORS(app)
socketio = SocketIO(app, cors_allowed_origins="*")

# Configuration
OPENAI_API_KEY = os.getenv('OPENAI_API_KEY')

if not OPENAI_API_KEY:
    raise ValueError("OPENAI_API_KEY not found in environment variables. Please set it in .env file")

# Initialize agents
ae_detector = AdverseEventDetector(OPENAI_API_KEY)
appointment_agent = AppointmentAgent(OPENAI_API_KEY)
emergency_detector = EmergencyDetector(OPENAI_API_KEY)
sentiment_analyzer = SentimentMismatchAnalyzer(OPENAI_API_KEY)
audio_processor = AudioProcessor(OPENAI_API_KEY)

# Store active sessions
active_sessions = {}

class CallSession:
    ALERT_COOLDOWN_SECONDS = 30

    def __init__(self, session_id):
        self.session_id = session_id
        self.transcript = []
        self.alerts = []
        self.start_time = datetime.now()
        self.is_active = True
        self._last_alert_time = {}  # alert_type -> datetime
        
    def add_transcript(self, text, speaker="user"):
        self.transcript.append({
            "timestamp": datetime.now().isoformat(),
            "speaker": speaker,
            "text": text
        })
        
    def can_emit_alert(self, alert_type):
        last = self._last_alert_time.get(alert_type)
        if last is None:
            return True
        return (datetime.now() - last).total_seconds() >= self.ALERT_COOLDOWN_SECONDS

    def add_alert(self, alert_type, message, severity, action=None):
        alert = {
            "timestamp": datetime.now().isoformat(),
            "type": alert_type,
            "message": message,
            "severity": severity,
            "action": action
        }
        self.alerts.append(alert)
        self._last_alert_time[alert_type] = datetime.now()
        return alert


def process_audio_chunk_parallel(session_id, audio_data, transcript_text):
    """Process audio with all agents in parallel using gpt-4o-mini"""
    session = active_sessions.get(session_id)
    if not session:
        print(f"❌ Session {session_id} not found in processing!")
        return

    session.add_transcript(transcript_text)
    print(f"🚀 Running 3 agents in parallel for: {transcript_text[:80]}...")

    try:
        agent_tasks = {
            'ae':          lambda: ae_detector.analyze(transcript_text, session.transcript),
            'appointment': lambda: appointment_agent.analyze(transcript_text, session.transcript),
            'emergency':   lambda: emergency_detector.analyze(transcript_text, session.transcript),
        }

        results = {}
        with ThreadPoolExecutor(max_workers=3) as executor:
            futures = {executor.submit(fn): key for key, fn in agent_tasks.items()}
            for future in as_completed(futures):
                key = futures[future]
                try:
                    results[key] = future.result()
                    print(f"✅ {key} agent done")
                except Exception as e:
                    print(f"❌ {key} agent error: {e}")
                    results[key] = {"detected": False, "issue_detected": False, "is_emergency": False, "error": str(e)}

        print("✅ All agents complete — emitting results")
        handle_analysis_results(session_id, results)
    except Exception as e:
        print(f"❌ CRITICAL ERROR in processing: {e}")
        import traceback
        traceback.print_exc()


def handle_analysis_results(session_id, results):
    """Handle results from parallel agents and emit alerts"""
    print(f"\n{'='*50}")
    print(f"📊 HANDLING ANALYSIS RESULTS")
    print(f"Session: {session_id}")
    print(f"Results keys: {list(results.keys())}")
    print(f"{'='*50}\n")
    
    session = active_sessions.get(session_id)
    if not session:
        print(f"❌ Session not found in handle_analysis_results!")
        return
    
    alerts_emitted = 0
    
    # Adverse Event Detection
    ae_result = results.get('ae', {})
    if ae_result and ae_result.get('detected') and session.can_emit_alert('adverse_event'):
        try:
            alert = session.add_alert(
                'adverse_event',
                ae_result.get('message', 'Adverse event detected'),
                'high',
                ae_result.get('recommended_action')
            )
            socketio.emit('alert', alert)
            alerts_emitted += 1
            print("✅ AE Alert emitted!")
        except Exception as e:
            print(f"❌ Error emitting AE alert: {e}")
    elif ae_result and ae_result.get('detected'):
        print("⏳ AE alert suppressed (cooldown)")

    # Appointment Issues
    appt_result = results.get('appointment', {})
    if appt_result and appt_result.get('issue_detected') and session.can_emit_alert('appointment'):
        try:
            alert = session.add_alert(
                'appointment',
                appt_result.get('message', 'Appointment issue detected'),
                'medium',
                appt_result.get('suggested_action')
            )
            socketio.emit('alert', alert)
            alerts_emitted += 1
            print("✅ Appointment Alert emitted!")
        except Exception as e:
            print(f"❌ Error emitting appointment alert: {e}")
    elif appt_result and appt_result.get('issue_detected'):
        print("⏳ Appointment alert suppressed (cooldown)")

    # Emergency Detection
    emerg_res
[truncated — 6590 more characters]
```

### frontend/src/index.js

```javascript
import React from 'react';
import ReactDOM from 'react-dom/client';
import './index.css';
import App from './App';

const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(
  <React.StrictMode>
    <App />
  </React.StrictMode>
);

```

### frontend/src/App.js

```javascript
import React, { useState, useEffect } from 'react';
import './App.css';
import CallMonitor from './components/CallMonitor';
import AlertDashboard from './components/AlertDashboard';
import TranscriptView from './components/TranscriptView';
import SessionControl from './components/SessionControl';
import AudioFileUpload from './components/AudioFileUpload';
import { Activity } from 'lucide-react';

function App() {
  const [sessionId, setSessionId] = useState(null);
  const [isSessionActive, setIsSessionActive] = useState(false);
  const [alerts, setAlerts] = useState([]);
  const [transcript, setTranscript] = useState([]);

  const handleSessionStart = (newSessionId) => {
    setSessionId(newSessionId);
    setIsSessionActive(true);
    setAlerts([]);
    setTranscript([]);
  };

  const handleSessionStop = () => {
    setIsSessionActive(false);
  };

  const handleNewAlert = (alert) => {
    setAlerts(prev => [...prev, alert]);
  };

  const handleTranscriptUpdate = (entry) => {
    setTranscript(prev => [...prev, entry]);
  };

  return (
    <div className="App">
      <header className="app-header">
        <div className="header-content">
          <div className="logo">
            <Activity size={32} color="#fff" />
            <h1>MedCall</h1>
          </div>
          <p className="tagline">AI-Powered Post-Surgery Call Monitoring</p>
        </div>
      </header>

      <main className="app-main">
        <div className="content-grid">
          {/* Session Control */}
          <div className="session-section">
            <SessionControl
              onSessionStart={handleSessionStart}
              onSessionStop={handleSessionStop}
              isActive={isSessionActive}
              sessionId={sessionId}
            />
          </div>

          {/* Call Monitor */}
          {isSessionActive && (
            <>
              <div className="monitor-section">
                <CallMonitor
                  sessionId={sessionId}
                  onAlert={handleNewAlert}
                  onTranscriptUpdate={handleTranscriptUpdate}
                />
              </div>

              <div className="upload-section">
                <AudioFileUpload
                  sessionId={sessionId}
                  onAlert={handleNewAlert}
                  onTranscriptUpdate={handleTranscriptUpdate}
                />
              </div>
            </>
          )}

          {/* Alert Dashboard */}
          <div className="dashboard-section">
            <AlertDashboard alerts={alerts} />
          </div>

          {/* Transcript */}
          {isSessionActive && (
            <div className="transcript-section">
              <TranscriptView transcript={transcript} />
            </div>
          )}
        </div>
      </main>

      <footer className="app-footer">
        <p>Parallel AI Agents: Post-Surgery AE Detection | Appointment Management | Emergency Detection</p>
      </footer>
    </div>
  );
}

export default App;

```

### setup.sh

```shell
#!/bin/bash

# MedCall Quick Start Script
# This script sets up and runs both backend and frontend

echo "🏥 MedCall - Quick Start"
echo "========================"

# Check if Python is installed
if ! command -v python &> /dev/null; then
    echo "❌ Python is not installed. Please install Python 3.8 or higher."
    exit 1
fi

# Check if Node.js is installed
if ! command -v node &> /dev/null; then
    echo "❌ Node.js is not installed. Please install Node.js 16 or higher."
    exit 1
fi

echo "✅ Prerequisites check passed"
echo ""

# Setup Backend
echo "📦 Setting up backend..."
cd backend

if [ ! -d "venv" ]; then
    echo "Creating virtual environment..."
    python -m venv venv
fi

source venv/bin/activate
pip install -r requirements.txt

if [ ! -f ".env" ]; then
    echo "Creating .env file..."
    cp .env.example .env
    echo "⚠️  Please edit backend/.env and add your OpenAI API key"
fi

cd ..

# Setup Frontend
echo "📦 Setting up frontend..."
cd frontend

if [ ! -d "node_modules" ]; then
    echo "Installing dependencies..."
    npm install
fi

if [ ! -f ".env" ]; then
    echo "Creating .env file..."
    cp .env.example .env
fi

cd ..

echo ""
echo "✅ Setup complete!"
echo ""
echo "📝 Next steps:"
echo "1. Add your OpenAI API key to backend/.env"
echo "2. Run 'npm start' in the frontend directory"
echo "3. Run 'python app.py' in the backend directory (with venv activated)"
echo ""
echo "🚀 Happy hacking!"

```

### backend/test_setup.py

```python
"""
Test script to verify backend setup
Run this after installing dependencies to ensure everything works
"""

import sys

def test_imports():
    """Test if all required packages can be imported"""
    print("Testing Python package imports...")
    
    packages = {
        'flask': 'Flask',
        'flask_cors': 'Flask-CORS',
        'flask_socketio': 'Flask-SocketIO',
        'openai': 'OpenAI',
        'dotenv': 'python-dotenv'
    }
    
    failed = []
    
    for package, name in packages.items():
        try:
            __import__(package)
            print(f"  ✓ {name}")
        except ImportError:
            print(f"  ✗ {name} - NOT FOUND")
            failed.append(name)
    
    return len(failed) == 0, failed

def test_env():
    """Test if .env file exists"""
    print("\nTesting environment configuration...")
    
    import os
    from pathlib import Path
    
    env_file = Path('.env')
    if env_file.exists():
        print("  ✓ .env file exists")
        
        from dotenv import load_dotenv
        load_dotenv()
        
        api_key = os.getenv('OPENAI_API_KEY')
        if api_key and api_key != 'your-openai-api-key-here':
            print("  ✓ OPENAI_API_KEY is set")
            return True
        else:
            print("  ✗ OPENAI_API_KEY not configured")
            print("    Please edit .env and add your OpenAI API key")
            return False
    else:
        print("  ✗ .env file not found")
        print("    Please copy .env.example to .env")
        return False

def test_openai_connection():
    """Test OpenAI API connection"""
    print("\nTesting OpenAI API connection...")
    
    try:
        import os
        from dotenv import load_dotenv
        from openai import OpenAI
        
        load_dotenv()
        api_key = os.getenv('OPENAI_API_KEY')
        
        if not api_key or api_key == 'your-openai-api-key-here':
            print("  ⚠ Skipping (API key not configured)")
            return True
        
        client = OpenAI(api_key=api_key)
        
        # Test with a simple completion
        response = client.chat.completions.create(
            model="gpt-3.5-turbo",
            messages=[{"role": "user", "content": "Hello"}],
            max_tokens=5
        )
        
        print("  ✓ OpenAI API connection successful")
        return True
        
    except Exception as e:
        print(f"  ✗ OpenAI API connection failed: {str(e)}")
        return False

def main():
    print("=" * 50)
    print("MedCall Backend Setup Verification")
    print("=" * 50)
    print()
    
    # Test imports
    imports_ok, failed = test_imports()
    
    if not imports_ok:
        print("\n❌ Some packages are missing. Please run:")
        print("   pip install -r requirements.txt")
        sys.exit(1)
    
    # Test environment
    env_ok = test_env()
    
    # Test OpenAI (optional)
    if env_ok:
        api_ok = test_openai_connection()
    else:
        api_ok = False
    
    print("\n" + "=" * 50)
    if imports_ok and env_ok:
        print("✅ Backend setup verified!")
        print("\nYou can now run: python app.py")
        if not api_ok:
            print("\n⚠️  Note: OpenAI API test was skipped or failed.")
            print("   The app will work once you configure a valid API key.")
    else:
        print("❌ Setup incomplete. Please fix the issues above.")
    print("=" * 50)

if __name__ == '__main__':
    main()

```

### backend/audio/__init__.py

```python
"""
Audio processing package initialization
"""

__all__ = ['processor']

```

### backend/agents/__init__.py

```python
"""
Agent package initialization
"""

__all__ = ['ae_detector', 'appointment_agent', 'emergency_detector', 'sentiment_analyzer']

```

[18 more indexed source files omitted to keep this export small. The full file list is in the Codebase structure section above.]