112 lines
3.2 KiB
Python
112 lines
3.2 KiB
Python
#!/usr/bin/env python
|
|
"""
|
|
Test script to verify the command center fix works
|
|
"""
|
|
import os
|
|
import sys
|
|
import django
|
|
|
|
# Setup Django
|
|
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.settings')
|
|
sys.path.insert(0, '/home/ismail/projects/HH')
|
|
django.setup()
|
|
|
|
from django.contrib.auth import get_user_model
|
|
from django.utils import timezone
|
|
from datetime import timedelta
|
|
from apps.analytics.services import UnifiedAnalyticsService
|
|
|
|
User = get_user_model()
|
|
|
|
def test_department_performance():
|
|
"""Test the department performance chart"""
|
|
print("Testing department performance chart...")
|
|
|
|
# Get a user
|
|
user = User.objects.first()
|
|
if not user:
|
|
print("ERROR: No users found in database")
|
|
return False
|
|
|
|
print(f"Using user: {user.username} (Is admin: {user.is_superuser})")
|
|
|
|
# Get date range
|
|
end_date = timezone.now()
|
|
start_date = end_date - timedelta(days=30)
|
|
|
|
try:
|
|
# Try to get department performance data
|
|
result = UnifiedAnalyticsService._get_department_performance(
|
|
user=user,
|
|
start_date=start_date,
|
|
end_date=end_date,
|
|
hospital_id=None
|
|
)
|
|
|
|
print(f"✓ SUCCESS: Got department performance data")
|
|
print(f" Chart type: {result.get('type')}")
|
|
print(f" Number of departments: {len(result.get('labels', []))}")
|
|
print(f" Labels: {result.get('labels', [])}")
|
|
print(f" Series data: {result.get('series', [])}")
|
|
|
|
return True
|
|
|
|
except Exception as e:
|
|
print(f"✗ FAILED: {type(e).__name__}: {e}")
|
|
import traceback
|
|
traceback.print_exc()
|
|
return False
|
|
|
|
def test_get_chart_data():
|
|
"""Test the get_chart_data method with department_performance"""
|
|
print("\nTesting get_chart_data method...")
|
|
|
|
# Get a user
|
|
user = User.objects.first()
|
|
if not user:
|
|
print("ERROR: No users found in database")
|
|
return False
|
|
|
|
try:
|
|
# Try to get department performance chart
|
|
result = UnifiedAnalyticsService.get_chart_data(
|
|
user=user,
|
|
chart_type='department_performance',
|
|
date_range='30d',
|
|
hospital_id=None,
|
|
department_id=None
|
|
)
|
|
|
|
print(f"✓ SUCCESS: Got chart data via get_chart_data")
|
|
print(f" Chart type: {result.get('type')}")
|
|
print(f" Number of departments: {len(result.get('labels', []))}")
|
|
|
|
if 'error' in result:
|
|
print(f"✗ WARNING: Chart returned an error: {result['error']}")
|
|
return False
|
|
|
|
return True
|
|
|
|
except Exception as e:
|
|
print(f"✗ FAILED: {type(e).__name__}: {e}")
|
|
import traceback
|
|
traceback.print_exc()
|
|
return False
|
|
|
|
if __name__ == '__main__':
|
|
print("=" * 60)
|
|
print("Testing Command Center Fix")
|
|
print("=" * 60)
|
|
|
|
test1_passed = test_department_performance()
|
|
test2_passed = test_get_chart_data()
|
|
|
|
print("\n" + "=" * 60)
|
|
if test1_passed and test2_passed:
|
|
print("✓ ALL TESTS PASSED!")
|
|
print("=" * 60)
|
|
sys.exit(0)
|
|
else:
|
|
print("✗ SOME TESTS FAILED")
|
|
print("=" * 60)
|
|
sys.exit(1) |