Bonosa2 commited on
Commit
d31fe8c
·
verified ·
1 Parent(s): 7bc42b8

Create tests/test_soap_note_generation.py

Browse files
Files changed (1) hide show
  1. tests/test_soap_note_generation.py +92 -0
tests/test_soap_note_generation.py ADDED
@@ -0,0 +1,92 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pytest
2
+ import sys
3
+ import os
4
+
5
+ # Add parent directory to path to import app modules
6
+ sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
7
+
8
+ class TestSOAPGeneration:
9
+ """Test SOAP note generation functionality"""
10
+
11
+ def test_generate_soap_note_with_valid_input(self, sample_medical_text):
12
+ """Test SOAP generation with valid medical text"""
13
+ # Mock the generate_soap_note function since it requires the model
14
+ def mock_generate_soap_note(text, include_timestamp=True):
15
+ if not text.strip():
16
+ return "❌ Please enter some medical notes to process."
17
+
18
+ # Return a mock SOAP note
19
+ return """
20
+ SUBJECTIVE:
21
+ 45-year-old male presents with chief complaint of chest pain for 2 hours.
22
+
23
+ OBJECTIVE:
24
+ Vital Signs: BP 150/90, HR 110, RR 22, O2 Sat 96%
25
+ Physical exam shows patient appears anxious and diaphoretic.
26
+
27
+ ASSESSMENT:
28
+ Acute chest pain, rule out myocardial infarction
29
+
30
+ PLAN:
31
+ 1. EKG
32
+ 2. Cardiac enzymes
33
+ 3. Chest X-ray
34
+ 4. Aspirin 325mg
35
+ """
36
+
37
+ result = mock_generate_soap_note(sample_medical_text)
38
+
39
+ assert "SUBJECTIVE:" in result
40
+ assert "OBJECTIVE:" in result
41
+ assert "ASSESSMENT:" in result
42
+ assert "PLAN:" in result
43
+ assert "45-year-old male" in result
44
+
45
+ def test_generate_soap_note_empty_input(self):
46
+ """Test SOAP generation with empty input"""
47
+ def mock_generate_soap_note(text, include_timestamp=True):
48
+ if not text.strip():
49
+ return "❌ Please enter some medical notes to process."
50
+ return "Valid SOAP note"
51
+
52
+ result = mock_generate_soap_note("")
53
+ assert "❌ Please enter some medical notes to process." in result
54
+
55
+ def test_generate_soap_note_whitespace_only(self):
56
+ """Test SOAP generation with whitespace only"""
57
+ def mock_generate_soap_note(text, include_timestamp=True):
58
+ if not text.strip():
59
+ return "❌ Please enter some medical notes to process."
60
+ return "Valid SOAP note"
61
+
62
+ result = mock_generate_soap_note(" \n\t ")
63
+ assert "❌ Please enter some medical notes to process." in result
64
+
65
+ def test_soap_note_structure(self, sample_medical_text):
66
+ """Test that generated SOAP notes have proper structure"""
67
+ def mock_generate_soap_note(text, include_timestamp=True):
68
+ return """
69
+ SUBJECTIVE:
70
+ Patient reports chest pain.
71
+
72
+ OBJECTIVE:
73
+ Vital signs stable.
74
+
75
+ ASSESSMENT:
76
+ Chest pain evaluation.
77
+
78
+ PLAN:
79
+ Further testing recommended.
80
+ """
81
+
82
+ result = mock_generate_soap_note(sample_medical_text)
83
+ lines = result.strip().split('\n')
84
+
85
+ # Check that SOAP sections are present and in order
86
+ soap_sections = []
87
+ for line in lines:
88
+ if line.strip().endswith(':') and line.strip() in ['SUBJECTIVE:', 'OBJECTIVE:', 'ASSESSMENT:', 'PLAN:']:
89
+ soap_sections.append(line.strip())
90
+
91
+ expected_order = ['SUBJECTIVE:', 'OBJECTIVE:', 'ASSESSMENT:', 'PLAN:']
92
+ assert soap_sections == expected_order