sonuprasad23 commited on
Commit
3453005
·
1 Parent(s): 328cc17

Almost Done

Browse files
Files changed (1) hide show
  1. worker.py +11 -24
worker.py CHANGED
@@ -11,7 +11,7 @@ from selenium.webdriver.common.by import By
11
  from selenium.webdriver.common.keys import Keys
12
  from selenium.webdriver.support.ui import WebDriverWait
13
  from selenium.webdriver.support import expected_conditions as EC
14
- from selenium.common.exceptions import TimeoutException
15
 
16
  class QuantumBot:
17
  def __init__(self, socketio, app, logger):
@@ -24,7 +24,6 @@ class QuantumBot:
24
  self.logger.info("Attempting to kill any lingering chromium processes...")
25
  subprocess.run(['pkill', '-f', 'chromium'], check=True, timeout=5)
26
  time.sleep(1)
27
- self.logger.info("Lingering processes terminated.")
28
  except Exception as e:
29
  self.logger.warning(f"Could not kill chrome processes (this is often normal): {e}")
30
 
@@ -141,32 +140,20 @@ class QuantumBot:
141
  try:
142
  self.micro_status(f"Searching for '{patient_name}'...")
143
  search_box = WebDriverWait(self.driver, self.DEFAULT_TIMEOUT).until(EC.element_to_be_clickable((By.XPATH, "//input[@placeholder='Search']")))
144
-
145
- # --- Definitive Search Fix ---
146
- # 1. Get a reference to the current first row of the table.
147
- try:
148
- old_first_row = self.driver.find_element(By.XPATH, "//tbody/tr[1]")
149
- except NoSuchElementException:
150
- old_first_row = None # Handle case where table is initially empty
151
-
152
- # 2. Type the search text.
153
  search_box.click(); time.sleep(0.5); search_box.clear(); time.sleep(0.5)
154
  search_box.send_keys(patient_name)
 
155
 
156
- # 3. Wait for the old row to disappear (become stale). This is the key.
157
- if old_first_row:
158
- self.micro_status("Waiting for search results to update...")
159
- WebDriverWait(self.driver, 15).until(EC.staleness_of(old_first_row))
160
- else:
161
- time.sleep(2) # If no old row, just pause briefly for results to appear
 
 
 
162
 
163
- # 4. Now, confidently wait for the new row to appear.
164
- self.micro_status("Waiting for new search result row to appear...")
165
- new_row_xpath = f"//tr[contains(., \"{patient_name}\")]"
166
- WebDriverWait(self.driver, 15).until(EC.presence_of_element_located((By.XPATH, new_row_xpath)))
167
-
168
- self.micro_status("Opening transaction details...")
169
- WebDriverWait(self.driver, self.DEFAULT_TIMEOUT).until(EC.element_to_be_clickable((By.XPATH, f"{new_row_xpath}//button[@data-v-b6b33fa0]"))).click()
170
  WebDriverWait(self.driver, self.DEFAULT_TIMEOUT).until(EC.element_to_be_clickable((By.LINK_TEXT, "Transaction Detail"))).click()
171
  self._wait_for_page_load()
172
  self.micro_status("Adding to Vault...")
 
11
  from selenium.webdriver.common.keys import Keys
12
  from selenium.webdriver.support.ui import WebDriverWait
13
  from selenium.webdriver.support import expected_conditions as EC
14
+ from selenium.common.exceptions import TimeoutException, NoSuchElementException
15
 
16
  class QuantumBot:
17
  def __init__(self, socketio, app, logger):
 
24
  self.logger.info("Attempting to kill any lingering chromium processes...")
25
  subprocess.run(['pkill', '-f', 'chromium'], check=True, timeout=5)
26
  time.sleep(1)
 
27
  except Exception as e:
28
  self.logger.warning(f"Could not kill chrome processes (this is often normal): {e}")
29
 
 
140
  try:
141
  self.micro_status(f"Searching for '{patient_name}'...")
142
  search_box = WebDriverWait(self.driver, self.DEFAULT_TIMEOUT).until(EC.element_to_be_clickable((By.XPATH, "//input[@placeholder='Search']")))
 
 
 
 
 
 
 
 
 
143
  search_box.click(); time.sleep(0.5); search_box.clear(); time.sleep(0.5)
144
  search_box.send_keys(patient_name)
145
+ self._wait_for_page_load()
146
 
147
+ try:
148
+ self.micro_status("Verifying search result...")
149
+ row_xpath = f"//tr[contains(., \"{patient_name}\")]"
150
+ WebDriverWait(self.driver, 10).until(EC.presence_of_element_located((By.XPATH, row_xpath)))
151
+ self.micro_status("Patient found. Opening transaction details...")
152
+ WebDriverWait(self.driver, self.DEFAULT_TIMEOUT).until(EC.element_to_be_clickable((By.XPATH, f"{row_xpath}//button[@data-v-b6b33fa0]"))).click()
153
+ except TimeoutException:
154
+ self.micro_status(f"Patient '{patient_name}' not found in search results.")
155
+ return 'Not Found'
156
 
 
 
 
 
 
 
 
157
  WebDriverWait(self.driver, self.DEFAULT_TIMEOUT).until(EC.element_to_be_clickable((By.LINK_TEXT, "Transaction Detail"))).click()
158
  self._wait_for_page_load()
159
  self.micro_status("Adding to Vault...")