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

@@ -53,32 +53,15 @@ async function processBcbsMaResult(
let createdPdfFileId: number | null = null; let createdPdfFileId: number | null = null;
try { try {
// Resolve patient name // Prefer names extracted from the BCBS MA results page (Demographic Information section)
const rawName = const firstName: string =
typeof seleniumResult?.patientName === "string" ? seleniumResult.patientName.trim() : null; (typeof seleniumResult?.firstName === "string" && seleniumResult.firstName.trim())
? seleniumResult.firstName.trim()
let firstName: string; : (formFirstName ?? "");
let lastName: string; const lastName: string =
(typeof seleniumResult?.lastName === "string" && seleniumResult.lastName.trim())
if (rawName) { ? seleniumResult.lastName.trim()
if (rawName.includes(",")) { : (formLastName ?? "");
const [last, ...firstParts] = rawName.split(",").map((s: string) => s.trim());
lastName = last || formLastName || "";
firstName = firstParts.join(" ").trim() || formFirstName || "";
} else {
const parsed = splitName(rawName);
if (!parsed.lastName) {
lastName = parsed.firstName || formLastName || "";
firstName = formFirstName || "";
} else {
firstName = parsed.firstName || formFirstName || "";
lastName = parsed.lastName || formLastName || "";
}
}
} else {
firstName = formFirstName ?? "";
lastName = formLastName ?? "";
}
await createOrUpdatePatientByInsuranceId({ insuranceId, firstName, lastName, dob: formDob, userId }); await createOrUpdatePatientByInsuranceId({ insuranceId, firstName, lastName, dob: formDob, userId });

View File

@@ -265,7 +265,7 @@ export function BcbsMaEligibilityButton({
<> <>
<Button <Button
className="w-full" className="w-full"
variant="outline" variant="default"
disabled={isFormIncomplete || isStarting} disabled={isFormIncomplete || isStarting}
onClick={handleStart} onClick={handleStart}
> >

View File

@@ -307,8 +307,16 @@ class AutomationBCBSMAEligibilityCheck:
7. Click Submit → wait for results page → PDF 7. Click Submit → wait for results page → PDF
""" """
from selenium.webdriver.support.ui import Select from selenium.webdriver.support.ui import Select
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.keys import Keys
try: 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...") print("[BCBS MA step2] Filling Eligibility Identifier form...")
# 1. Enter provider NPI # 1. Enter provider NPI
@@ -362,9 +370,6 @@ class AutomationBCBSMAEligibilityCheck:
print(f"[BCBS MA step2] Member ID entered: {self.member_id}") print(f"[BCBS MA step2] Member ID entered: {self.member_id}")
# 6. Date of birth — id="subscriberDateOfBirth", placeholder="mm/dd/yyyy" # 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_formatted = self._dob_mmddyyyy()
dob_input = self._wait(10).until( dob_input = self._wait(10).until(
EC.presence_of_element_located((By.ID, "subscriberDateOfBirth")) EC.presence_of_element_located((By.ID, "subscriberDateOfBirth"))
@@ -409,7 +414,7 @@ class AutomationBCBSMAEligibilityCheck:
except Exception as e: except Exception as e:
print(f"[BCBS MA step2] Expand All not found or failed: {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 page_text = self.driver.find_element(By.TAG_NAME, "body").text
text_lower = page_text.lower() text_lower = page_text.lower()
if "not eligible" in text_lower or "inactive" in text_lower or "terminated" in 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: else:
eligibility = "Unknown" eligibility = "Unknown"
patient_name = f"{self.first_name} {self.last_name}".strip() # Extract first/last name from DOM — scope to "Patient Information" column only
print(f"[BCBS MA step2] Eligibility: {eligibility}") # 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 the results page via CDP
pdf_base64 = "" pdf_base64 = ""
@@ -447,10 +487,16 @@ class AutomationBCBSMAEligibilityCheck:
except Exception as e: except Exception as e:
print(f"[BCBS MA step2] PDF generation failed: {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 { return {
"status": "success", "status": "success",
"eligibility": eligibility, "eligibility": eligibility,
"patientName": patient_name, "patientName": patient_name,
"firstName": first_name,
"lastName": last_name,
"memberId": self.member_id, "memberId": self.member_id,
"insurerName": "BCBS MA", "insurerName": "BCBS MA",
"pdfBase64": pdf_base64, "pdfBase64": pdf_base64,