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>
This commit is contained in:
+56
-115
@@ -5,9 +5,6 @@ from fastapi.staticfiles import StaticFiles
|
||||
import uvicorn
|
||||
import asyncio
|
||||
from selenium_claimSubmitWorker import AutomationMassHealthClaimsLogin
|
||||
from selenium_eligibilityCheckWorker import AutomationMassHealthEligibilityCheck
|
||||
from selenium_MH_eligibilityHistoryCheckWorker import AutomationMassHealthEligibilityHistoryCheck
|
||||
from selenium_CMSP_eligibilityHistoryRemainingCheckWorker import AutomationCMSPEligibilityHistoryRemainingCheck
|
||||
from selenium_claimStatusCheckWorker import AutomationMassHealthClaimStatusCheck
|
||||
from selenium_preAuthWorker import AutomationMassHealthPreAuth
|
||||
from selenium_MHSinglePaymentCheckWorker import AutomationMassHealthSinglePaymentCheck
|
||||
@@ -26,6 +23,7 @@ import helpers_deltains_eligibility as hdeltains
|
||||
import helpers_unitedsco_eligibility as hunitedsco
|
||||
import helpers_uniteducard_eligibility as huniteducard
|
||||
import helpers_dentaquest_eligibility as hdentaquest
|
||||
import helpers_mh_eligibility as hmh
|
||||
import helpers_cca_eligibility as hcca
|
||||
import helpers_cca_claim as hcca_claim
|
||||
import helpers_cca_preauth as hcca_preauth
|
||||
@@ -50,6 +48,7 @@ from deltains_browser_manager import clear_deltains_session_on_startup
|
||||
from unitedsco_browser_manager import clear_unitedsco_session_on_startup
|
||||
from uniteducard_browser_manager import clear_uniteducard_session_on_startup
|
||||
from dentaquest_browser_manager import clear_dentaquest_session_on_startup
|
||||
from mh_browser_manager import clear_mh_session_on_startup
|
||||
from cca_browser_manager import clear_cca_session_on_startup
|
||||
from metlife_browser_manager import clear_metlife_session_on_startup
|
||||
|
||||
@@ -69,6 +68,7 @@ clear_deltains_session_on_startup()
|
||||
clear_unitedsco_session_on_startup()
|
||||
clear_uniteducard_session_on_startup()
|
||||
clear_dentaquest_session_on_startup()
|
||||
clear_mh_session_on_startup()
|
||||
clear_cca_session_on_startup()
|
||||
clear_metlife_session_on_startup()
|
||||
print("=" * 50)
|
||||
@@ -135,79 +135,6 @@ async def start_workflow(request: Request):
|
||||
async with lock:
|
||||
active_jobs -= 1
|
||||
|
||||
# Endpoint: 2 — Start the automation of cheking eligibility
|
||||
@app.post("/eligibility-check")
|
||||
async def start_workflow(request: Request):
|
||||
global active_jobs, waiting_jobs
|
||||
data = await request.json()
|
||||
|
||||
async with lock:
|
||||
waiting_jobs += 1
|
||||
|
||||
async with semaphore:
|
||||
async with lock:
|
||||
waiting_jobs -= 1
|
||||
active_jobs += 1
|
||||
try:
|
||||
bot = AutomationMassHealthEligibilityCheck(data)
|
||||
result = bot.main_workflow("https://provider.masshealth-dental.org/mh_provider_login")
|
||||
|
||||
if result.get("status") != "success":
|
||||
return {"status": "error", "message": result.get("message")}
|
||||
|
||||
# Convert pdf_path to pdf_url
|
||||
if result.get("pdf_path"):
|
||||
filename = os.path.basename(result["pdf_path"])
|
||||
port = os.getenv("PORT", "5002")
|
||||
url_host = os.getenv("HOST", "localhost")
|
||||
result["pdf_url"] = f"http://{url_host}:{port}/downloads/{filename}"
|
||||
print(f"DEBUG: Generated pdf_url = {result['pdf_url']}")
|
||||
|
||||
return result
|
||||
except Exception as e:
|
||||
return {"status": "error", "message": str(e)}
|
||||
finally:
|
||||
async with lock:
|
||||
active_jobs -= 1
|
||||
|
||||
# Endpoint: 2a — MH Eligibility + Service History
|
||||
@app.post("/mh-eligibility-history-check")
|
||||
async def mh_eligibility_history_check(request: Request):
|
||||
global active_jobs, waiting_jobs
|
||||
data = await request.json()
|
||||
|
||||
async with lock:
|
||||
waiting_jobs += 1
|
||||
|
||||
async with semaphore:
|
||||
async with lock:
|
||||
waiting_jobs -= 1
|
||||
active_jobs += 1
|
||||
try:
|
||||
bot = AutomationMassHealthEligibilityHistoryCheck(data)
|
||||
result = bot.main_workflow("https://provider.masshealth-dental.org/mh_provider_login")
|
||||
|
||||
if result.get("status") == "error":
|
||||
return {"status": "error", "message": result.get("message")}
|
||||
|
||||
port = os.getenv("PORT", "5002")
|
||||
url_host = os.getenv("HOST", "localhost")
|
||||
|
||||
if result.get("pdf_path"):
|
||||
filename = os.path.basename(result["pdf_path"])
|
||||
result["pdf_url"] = f"http://{url_host}:{port}/downloads/{filename}"
|
||||
|
||||
if result.get("history_pdf_path"):
|
||||
filename = os.path.basename(result["history_pdf_path"])
|
||||
result["history_pdf_url"] = f"http://{url_host}:{port}/downloads/{filename}"
|
||||
|
||||
return result
|
||||
except Exception as e:
|
||||
return {"status": "error", "message": str(e)}
|
||||
finally:
|
||||
async with lock:
|
||||
active_jobs -= 1
|
||||
|
||||
# Endpoint: 2c — Altus Dental eligibility (no OTP, fresh browser per run)
|
||||
@app.post("/altus-eligibility-check")
|
||||
async def altus_eligibility_check(request: Request):
|
||||
@@ -244,45 +171,6 @@ async def altus_eligibility_check(request: Request):
|
||||
async with lock:
|
||||
active_jobs -= 1
|
||||
|
||||
# Endpoint: 2b — CMSP Eligibility + Service History + Accumulator (Remaining)
|
||||
@app.post("/cmsp-eligibility-history-remaining-check")
|
||||
async def cmsp_eligibility_history_remaining_check(request: Request):
|
||||
global active_jobs, waiting_jobs
|
||||
data = await request.json()
|
||||
|
||||
async with lock:
|
||||
waiting_jobs += 1
|
||||
|
||||
async with semaphore:
|
||||
async with lock:
|
||||
waiting_jobs -= 1
|
||||
active_jobs += 1
|
||||
try:
|
||||
bot = AutomationCMSPEligibilityHistoryRemainingCheck(data)
|
||||
result = bot.main_workflow("https://provider.masshealth-dental.org/mh_provider_login")
|
||||
|
||||
if result.get("status") == "error":
|
||||
return {"status": "error", "message": result.get("message")}
|
||||
|
||||
port = os.getenv("PORT", "5002")
|
||||
url_host = os.getenv("HOST", "localhost")
|
||||
|
||||
for key, url_key in [
|
||||
("pdf_path", "pdf_url"),
|
||||
("history_pdf_path", "history_pdf_url"),
|
||||
("accumulator_pdf_path", "accumulator_pdf_url"),
|
||||
]:
|
||||
if result.get(key):
|
||||
filename = os.path.basename(result[key])
|
||||
result[url_key] = f"http://{url_host}:{port}/downloads/{filename}"
|
||||
|
||||
return result
|
||||
except Exception as e:
|
||||
return {"status": "error", "message": str(e)}
|
||||
finally:
|
||||
async with lock:
|
||||
active_jobs -= 1
|
||||
|
||||
# Endpoint: 2.1 — Start the automation for Claims login (open browser and log in)
|
||||
@app.post("/claims-login")
|
||||
async def start_claims_login(request: Request):
|
||||
@@ -839,6 +727,45 @@ async def dentaquest_eligibility(request: Request):
|
||||
return {"status": "started", "session_id": sid}
|
||||
|
||||
|
||||
async def _mh_worker_wrapper(sid: str, data: dict, url: str):
|
||||
"""Background worker for MassHealth eligibility — acquires semaphore, updates counters."""
|
||||
global active_jobs, waiting_jobs
|
||||
async with semaphore:
|
||||
async with lock:
|
||||
waiting_jobs -= 1
|
||||
active_jobs += 1
|
||||
try:
|
||||
await hmh.start_mh_run(sid, data, url)
|
||||
finally:
|
||||
async with lock:
|
||||
active_jobs -= 1
|
||||
|
||||
|
||||
@app.post("/mh-eligibility")
|
||||
async def mh_eligibility(request: Request):
|
||||
"""
|
||||
Starts a MassHealth eligibility session in the background
|
||||
(providers.masshealth-dental.org — same DentaQuest portal as Tufts SCO).
|
||||
Body: { "data": { ... } }
|
||||
Returns: { status: "started", session_id: "<uuid>" }
|
||||
"""
|
||||
global waiting_jobs
|
||||
|
||||
body = await request.json()
|
||||
data = body.get("data", {})
|
||||
|
||||
sid = hmh.make_session_entry()
|
||||
hmh.sessions[sid]["type"] = "mh_eligibility"
|
||||
hmh.sessions[sid]["last_activity"] = time.time()
|
||||
|
||||
async with lock:
|
||||
waiting_jobs += 1
|
||||
|
||||
asyncio.create_task(_mh_worker_wrapper(sid, data, url=hmh.MH_BASE_URL))
|
||||
|
||||
return {"status": "started", "session_id": sid}
|
||||
|
||||
|
||||
async def _cca_worker_wrapper(sid: str, data: dict, url: str):
|
||||
"""Background worker for CCA — acquires semaphore, updates counters. No OTP."""
|
||||
global active_jobs, waiting_jobs
|
||||
@@ -1412,6 +1339,8 @@ async def submit_otp(request: Request):
|
||||
res = huniteducard.submit_otp(sid, otp)
|
||||
elif sid in hdentaquest.sessions:
|
||||
res = hdentaquest.submit_otp(sid, otp)
|
||||
elif sid in hmh.sessions:
|
||||
res = hmh.submit_otp(sid, otp)
|
||||
elif sid in hddma_claim.sessions:
|
||||
res = hddma_claim.submit_otp(sid, otp)
|
||||
elif sid in hddma_payment.sessions:
|
||||
@@ -1459,6 +1388,8 @@ async def session_status(sid: str):
|
||||
s = huniteducard.get_session_status(sid)
|
||||
elif sid in hdentaquest.sessions:
|
||||
s = hdentaquest.get_session_status(sid)
|
||||
elif sid in hmh.sessions:
|
||||
s = hmh.get_session_status(sid)
|
||||
elif sid in hcca.sessions:
|
||||
s = hcca.get_session_status(sid)
|
||||
elif sid in hcca_claim.sessions:
|
||||
@@ -1566,6 +1497,16 @@ async def clear_uniteducard_session_endpoint():
|
||||
return {"status": "error", "message": str(e)}
|
||||
|
||||
|
||||
@app.post("/clear-mh-session")
|
||||
async def clear_mh_session_endpoint():
|
||||
"""Clears the MassHealth browser session. Call when credentials are deleted or changed."""
|
||||
try:
|
||||
clear_mh_session_on_startup()
|
||||
return {"status": "success", "message": "MH session cleared"}
|
||||
except Exception as e:
|
||||
return {"status": "error", "message": str(e)}
|
||||
|
||||
|
||||
@app.post("/clear-cca-session")
|
||||
async def clear_cca_session_endpoint():
|
||||
"""Clears the CCA browser session. Call when credentials are deleted or changed."""
|
||||
|
||||
Reference in New Issue
Block a user