feat(check-all-eligibility) - v2

This commit is contained in:
2025-10-29 20:12:57 +05:30
parent 9a3da21695
commit a163d2a73f

View File

@@ -537,16 +537,50 @@ router.post(
if (!memberId) { if (!memberId) {
resultItem.error = `Missing insuranceId for ${patientLabel} — skipping ${aptLabel}`; resultItem.error = `Missing insuranceId for ${patientLabel} — skipping ${aptLabel}`;
results.push(resultItem); results.push(resultItem);
continue; continue;
} }
// prepare eligibility data; prefer patient DOB + name if present // 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 = { const payload = {
memberId, memberId,
dateOfBirth: dob, dateOfBirth: dobStr,
insuranceSiteKey: "MH", insuranceSiteKey: "MH",
}; };