import pytest import sys import os # Add parent directory to path to import app modules sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) class TestSOAPGeneration: """Test SOAP note generation functionality""" def test_generate_soap_note_with_valid_input(self, sample_medical_text): """Test SOAP generation with valid medical text""" # Mock the generate_soap_note function since it requires the model def mock_generate_soap_note(text, include_timestamp=True): if not text.strip(): return "❌ Please enter some medical notes to process." # Return a mock SOAP note return """ SUBJECTIVE: 45-year-old male presents with chief complaint of chest pain for 2 hours. OBJECTIVE: Vital Signs: BP 150/90, HR 110, RR 22, O2 Sat 96% Physical exam shows patient appears anxious and diaphoretic. ASSESSMENT: Acute chest pain, rule out myocardial infarction PLAN: 1. EKG 2. Cardiac enzymes 3. Chest X-ray 4. Aspirin 325mg """ result = mock_generate_soap_note(sample_medical_text) assert "SUBJECTIVE:" in result assert "OBJECTIVE:" in result assert "ASSESSMENT:" in result assert "PLAN:" in result assert "45-year-old male" in result def test_generate_soap_note_empty_input(self): """Test SOAP generation with empty input""" def mock_generate_soap_note(text, include_timestamp=True): if not text.strip(): return "❌ Please enter some medical notes to process." return "Valid SOAP note" result = mock_generate_soap_note("") assert "❌ Please enter some medical notes to process." in result def test_generate_soap_note_whitespace_only(self): """Test SOAP generation with whitespace only""" def mock_generate_soap_note(text, include_timestamp=True): if not text.strip(): return "❌ Please enter some medical notes to process." return "Valid SOAP note" result = mock_generate_soap_note(" \n\t ") assert "❌ Please enter some medical notes to process." in result def test_soap_note_structure(self, sample_medical_text): """Test that generated SOAP notes have proper structure""" def mock_generate_soap_note(text, include_timestamp=True): return """ SUBJECTIVE: Patient reports chest pain. OBJECTIVE: Vital signs stable. ASSESSMENT: Chest pain evaluation. PLAN: Further testing recommended. """ result = mock_generate_soap_note(sample_medical_text) lines = result.strip().split('\n') # Check that SOAP sections are present and in order soap_sections = [] for line in lines: if line.strip().endswith(':') and line.strip() in ['SUBJECTIVE:', 'OBJECTIVE:', 'ASSESSMENT:', 'PLAN:']: soap_sections.append(line.strip()) expected_order = ['SUBJECTIVE:', 'OBJECTIVE:', 'ASSESSMENT:', 'PLAN:'] assert soap_sections == expected_order