fix: DDMA claim checkbox, eligibility patient name, and ID+DOB patient lookup
- Claim step2: robust member checkbox selection with page-wide fallback - Eligibility: take patient name from 'Benefits for' heading, not subscriber name - Processor: update the patient just created/matched by ID+DOB, not first ID match Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -167,12 +167,17 @@ export async function createOrUpdatePatientByInsuranceId(options: {
|
||||
}
|
||||
|
||||
try {
|
||||
await storage.createPatient(patientData);
|
||||
const created = await storage.createPatient(patientData);
|
||||
console.log(`[createOrUpdatePatient] patient created successfully for insuranceId="${normalizedId}"`);
|
||||
// Return the record just created — family members share an insuranceId, so an
|
||||
// id-only lookup could return a different member.
|
||||
if (created?.id) return created;
|
||||
} catch (dbErr: any) {
|
||||
console.error(`[createOrUpdatePatient] DB create failed:`, dbErr?.message ?? dbErr);
|
||||
throw dbErr;
|
||||
}
|
||||
|
||||
return storage.getPatientByInsuranceId(normalizedId);
|
||||
return dobDate
|
||||
? storage.getPatientByInsuranceIdAndDob(normalizedId, dobDate)
|
||||
: storage.getPatientByInsuranceId(normalizedId);
|
||||
}
|
||||
|
||||
@@ -119,7 +119,7 @@ async function processDdmaResult(
|
||||
}
|
||||
|
||||
// 2) Create / update patient
|
||||
await createOrUpdatePatientByInsuranceId({
|
||||
const upsertedPatient = await createOrUpdatePatientByInsuranceId({
|
||||
insuranceId,
|
||||
firstName,
|
||||
lastName,
|
||||
@@ -129,7 +129,14 @@ async function processDdmaResult(
|
||||
|
||||
// 3) Fetch patient (needed for ID)
|
||||
const normalizedInsuranceId = insuranceId.replace(/\s+/g, "");
|
||||
const patient = await storage.getPatientByInsuranceId(normalizedInsuranceId);
|
||||
// Use the patient just created/updated (family members share an insuranceId, so an
|
||||
// id-only lookup could return a different member).
|
||||
const dobForLookup = formDob ? new Date(formDob) : null;
|
||||
const patient =
|
||||
upsertedPatient ??
|
||||
(dobForLookup && !isNaN(dobForLookup.getTime())
|
||||
? await storage.getPatientByInsuranceIdAndDob(normalizedInsuranceId, dobForLookup)
|
||||
: await storage.getPatientByInsuranceId(normalizedInsuranceId));
|
||||
log("ddma-processor", `patient lookup after create: ${patient ? `id=${patient.id}` : "NOT FOUND"} for insuranceId="${normalizedInsuranceId}"`);
|
||||
if (!patient?.id) {
|
||||
output.patientUpdateStatus = "Patient not found; no update performed";
|
||||
|
||||
Reference in New Issue
Block a user