From a163d2a73f85caa6826a246f7c81dba6d389ad50 Mon Sep 17 00:00:00 2001 From: Potenz Date: Wed, 29 Oct 2025 20:12:57 +0530 Subject: [PATCH] feat(check-all-eligibility) - v2 --- apps/Backend/src/routes/insuranceStatus.ts | 40 ++++++++++++++++++++-- 1 file changed, 37 insertions(+), 3 deletions(-) diff --git a/apps/Backend/src/routes/insuranceStatus.ts b/apps/Backend/src/routes/insuranceStatus.ts index c947428..534758b 100644 --- a/apps/Backend/src/routes/insuranceStatus.ts +++ b/apps/Backend/src/routes/insuranceStatus.ts @@ -537,16 +537,50 @@ router.post( if (!memberId) { resultItem.error = `Missing insuranceId for ${patientLabel} — skipping ${aptLabel}`; - results.push(resultItem); continue; } // prepare eligibility data; prefer patient DOB + name if present - const dob = patient?.dateOfBirth ? patient.dateOfBirth : null; // string | Date + const dob = patient?.dateOfBirth; + if (!dob) { + resultItem.error = `Missing dob for ${patientLabel} — skipping ${aptLabel}`; + results.push(resultItem); + continue; + } + + // Convert Date object → YYYY-MM-DD string - req for selenium agent. + let dobStr: string; + try { + if (dob instanceof Date) { + const year = dob.getFullYear(); + const month = String(dob.getMonth() + 1).padStart(2, "0"); + const day = String(dob.getDate()).padStart(2, "0"); + dobStr = `${year}-${month}-${day}`; + } else if (typeof dob === "string") { + // handle stored string already formatted + const dateObj = new Date(dob); + if (!isNaN(dateObj.getTime())) { + const year = dateObj.getFullYear(); + const month = String(dateObj.getMonth() + 1).padStart(2, "0"); + const day = String(dateObj.getDate()).padStart(2, "0"); + dobStr = `${year}-${month}-${day}`; + } else { + // assume string is already "YYYY-MM-DD" + dobStr = dob; + } + } else { + throw new Error("Unsupported DOB format"); + } + } catch (fmtErr) { + resultItem.error = `Invalid DOB format for ${patientLabel} — skipping ${aptLabel}`; + results.push(resultItem); + continue; + } + const payload = { memberId, - dateOfBirth: dob, + dateOfBirth: dobStr, insuranceSiteKey: "MH", };