From 092f0778feb85dc659eb8beabaf68ca7858ed5a4 Mon Sep 17 00:00:00 2001 From: ff Date: Thu, 18 Jun 2026 15:06:45 -0400 Subject: [PATCH] =?UTF-8?q?fix:=20DDMA=20eligibility=20worker=20=E2=80=94?= =?UTF-8?q?=20extract=20name=20from=20row,=20pass=20DOB=20from=20input,=20?= =?UTF-8?q?wait=20for=20page=20load?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Extract patient name from search results row instead of failing on detail page - Return dateOfBirth from input data (no need to scrape from webpage) - Wait for search page to fully load before provider dropdown selection - Add 3s wait after search results appear for row content to render - Backend: fallback to update existing patient DOB instead of creating duplicate Co-Authored-By: Claude Sonnet 4.6 --- apps/Backend/src/queue/processors/_shared.ts | 10 ++++++++-- .../selenium_DDMA_eligibilityCheckWorker.py | 18 ++++++++++++++---- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/apps/Backend/src/queue/processors/_shared.ts b/apps/Backend/src/queue/processors/_shared.ts index 92fe9305..8d1059f4 100644 --- a/apps/Backend/src/queue/processors/_shared.ts +++ b/apps/Backend/src/queue/processors/_shared.ts @@ -117,8 +117,14 @@ export async function createOrUpdatePatientByInsuranceId(options: { // Primary lookup: exact insuranceId + DOB match patient = await storage.getPatientByInsuranceIdAndDob(normalizedId, dobDate); console.log(`[createOrUpdatePatient] id+DOB lookup: ${patient ? `found id=${patient.id}` : "not found"}`); - // Do NOT fall back to insuranceId-only lookup — another record with that ID - // is a different family member and must not be overwritten. + if (!patient) { + // Fallback: patient exists but has no DOB yet — update rather than duplicate + const byIdOnly = await storage.getPatientByInsuranceId(normalizedId); + if (byIdOnly && !byIdOnly.dateOfBirth) { + patient = byIdOnly; + console.log(`[createOrUpdatePatient] id-only fallback (no DOB on record): found id=${patient.id}`); + } + } } else { // No DOB supplied — fall back to insuranceId-only (legacy / non-family plans) patient = await storage.getPatientByInsuranceId(normalizedId); diff --git a/apps/SeleniumService/selenium_DDMA_eligibilityCheckWorker.py b/apps/SeleniumService/selenium_DDMA_eligibilityCheckWorker.py index c885ad53..76b5a90b 100755 --- a/apps/SeleniumService/selenium_DDMA_eligibilityCheckWorker.py +++ b/apps/SeleniumService/selenium_DDMA_eligibilityCheckWorker.py @@ -342,6 +342,12 @@ class AutomationDeltaDentalMAEligibilityCheck: fields.append(f"DOB: {self.dateOfBirth}") print(f"[DDMA step1] Starting search with: {', '.join(fields)}") + # Wait for the search page to be fully loaded before interacting + wait.until(EC.presence_of_element_located( + (By.XPATH, '//input[@placeholder="Search by member ID"]') + )) + time.sleep(1) + # Select provider from dropdown based on NPI settings self._select_provider_dropdown() @@ -408,6 +414,7 @@ class AutomationDeltaDentalMAEligibilityCheck: EC.presence_of_element_located((By.XPATH, '//div[@data-testid="member-search-result-no-results"]')), ) ) + time.sleep(3) except TimeoutException: pass # proceed and let step2 handle missing results @@ -447,7 +454,7 @@ class AutomationDeltaDentalMAEligibilityCheck: foundMemberId = self.memberId or "" patientName = "" - # Extract eligibility status and member ID from search results row + # Extract patient name from search results row try: first_row = self.driver.find_element(By.XPATH, "(//tbody//tr)[1]") row_text = first_row.text.strip() @@ -456,9 +463,11 @@ class AutomationDeltaDentalMAEligibilityCheck: lines = row_text.split('\n') if row_text else [] for line in lines: line = line.strip() - if line and re.match(r'^[A-Z0-9]{5,}$', line) and not line.startswith('DOB'): - foundMemberId = line - print(f"[DDMA step2] Extracted Member ID: {foundMemberId}") + if not line: + continue + if re.match(r"^[A-Za-z\s\-']{2,60}$", line): + patientName = line + print(f"[DDMA step2] Extracted patient name from row: '{patientName}'") break except Exception as e: print(f"[DDMA step2] Error reading first row: {e}") @@ -657,6 +666,7 @@ class AutomationDeltaDentalMAEligibilityCheck: "pdf_path": pdf_path, # explicit pdf_path "patientName": patientName, "memberId": foundMemberId, + "dateOfBirth": self.dateOfBirth, } except Exception as e: