feat: integrate DeltaIns, Tufts SCO, United SCO, and CCA eligibility checks
This commit is contained in:
@@ -11,19 +11,27 @@ from selenium_preAuthWorker import AutomationMassHealthPreAuth
|
||||
import os
|
||||
import time
|
||||
import helpers_ddma_eligibility as hddma
|
||||
import helpers_deltains_eligibility as hdeltains
|
||||
import helpers_unitedsco_eligibility as hunitedsco
|
||||
import helpers_cca_eligibility as hcca
|
||||
|
||||
# Import startup session-clear functions
|
||||
from ddma_browser_manager import clear_ddma_session_on_startup
|
||||
from deltains_browser_manager import clear_deltains_session_on_startup
|
||||
from unitedsco_browser_manager import clear_unitedsco_session_on_startup
|
||||
from cca_browser_manager import clear_cca_session_on_startup
|
||||
|
||||
from dotenv import load_dotenv
|
||||
load_dotenv()
|
||||
|
||||
# Clear DDMA session on startup so fresh login is required after PC restart.
|
||||
# Device trust tokens are preserved so OTP is still skipped after first login.
|
||||
# Clear sessions on startup so fresh login is required after PC restart.
|
||||
print("=" * 50)
|
||||
print("SELENIUM AGENT STARTING - CLEARING DDMA SESSION")
|
||||
print("SELENIUM AGENT STARTING - CLEARING SESSIONS")
|
||||
print("=" * 50)
|
||||
clear_ddma_session_on_startup()
|
||||
clear_deltains_session_on_startup()
|
||||
clear_unitedsco_session_on_startup()
|
||||
clear_cca_session_on_startup()
|
||||
print("=" * 50)
|
||||
print("SESSION CLEAR COMPLETE")
|
||||
print("=" * 50)
|
||||
@@ -251,11 +259,134 @@ async def ddma_eligibility(request: Request):
|
||||
return {"status": "started", "session_id": sid}
|
||||
|
||||
|
||||
async def _deltains_worker_wrapper(sid: str, data: dict, url: str):
|
||||
"""Background worker for DeltaIns — acquires semaphore, updates counters."""
|
||||
global active_jobs, waiting_jobs
|
||||
async with semaphore:
|
||||
async with lock:
|
||||
waiting_jobs -= 1
|
||||
active_jobs += 1
|
||||
try:
|
||||
await hdeltains.start_deltains_run(sid, data, url)
|
||||
finally:
|
||||
async with lock:
|
||||
active_jobs -= 1
|
||||
|
||||
|
||||
@app.post("/deltains-eligibility")
|
||||
async def deltains_eligibility(request: Request):
|
||||
"""
|
||||
Starts a DeltaIns eligibility session in the background.
|
||||
Body: { "data": { ... } }
|
||||
Returns: { status: "started", session_id: "<uuid>" }
|
||||
"""
|
||||
global waiting_jobs
|
||||
|
||||
body = await request.json()
|
||||
data = body.get("data", {})
|
||||
|
||||
sid = hdeltains.make_session_entry()
|
||||
hdeltains.sessions[sid]["type"] = "deltains_eligibility"
|
||||
hdeltains.sessions[sid]["last_activity"] = time.time()
|
||||
|
||||
async with lock:
|
||||
waiting_jobs += 1
|
||||
|
||||
asyncio.create_task(_deltains_worker_wrapper(
|
||||
sid, data,
|
||||
url="https://www.deltadentalins.com/ciam/login?TARGET=%2Fprovider-tools%2Fv2"
|
||||
))
|
||||
|
||||
return {"status": "started", "session_id": sid}
|
||||
|
||||
|
||||
async def _unitedsco_worker_wrapper(sid: str, data: dict, url: str):
|
||||
"""Background worker for UnitedSCO — acquires semaphore, updates counters."""
|
||||
global active_jobs, waiting_jobs
|
||||
async with semaphore:
|
||||
async with lock:
|
||||
waiting_jobs -= 1
|
||||
active_jobs += 1
|
||||
try:
|
||||
await hunitedsco.start_unitedsco_run(sid, data, url)
|
||||
finally:
|
||||
async with lock:
|
||||
active_jobs -= 1
|
||||
|
||||
|
||||
@app.post("/unitedsco-eligibility")
|
||||
async def unitedsco_eligibility(request: Request):
|
||||
"""
|
||||
Starts a UnitedSCO eligibility session in the background.
|
||||
Body: { "data": { ... } }
|
||||
Returns: { status: "started", session_id: "<uuid>" }
|
||||
"""
|
||||
global waiting_jobs
|
||||
|
||||
body = await request.json()
|
||||
data = body.get("data", {})
|
||||
|
||||
sid = hunitedsco.make_session_entry()
|
||||
hunitedsco.sessions[sid]["type"] = "unitedsco_eligibility"
|
||||
hunitedsco.sessions[sid]["last_activity"] = time.time()
|
||||
|
||||
async with lock:
|
||||
waiting_jobs += 1
|
||||
|
||||
asyncio.create_task(_unitedsco_worker_wrapper(
|
||||
sid, data,
|
||||
url="https://app.dentalhub.com/app/login"
|
||||
))
|
||||
|
||||
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
|
||||
async with semaphore:
|
||||
async with lock:
|
||||
waiting_jobs -= 1
|
||||
active_jobs += 1
|
||||
try:
|
||||
await hcca.start_cca_run(sid, data, url)
|
||||
finally:
|
||||
async with lock:
|
||||
active_jobs -= 1
|
||||
|
||||
|
||||
@app.post("/cca-eligibility")
|
||||
async def cca_eligibility(request: Request):
|
||||
"""
|
||||
Starts a CCA eligibility session in the background (no OTP).
|
||||
Body: { "data": { ... } }
|
||||
Returns: { status: "started", session_id: "<uuid>" }
|
||||
"""
|
||||
global waiting_jobs
|
||||
|
||||
body = await request.json()
|
||||
data = body.get("data", {})
|
||||
|
||||
sid = hcca.make_session_entry()
|
||||
hcca.sessions[sid]["type"] = "cca_eligibility"
|
||||
hcca.sessions[sid]["last_activity"] = time.time()
|
||||
|
||||
async with lock:
|
||||
waiting_jobs += 1
|
||||
|
||||
asyncio.create_task(_cca_worker_wrapper(
|
||||
sid, data,
|
||||
url="https://pwp.sciondental.com/PWP/Landing"
|
||||
))
|
||||
|
||||
return {"status": "started", "session_id": sid}
|
||||
|
||||
|
||||
@app.post("/submit-otp")
|
||||
async def submit_otp(request: Request):
|
||||
"""
|
||||
Body: { "session_id": "<sid>", "otp": "123456" }
|
||||
Node / frontend call this when user provides OTP.
|
||||
Tries each session store in order (CCA has no OTP but included for completeness).
|
||||
"""
|
||||
body = await request.json()
|
||||
sid = body.get("session_id")
|
||||
@@ -263,7 +394,16 @@ async def submit_otp(request: Request):
|
||||
if not sid or not otp:
|
||||
raise HTTPException(status_code=400, detail="session_id and otp required")
|
||||
|
||||
res = hddma.submit_otp(sid, otp)
|
||||
# Try each session store in order
|
||||
if sid in hddma.sessions:
|
||||
res = hddma.submit_otp(sid, otp)
|
||||
elif sid in hdeltains.sessions:
|
||||
res = hdeltains.submit_otp(sid, otp)
|
||||
elif sid in hunitedsco.sessions:
|
||||
res = hunitedsco.submit_otp(sid, otp)
|
||||
else:
|
||||
raise HTTPException(status_code=404, detail="session not found")
|
||||
|
||||
if res.get("status") == "error":
|
||||
raise HTTPException(status_code=400, detail=res.get("message"))
|
||||
return res
|
||||
@@ -271,7 +411,17 @@ async def submit_otp(request: Request):
|
||||
|
||||
@app.get("/session/{sid}/status")
|
||||
async def session_status(sid: str):
|
||||
s = hddma.get_session_status(sid)
|
||||
# Try each session store in order
|
||||
if sid in hddma.sessions:
|
||||
s = hddma.get_session_status(sid)
|
||||
elif sid in hdeltains.sessions:
|
||||
s = hdeltains.get_session_status(sid)
|
||||
elif sid in hunitedsco.sessions:
|
||||
s = hunitedsco.get_session_status(sid)
|
||||
elif sid in hcca.sessions:
|
||||
s = hcca.get_session_status(sid)
|
||||
else:
|
||||
s = {"status": "not_found"}
|
||||
if s.get("status") == "not_found":
|
||||
raise HTTPException(status_code=404, detail="session not found")
|
||||
return s
|
||||
@@ -281,10 +431,7 @@ async def session_status(sid: str):
|
||||
|
||||
@app.post("/clear-ddma-session")
|
||||
async def clear_ddma_session_endpoint():
|
||||
"""
|
||||
Clears the DDMA browser session (cookies + cached credentials).
|
||||
Call this when DDMA credentials are deleted or changed.
|
||||
"""
|
||||
"""Clears the DDMA browser session. Call when credentials are deleted or changed."""
|
||||
try:
|
||||
clear_ddma_session_on_startup()
|
||||
return {"status": "success", "message": "DDMA session cleared"}
|
||||
@@ -292,6 +439,36 @@ async def clear_ddma_session_endpoint():
|
||||
return {"status": "error", "message": str(e)}
|
||||
|
||||
|
||||
@app.post("/clear-deltains-session")
|
||||
async def clear_deltains_session_endpoint():
|
||||
"""Clears the DeltaIns browser session. Call when credentials are deleted or changed."""
|
||||
try:
|
||||
clear_deltains_session_on_startup()
|
||||
return {"status": "success", "message": "DeltaIns session cleared"}
|
||||
except Exception as e:
|
||||
return {"status": "error", "message": str(e)}
|
||||
|
||||
|
||||
@app.post("/clear-unitedsco-session")
|
||||
async def clear_unitedsco_session_endpoint():
|
||||
"""Clears the UnitedSCO browser session. Call when credentials are deleted or changed."""
|
||||
try:
|
||||
clear_unitedsco_session_on_startup()
|
||||
return {"status": "success", "message": "UnitedSCO 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."""
|
||||
try:
|
||||
clear_cca_session_on_startup()
|
||||
return {"status": "success", "message": "CCA session cleared"}
|
||||
except Exception as e:
|
||||
return {"status": "error", "message": str(e)}
|
||||
|
||||
|
||||
# ✅ Health Check Endpoint
|
||||
@app.get("/")
|
||||
async def health_check():
|
||||
|
||||
Reference in New Issue
Block a user