fix: BCBS MA — identify patient by member ID + DOB, prevent overwriting subscriber

- Added getPatientByInsuranceIdAndDob to storage
- Processor uses insuranceId + DOB as unique key instead of insuranceId alone
- Dependent with same subscriber ID but different DOB gets a new patient record
  (bypasses createOrUpdatePatientByInsuranceId which would overwrite subscriber)
- Name extraction anchored to "Relationship:" to scope Patient Info column only

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
ff
2026-06-01 23:51:11 -04:00
parent 87d7ce9ed9
commit 3ac185b0ec
3 changed files with 87 additions and 31 deletions

View File

@@ -424,39 +424,46 @@ class AutomationBCBSMAEligibilityCheck:
else:
eligibility = "Unknown"
# Extract first/last name from DOM — scope to "Patient Information" column only
# to avoid picking up the duplicate values in the Subscriber Information column.
# Extract first/last name from Patient Information column only.
# "Relationship:" is unique to the Patient column (not in Subscriber column).
# Use it as anchor: grab text from "Relationship:" up to "Member ID:" (Subscriber starts there).
import re
first_name = self.first_name
last_name = self.last_name
try:
# Find the "Patient Information" header, then search within its parent container
patient_section = self.driver.find_element(By.XPATH,
"//*[normalize-space(text())='Patient Information']/ancestor::*[3]"
# Slice out just the Patient Information section
patient_match = re.search(
r"Relationship:(.+?)(?=Member ID:|Subscriber Information|Plan Name:)",
page_text,
re.DOTALL
)
section_text = patient_section.text
print(f"[BCBS MA step2] Patient section text:\n{section_text[:300]}")
if patient_match:
patient_text = patient_match.group(1)
print(f"[BCBS MA step2] Patient section:\n{patient_text[:200]}")
lines = section_text.split("\n")
capturing_last = False
for line in lines:
stripped = line.strip()
if "First Name:" in stripped and not first_name:
val = stripped.split("First Name:", 1)[1].strip()
val = val.split("Middle Name:")[0].split("Last Name:")[0].strip()
if val:
first_name = val
elif "Last Name:" in stripped and not last_name:
val = stripped.split("Last Name:", 1)[1].strip()
val = val.split("SSN:")[0].split("Date of Birth:")[0].split("Member ID:")[0].strip()
if val:
last_name = val
capturing_last = True
elif capturing_last:
if stripped and ":" not in stripped and stripped == stripped.upper():
last_name += " " + stripped
capturing_last = False
if first_name and last_name and not capturing_last:
break
lines = patient_text.split("\n")
capturing_last = False
for line in lines:
stripped = line.strip()
if "First Name:" in stripped and not first_name:
val = stripped.split("First Name:", 1)[1].strip()
val = val.split("Middle Name:")[0].split("Last Name:")[0].strip()
if val:
first_name = val
elif "Last Name:" in stripped and not last_name:
val = stripped.split("Last Name:", 1)[1].strip()
val = val.split("SSN:")[0].split("Date of Birth:")[0].strip()
if val:
last_name = val
capturing_last = True
elif capturing_last:
if stripped and ":" not in stripped and stripped == stripped.upper():
last_name += " " + stripped
capturing_last = False
if first_name and last_name and not capturing_last:
break
else:
print("[BCBS MA step2] Patient section not found in page text")
print(f"[BCBS MA step2] Extracted — First: '{first_name}', Last: '{last_name}'")
except Exception as e: