feat: AI chat Eligibility & Appointment button with 15-min slots and Column B fallback

- Add "Eligibility & Appointment" button to chatbot eligibility-id-ready card
- For known patients: creates today's appointment immediately, then opens eligibility page
- For unknown patients: navigates to eligibility page; after Selenium creates the patient,
  auto-creates appointment via tryAppointmentFromChatbot on the insurance-status page
- Update MH Eligibility & Appointment button to create a today's schedule slot instead of
  navigating to the appointments page; shows PDF preview on completion
- createAppointmentToday falls back from Column A to Column B when Column A is full;
  returns column label in response so UI can display it
- Set AI-scheduled appointment duration to 15 minutes

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
ff
2026-06-09 16:14:08 -04:00
parent a8ec1a21c0
commit 541d65da6d
4 changed files with 192 additions and 13 deletions

View File

@@ -299,6 +299,35 @@ export function ChatbotButton() {
prefillAndNavigate(eligibilityIdData.memberId, eligibilityIdData.dob, eligibilityIdData.autoCheck);
};
const handleEligibilityAndAppointment = async () => {
if (!eligibilityIdData) return;
addMsg("user", "Check eligibility & add to today's schedule");
if (!eligibilityIdData.patient) {
// Patient not yet in DB — eligibility check will create them; flag for post-check appointment
addMsg("bot", "Running eligibility check — will add patient and create today's appointment after...");
sessionStorage.setItem("chatbot_appt_after_eligibility", JSON.stringify({ memberId: eligibilityIdData.memberId }));
prefillAndNavigate(eligibilityIdData.memberId, eligibilityIdData.dob, eligibilityIdData.autoCheck);
return;
}
addMsg("bot", "Creating appointment for today...", true);
try {
const res = await apiRequest("POST", "/api/ai/create-appointment-today", {
patientId: eligibilityIdData.patient.id,
});
const data = await res.json();
if (!res.ok) {
replaceLastMsg(data.message ?? "Could not create appointment.");
return;
}
replaceLastMsg(`Appointment added at ${data.startTime} (${data.column ?? "Column A"}) — opening eligibility check page...`);
prefillAndNavigate(eligibilityIdData.memberId, eligibilityIdData.dob, eligibilityIdData.autoCheck);
} catch {
replaceLastMsg("Could not create appointment. Please try again.");
}
};
const handleCheckAndClaimRun = () => {
if (!checkAndClaimData) return;
addMsg("user", "Run check & claim");
@@ -653,16 +682,24 @@ export function ChatbotButton() {
{eligibilityIdData.patient?.insuranceProvider && (
<p className="text-xs text-gray-500">{eligibilityIdData.patient.insuranceProvider}</p>
)}
<div className="flex gap-2 pt-1">
<div className="flex flex-col gap-2 pt-1">
<Button
size="sm"
className="flex-1 h-8 text-xs bg-primary hover:bg-primary/90"
className="w-full h-8 text-xs bg-primary hover:bg-primary/90"
onClick={handleEligibilityIdRun}
>
<Stethoscope className="h-3 w-3 mr-1" />
Check Eligibility
</Button>
<Button size="sm" variant="ghost" className="h-8 text-xs" onClick={reset}>
<Button
size="sm"
className="w-full h-8 text-xs bg-emerald-600 hover:bg-emerald-700 text-white"
onClick={handleEligibilityAndAppointment}
>
<Calendar className="h-3 w-3 mr-1" />
Eligibility &amp; Appointment
</Button>
<Button size="sm" variant="ghost" className="w-full h-8 text-xs" onClick={reset}>
Cancel
</Button>
</div>