File size: 2,624 Bytes
56edde7
 
a8f12f6
56edde7
 
 
 
a8f12f6
56edde7
a8f12f6
56edde7
 
 
 
 
 
 
a8f12f6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
fd20bd2
 
a8f12f6
 
fd20bd2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a8f12f6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from fastapi.testclient import TestClient
from src.main import app
from io import BytesIO

client = TestClient(app)

def test_coding_endpoint():
    """Test existing text input endpoint"""
    provider_notes = {
        "provider_notes": "Patient has a fever and cough."
    }
    
    response = client.post("/api/coding", json=provider_notes)
    
    assert response.status_code == 200
    data = response.json()
    
    assert "cpt_codes" in data
    assert "icd_codes" in data
    assert isinstance(data["cpt_codes"], list)
    assert isinstance(data["icd_codes"], list)


def test_file_upload_endpoint():
    """Test new file upload endpoint"""
    file_content = b"Patient John Doe presents with acute bronchitis. Cough for 5 days, productive with yellow sputum. Lung exam reveals diffuse wheezing."
    
    files = {
        "file": ("provider_notes.txt", BytesIO(file_content), "text/plain")
    }
    
    response = client.post("/api/upload-file", files=files)
    
    assert response.status_code == 200
    data = response.json()
    
    assert data["success"] is True
    assert data["filename"] == "provider_notes.txt"
    assert data["extracted_text_length"] > 0
    assert "pii_removed" in data
    assert "pii_count" in data
    assert "cpt_codes" in data
    assert "icd_codes" in data


def test_file_upload_with_pii():
    """Test file upload with PII - should be removed"""
    file_content = b"""
    Patient: John Doe
    DOB: 01/15/1980
    Phone: 555-123-4567
    Address: 123 Main St, New York, NY
    
    Chief Complaint: Chest pain
    History: Patient presents with acute chest pain...
    """
    
    files = {
        "file": ("notes_with_pii.txt", BytesIO(file_content), "text/plain")
    }
    
    response = client.post("/api/upload-file", files=files)
    
    assert response.status_code == 200
    data = response.json()
    
    # PII should be detected and removed
    assert data["pii_removed"] is True
    assert data["pii_count"] > 0


def test_file_upload_invalid_extension():
    """Test file upload with invalid file type"""
    file_content = b"Some content"
    
    files = {
        "file": ("document.pdf", BytesIO(file_content), "application/pdf")
    }
    
    response = client.post("/api/upload-file", files=files)
    
    assert response.status_code == 400


def test_file_upload_empty_file():
    """Test file upload with empty file"""
    file_content = b""
    
    files = {
        "file": ("empty.txt", BytesIO(file_content), "text/plain")
    }
    
    response = client.post("/api/upload-file", files=files)
    
    assert response.status_code == 400