Spaces:
Sleeping
Sleeping
File size: 9,978 Bytes
be1b5d2 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 | # test_coherent_summary_formatter.py
"""
Unit tests for Coherent Summary Formatter functionality.
Tests the new coherent paragraph formatting functionality added to
ProviderSummaryGenerator for requirements 2.1-2.8.
"""
import pytest
from unittest.mock import Mock
from datetime import datetime
from src.core.provider_summary_generator import ProviderSummaryGenerator, ProviderSummary
class TestCoherentSummaryFormatter:
"""Test cases for coherent summary formatting functionality."""
def setup_method(self):
"""Set up test fixtures."""
self.generator = ProviderSummaryGenerator()
def test_format_coherent_paragraph_basic(self):
"""Test basic coherent paragraph formatting."""
# Create sample provider summary
summary = ProviderSummary(
patient_name="John Doe",
patient_phone="(555) 123-4567",
indicators=["Loss of faith", "Spiritual distress"],
situation_description="existential crisis",
medical_context={
"age": 45,
"gender": "male",
"conditions": ["Diabetes", "Hypertension"]
}
)
result = self.generator.format_coherent_paragraph(summary)
# Check that all required elements are present (Requirements 2.2, 2.3, 2.4, 2.5)
assert "John Doe is a 45-year-old male" in result
assert "clinical history of Diabetes and Hypertension" in result
assert "Loss of faith and Spiritual distress" in result
assert "existential crisis" in result
assert "RED FLAG" in result
assert "(555) 123-4567" in result
# Check that it's a single paragraph (Requirement 2.1)
lines = result.split('\n')
main_paragraph_lines = [line for line in lines if line.strip() and not line.startswith('Patient reported:')]
assert len(main_paragraph_lines) == 1
def test_format_coherent_paragraph_no_medical_history(self):
"""Test coherent paragraph with no medical history."""
summary = ProviderSummary(
patient_name="Jane Smith",
patient_phone="(555) 987-6543",
indicators=["Anxiety"],
situation_description="mild distress",
medical_context={"age": 30, "gender": "female"}
)
result = self.generator.format_coherent_paragraph(summary)
assert "Jane Smith is a 30-year-old female" in result
assert "no significant medical history documented" in result
assert "Anxiety" in result
assert "mild distress" in result
def test_format_coherent_paragraph_single_condition(self):
"""Test coherent paragraph with single medical condition."""
summary = ProviderSummary(
patient_name="Bob Wilson",
patient_phone="(555) 456-7890",
indicators=["Depression"],
situation_description="emotional distress",
medical_context={
"age": 55,
"gender": "male",
"conditions": ["Cancer"]
}
)
result = self.generator.format_coherent_paragraph(summary)
assert "clinical history of Cancer" in result
assert "Depression" in result
def test_format_coherent_paragraph_multiple_conditions(self):
"""Test coherent paragraph with multiple medical conditions."""
summary = ProviderSummary(
patient_name="Alice Brown",
patient_phone="(555) 321-0987",
indicators=["Fear", "Uncertainty", "Loss of hope"],
situation_description="complex medical situation",
medical_context={
"age": 67,
"gender": "female",
"conditions": ["Heart Disease", "Diabetes", "Arthritis", "COPD"]
}
)
result = self.generator.format_coherent_paragraph(summary)
# Should format as "X, Y, Z, and W"
assert "clinical history of Heart Disease, Diabetes, Arthritis, and COPD" in result
assert "Fear, Uncertainty, and Loss of hope" in result
def test_format_coherent_paragraph_no_phone(self):
"""Test coherent paragraph with no phone number."""
summary = ProviderSummary(
patient_name="Charlie Davis",
patient_phone="",
indicators=["Spiritual questioning"],
situation_description="seeking meaning",
medical_context={"age": 40, "gender": "male"}
)
result = self.generator.format_coherent_paragraph(summary)
assert "No contact number is currently available" in result
def test_format_coherent_paragraph_with_conversation_context(self):
"""Test coherent paragraph with patient quote from conversation."""
summary = ProviderSummary(
patient_name="Diana Evans",
patient_phone="(555) 654-3210",
indicators=["Existential questioning"],
situation_description="spiritual crisis",
medical_context={"age": 35, "gender": "female"},
conversation_context="I don't understand why this is happening to me and my family"
)
result = self.generator.format_coherent_paragraph(summary)
# Should include patient quote as separate line (Requirement 2.8)
assert 'Patient reported: "I don\'t understand why this is happening to me and my family"' in result
# Should have main paragraph and quote separated
parts = result.split('\n\n')
assert len(parts) == 2
def test_format_coherent_paragraph_no_indicators(self):
"""Test coherent paragraph with no specific indicators."""
summary = ProviderSummary(
patient_name="Frank Green",
patient_phone="(555) 789-0123",
indicators=[],
situation_description="general concern",
medical_context={"age": 50, "gender": "male"}
)
result = self.generator.format_coherent_paragraph(summary)
assert "general distress" in result
assert "general concern" in result
def test_format_coherent_paragraph_unknown_gender(self):
"""Test coherent paragraph with unknown gender."""
summary = ProviderSummary(
patient_name="Taylor Smith",
patient_phone="(555) 111-2222",
indicators=["Anxiety"],
situation_description="stress",
medical_context={"age": 28} # No gender specified
)
result = self.generator.format_coherent_paragraph(summary)
assert "Taylor Smith is a 28-year-old individual" in result
def test_format_coherent_paragraph_no_age(self):
"""Test coherent paragraph with no age specified."""
summary = ProviderSummary(
patient_name="Sam Johnson",
patient_phone="(555) 333-4444",
indicators=["Worry"],
situation_description="concern",
medical_context={"gender": "non-binary"}
)
result = self.generator.format_coherent_paragraph(summary)
assert "Sam Johnson is a unknown age non-binary" in result
def test_format_coherent_paragraph_minimal_data(self):
"""Test coherent paragraph with minimal data."""
summary = ProviderSummary(
patient_name="Minimal Patient",
patient_phone="",
indicators=[],
situation_description="",
medical_context=None
)
result = self.generator.format_coherent_paragraph(summary)
# Should still produce a valid paragraph
assert "Minimal Patient is a unknown age individual" in result
assert "no significant medical history documented" in result
assert "general distress" in result
assert "spiritual or emotional distress" in result
assert "No contact number is currently available" in result
def test_format_coherent_paragraph_sentence_structure(self):
"""Test that coherent paragraph has proper sentence structure."""
summary = ProviderSummary(
patient_name="Structure Test",
patient_phone="(555) 555-5555",
indicators=["Test indicator"],
situation_description="test situation",
medical_context={"age": 40, "gender": "male", "conditions": ["Test condition"]}
)
result = self.generator.format_coherent_paragraph(summary)
# Should end with period
main_paragraph = result.split('\n\n')[0]
assert main_paragraph.endswith('.')
# Should be properly connected sentences
sentences = main_paragraph.split('. ')
assert len(sentences) >= 4 # Should have multiple connected sentences
def test_format_coherent_paragraph_integration_with_existing(self):
"""Test that coherent paragraph doesn't break existing functionality."""
summary = ProviderSummary(
patient_name="Integration Test",
patient_phone="(555) 999-8888",
indicators=["Integration test"],
situation_description="testing integration"
)
# Test that existing format_for_display still works
structured_result = self.generator.format_for_display(summary)
assert "PROVIDER SUMMARY - SPIRITUAL CARE REFERRAL" in structured_result
# Test that new coherent format works
coherent_result = self.generator.format_coherent_paragraph(summary)
assert "Integration Test is a unknown age individual" in coherent_result
# Results should be different formats
assert structured_result != coherent_result
if __name__ == "__main__":
pytest.main([__file__]) |