feat: Check Preauth from claim details, Tufts SCO approval PDF, all-folder appointment picker
- Same patient may be booked at the same time in different columns (appointment + preauth) - New preauths save service lines and attachments so the details view shows them - Claim/Preauth Details: renamed, Check Preauth button picks the worker from the claim's insurance (MassHealth, United SCO, Tufts SCO, CCA); OTP popup survives closing the window, window closes after a successful check - Tufts SCO Check Preauth: searches Submitted by pre-auth number, saves the detail page PDF to the patient's new Approval folder (PdfTitleKey PREAUTH_APPROVAL migration) - Appointment attachment picker lists files from all of the patient's folders Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -13,6 +13,10 @@ from selenium_preAuthWorker import AutomationMassHealthPreAuth
|
||||
from selenium_MHSinglePaymentCheckWorker import AutomationMassHealthSinglePaymentCheck
|
||||
from selenium_MHBatchPaymentCheckWorker import AutomationMassHealthBatchPaymentCheck
|
||||
from selenium_Altus_eligibilityCheckWorker import AutomationAltusEligibilityCheck
|
||||
from selenium_MH_preAuthCheckWorker import AutomationMassHealthPreAuthCheck
|
||||
from selenium_UnitedSCO_preAuthCheckWorker import AutomationUnitedSCOPreAuthCheck
|
||||
from selenium_TuftsSCO_preAuthCheckWorker import AutomationTuftsSCOPreAuthCheck
|
||||
from selenium_CCA_preAuthCheckWorker import AutomationCCAPreAuthCheck
|
||||
import os
|
||||
import time
|
||||
import helpers_ddma_eligibility as hddma
|
||||
@@ -1253,6 +1257,93 @@ async def cca_preauth(request: Request):
|
||||
return {"status": "started", "session_id": sid}
|
||||
|
||||
|
||||
# ── Check PreAuth (MH, United SCO, Tufts SCO, CCA) ──────────────────────────
|
||||
# Same flow as each insurer's eligibility check, run with its own preauth-check worker.
|
||||
# United SCO / Tufts SCO / CCA share the eligibility session stores, so /session/{sid}/status
|
||||
# and /submit-otp already cover them.
|
||||
|
||||
@app.post("/mh-preauth-check")
|
||||
async def mh_preauth_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 = AutomationMassHealthPreAuthCheck(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")}
|
||||
return result
|
||||
except Exception as e:
|
||||
return {"status": "error", "message": str(e)}
|
||||
finally:
|
||||
async with lock:
|
||||
active_jobs -= 1
|
||||
|
||||
|
||||
async def _preauth_check_wrapper(start_run, sid: str, data: dict, url: str, worker_cls):
|
||||
"""Background worker for a Check PreAuth session — acquires semaphore, updates counters."""
|
||||
global active_jobs, waiting_jobs
|
||||
async with semaphore:
|
||||
async with lock:
|
||||
waiting_jobs -= 1
|
||||
active_jobs += 1
|
||||
try:
|
||||
await start_run(sid, data, url, worker_cls=worker_cls)
|
||||
finally:
|
||||
async with lock:
|
||||
active_jobs -= 1
|
||||
|
||||
|
||||
async def _start_preauth_check(request: Request, helper, start_run, session_type: str, url: str, worker_cls):
|
||||
global waiting_jobs
|
||||
|
||||
body = await request.json()
|
||||
data = body.get("data", {})
|
||||
|
||||
sid = helper.make_session_entry()
|
||||
helper.sessions[sid]["type"] = session_type
|
||||
helper.sessions[sid]["last_activity"] = time.time()
|
||||
|
||||
async with lock:
|
||||
waiting_jobs += 1
|
||||
|
||||
asyncio.create_task(_preauth_check_wrapper(start_run, sid, data, url, worker_cls))
|
||||
|
||||
return {"status": "started", "session_id": sid}
|
||||
|
||||
|
||||
@app.post("/unitedsco-preauth-check")
|
||||
async def unitedsco_preauth_check(request: Request):
|
||||
return await _start_preauth_check(
|
||||
request, hunitedsco, hunitedsco.start_unitedsco_run, "unitedsco_preauth_check",
|
||||
"https://app.dentalhub.com/app/login", AutomationUnitedSCOPreAuthCheck,
|
||||
)
|
||||
|
||||
|
||||
@app.post("/tuftssco-preauth-check")
|
||||
async def tuftssco_preauth_check(request: Request):
|
||||
return await _start_preauth_check(
|
||||
request, hdentaquest, hdentaquest.start_dentaquest_run, "tuftssco_preauth_check",
|
||||
"https://providers.dentaquest.com/", AutomationTuftsSCOPreAuthCheck,
|
||||
)
|
||||
|
||||
|
||||
@app.post("/cca-preauth-check")
|
||||
async def cca_preauth_check(request: Request):
|
||||
return await _start_preauth_check(
|
||||
request, hcca, hcca.start_cca_run, "cca_preauth_check",
|
||||
"https://pwp.sciondental.com/PWP/Landing", AutomationCCAPreAuthCheck,
|
||||
)
|
||||
|
||||
|
||||
@app.post("/submit-otp")
|
||||
async def submit_otp(request: Request):
|
||||
"""
|
||||
|
||||
@@ -71,7 +71,7 @@ def _close_browser(bot):
|
||||
print(f"[CCA] Could not close browser: {e}")
|
||||
|
||||
|
||||
async def start_cca_run(sid: str, data: dict, url: str):
|
||||
async def start_cca_run(sid: str, data: dict, url: str, worker_cls=None):
|
||||
"""
|
||||
Run the CCA eligibility check workflow (no OTP):
|
||||
1. Login
|
||||
@@ -87,7 +87,8 @@ async def start_cca_run(sid: str, data: dict, url: str):
|
||||
bot = None
|
||||
|
||||
try:
|
||||
bot = AutomationCCAEligibilityCheck({"data": data})
|
||||
# worker_cls lets Check PreAuth reuse this flow with its own worker
|
||||
bot = (worker_cls or AutomationCCAEligibilityCheck)({"data": data})
|
||||
bot.config_driver()
|
||||
|
||||
s["bot"] = bot
|
||||
|
||||
@@ -66,7 +66,7 @@ async def _remove_session_later(sid: str, delay: int = 30):
|
||||
sessions.pop(sid, None)
|
||||
|
||||
|
||||
async def start_dentaquest_run(sid: str, data: dict, url: str):
|
||||
async def start_dentaquest_run(sid: str, data: dict, url: str, worker_cls=None):
|
||||
"""
|
||||
Run the DentaQuest workflow for a session (WITHOUT managing semaphore/counters).
|
||||
Called by agent.py inside a wrapper that handles queue/counters.
|
||||
@@ -79,7 +79,8 @@ async def start_dentaquest_run(sid: str, data: dict, url: str):
|
||||
s["last_activity"] = time.time()
|
||||
|
||||
try:
|
||||
bot = AutomationDentaQuestEligibilityCheck({"data": data})
|
||||
# worker_cls lets Check PreAuth reuse this flow with its own worker
|
||||
bot = (worker_cls or AutomationDentaQuestEligibilityCheck)({"data": data})
|
||||
bot.config_driver()
|
||||
|
||||
s["bot"] = bot
|
||||
|
||||
@@ -99,7 +99,7 @@ def _minimize_browser(bot):
|
||||
print(f"[UnitedSCO] Could not hide browser: {e}")
|
||||
|
||||
|
||||
async def start_unitedsco_run(sid: str, data: dict, url: str):
|
||||
async def start_unitedsco_run(sid: str, data: dict, url: str, worker_cls=None):
|
||||
"""
|
||||
Run the United SCO workflow for a session (WITHOUT managing semaphore/counters).
|
||||
Called by agent.py inside a wrapper that handles queue/counters.
|
||||
@@ -112,7 +112,8 @@ async def start_unitedsco_run(sid: str, data: dict, url: str):
|
||||
s["last_activity"] = time.time()
|
||||
|
||||
try:
|
||||
bot = AutomationUnitedSCOEligibilityCheck({"data": data})
|
||||
# worker_cls lets Check PreAuth reuse this flow with its own worker
|
||||
bot = (worker_cls or AutomationUnitedSCOEligibilityCheck)({"data": data})
|
||||
bot.config_driver()
|
||||
|
||||
s["bot"] = bot
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
from selenium_CCA_eligibilityCheckWorker import AutomationCCAEligibilityCheck
|
||||
|
||||
|
||||
class AutomationCCAPreAuthCheck(AutomationCCAEligibilityCheck):
|
||||
"""
|
||||
CCA (ScionDental) Check PreAuth.
|
||||
|
||||
Starts with the same steps as the eligibility check: login, step1, step2.
|
||||
Reuses the eligibility check's persistent browser session (same Chrome profile and cookies).
|
||||
Override a step here when the preauth check needs to do something different.
|
||||
"""
|
||||
@@ -0,0 +1,11 @@
|
||||
from selenium_eligibilityCheckWorker import AutomationMassHealthEligibilityCheck
|
||||
|
||||
|
||||
class AutomationMassHealthPreAuthCheck(AutomationMassHealthEligibilityCheck):
|
||||
"""
|
||||
MassHealth Check PreAuth.
|
||||
|
||||
Starts with the same steps as the eligibility check: login, step1, step2.
|
||||
Fresh login every run (MassHealth keeps no persistent session).
|
||||
Override a step here when the preauth check needs to do something different.
|
||||
"""
|
||||
@@ -0,0 +1,147 @@
|
||||
from selenium.common.exceptions import TimeoutException
|
||||
from selenium.webdriver.common.by import By
|
||||
from selenium.webdriver.common.keys import Keys
|
||||
from selenium.webdriver.support.ui import WebDriverWait
|
||||
from selenium.webdriver.support import expected_conditions as EC
|
||||
import base64
|
||||
import os
|
||||
import time
|
||||
|
||||
from selenium_DentaQuest_eligibilityCheckWorker import AutomationDentaQuestEligibilityCheck
|
||||
|
||||
SUBMITTED_URL = "https://providers.dentaquest.com/pre-auth-claims/submitted/"
|
||||
|
||||
|
||||
class AutomationTuftsSCOPreAuthCheck(AutomationDentaQuestEligibilityCheck):
|
||||
"""
|
||||
Tufts SCO (DentaQuest) Check PreAuth.
|
||||
|
||||
login: same as the eligibility check (persistent browser session, OTP if asked).
|
||||
step1: open Pre-authorizations and Claims > Submitted, clear the date range,
|
||||
search by pre-auth / claim number.
|
||||
step2: open the pre-auth from the result row and save its detail page as a PDF
|
||||
(filed under the patient's Approval folder by the backend).
|
||||
"""
|
||||
|
||||
def __init__(self, data):
|
||||
super().__init__(data)
|
||||
self.preAuthNumber = str(self.data.get("preAuthNumber") or "").strip()
|
||||
self.claimNumber = str(self.data.get("claimNumber") or "").strip()
|
||||
|
||||
def step1(self):
|
||||
number = self.preAuthNumber or self.claimNumber
|
||||
if not number:
|
||||
return "ERROR: This record has no pre-auth or claim number to search for."
|
||||
|
||||
wait = WebDriverWait(self.driver, 30)
|
||||
try:
|
||||
print(f"[TuftsSCO PreAuthCheck step1] Opening {SUBMITTED_URL}")
|
||||
self.driver.get(SUBMITTED_URL)
|
||||
|
||||
if self._is_maintenance_page():
|
||||
return "ERROR: DentaQuest server is temporarily unavailable (maintenance). Please try again later."
|
||||
|
||||
# Clear "Set date range" (defaults to the last 2 weeks) so older preauths are found
|
||||
try:
|
||||
clear_btn = WebDriverWait(self.driver, 15).until(EC.element_to_be_clickable(
|
||||
(By.XPATH, "//button[@aria-label='Clear date range']")
|
||||
))
|
||||
clear_btn.click()
|
||||
print("[TuftsSCO PreAuthCheck step1] Cleared date range")
|
||||
time.sleep(0.5)
|
||||
except TimeoutException:
|
||||
print("[TuftsSCO PreAuthCheck step1] No date range to clear")
|
||||
|
||||
number_input = wait.until(EC.element_to_be_clickable(
|
||||
(By.XPATH, "//input[@data-testid='claims-search_claim-number_input']")
|
||||
))
|
||||
number_input.click()
|
||||
number_input.send_keys(Keys.CONTROL, "a")
|
||||
number_input.send_keys(Keys.DELETE)
|
||||
number_input.send_keys(number)
|
||||
print(f"[TuftsSCO PreAuthCheck step1] Entered number: {number}")
|
||||
|
||||
search_btn = wait.until(EC.element_to_be_clickable(
|
||||
(By.XPATH, "//button[@data-testid='claims-search_submit-btn']")
|
||||
))
|
||||
search_btn.click()
|
||||
print("[TuftsSCO PreAuthCheck step1] Clicked Search")
|
||||
return "SUCCESS"
|
||||
except TimeoutException:
|
||||
return "ERROR: Pre-auth/claim search form not found on the Submitted page."
|
||||
except Exception as e:
|
||||
return f"ERROR: Pre-auth search failed: {e}"
|
||||
|
||||
def step2(self):
|
||||
number = self.preAuthNumber or self.claimNumber
|
||||
try:
|
||||
# 1) Wait for the result row and click the pre-auth number in its first column
|
||||
try:
|
||||
id_link = WebDriverWait(self.driver, 30).until(EC.element_to_be_clickable(
|
||||
(By.XPATH, f"//tbody//tr[1]/*[1]//*[self::a or self::button][contains(normalize-space(.), '{number}')]")
|
||||
))
|
||||
except TimeoutException:
|
||||
body = self.driver.find_element(By.TAG_NAME, "body").text
|
||||
if "0 records found" in body or "no records" in body.lower() or "no results" in body.lower():
|
||||
return {"status": "error", "message": f"Tufts SCO found no pre-auth/claim #{number}."}
|
||||
return {"status": "error", "message": f"Search result for #{number} did not load."}
|
||||
# Status column of the result row (e.g. "Approved"), read before leaving the page
|
||||
status = ""
|
||||
try:
|
||||
headers = [h.text.strip().lower() for h in self.driver.find_elements(By.XPATH, "//thead//th")]
|
||||
cells = self.driver.find_elements(By.XPATH, "//tbody//tr[1]/td")
|
||||
if "status" in headers and headers.index("status") < len(cells):
|
||||
status = cells[headers.index("status")].text.strip()
|
||||
except Exception:
|
||||
pass
|
||||
print(f"[TuftsSCO PreAuthCheck step2] Status: {status!r}")
|
||||
|
||||
id_link.click()
|
||||
print(f"[TuftsSCO PreAuthCheck step2] Opened #{number}")
|
||||
|
||||
# 2) Wait for the detail page ("Pre-authorization <number> for <name>")
|
||||
try:
|
||||
WebDriverWait(self.driver, 30).until(EC.presence_of_element_located(
|
||||
(By.XPATH, f"//h1[contains(., '{number}')] | //*[self::h1 or self::h2][contains(., 'for ')][contains(., '{number}')]")
|
||||
))
|
||||
WebDriverWait(self.driver, 30).until(EC.presence_of_element_located(
|
||||
(By.XPATH, "//*[contains(normalize-space(.), 'Procedure information')]")
|
||||
))
|
||||
except TimeoutException:
|
||||
return {"status": "error", "message": f"Detail page for #{number} did not load."}
|
||||
time.sleep(2) # let the procedure table finish rendering
|
||||
|
||||
# 3) The page's Print button opens Chrome's print dialog, which Selenium can't drive;
|
||||
# printing to PDF through DevTools produces the same printable page.
|
||||
pdf = self.driver.execute_cdp_cmd("Page.printToPDF", {
|
||||
"printBackground": True,
|
||||
"paperWidth": 8.5,
|
||||
"paperHeight": 11,
|
||||
"marginTop": 0.4,
|
||||
"marginBottom": 0.4,
|
||||
"marginLeft": 0.4,
|
||||
"marginRight": 0.4,
|
||||
})
|
||||
pdf_path = os.path.join(
|
||||
self.download_dir, f"tuftssco_preauth_approval_{number}_{int(time.time())}.pdf"
|
||||
)
|
||||
with open(pdf_path, "wb") as f:
|
||||
f.write(base64.b64decode(pdf.get("data", "")))
|
||||
print(f"[TuftsSCO PreAuthCheck step2] PDF saved: {pdf_path}")
|
||||
|
||||
# Leave the browser idle so the session stays logged in for the next run
|
||||
try:
|
||||
self.driver.get("about:blank")
|
||||
self.driver.minimize_window()
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
return {
|
||||
"status": "success",
|
||||
"message": f"Tufts SCO pre-auth #{number}" + (f": {status}." if status else "."),
|
||||
"preAuthNumber": number,
|
||||
"preAuthStatus": status,
|
||||
"approval_pdf_path": pdf_path,
|
||||
}
|
||||
except Exception as e:
|
||||
return {"status": "error", "message": f"Tufts SCO pre-auth check failed: {e}"}
|
||||
@@ -0,0 +1,11 @@
|
||||
from selenium_UnitedSCO_eligibilityCheckWorker import AutomationUnitedSCOEligibilityCheck
|
||||
|
||||
|
||||
class AutomationUnitedSCOPreAuthCheck(AutomationUnitedSCOEligibilityCheck):
|
||||
"""
|
||||
United SCO (DentalHub) Check PreAuth.
|
||||
|
||||
Starts with the same steps as the eligibility check: login, step1, step2.
|
||||
Reuses the eligibility check's persistent browser session (same Chrome profile and cookies).
|
||||
Override a step here when the preauth check needs to do something different.
|
||||
"""
|
||||
Reference in New Issue
Block a user