Add medicine management functionality with UI and data handling
- Implemented MedicineManagementWindow for adding, editing, and removing medicines. - Created MedicineManager to handle medicine configurations, including loading and saving to JSON. - Updated UIManager to dynamically generate medicine-related UI components based on the MedicineManager. - Enhanced test suite with mock objects for MedicineManager to ensure proper functionality in DataManager tests. - Added validation for medicine input fields in the UI. - Introduced default medicine configurations for initial setup.
This commit is contained in:
@@ -8,6 +8,12 @@ import pandas as pd
|
||||
from unittest.mock import Mock
|
||||
import logging
|
||||
|
||||
# Add src to path for imports
|
||||
import sys
|
||||
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', 'src'))
|
||||
|
||||
from src.medicine_manager import MedicineManager, Medicine
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def temp_csv_file():
|
||||
@@ -20,6 +26,64 @@ def temp_csv_file():
|
||||
os.unlink(path)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def mock_medicine_manager():
|
||||
"""Create a mock medicine manager with default medicines for testing."""
|
||||
mock_manager = Mock(spec=MedicineManager)
|
||||
|
||||
# Default medicines matching the original system
|
||||
default_medicines = {
|
||||
"bupropion": Medicine(
|
||||
key="bupropion",
|
||||
display_name="Bupropion",
|
||||
dosage_info="150/300 mg",
|
||||
quick_doses=["150", "300"],
|
||||
color="#FF6B6B",
|
||||
default_enabled=True
|
||||
),
|
||||
"hydroxyzine": Medicine(
|
||||
key="hydroxyzine",
|
||||
display_name="Hydroxyzine",
|
||||
dosage_info="25 mg",
|
||||
quick_doses=["25", "50"],
|
||||
color="#4ECDC4",
|
||||
default_enabled=False
|
||||
),
|
||||
"gabapentin": Medicine(
|
||||
key="gabapentin",
|
||||
display_name="Gabapentin",
|
||||
dosage_info="100 mg",
|
||||
quick_doses=["100", "300", "600"],
|
||||
color="#45B7D1",
|
||||
default_enabled=False
|
||||
),
|
||||
"propranolol": Medicine(
|
||||
key="propranolol",
|
||||
display_name="Propranolol",
|
||||
dosage_info="10 mg",
|
||||
quick_doses=["10", "20", "40"],
|
||||
color="#96CEB4",
|
||||
default_enabled=True
|
||||
),
|
||||
"quetiapine": Medicine(
|
||||
key="quetiapine",
|
||||
display_name="Quetiapine",
|
||||
dosage_info="25 mg",
|
||||
quick_doses=["25", "50", "100"],
|
||||
color="#FFEAA7",
|
||||
default_enabled=False
|
||||
)
|
||||
}
|
||||
|
||||
mock_manager.get_medicine_keys.return_value = list(default_medicines.keys())
|
||||
mock_manager.get_all_medicines.return_value = default_medicines
|
||||
mock_manager.get_medicine.side_effect = lambda key: default_medicines.get(key)
|
||||
mock_manager.get_graph_colors.return_value = {k: v.color for k, v in default_medicines.items()}
|
||||
mock_manager.get_quick_doses.side_effect = lambda key: default_medicines.get(key, Medicine("", "", "", [], "", False)).quick_doses
|
||||
|
||||
return mock_manager
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def sample_data():
|
||||
"""Sample data for testing."""
|
||||
|
||||
Reference in New Issue
Block a user