#!/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()