SmartHeal commited on
Commit
a10fc7c
·
verified ·
1 Parent(s): 38f2e7c

Update src/ui_components_original.py

Browse files
Files changed (1) hide show
  1. src/ui_components_original.py +50 -20
src/ui_components_original.py CHANGED
@@ -403,8 +403,8 @@ button.gr-button:hover, button.gr-button-primary:hover {
403
 
404
  def _refresh_patient_dropdown(user_id: int):
405
  """Query patient's list and prepare dropdown choices."""
406
- self._patient_choices = []
407
- self._patient_map = {}
408
  try:
409
  rows = self.patient_history_manager.get_patient_list(user_id) or []
410
  # label starts with id -> stable parse
@@ -482,6 +482,34 @@ button.gr-button:hover, button.gr-button-primary:hover {
482
  out.append(r)
483
  return out
484
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
485
  # ----------------------- Blocks UI -----------------------
486
 
487
  with gr.Blocks(css=self.get_custom_css(), title="SmartHeal - AI Wound Care Assistant") as app:
@@ -614,25 +642,26 @@ button.gr-button:hover, button.gr-button-primary:hover {
614
 
615
  def handle_signup(username, email, password, name, role, org_name_v, phone_v, cc_v, dept_v, loc_v, org_dropdown):
616
  try:
617
- if role == "organization":
618
- org_data = {
619
- 'org_name': org_name_v,
620
- 'email': email,
621
- 'phone': phone_v,
622
- 'country_code': cc_v,
623
- 'department': dept_v,
624
- 'location': loc_v
625
- }
626
- org_id = self.database_manager.create_organization(org_data)
627
- else:
628
- # For now pick first org (or default)
629
- org_id = 1
 
 
 
 
 
 
630
 
631
- user_data = {
632
- 'username': username, 'email': email, 'password': password,
633
- 'name': name, 'role': role, 'org_id': org_id
634
- }
635
- ok = self.auth_manager.create_user(user_data)
636
  if ok:
637
  return "<div class='status-success'>✅ Account created. Please log in.</div>"
638
  return "<div class='status-error'>❌ Could not create account. Username/email may exist.</div>"
@@ -890,6 +919,7 @@ button.gr-button:hover, button.gr-button-primary:hover {
890
 
891
  return app
892
 
 
893
 
894
  def _format_comprehensive_analysis_results(self, analysis_result, image_url=None, questionnaire_data=None):
895
  """Format comprehensive analysis results with all visualization images from AIProcessor."""
 
403
 
404
  def _refresh_patient_dropdown(user_id: int):
405
  """Query patient's list and prepare dropdown choices."""
406
+ self._patient_choices.clear()
407
+ self._patient_map.clear()
408
  try:
409
  rows = self.patient_history_manager.get_patient_list(user_id) or []
410
  # label starts with id -> stable parse
 
482
  out.append(r)
483
  return out
484
 
485
+ def _resolve_org_id_from_dropdown(label: str) -> Optional[int]:
486
+ """
487
+ Dropdown items look like: 'Org Name - Location'.
488
+ Try to resolve to organizations.id.
489
+ """
490
+ if not label:
491
+ return None
492
+ try:
493
+ if " - " in label:
494
+ org_name, location = label.split(" - ", 1)
495
+ row = self.database_manager.execute_query_one(
496
+ "SELECT id FROM organizations WHERE name=%s AND location=%s ORDER BY id DESC LIMIT 1",
497
+ (org_name.strip(), location.strip())
498
+ )
499
+ if row and "id" in row:
500
+ return int(row["id"])
501
+ else:
502
+ # fallback: match by name only
503
+ row = self.database_manager.execute_query_one(
504
+ "SELECT id FROM organizations WHERE name=%s ORDER BY id DESC LIMIT 1",
505
+ (label.strip(),)
506
+ )
507
+ if row and "id" in row:
508
+ return int(row["id"])
509
+ except Exception as e:
510
+ logging.error(f"resolve org id error: {e}")
511
+ return None
512
+
513
  # ----------------------- Blocks UI -----------------------
514
 
515
  with gr.Blocks(css=self.get_custom_css(), title="SmartHeal - AI Wound Care Assistant") as app:
 
642
 
643
  def handle_signup(username, email, password, name, role, org_name_v, phone_v, cc_v, dept_v, loc_v, org_dropdown):
644
  try:
645
+ # Resolve org_id for practitioner (based on dropdown selection)
646
+ organization_id = None
647
+ if role == "practitioner":
648
+ organization_id = _resolve_org_id_from_dropdown(org_dropdown)
649
+
650
+ # Create user using AuthManager's signature (it will handle org creation if role=='organization')
651
+ ok = self.auth_manager.create_user(
652
+ username=username,
653
+ email=email,
654
+ password=password,
655
+ name=name,
656
+ role=role,
657
+ org_name=(org_name_v or name) if role == "organization" else "",
658
+ phone=phone_v if role == "organization" else "",
659
+ country_code=cc_v if role == "organization" else "",
660
+ department=dept_v if role == "organization" else "",
661
+ location=loc_v if role == "organization" else "",
662
+ organization_id=organization_id
663
+ )
664
 
 
 
 
 
 
665
  if ok:
666
  return "<div class='status-success'>✅ Account created. Please log in.</div>"
667
  return "<div class='status-error'>❌ Could not create account. Username/email may exist.</div>"
 
919
 
920
  return app
921
 
922
+
923
 
924
  def _format_comprehensive_analysis_results(self, analysis_result, image_url=None, questionnaire_data=None):
925
  """Format comprehensive analysis results with all visualization images from AIProcessor."""