feat(check-all-eligibility) - v3
This commit is contained in:
@@ -13,6 +13,7 @@ import {
|
|||||||
InsertPatient,
|
InsertPatient,
|
||||||
insertPatientSchema,
|
insertPatientSchema,
|
||||||
} from "../../../../packages/db/types/patient-types";
|
} from "../../../../packages/db/types/patient-types";
|
||||||
|
import { formatDobForAgent } from "../utils/dateUtils";
|
||||||
|
|
||||||
const router = Router();
|
const router = Router();
|
||||||
|
|
||||||
@@ -550,30 +551,9 @@ router.post(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Convert Date object → YYYY-MM-DD string - req for selenium agent.
|
// Convert Date object → YYYY-MM-DD string - req for selenium agent.
|
||||||
let dobStr: string;
|
const dobStr = formatDobForAgent(dob);
|
||||||
try {
|
if (!dobStr) {
|
||||||
if (dob instanceof Date) {
|
resultItem.error = `Invalid or missing DOB for ${patientLabel} — skipping ${aptLabel}`;
|
||||||
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);
|
results.push(resultItem);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,3 +24,38 @@ export function convertOCRDate(input: string | number | null | undefined): Date
|
|||||||
|
|
||||||
return new Date(year, month, day);
|
return new Date(year, month, day);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Normalize a DOB value to "YYYY-MM-DD" string expected by the Python agent.
|
||||||
|
* - If dob is already "YYYY-MM-DD" string, returns it.
|
||||||
|
* - If dob is an ISO datetime string or Date, returns YYYY-MM-DD derived from UTC parts (no timezone shifts).
|
||||||
|
* - Returns null for invalid values.
|
||||||
|
*/
|
||||||
|
export function formatDobForAgent(dob: Date | string | null | undefined): string | null {
|
||||||
|
if (!dob) return null;
|
||||||
|
|
||||||
|
// If it's a string in exact YYYY-MM-DD format, return as-is (most ideal).
|
||||||
|
if (typeof dob === "string") {
|
||||||
|
const simpleDateMatch = /^\d{4}-\d{2}-\d{2}$/.test(dob);
|
||||||
|
if (simpleDateMatch) return dob;
|
||||||
|
|
||||||
|
// Otherwise try parsing as a Date/ISO string and use UTC parts
|
||||||
|
const parsed = new Date(dob);
|
||||||
|
if (isNaN(parsed.getTime())) return null;
|
||||||
|
const y = parsed.getUTCFullYear();
|
||||||
|
const m = String(parsed.getUTCMonth() + 1).padStart(2, "0");
|
||||||
|
const d = String(parsed.getUTCDate()).padStart(2, "0");
|
||||||
|
return `${y}-${m}-${d}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
// If it's a Date object, use UTC getters to avoid timezone shifts
|
||||||
|
if (dob instanceof Date) {
|
||||||
|
if (isNaN(dob.getTime())) return null;
|
||||||
|
const y = dob.getUTCFullYear();
|
||||||
|
const m = String(dob.getUTCMonth() + 1).padStart(2, "0");
|
||||||
|
const d = String(dob.getUTCDate()).padStart(2, "0");
|
||||||
|
return `${y}-${m}-${d}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user