widgets

๐Ÿ”— Python Form System Integration Guide

This guide shows how to integrate the Python Form System with your existing LocumTele workflow.

๐Ÿš€ Quick Integration

1. Deploy Python System

# Copy Python system to your server
scp -r python-forms/ user@your-server:/path/to/locumtele/

# Install dependencies
cd /path/to/locumtele/python-forms/
pip3 install -r requirements.txt

# Run the system
python3 flask_app.py

2. Update Your Embed Codes

Option A: Use Forms Dashboard (Recommended)

  1. Open forms-dashboard.html
  2. Navigate to Dashboard tab (Embed Code Library)
  3. Copy embed codes for your forms
  4. Replace existing embeds with new codes

Option B: Use Python API Directly

Replace your existing JavaScript embeds with Python API calls:

Before (JavaScript):

<script src="https://locumtele.github.io/widgets/python-forms/components/universalFormLoader.js"></script>
<script>
    const formData = { /* your form data */ };
    await window.generateForm(formData, 'form-container');
</script>

After (Python API):

<div id="form-container"></div>
<script>
fetch('https://your-server.com/api/generate-form', {
    method: 'POST',
    headers: {'Content-Type': 'application/json'},
    body: JSON.stringify({
        form_data: { /* your form data */ },
        container_id: 'form-container'
    })
})
.then(response => response.json())
.then(data => {
    document.getElementById('form-container').innerHTML = data.html;
});
</script>

๐Ÿ“‹ API Endpoints

Form Generation

POST /api/generate-form
Content-Type: application/json

{
    "form_data": {
        "title": "Medical Screening",
        "category": "weightloss",
        "questions": [...]
    },
    "container_id": "form-container",
    "options": {}
}

State Processing

POST /api/process-state
Content-Type: application/json

{
    "state_code": "CA",
    "form_data": {...},
    "category": "weightloss",
    "location_id": "clinic_123",
    "location_name": "Downtown Clinic",
    "root_domain": "https://locumtele.com"
}

๐Ÿ”„ Migration Strategy

Phase 1: Parallel Deployment

Phase 2: Gradual Migration

Phase 3: Full Migration

๐ŸŽฏ Benefits of Python System

  1. Better Performance: Server-side processing
  2. Easier Maintenance: Cleaner, more readable code
  3. Better Testing: Comprehensive test suite
  4. API Integration: Built-in REST API
  5. Scalability: Better for high traffic
  6. Error Handling: More robust error management

๐Ÿ”ง Configuration

Environment Variables

export FLASK_ENV=production
export WEBHOOK_URL=https://locumtele.app.n8n.cloud/webhook/patient-screener
export DEFAULT_ROOT_DOMAIN=https://locumtele.com

Nginx Configuration

location /api/ {
    proxy_pass http://localhost:5000;
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
}

๐Ÿ“Š Monitoring

Health Check

curl https://your-server.com/api/info

Logs

tail -f /var/log/locumtele-python.log

๐Ÿงช Testing

Run Tests

cd python-forms/
python3 test_system.py

Integration Test

python3 integration_demo.py

๐Ÿšจ Troubleshooting

Common Issues

  1. Port 5000 in use: Use different port
    python3 flask_app.py --port 5001
    
  2. Module not found: Install dependencies
    pip3 install -r requirements.txt
    
  3. Webhook errors: Check API endpoint
    curl -X POST https://locumtele.app.n8n.cloud/webhook/patient-screener
    

๐Ÿ“ž Support

โœ… Success Checklist