185 lines
5.4 KiB
Python
185 lines
5.4 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Test script to isolate and verify the multiple dose saving issue.
|
|
"""
|
|
|
|
import os
|
|
import sys
|
|
import tkinter as tk
|
|
|
|
# Add the src directory to the path
|
|
sys.path.insert(0, os.path.join(os.path.dirname(__file__), "src"))
|
|
|
|
import logging
|
|
|
|
from ui_manager import UIManager
|
|
|
|
|
|
def test_parse_dose_text():
|
|
"""Test the _parse_dose_text function directly."""
|
|
print("🧪 Testing _parse_dose_text function...")
|
|
|
|
# Create a minimal UIManager for testing
|
|
root = tk.Tk()
|
|
root.withdraw()
|
|
logger = logging.getLogger("test")
|
|
ui_manager = UIManager(root, logger)
|
|
|
|
# Test data: multiple doses in the format shown in the text widget
|
|
test_text = """21:30: 150mg
|
|
21:35: 300mg
|
|
21:40: 75mg"""
|
|
|
|
test_date = "07/29/2025"
|
|
|
|
result = ui_manager._parse_dose_text(test_text, test_date)
|
|
print(f"Input text:\n{test_text}")
|
|
print(f"Date: {test_date}")
|
|
print(f"Parsed result: {result}")
|
|
|
|
# Count how many doses were parsed
|
|
if result:
|
|
dose_count = len(result.split("|"))
|
|
print(f"Number of doses parsed: {dose_count}")
|
|
|
|
if dose_count == 3:
|
|
print("✅ _parse_dose_text is working correctly!")
|
|
return True
|
|
else:
|
|
print("❌ _parse_dose_text is not parsing all doses!")
|
|
return False
|
|
else:
|
|
print("❌ _parse_dose_text returned empty result!")
|
|
return False
|
|
|
|
root.destroy()
|
|
|
|
|
|
def test_punch_button_accumulation():
|
|
"""Test that punch buttons properly accumulate in the text widget."""
|
|
print("\n🧪 Testing punch button dose accumulation...")
|
|
|
|
root = tk.Tk()
|
|
root.title("Punch Button Test")
|
|
root.geometry("400x300")
|
|
|
|
logger = logging.getLogger("test")
|
|
ui_manager = UIManager(root, logger)
|
|
|
|
# Sample values for creating edit window
|
|
sample_values = (
|
|
"07/29/2025", # date
|
|
5,
|
|
3,
|
|
7,
|
|
6, # symptoms
|
|
1,
|
|
"", # bupropion, bupropion_doses
|
|
0,
|
|
"", # hydroxyzine, hydroxyzine_doses
|
|
0,
|
|
"", # gabapentin, gabapentin_doses
|
|
0,
|
|
"", # propranolol, propranolol_doses
|
|
"Test entry", # note
|
|
)
|
|
|
|
save_called = False
|
|
saved_dose_data = None
|
|
|
|
def test_save(*args):
|
|
nonlocal save_called, saved_dose_data
|
|
save_called = True
|
|
saved_dose_data = args[-1] if args else None
|
|
|
|
print("\n💾 Save callback triggered")
|
|
if saved_dose_data:
|
|
print("Dose data received:")
|
|
for med, doses in saved_dose_data.items():
|
|
if doses:
|
|
dose_count = len(doses.split("|")) if "|" in doses else 1
|
|
print(f" {med}: {dose_count} dose(s) - {doses}")
|
|
else:
|
|
print(f" {med}: No doses")
|
|
|
|
# Close window
|
|
if args and hasattr(args[0], "destroy"):
|
|
args[0].destroy()
|
|
|
|
callbacks = {"save": test_save, "delete": lambda x: x.destroy()}
|
|
|
|
try:
|
|
edit_window = ui_manager.create_edit_window(sample_values, callbacks)
|
|
edit_window.lift()
|
|
edit_window.focus_force()
|
|
|
|
print("\n📝 TEST INSTRUCTIONS:")
|
|
print("1. Select ANY medicine (e.g., Bupropion)")
|
|
print("2. Enter '100mg' in the dose field")
|
|
print("3. Click 'Take [Medicine]' button")
|
|
print("4. Enter '200mg' in the dose field")
|
|
print("5. Click 'Take [Medicine]' button again")
|
|
print("6. Enter '300mg' in the dose field")
|
|
print("7. Click 'Take [Medicine]' button a third time")
|
|
print("8. Verify you see THREE entries in the text area")
|
|
print("9. Click 'Save'")
|
|
print("\n⏳ Please perform the test...")
|
|
|
|
edit_window.wait_window()
|
|
|
|
if save_called and saved_dose_data:
|
|
# Check if any medicine has multiple doses
|
|
multiple_found = False
|
|
for med, doses in saved_dose_data.items():
|
|
if doses and "|" in doses:
|
|
dose_count = len(doses.split("|"))
|
|
if dose_count > 1:
|
|
print(f"✅ Multiple doses found for {med}: {dose_count} doses")
|
|
multiple_found = True
|
|
|
|
if multiple_found:
|
|
print("✅ Multiple dose accumulation is working!")
|
|
return True
|
|
else:
|
|
print("❌ No multiple doses found in save data")
|
|
return False
|
|
else:
|
|
print("❌ Save was not called or no dose data received")
|
|
return False
|
|
|
|
except Exception as e:
|
|
print(f"❌ Error during test: {e}")
|
|
import traceback
|
|
|
|
traceback.print_exc()
|
|
return False
|
|
finally:
|
|
root.destroy()
|
|
|
|
|
|
def main():
|
|
print("🔬 Multiple Dose Issue Investigation")
|
|
print("=" * 50)
|
|
|
|
os.chdir("/home/will/Code/thechart")
|
|
|
|
# Test 1: Parse function
|
|
parse_test = test_parse_dose_text()
|
|
|
|
# Test 2: UI workflow
|
|
ui_test = test_punch_button_accumulation()
|
|
|
|
print("\n📊 Results:")
|
|
print(f" Parse function test: {'✅ PASS' if parse_test else '❌ FAIL'}")
|
|
print(f" UI workflow test: {'✅ PASS' if ui_test else '❌ FAIL'}")
|
|
|
|
if parse_test and ui_test:
|
|
print("\n🎯 Multiple dose functionality appears to be working correctly")
|
|
print("If you're still experiencing issues, please describe the exact steps")
|
|
else:
|
|
print("\n🚨 Issues found with multiple dose functionality")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|