fix: improve eligibility checks for MassHealth and DentaQuest

- MassHealth: detect SSO/portal maintenance page and return clear error
  instead of cryptic step1 timeout; wait for SSO redirect to complete
  before running step1; add modal dismissal and failure screenshot/logging
- DentaQuest: detect maintenance page in login and step1; search by
  member ID + DOB only (remove first/last name to prevent stale data
  from previous patient being submitted)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Gitead
2026-05-19 23:05:48 -04:00
parent 95ce4c2fb4
commit 7284598c97
2 changed files with 98 additions and 33 deletions

View File

@@ -30,8 +30,8 @@ class AutomationMassHealthEligibilityCheck:
year, month, day = parts
self.dateOfBirth = f"{month.zfill(2)}{day.zfill(2)}{year}"
self.download_dir = os.path.abspath("downloads")
os.makedirs(self.download_dir, exist_ok=True)
self.download_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), "downloads")
os.makedirs(self.download_dir, exist_ok=True)
def config_driver(self):
options = webdriver.ChromeOptions()
@@ -51,10 +51,30 @@ class AutomationMassHealthEligibilityCheck:
driver = webdriver.Chrome(service=s, options=options)
self.driver = driver
def _is_maintenance_page(self) -> bool:
"""Return True if the current page is a server maintenance/capacity error page."""
try:
body = self.driver.find_element(By.TAG_NAME, "body").text
markers = [
"temporarily unable to service",
"maintenance downtime",
"capacity problems",
"Please try again later",
]
body_lower = body.lower()
return any(m.lower() in body_lower for m in markers)
except Exception:
return False
def login(self):
wait = WebDriverWait(self.driver, 30)
try:
# Check immediately if the portal is showing a maintenance page
if self._is_maintenance_page():
print("[login] Maintenance page detected on initial load")
return "ERROR: MassHealth portal is temporarily unavailable (maintenance). Please try again later."
# Step 1: Click the SIGN IN button on the initial page
signin_button = wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, "a.btn.btn-block.btn-primary[href='https://connectsso.masshealth-dental.org/mhprovider/index.html']")))
signin_button.click()
@@ -76,6 +96,23 @@ class AutomationMassHealthEligibilityCheck:
login_button = wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, "input[type='submit'][name='submit'][value='Login']")))
login_button.click()
# Wait for SSO redirect to complete and land on the MassHealth portal.
# Must check the hostname only — the SSO URL itself contains "provider.masshealth-dental.org"
# as a query parameter, so a plain substring check would match too early.
print("[login] Waiting for SSO redirect to provider.masshealth-dental.org ...")
try:
WebDriverWait(self.driver, 30).until(
lambda d: d.current_url.startswith("https://provider.masshealth-dental.org")
)
print(f"[login] Redirect complete. URL: {self.driver.current_url}")
except TimeoutException:
print(f"[login] Redirect timeout. Still on: {self.driver.current_url}")
return "ERROR: Login redirect timed out — check credentials or portal availability."
if self._is_maintenance_page():
print("[login] Maintenance page detected after login submission")
return "ERROR: MassHealth portal is temporarily unavailable (maintenance). Please try again later."
return "Success"
except Exception as e:
@@ -90,6 +127,26 @@ class AutomationMassHealthEligibilityCheck:
print(f"[step1] current URL after login: {self.driver.current_url}")
print(f"[step1] page title: {self.driver.title}")
if self._is_maintenance_page():
print("[step1] Maintenance page detected")
return "ERROR: MassHealth portal is temporarily unavailable (maintenance). Please try again later."
# Dismiss any post-login modal/alert dialogs (session warnings, notices, etc.)
for btn_xpath in [
"//button[contains(text(),'OK') or contains(text(),'Ok') or contains(text(),'ok')]",
"//button[contains(text(),'Continue') or contains(text(),'Accept') or contains(text(),'Close')]",
"//button[contains(text(),'Dismiss') or contains(text(),'Got it')]",
"//a[contains(@class,'close') or @data-dismiss='modal']",
]:
try:
btn = WebDriverWait(self.driver, 3).until(EC.element_to_be_clickable((By.XPATH, btn_xpath)))
btn.click()
print(f"[step1] Dismissed modal via: {btn_xpath}")
time.sleep(1)
break
except Exception:
pass
substep = "patient_management"
patient_mgmt = wait.until(
EC.presence_of_element_located(
@@ -162,7 +219,19 @@ class AutomationMassHealthEligibilityCheck:
return "Success"
except Exception as e:
print(f"[step1] FAILED at substep='{substep}': {e}")
print(f"[step1] URL at failure: {self.driver.current_url}")
try:
print(f"[step1] URL at failure: {self.driver.current_url}")
print(f"[step1] Page title: {self.driver.title}")
body_text = self.driver.find_element(By.TAG_NAME, "body").text
print(f"[step1] Page body (first 500 chars): {body_text[:500]}")
except Exception:
pass
try:
ss_path = os.path.join(self.download_dir, f"step1_failure_{substep}_{int(time.time())}.png")
self.driver.save_screenshot(ss_path)
print(f"[step1] Screenshot saved: {ss_path}")
except Exception as ss_err:
print(f"[step1] Could not save screenshot: {ss_err}")
return f"ERROR:STEP1:{substep}"
def _cell_text(self, cell):