Files
DentalManagement09/apps/SeleniumService/mh_member_plan.py
T
GiteadandClaude Opus 5.5 f5b91a75d4 feat: MassHealth eligibility on new portal with persistent session and Gmail OTP auto-read
- New MH eligibility worker for providers.masshealth-dental.org (same DentaQuest
  portal as Tufts SCO): persistent Chrome profile, OTP via app popup, member
  details PDF, address, service history, plan name and remaining benefit
- Reads the OTP from the office Gmail over IMAP (App Password) and types it in;
  falls back to the manual OTP popup
- Insurance credentials: OTP Email / Phone and OTP Email Password fields
- New patient status ACTIVE_PLAN_NOT_ACCEPTED (coverage active, plan not accepted)
- Removes the old MH eligibility, MH history and CMSP remaining workers/processors;
  batch appointment check and AI conversation use the new MH processor

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-05 16:47:22 -05:00

53 lines
2.2 KiB
Python

"""Plan name, remaining annual benefit and phone from the MassHealth Dental
(providers.masshealth-dental.org) member details page."""
import re
import time
from selenium.webdriver.common.by import By
# "Plan:" (not "Plan/Group number:" or "Plan year:"); value on the same line or the next
_PLAN_RE = re.compile(r"^[ \t]*Plan:[ \t]*(?:\n[ \t]*)?([^\n\t]+)", re.M)
# "$1,638.00 before Individual annual maximum (All Networks) is met"
_REMAINING_RE = re.compile(r"(\$\s?[\d,]+(?:\.\d{2})?)\s*before\s+[^\n]*?maximum", re.I)
# Coverage status in the "Employee & family information" table (the member's own row)
_FAMILY_SECTION_RE = re.compile(r"Employee\s*&\s*family information(.*?)(?:Dental plan information|$)", re.S | re.I)
_PHONE_RE = re.compile(r"Phone number:\s*\(?(\d{3})\)?[\s.-]*(\d{3})[\s.-]*(\d{4})")
def parse_mh_plan_details(text):
result = {}
m = _PLAN_RE.search(text or "")
if m and m.group(1).strip():
result["planName"] = m.group(1).strip()
m = _REMAINING_RE.search(text or "")
if m:
result["remainingBenefit"] = re.sub(r"\s", "", m.group(1))
sec = _FAMILY_SECTION_RE.search(text or "")
if sec:
# Case-sensitive whole word, so "Inactive" never counts as "Active"
if re.search(r"\bActive\b", sec.group(1)):
result["coverageStatus"] = "active"
elif re.search(r"\b(Inactive|Terminated)\b", sec.group(1)):
result["coverageStatus"] = "inactive"
m = _PHONE_RE.search(text or "")
if m:
result["phone"] = "-".join(m.groups())
return result
def extract_mh_plan_details(driver, timeout=10):
"""Poll because "Deductibles & maximums" fills in after the rest of the page."""
result = {}
try:
deadline = time.time() + timeout
while True:
text = driver.find_element(By.TAG_NAME, "body").get_attribute("innerText") or ""
result = parse_mh_plan_details(text)
if ("planName" in result and "remainingBenefit" in result) or time.time() >= deadline:
break
time.sleep(1)
print(f"[extract_mh_plan_details] {result}")
except Exception as e:
print(f"[extract_mh_plan_details] failed: {e}")
return result