PainReportHuggingFace / test_report.py
DIrtyCha's picture
Initial commit from PainReport
acaf471
"""
Test script to verify report generation is using the new Medical Anthropologist prompt
"""
import sys
import os
sys.path.append('Backend')
# Load .env from Backend directory
try:
from dotenv import load_dotenv
load_dotenv('Backend/.env')
except ImportError:
print("Note: dotenv not available, using system environment variables")
# Now import after dotenv is loaded
from utils.report_generator import generate_comprehensive_report
# Test data
test_original_text = "我这两天一直觉得肚子钝痛,不是那种特别剧烈的,就是一直隐隐作痛。有时候会觉得按到那个部位的时候会更明显一点,躺着会好一点,还挺烦有点受不了的感觉。"
test_structured_data = {
'pain_type': 'Nociceptive (aching, dull, tingling, constant, tender)',
'location': 'Abdomen',
'temporal_pattern': 'Constant',
'intensity': '不是那种特别剧烈的 [Not that particularly severe]',
'emotion': 'exhausted, depressed',
'functional_impact': '走路或者按到那个的时候会更明显一点,躺着会好一点 [more noticeable when walking or pressing the area, better when lying down]'
}
test_ontology_mappings = [
{'original_term': '钝痛', 'mapped_english': 'dull', 'pain_type': 'nociceptive'},
{'original_term': '隐隐作痛', 'mapped_english': 'aching', 'pain_type': 'nociceptive'},
{'original_term': '一直', 'mapped_english': 'constant', 'pain_type': 'temporal'}
]
test_clinical_recommendations = [
{
'triggered_by_rule': 'Nociceptive Pain Assessment',
'recommendation': 'Standard pain assessment and management pathway recommended. Consider detailed clinical interview for further characterization.',
'confidence': 'medium'
}
]
test_detected_language = 'Chinese'
print("=" * 80)
print("TESTING REPORT GENERATOR")
print("=" * 80)
print("\nCalling generate_comprehensive_report()...\n")
try:
report = generate_comprehensive_report(
original_text=test_original_text,
structured_data=test_structured_data,
ontology_mappings=test_ontology_mappings,
clinical_recommendations=test_clinical_recommendations,
detected_language=test_detected_language
)
print("=" * 80)
print("GENERATED REPORT:")
print("=" * 80)
print(report)
print("\n" + "=" * 80)
# Check if it's using the new format
if "📝 Patient's Description" in report:
print("✅ SUCCESS: Using new Medical Anthropologist format!")
elif "Patient Presentation:" in report:
print("❌ FAIL: Still using old template format!")
print("\nThis means the function is hitting the exception handler.")
else:
print("⚠️ UNKNOWN: Cannot determine format")
except Exception as e:
print(f"❌ ERROR: {e}")
import traceback
traceback.print_exc()
print("=" * 80)