fix: DDMA eligibility worker — extract name from row, pass DOB from input, wait for page load

- 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 <noreply@anthropic.com>
This commit is contained in:
ff
2026-06-18 15:06:45 -04:00
parent 6958d13282
commit 092f0778fe
2 changed files with 22 additions and 6 deletions

View File

@@ -117,8 +117,14 @@ export async function createOrUpdatePatientByInsuranceId(options: {
// Primary lookup: exact insuranceId + DOB match // Primary lookup: exact insuranceId + DOB match
patient = await storage.getPatientByInsuranceIdAndDob(normalizedId, dobDate); patient = await storage.getPatientByInsuranceIdAndDob(normalizedId, dobDate);
console.log(`[createOrUpdatePatient] id+DOB lookup: ${patient ? `found id=${patient.id}` : "not found"}`); 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 if (!patient) {
// is a different family member and must not be overwritten. // 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 { } else {
// No DOB supplied — fall back to insuranceId-only (legacy / non-family plans) // No DOB supplied — fall back to insuranceId-only (legacy / non-family plans)
patient = await storage.getPatientByInsuranceId(normalizedId); patient = await storage.getPatientByInsuranceId(normalizedId);

View File

@@ -342,6 +342,12 @@ class AutomationDeltaDentalMAEligibilityCheck:
fields.append(f"DOB: {self.dateOfBirth}") fields.append(f"DOB: {self.dateOfBirth}")
print(f"[DDMA step1] Starting search with: {', '.join(fields)}") 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 # Select provider from dropdown based on NPI settings
self._select_provider_dropdown() 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"]')), EC.presence_of_element_located((By.XPATH, '//div[@data-testid="member-search-result-no-results"]')),
) )
) )
time.sleep(3)
except TimeoutException: except TimeoutException:
pass # proceed and let step2 handle missing results pass # proceed and let step2 handle missing results
@@ -447,7 +454,7 @@ class AutomationDeltaDentalMAEligibilityCheck:
foundMemberId = self.memberId or "" foundMemberId = self.memberId or ""
patientName = "" patientName = ""
# Extract eligibility status and member ID from search results row # Extract patient name from search results row
try: try:
first_row = self.driver.find_element(By.XPATH, "(//tbody//tr)[1]") first_row = self.driver.find_element(By.XPATH, "(//tbody//tr)[1]")
row_text = first_row.text.strip() row_text = first_row.text.strip()
@@ -456,9 +463,11 @@ class AutomationDeltaDentalMAEligibilityCheck:
lines = row_text.split('\n') if row_text else [] lines = row_text.split('\n') if row_text else []
for line in lines: for line in lines:
line = line.strip() line = line.strip()
if line and re.match(r'^[A-Z0-9]{5,}$', line) and not line.startswith('DOB'): if not line:
foundMemberId = line continue
print(f"[DDMA step2] Extracted Member ID: {foundMemberId}") if re.match(r"^[A-Za-z\s\-']{2,60}$", line):
patientName = line
print(f"[DDMA step2] Extracted patient name from row: '{patientName}'")
break break
except Exception as e: except Exception as e:
print(f"[DDMA step2] Error reading first row: {e}") print(f"[DDMA step2] Error reading first row: {e}")
@@ -657,6 +666,7 @@ class AutomationDeltaDentalMAEligibilityCheck:
"pdf_path": pdf_path, # explicit pdf_path "pdf_path": pdf_path, # explicit pdf_path
"patientName": patientName, "patientName": patientName,
"memberId": foundMemberId, "memberId": foundMemberId,
"dateOfBirth": self.dateOfBirth,
} }
except Exception as e: except Exception as e: