feat: route MH eligibility to CMSP button for patients under 21 in AI chat
siteKeyToAutoCheck now accepts an optional dob parameter. When siteKey is MH and the patient is under 21 years old, returns "cmsp" so the AI chat triggers the CMSP eligibility & history & remaining button instead of the adult MH one. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -55,15 +55,29 @@ export function deriveSiteKey(provider: string): string {
|
||||
return "MH";
|
||||
}
|
||||
|
||||
// siteKey → autoCheck value used by the insurance-status page prefill
|
||||
export function siteKeyToAutoCheck(siteKey: string): string {
|
||||
// siteKey → autoCheck value used by the insurance-status page prefill.
|
||||
// For MH, pass the patient's DOB so under-21 patients route to CMSP.
|
||||
export function siteKeyToAutoCheck(siteKey: string, dob?: string | Date | null): string {
|
||||
switch (siteKey) {
|
||||
case "CCA": return "cca";
|
||||
case "DDMA": return "ddma";
|
||||
case "DELTA_INS": return "delta-ins";
|
||||
case "TUFTS_SCO": return "tufts-sco";
|
||||
case "UNITED_SCO": return "united-sco";
|
||||
default: return "mh"; // MH (caller may downgrade to "cmsp" by age)
|
||||
default: {
|
||||
// MassHealth: patients under 21 use the CMSP button
|
||||
if (dob) {
|
||||
try {
|
||||
const birth = dob instanceof Date ? dob : new Date(dob);
|
||||
const today = new Date();
|
||||
let age = today.getFullYear() - birth.getFullYear();
|
||||
const m = today.getMonth() - birth.getMonth();
|
||||
if (m < 0 || (m === 0 && today.getDate() < birth.getDate())) age--;
|
||||
if (age < 21) return "cmsp";
|
||||
} catch {}
|
||||
}
|
||||
return "mh";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -231,7 +245,7 @@ export async function runInternalChatWorkflow(
|
||||
memberId: patient.insuranceId,
|
||||
dob: resolvedDob,
|
||||
siteKey,
|
||||
autoCheck: siteKeyToAutoCheck(siteKey),
|
||||
autoCheck: siteKeyToAutoCheck(siteKey, resolvedDob),
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user