feat: add assistant chatbot with eligibility auto-check

- Add ChatbotButton component to top-app-bar (bot icon, upper right)
- Slide-in chat panel with 4 options: Check Eligibility, Schedule, Claims, Chat
- Single paste area accepts member ID + DOB in either order
- Age-based routing: ≥21 → MH Eligibility & History, <21 → CMSP auto-triggered
- Insurance-status page prefills fields and auto-fires the correct button via sessionStorage + custom event

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Gitead
2026-05-14 13:42:53 -04:00
parent 4f2cbc2c60
commit c1f55778ca
3 changed files with 398 additions and 2 deletions

View File

@@ -1,4 +1,4 @@
import { useEffect, useState } from "react";
import { useEffect, useRef, useState } from "react";
import { useMutation, useQuery } from "@tanstack/react-query";
import { Input } from "@/components/ui/input";
import { Button } from "@/components/ui/button";
@@ -114,6 +114,27 @@ export default function InsuranceStatusPage() {
const [cmspAccumulatorPdfId, setCmspAccumulatorPdfId] = useState<number | null>(null);
const [cmspAccumulatorFilename, setCmspAccumulatorFilename] = useState<string | null>(null);
const pendingAutoCheck = useRef<"mh" | "cmsp" | null>(null);
// Prefill from chatbot
useEffect(() => {
const apply = () => {
const raw = sessionStorage.getItem("chatbot_eligibility");
if (!raw) return;
try {
const { memberId: id, dob, autoCheck: ac } = JSON.parse(raw);
if (id) setMemberId(id);
if (dob) setDateOfBirth(parseLocalDate(dob));
if (ac === "mh" || ac === "cmsp") pendingAutoCheck.current = ac;
sessionStorage.removeItem("chatbot_eligibility");
} catch {}
};
apply();
window.addEventListener("chatbot:eligibility-prefill", apply);
return () =>
window.removeEventListener("chatbot:eligibility-prefill", apply);
}, []);
// Populate fields from selected patient
useEffect(() => {
if (selectedPatient) {
@@ -125,7 +146,7 @@ export default function InsuranceStatusPage() {
typeof selectedPatient.dateOfBirth === "string"
? parseLocalDate(selectedPatient.dateOfBirth)
: selectedPatient.dateOfBirth;
setDateOfBirth(dob);
setDateOfBirth(dob ?? null);
} else {
setMemberId("");
setFirstName("");
@@ -574,6 +595,19 @@ export default function InsuranceStatusPage() {
}
};
// Auto-trigger from chatbot after prefill
useEffect(() => {
if (!pendingAutoCheck.current || !memberId || !dateOfBirth) return;
const check = pendingAutoCheck.current;
pendingAutoCheck.current = null;
if (check === "mh") {
handleMHEligibilityHistoryButton();
} else {
handleCMSPButton();
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [memberId, dateOfBirth]);
// small helper: remove given query params from the current URL (silent, no reload)
const clearUrlParams = (params: string[]) => {
try {