fix: link patientId to appointment in WhatsApp booking

Appointments created via WhatsApp had null patientId — lookup_appointments
couldn't find them. Now resolves patient before booking and includes
patientId in the createAppointment mutation. Fixed in both flow tool
registry and legacy messaging service.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-04-20 18:56:39 +05:30
parent 903e82b536
commit 963cf28d23
2 changed files with 8 additions and 5 deletions

View File

@@ -380,6 +380,7 @@ ${callerContext ? `\n${callerContext}` : ''}`;
return { booked: false, message: `${doctorName} is fully booked at this time. Please choose a different slot.` };
}
let patientId = resolved?.patientId;
if (resolved?.isNew) {
const firstName = patientName.split(' ')[0];
const lastName = patientName.split(' ').slice(1).join(' ') || '';
@@ -400,7 +401,7 @@ ${callerContext ? `\n${callerContext}` : ''}`;
const result = await platform.query<any>(
`mutation($data: AppointmentCreateInput!) { createAppointment(data: $data) { id } }`,
{ data: { name: `WhatsApp Booking — ${patientName} (${department})`, scheduledAt, status: 'SCHEDULED', doctorName, department, reasonForVisit: reason } },
{ data: { name: `WhatsApp Booking — ${patientName} (${department})`, scheduledAt, status: 'SCHEDULED', doctorName, department, reasonForVisit: reason, ...(patientId ? { patientId } : {}) } },
);
const id = result?.createAppointment?.id;
if (id) {