fix: MH eligibility selenium integration and patient data extraction

This commit is contained in:
ff
2026-04-14 22:10:19 -04:00
parent f415100cdb
commit 714029df24
12 changed files with 6677 additions and 98 deletions

View File

@@ -162,6 +162,20 @@ class AutomationMassHealthEligibilityCheck:
print(f"Error while step1: {e}")
return "ERROR:STEP1"
def _cell_text(self, cell):
"""Get text from a cell, falling back to JS innerText if .text is empty."""
text = cell.text.strip()
if not text:
try:
text = (self.driver.execute_script("return arguments[0].innerText;", cell) or "").strip()
except Exception:
pass
return text
def _normalize_id(self, s):
"""Strip all non-alphanumeric characters and lowercase for robust ID matching."""
return ''.join(c for c in str(s) if c.isalnum()).lower()
def _extract_data_from_page(self):
wait = WebDriverWait(self.driver, 5)
extracted = {}
@@ -183,19 +197,32 @@ class AutomationMassHealthEligibilityCheck:
for row in eligible_rows:
cells = row.find_elements(By.TAG_NAME, "td")
if len(cells) < 6:
if len(cells) < 3:
continue
member_number = cells[2].text.strip()
member_number = self._cell_text(cells[2])
norm_cell = self._normalize_id(member_number)
norm_self = self._normalize_id(self.memberId)
print(f"[eligible] cells count={len(cells)}, memberId check: '{norm_self}' vs '{norm_cell}' (raw: '{member_number}')")
if len(cells) >= 5:
print(f" cells[3]='{self._cell_text(cells[3])}' cells[4]='{self._cell_text(cells[4])}'", end="")
if len(cells) > 5:
print(f" cells[5]='{self._cell_text(cells[5])}'", end="")
if len(cells) > 6:
print(f" cells[6]='{self._cell_text(cells[6])}'", end="")
print()
if str(self.memberId) in member_number:
full_name = cells[4].text.strip()
plan_name = cells[6].text.strip() if len(cells) > 6 else cells[-1].text.strip()
if norm_self and norm_cell and (norm_self in norm_cell or norm_cell in norm_self):
# name is in cells[4], insurance in cells[6] (fallback to last cell)
full_name = self._cell_text(cells[4]) if len(cells) > 4 else ""
plan_name = self._cell_text(cells[6]) if len(cells) > 6 else (self._cell_text(cells[-1]) if len(cells) > 4 else "")
name_parts = full_name.split()
first_name = name_parts[0] if name_parts else ""
last_name = " ".join(name_parts[1:]) if len(name_parts) > 1 else ""
print(f"[eligible] MATCHED → name='{full_name}' plan='{plan_name}'")
extracted = {
"eligibility": "Y",
"firstName": first_name,
@@ -204,7 +231,7 @@ class AutomationMassHealthEligibilityCheck:
}
return extracted
ineligible_rows = self.driver.find_elements(
By.XPATH,
"//h4[text()='Ineligible']/following::table[1]/tbody/tr"
@@ -214,19 +241,29 @@ class AutomationMassHealthEligibilityCheck:
for row in ineligible_rows:
cells = row.find_elements(By.TAG_NAME, "td")
if len(cells) < 5:
if len(cells) < 3:
continue
member_number = cells[2].text.strip()
member_number = self._cell_text(cells[2])
norm_cell = self._normalize_id(member_number)
norm_self = self._normalize_id(self.memberId)
print(f"[ineligible] cells count={len(cells)}, memberId check: '{norm_self}' vs '{norm_cell}' (raw: '{member_number}')")
if len(cells) >= 5:
print(f" cells[3]='{self._cell_text(cells[3])}' cells[4]='{self._cell_text(cells[4])}'", end="")
if len(cells) > 5:
print(f" cells[5]='{self._cell_text(cells[5])}'", end="")
print()
if str(self.memberId) in member_number:
full_name = cells[4].text.strip()
plan_name = cells[5].text.strip()
if norm_self and norm_cell and (norm_self in norm_cell or norm_cell in norm_self):
full_name = self._cell_text(cells[4]) if len(cells) > 4 else ""
plan_name = self._cell_text(cells[5]) if len(cells) > 5 else (self._cell_text(cells[-1]) if len(cells) > 4 else "")
name_parts = full_name.split()
first_name = name_parts[0] if name_parts else ""
last_name = " ".join(name_parts[1:]) if len(name_parts) > 1 else ""
print(f"[ineligible] MATCHED → name='{full_name}' plan='{plan_name}'")
extracted = {
"eligibility": "N",
"firstName": first_name,
@@ -235,7 +272,8 @@ class AutomationMassHealthEligibilityCheck:
}
return extracted
print(f"[extraction] No matching row found for memberId='{self.memberId}'")
return {"eligibility": None}
except Exception as e: