fix: BCBS MA eligibility — name extraction, tab switching, DOB input, button color

- Extract patient first/last name from Patient Information DOM section
  (scoped to avoid duplicate Subscriber Information column values)
- Switch to latest tab at start of step2 (Eligibility Identifier opens in new tab)
- DOB: double-click + ActionChains.send_keys (no pyperclip, avoids Chrome crash)
- BCBS MA button changed to variant="default" to match nearby buttons
- Backend processor uses extracted names from selenium result

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
ff
2026-06-01 01:18:20 -04:00
parent e644d21cee
commit 87d7ce9ed9
3 changed files with 62 additions and 33 deletions

View File

@@ -307,8 +307,16 @@ class AutomationBCBSMAEligibilityCheck:
7. Click Submit → wait for results page → PDF
"""
from selenium.webdriver.support.ui import Select
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.keys import Keys
try:
# New Eligibility Request opens in a new tab — switch to the latest one
self._wait(10).until(lambda d: len(d.window_handles) >= 2)
self.driver.switch_to.window(self.driver.window_handles[-1])
print(f"[BCBS MA step2] Switched to tab ({len(self.driver.window_handles)} open): {self.driver.current_url[:70]}")
time.sleep(2)
print("[BCBS MA step2] Filling Eligibility Identifier form...")
# 1. Enter provider NPI
@@ -362,9 +370,6 @@ class AutomationBCBSMAEligibilityCheck:
print(f"[BCBS MA step2] Member ID entered: {self.member_id}")
# 6. Date of birth — id="subscriberDateOfBirth", placeholder="mm/dd/yyyy"
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.keys import Keys
dob_formatted = self._dob_mmddyyyy()
dob_input = self._wait(10).until(
EC.presence_of_element_located((By.ID, "subscriberDateOfBirth"))
@@ -409,7 +414,7 @@ class AutomationBCBSMAEligibilityCheck:
except Exception as e:
print(f"[BCBS MA step2] Expand All not found or failed: {e}")
# Extract eligibility status
# Extract eligibility status and patient name from live page text
page_text = self.driver.find_element(By.TAG_NAME, "body").text
text_lower = page_text.lower()
if "not eligible" in text_lower or "inactive" in text_lower or "terminated" in text_lower:
@@ -419,8 +424,43 @@ class AutomationBCBSMAEligibilityCheck:
else:
eligibility = "Unknown"
patient_name = f"{self.first_name} {self.last_name}".strip()
print(f"[BCBS MA step2] Eligibility: {eligibility}")
# Extract first/last name from DOM — scope to "Patient Information" column only
# to avoid picking up the duplicate values in the Subscriber Information column.
first_name = self.first_name
last_name = self.last_name
try:
# Find the "Patient Information" header, then search within its parent container
patient_section = self.driver.find_element(By.XPATH,
"//*[normalize-space(text())='Patient Information']/ancestor::*[3]"
)
section_text = patient_section.text
print(f"[BCBS MA step2] Patient section text:\n{section_text[:300]}")
lines = section_text.split("\n")
capturing_last = False
for line in lines:
stripped = line.strip()
if "First Name:" in stripped and not first_name:
val = stripped.split("First Name:", 1)[1].strip()
val = val.split("Middle Name:")[0].split("Last Name:")[0].strip()
if val:
first_name = val
elif "Last Name:" in stripped and not last_name:
val = stripped.split("Last Name:", 1)[1].strip()
val = val.split("SSN:")[0].split("Date of Birth:")[0].split("Member ID:")[0].strip()
if val:
last_name = val
capturing_last = True
elif capturing_last:
if stripped and ":" not in stripped and stripped == stripped.upper():
last_name += " " + stripped
capturing_last = False
if first_name and last_name and not capturing_last:
break
print(f"[BCBS MA step2] Extracted — First: '{first_name}', Last: '{last_name}'")
except Exception as e:
print(f"[BCBS MA step2] Name extraction failed: {e}")
# PDF the results page via CDP
pdf_base64 = ""
@@ -447,10 +487,16 @@ class AutomationBCBSMAEligibilityCheck:
except Exception as e:
print(f"[BCBS MA step2] PDF generation failed: {e}")
patient_name = f"{first_name} {last_name}".strip()
print(f"[BCBS MA step2] Eligibility: {eligibility}, Patient: {patient_name}")
return {
"status": "success",
"eligibility": eligibility,
"patientName": patient_name,
"firstName": first_name,
"lastName": last_name,
"memberId": self.member_id,
"insurerName": "BCBS MA",
"pdfBase64": pdf_base64,