From 90f587ac9d04c4e98a312576bf71e1e89438574e Mon Sep 17 00:00:00 2001 From: Gitead Date: Thu, 24 Sep 2026 12:20:40 -0400 Subject: [PATCH] =?UTF-8?q?feat:=20CCA=20multi-record=20popup=20=E2=80=94?= =?UTF-8?q?=20save=20popup=20as=20PDF=20and=20read=20green/red=20status=20?= =?UTF-8?q?badge?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Sonnet 5 --- .../selenium_CCA_eligibilityCheckWorker.py | 70 +++++++++++++++++-- 1 file changed, 66 insertions(+), 4 deletions(-) diff --git a/apps/SeleniumService/selenium_CCA_eligibilityCheckWorker.py b/apps/SeleniumService/selenium_CCA_eligibilityCheckWorker.py index 68eb3284..6c525283 100644 --- a/apps/SeleniumService/selenium_CCA_eligibilityCheckWorker.py +++ b/apps/SeleniumService/selenium_CCA_eligibilityCheckWorker.py @@ -482,6 +482,40 @@ class AutomationCCAEligibilityCheck: print(f"[CCA step1] Exception: {e}") return f"ERROR: step1 failed: {e}" + def _capture_popup_pdf(self): + """Screenshot the visible popup and wrap it in a PDF (no extra deps).""" + try: + shot = self.driver.execute_cdp_cmd("Page.captureScreenshot", {"format": "png"}) + png_b64 = shot.get("data", "") + if not png_b64: + return "" + original_window = self.driver.current_window_handle + self.driver.execute_script("window.open('about:blank','_blank');") + self.driver.switch_to.window(self.driver.window_handles[-1]) + html = ("") + self.driver.get("data:text/html;base64," + base64.b64encode(html.encode()).decode()) + time.sleep(1) + res = self.driver.execute_cdp_cmd("Page.printToPDF", { + "printBackground": True, + "paperWidth": 11, + "paperHeight": 8.5, + "marginTop": 0.2, "marginBottom": 0.2, + "marginLeft": 0.2, "marginRight": 0.2, + }) + self.driver.close() + self.driver.switch_to.window(original_window) + data = res.get("data", "") + print(f"[CCA step2] Popup PDF, b64 len={len(data)}") + return data + except Exception as e: + print(f"[CCA step2] Popup capture failed: {e}") + try: + self.driver.switch_to.window(self.driver.window_handles[0]) + except Exception: + pass + return "" + def step2(self): """ Extract all patient information from the result popup, @@ -508,6 +542,29 @@ class AutomationCCAEligibilityCheck: eligibility = "Eligible" elif "not eligible" in body_text.lower() or "ineligible" in body_text.lower(): eligibility = "Not Eligible" + else: + # Popup rows show a status badge: green = active, red = not active + try: + badge = self.driver.execute_script(""" + const out = []; + document.querySelectorAll('span,div,label').forEach(el => { + if (el.children.length === 0 && /^\\s*(not\\s+)?(eligible|ineligible|inactive)\\s*$/i.test(el.textContent)) { + if (el.offsetParent === null) return; + const m = getComputedStyle(el).backgroundColor.match(/\\d+/g) || []; + out.push({t: el.textContent.trim(), r: +m[0], g: +m[1], b: +m[2]}); + } + }); + return out; + """) or [] + for b in badge: + if b["g"] > b["r"] and b["g"] > b["b"]: + eligibility = "Eligible" + break + if b["r"] > b["g"] and b["r"] > b["b"]: + eligibility = "Not Eligible" + print(f"[CCA step2] Status badges: {badge} -> {eligibility}") + except Exception as e: + print(f"[CCA step2] Badge check failed: {e}") # --- Patient name --- for sel in [ @@ -643,15 +700,18 @@ class AutomationCCAEligibilityCheck: continue if not view_report_clicked: - print("[CCA step2] 'View Eligibility Report' button not found") - raise Exception("View Eligibility Report button not found") + print("[CCA step2] 'View Eligibility Report' button not found; " + "capturing the popup itself") + pdfBase64 = self._capture_popup_pdf() + if not pdfBase64: + raise Exception("View Eligibility Report button not found") # Wait for download to start time.sleep(3) # Check for downloaded file (this site downloads rather than opens in-tab) pdf_path = None - for i in range(15): + for i in range(0 if pdfBase64 else 15): time.sleep(1) current_files = set(glob.glob(os.path.join(self.download_dir, "*"))) new_files = current_files - existing_files @@ -662,7 +722,9 @@ class AutomationCCAEligibilityCheck: print(f"[CCA step2] PDF downloaded: {pdf_path}") break - if pdf_path and os.path.exists(pdf_path): + if pdfBase64: + pass + elif pdf_path and os.path.exists(pdf_path): with open(pdf_path, "rb") as f: pdfBase64 = base64.b64encode(f.read()).decode() print(f"[CCA step2] PDF from download: {os.path.basename(pdf_path)} "