84 lines
3.2 KiB
Python
84 lines
3.2 KiB
Python
import pytest
|
|
from app.ai.orchestrator import classify_specialty_from_symptoms, SPECIALTY_RULES
|
|
from app.specialties.registry import SPECIALTIES, CANONICAL_ALIASES, get_specialty_config, validate_specialty_registry
|
|
|
|
|
|
def test_diabetology_detection():
|
|
"""Verify diabetes keywords resolve to canonical code 'diabetology'."""
|
|
phrases = [
|
|
"My sugar level is very high",
|
|
"I have type 2 diabetes",
|
|
"Taking Glycomet 500mg daily",
|
|
"HbA1c report shows 8.1%",
|
|
"High blood sugar after meals",
|
|
"Taking insulin injections",
|
|
]
|
|
for text in phrases:
|
|
res = classify_specialty_from_symptoms(text)
|
|
assert res["code"] == "diabetology", f"Failed for '{text}': got {res['code']}"
|
|
|
|
|
|
def test_mental_health_canonical_code():
|
|
"""Verify mental health symptoms resolve to canonical 'mental_health', not 'psychiatry'."""
|
|
phrases = [
|
|
"Feeling depressed and anxious",
|
|
"Having severe panic attacks and insomnia",
|
|
"மன அழுத்தம் அதிகமாக இருக்கு",
|
|
]
|
|
for text in phrases:
|
|
res = classify_specialty_from_symptoms(text)
|
|
assert res["code"] == "mental_health", f"Failed for '{text}': got {res['code']}"
|
|
|
|
|
|
def test_general_canonical_code():
|
|
"""Verify general symptoms resolve to canonical 'general', not 'general_medicine'."""
|
|
phrases = [
|
|
"I have mild fever and body pain",
|
|
"Feeling weak for 2 days",
|
|
]
|
|
for text in phrases:
|
|
res = classify_specialty_from_symptoms(text)
|
|
assert res["code"] == "general", f"Failed for '{text}': got {res['code']}"
|
|
|
|
|
|
def test_all_specialties_have_configs():
|
|
"""Verify all 9 canonical specialties have dedicated, non-fallback configuration files."""
|
|
canonical_codes = [
|
|
"general",
|
|
"mental_health",
|
|
"diabetology",
|
|
"cardiology",
|
|
"dermatology",
|
|
"neurology",
|
|
"orthopedics",
|
|
"gastroenterology",
|
|
"pulmonology",
|
|
]
|
|
for code in canonical_codes:
|
|
assert code in SPECIALTIES, f"Missing specialty config in registry for {code}"
|
|
config = get_specialty_config(code)
|
|
assert config["code"] == code, f"Specialty {code} resolved to fallback code {config['code']}"
|
|
assert len(config.get("focus_areas", [])) > 0
|
|
|
|
|
|
def test_no_supported_specialty_falls_back_to_general():
|
|
"""Verify that every classifier output is registered and does not fall back to general."""
|
|
validation = validate_specialty_registry()
|
|
assert validation["valid"] is True
|
|
assert validation["registered_count"] >= 9
|
|
assert len(validation["missing_configs"]) == 0
|
|
|
|
|
|
def test_registry_classifier_consistency():
|
|
"""Verify all classifier rule codes match registered specialty codes."""
|
|
registered = set(SPECIALTIES.keys())
|
|
for rule in SPECIALTY_RULES:
|
|
code = rule["code"]
|
|
assert code in registered, f"Classifier rule code '{code}' is not in registered SPECIALTIES"
|
|
|
|
|
|
def test_alias_compatibility():
|
|
"""Verify legacy aliases convert to canonical configs cleanly."""
|
|
assert get_specialty_config("general_medicine")["code"] == "general"
|
|
assert get_specialty_config("psychiatry")["code"] == "mental_health"
|