Files
thechart/scripts/add_medicine_example.py
William Valentin d7d4b332d4 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.
2025-07-30 16:01:02 -07:00

67 lines
2.1 KiB
Python

#!/usr/bin/env python3
"""
Example script showing how to add a new medicine programmatically.
This demonstrates the modular medicine system.
"""
import os
import sys
# Add src to path
sys.path.insert(0, os.path.join(os.path.dirname(__file__), "src"))
from init import logger
from medicine_manager import Medicine, MedicineManager
def add_example_medicine():
"""Add an example medicine to demonstrate the system."""
print("🔧 Adding a new medicine example...")
# Initialize medicine manager
medicine_manager = MedicineManager(logger=logger)
# Display current medicines
print("\nCurrent medicines:")
for _, medicine in medicine_manager.get_all_medicines().items():
print(f" - {medicine.display_name} ({medicine.dosage_info})")
# Add a new medicine
new_medicine = Medicine(
key="lorazepam",
display_name="Lorazepam",
dosage_info="0.5mg",
quick_doses=["0.5", "1", "2"],
color="#8E44AD",
default_enabled=False,
)
if medicine_manager.add_medicine(new_medicine):
print(f"\n✅ Successfully added {new_medicine.display_name}!")
print("\nUpdated medicines:")
for _, medicine in medicine_manager.get_all_medicines().items():
status = "🟢" if medicine.default_enabled else ""
print(f" {status} {medicine.display_name} ({medicine.dosage_info})")
print("\n📋 The medicine configuration has been saved to medicines.json")
print("📱 Restart the application to see the new medicine in the UI")
print("🎨 The new medicine will appear in:")
print(" - Input form checkboxes")
print(" - Data table columns")
print(" - Graph toggle controls")
print(" - CSV file headers")
# Optionally remove it for demo purposes
response = input("\nRemove the example medicine? (y/n): ").lower().strip()
if response == "y":
medicine_manager.remove_medicine("lorazepam")
print("🗑️ Example medicine removed.")
else:
print("❌ Failed to add medicine (it may already exist)")
if __name__ == "__main__":
add_example_medicine()