From 1ee3b0cfc957ede5e645467424720846d81fc44a Mon Sep 17 00:00:00 2001 From: Gitead Date: Wed, 4 Nov 2026 11:58:27 -0500 Subject: [PATCH] feat: Tufts SCO (DentaQuest) eligibility extracts member address - Read the address from the Member's information block on the member details page and save street, city, state and zip to the patient - The portal prints no comma between street and city, so split on street words and unit markers; when no boundary is found the whole text stays in the street field with city blank - Poll up to 10s for the details to load; ignore the office address in the page header Co-Authored-By: Claude Opus 5.5 --- .../dentaQuestEligibilityProcessor.ts | 8 +- .../dentaquest_member_details.py | 76 +++++++++++++++++++ ...enium_DentaQuest_eligibilityCheckWorker.py | 7 +- 3 files changed, 89 insertions(+), 2 deletions(-) create mode 100644 apps/SeleniumService/dentaquest_member_details.py diff --git a/apps/Backend/src/queue/processors/dentaQuestEligibilityProcessor.ts b/apps/Backend/src/queue/processors/dentaQuestEligibilityProcessor.ts index 44925d13..ec63bfa9 100644 --- a/apps/Backend/src/queue/processors/dentaQuestEligibilityProcessor.ts +++ b/apps/Backend/src/queue/processors/dentaQuestEligibilityProcessor.ts @@ -7,7 +7,12 @@ import { forwardToSeleniumDentaQuestEligibilityAgent, getSeleniumDentaQuestSessionStatus, } from "../../services/seleniumDentaQuestEligibilityClient"; -import { splitName, createOrUpdatePatientByInsuranceId, imageToPdfBuffer } from "./_shared"; +import { + splitName, + createOrUpdatePatientByInsuranceId, + imageToPdfBuffer, + memberDetailDemographics, +} from "./_shared"; import { io } from "../../socket"; function now() { @@ -94,6 +99,7 @@ async function processDentaQuestResult( await storage.updatePatient(patient.id, { status: newStatus, insuranceProvider: "DentaQuest", + ...memberDetailDemographics(seleniumResult, patient.phone), }); output.patientUpdateStatus = `Patient status updated to ${newStatus}`; diff --git a/apps/SeleniumService/dentaquest_member_details.py b/apps/SeleniumService/dentaquest_member_details.py new file mode 100644 index 00000000..913e359b --- /dev/null +++ b/apps/SeleniumService/dentaquest_member_details.py @@ -0,0 +1,76 @@ +import re +import time + +from selenium.webdriver.common.by import By + +# DentaQuest prints the address without commas between street and city, e.g. +# Address: 311 CAPTAIN EAMES CIRCLE ASHLAND MA 01721 +_ADDRESS_RE = re.compile(r"Address:\s*([^:]{5,150}?)[,\s]+([A-Z]{2})\s+(\d{5})(?:-?\d{4})?\b") + +# Words that end a street. Leaves out words common at the end of city names in +# MA (HILL, PARK, BAY, FALLS, CENTER...) so "HYDE PARK" stays in the city. +_STREET_SUFFIXES = { + "ST", "STREET", "AVE", "AVENUE", "RD", "ROAD", "DR", "DRIVE", "LN", "LANE", + "CT", "COURT", "CIR", "CIRCLE", "BLVD", "BOULEVARD", "WAY", "PL", "PLACE", + "TER", "TERRACE", "PKWY", "PARKWAY", "HWY", "HIGHWAY", "TPKE", "TURNPIKE", + "SQ", "SQUARE", "ALY", "ALLEY", "EXT", +} +_UNIT_WORDS = {"APT", "UNIT", "STE", "SUITE", "RM", "ROOM", "FL", "FLOOR", "BLDG"} + + +def _split_street_city(text): + """Split "311 CAPTAIN EAMES CIRCLE ASHLAND" into (street, city). The city + is empty when the boundary can't be told, so the whole text stays in street.""" + parts = [p.strip() for p in re.split(r"\s*(?:,|\n)\s*", text) if p.strip()] + if len(parts) > 1: + return " ".join(parts[:-1]), parts[-1] + + # Search from the end: "5 MAIN ST APT 2 ASHLAND" splits after the unit + words = text.split() + for i in range(len(words) - 1, 0, -1): + word = words[i].upper() + if word in _STREET_SUFFIXES: + end = i + 1 + elif word in _UNIT_WORDS: + end = i + 2 # the unit number follows + elif word.startswith("#"): + end = i + 1 + else: + continue + if end < len(words): + return " ".join(words[:end]), " ".join(words[end:]) + break + return " ".join(words), "" + + +def parse_member_address(text): + """Address fields from the page text: address, city, state, zipCode. + Empty dict when the page shows no member address.""" + # Skip anything above the member block; the label may be on its own line + section = re.search(r"Member.s information", text, re.IGNORECASE) + m = _ADDRESS_RE.search(text[section.start():] if section else text) + if not m: + return {} + street, city = _split_street_city(m.group(1).strip()) + result = {"address": street, "state": m.group(2), "zipCode": m.group(3)} + if city: + result["city"] = city + return result + + +def extract_member_address(driver, timeout=10): + """Read the member's address from the DentaQuest member details page, + polling because the details fill in after the page reports complete.""" + result = {} + try: + deadline = time.time() + timeout + while True: + text = driver.find_element(By.TAG_NAME, "body").get_attribute("innerText") or "" + result = parse_member_address(text) + if result or time.time() >= deadline: + break + time.sleep(1) + print(f"[extract_member_address] {result}") + except Exception as e: + print(f"[extract_member_address] failed: {e}") + return result diff --git a/apps/SeleniumService/selenium_DentaQuest_eligibilityCheckWorker.py b/apps/SeleniumService/selenium_DentaQuest_eligibilityCheckWorker.py index 171537b0..9e34c1ea 100644 --- a/apps/SeleniumService/selenium_DentaQuest_eligibilityCheckWorker.py +++ b/apps/SeleniumService/selenium_DentaQuest_eligibilityCheckWorker.py @@ -13,6 +13,7 @@ import re import base64 from dentaquest_browser_manager import get_browser_manager +from dentaquest_member_details import extract_member_address class AutomationDentaQuestEligibilityCheck: def __init__(self, data): @@ -677,6 +678,9 @@ class AutomationDentaQuestEligibilityCheck: patientName = _re.sub(r'\s*DOB[:\s]*\d{1,2}/\d{1,2}/\d{2,4}\s*', '', patientName, flags=_re.IGNORECASE).strip() print(f"[DentaQuest step2] Patient name: {patientName}") + # Address from the Member's information block (empty on the search results page) + member_address = extract_member_address(self.driver) if detail_url else {} + # Wait for page to fully load before generating PDF try: WebDriverWait(self.driver, 30).until( @@ -733,7 +737,8 @@ class AutomationDentaQuestEligibilityCheck: "ss_path": pdf_path, # Keep key as ss_path for backward compatibility "pdf_path": pdf_path, # Also add explicit pdf_path "patientName": patientName, - "memberId": foundMemberId # Member ID extracted from the page + "memberId": foundMemberId, # Member ID extracted from the page + **member_address, # address, city, state, zipCode } print(f"[DentaQuest step2] Success: {output}") return output