fix: use rendering provider from claim form for MassHealth dentist search, default to Mary Scannell, select first office option
This commit is contained in:
@@ -89,6 +89,17 @@ class AutomationMassHealthClaimsLogin:
|
||||
print(f"DEBUG: toothNumber = '{self.toothNumber}'")
|
||||
print(f"DEBUG: toothSurface = '{self.toothSurface}'")
|
||||
|
||||
# Extract rendering provider info from npiProvider field
|
||||
self.rendering_provider_name = ""
|
||||
self.rendering_provider_npi = ""
|
||||
if isinstance(data, dict) and isinstance(data.get("claim"), dict):
|
||||
npi_provider = data["claim"].get("npiProvider") or {}
|
||||
self.rendering_provider_name = (npi_provider.get("providerName") or "").strip()
|
||||
self.rendering_provider_npi = (npi_provider.get("npiNumber") or "").strip()
|
||||
|
||||
print(f"DEBUG: rendering_provider_name = '{self.rendering_provider_name}'")
|
||||
print(f"DEBUG: rendering_provider_npi = '{self.rendering_provider_npi}'")
|
||||
|
||||
# Convert dateOfBirth to MMDDYYYY format (if needed later)
|
||||
if self.dateOfBirth:
|
||||
dob_raw = str(self.dateOfBirth).strip()
|
||||
@@ -569,7 +580,7 @@ class AutomationMassHealthClaimsLogin:
|
||||
wait = WebDriverWait(self.driver, 30)
|
||||
|
||||
try:
|
||||
# Step 1: Wait for the office dropdown to be visible and enabled
|
||||
# Wait for the office dropdown to be visible and enabled
|
||||
office_dropdown = wait.until(
|
||||
EC.visibility_of_element_located(
|
||||
(By.XPATH, "//select[@id='selectOffice']")
|
||||
@@ -577,23 +588,41 @@ class AutomationMassHealthClaimsLogin:
|
||||
)
|
||||
time.sleep(1)
|
||||
|
||||
# Step 2: Use Select class to choose Summit Dental Care - Framingham -
|
||||
# Select the first non-placeholder option in the dropdown
|
||||
select = Select(office_dropdown)
|
||||
# Fallback: try by visible text, then by value
|
||||
try:
|
||||
select.select_by_visible_text("Summit Dental Care - Framingham - ")
|
||||
except:
|
||||
select.select_by_value("string:0010a00001XPhhtAAD")
|
||||
options = select.options
|
||||
for opt in options:
|
||||
if opt.get_attribute("value") not in (None, "", "string:") and opt.text.strip():
|
||||
select.select_by_index(options.index(opt))
|
||||
print(f"DEBUG: Selected office option: '{opt.text.strip()}'")
|
||||
break
|
||||
time.sleep(2)
|
||||
|
||||
return "Success"
|
||||
except Exception as e:
|
||||
print(f"Error selecting Summit Dental Care - Framingham office: {e}")
|
||||
print(f"Error selecting service office: {e}")
|
||||
return "ERROR:SELECTION FAILED"
|
||||
|
||||
def select_dentist_gao_kai(self):
|
||||
wait = WebDriverWait(self.driver, 30)
|
||||
|
||||
# Resolve provider name and NPI — fall back to Mary Scannell if not set
|
||||
provider_name = self.rendering_provider_name or "Mary Scannell"
|
||||
provider_npi = self.rendering_provider_npi or ""
|
||||
|
||||
# Convert "First Last" → search by last name, match "Last, First - NPI"
|
||||
parts = provider_name.strip().split()
|
||||
if len(parts) >= 2:
|
||||
last_name = parts[-1]
|
||||
first_names = " ".join(parts[:-1])
|
||||
search_keyword = last_name
|
||||
display_name = f"{last_name}, {first_names} - {provider_npi}"
|
||||
else:
|
||||
search_keyword = provider_name
|
||||
display_name = f"{provider_name} - {provider_npi}"
|
||||
|
||||
print(f"DEBUG: Searching dentist: keyword='{search_keyword}', expected='{display_name}'")
|
||||
|
||||
try:
|
||||
# Step 1: Wait for the dentist input field to be visible and enabled
|
||||
dentist_input = wait.until(
|
||||
@@ -603,37 +632,32 @@ class AutomationMassHealthClaimsLogin:
|
||||
)
|
||||
time.sleep(1)
|
||||
|
||||
# Step 2: Type "Gao" to trigger typeahead
|
||||
# Step 2: Type last name to trigger typeahead
|
||||
dentist_input.clear()
|
||||
dentist_input.send_keys("Gao")
|
||||
dentist_input.send_keys(search_keyword)
|
||||
time.sleep(3) # Wait for typeahead to load
|
||||
|
||||
# Step 3: Wait for the typeahead dropdown to appear and find the specific option
|
||||
# Look for the <a> element with ng-bind-html containing the text
|
||||
option_xpath = "//a[@ng-bind-html and contains(., 'Gao, Kai - 1457649006')]"
|
||||
|
||||
# Step 3: Wait for the typeahead dropdown and find the matching option
|
||||
option_xpath = f"//a[@ng-bind-html and contains(., '{display_name}')]"
|
||||
|
||||
try:
|
||||
# Wait for the option to be clickable
|
||||
option = wait.until(
|
||||
EC.element_to_be_clickable((By.XPATH, option_xpath))
|
||||
)
|
||||
print("DEBUG: Found dentist option, clicking...")
|
||||
|
||||
# Scroll into view and click
|
||||
self.driver.execute_script("arguments[0].scrollIntoView(true);", option)
|
||||
time.sleep(1)
|
||||
option.click()
|
||||
time.sleep(2)
|
||||
|
||||
return "Success"
|
||||
except:
|
||||
# Fallback: Try alternative selectors
|
||||
fallback_selectors = [
|
||||
"//ul[contains(@class,'dropdown-menu')]//a[contains(., 'Gao, Kai - 1457649006')]",
|
||||
"//ul[contains(@class,'dropdown-menu')]//li[contains(., 'Gao, Kai - 1457649006')]",
|
||||
"//div[contains(@class,'typeahead')]//a[contains(., 'Gao, Kai - 1457649006')]",
|
||||
f"//ul[contains(@class,'dropdown-menu')]//a[contains(., '{display_name}')]",
|
||||
f"//ul[contains(@class,'dropdown-menu')]//li[contains(., '{display_name}')]",
|
||||
f"//div[contains(@class,'typeahead')]//a[contains(., '{display_name}')]",
|
||||
]
|
||||
|
||||
|
||||
for selector in fallback_selectors:
|
||||
try:
|
||||
option = wait.until(
|
||||
@@ -647,8 +671,8 @@ class AutomationMassHealthClaimsLogin:
|
||||
return "Success"
|
||||
except:
|
||||
continue
|
||||
|
||||
# If all selectors fail, use Arrow Down + Enter
|
||||
|
||||
# Last resort: Arrow Down + Enter
|
||||
print("DEBUG: Using Arrow Down + Enter fallback")
|
||||
dentist_input.send_keys(Keys.ARROW_DOWN)
|
||||
time.sleep(1)
|
||||
@@ -657,7 +681,7 @@ class AutomationMassHealthClaimsLogin:
|
||||
return "Success"
|
||||
|
||||
except Exception as e:
|
||||
print(f"Error selecting dentist Gao, Kai: {e}")
|
||||
print(f"Error selecting dentist {display_name}: {e}")
|
||||
return "ERROR:SELECTION_FAILED"
|
||||
|
||||
def click_plus_button(self):
|
||||
|
||||
Reference in New Issue
Block a user