"""Tests for patient data loader."""
import pytest
from src.epic_mcp.data import PatientDataLoader
@pytest.fixture
def loader():
"""Create a PatientDataLoader instance."""
return PatientDataLoader()
class TestPatientDataLoader:
"""Test PatientDataLoader functionality."""
def test_load_yaml_and_parse_types(self, loader):
"""Test YAML loading and Pydantic type parsing."""
allergies = loader.get_allergies("patient_001")
assert len(allergies) == 2
assert allergies[0].allergen == "Penicillin"
def test_medication_filtering(self, loader):
"""Test filtering medications by status."""
active_meds = loader.get_medications("patient_001", status="active")
assert all(m.status == "active" for m in active_meds)
def test_clinical_notes_with_attachments(self, loader):
"""Test notes include attachment metadata."""
notes = loader.get_clinical_notes("patient_001")
notes_with_attachments = [n for n in notes if len(n.attachments) > 0]
assert len(notes_with_attachments) >= 2
def test_attachment_loading(self, loader):
"""Test loading attachment content from file."""
content = loader.get_attachment("patient_001", "att-1")
assert content is not None
assert "SPRINGFIELD MEDICAL LABORATORY" in content
def test_nonexistent_patient(self, loader):
"""Test querying non-existent patient returns empty/None."""
assert not loader.patient_exists("patient_999")
assert loader.get_demographics("patient_999") is None
assert len(loader.get_allergies("patient_999")) == 0