fix(ai-chat): use correct Clinic schema in knowledge-base query

The Clinic entity has never had weekdayHours / saturdayHours /
sundayHours. Schema uses 7 booleans (openMonday..openSunday) + a single
opensAt/closesAt pair, and requiredDocuments is a RELATION
(ClinicRequiredDocumentConnection), not a scalar TEXT.

Query was failing silently since 2026-03-18 — AI chat knowledge base
was missing clinic info for a month.

Fix:
- Query the real fields: openMonday..openSunday, opensAt, closesAt
- Render "Open: Mon, Tue, ... HH:MM–HH:MM" + "Closed: Sat, Sun"
- Walk requiredDocuments.edges for documentType list instead of treating
  it as a string

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-04-15 10:31:00 +05:30
parent 048545317d
commit 98f5bc0347

View File

@@ -567,16 +567,23 @@ export class AiChatController {
`{ clinics(first: 20) { edges { node { `{ clinics(first: 20) { edges { node {
id name clinicName id name clinicName
addressCustom { addressStreet1 addressCity addressState addressPostcode } addressCustom { addressStreet1 addressCity addressState addressPostcode }
weekdayHours saturdayHours sundayHours openMonday openTuesday openWednesday openThursday openFriday openSaturday openSunday
opensAt closesAt
status walkInAllowed onlineBooking status walkInAllowed onlineBooking
cancellationWindowHours arriveEarlyMin requiredDocuments cancellationWindowHours arriveEarlyMin
acceptsCash acceptsCard acceptsUpi acceptsCash acceptsCard acceptsUpi
requiredDocuments { edges { node { documentType notes } } }
} } } }`, } } } }`,
undefined, auth, undefined, auth,
); );
const clinics = clinicData.clinics.edges.map((e: any) => e.node); const clinics = clinicData.clinics.edges.map((e: any) => e.node);
if (clinics.length) { if (clinics.length) {
sections.push('## CLINICS & TIMINGS'); sections.push('## CLINICS & TIMINGS');
const dayFlags: Array<[string, string]> = [
['Mon', 'openMonday'], ['Tue', 'openTuesday'], ['Wed', 'openWednesday'],
['Thu', 'openThursday'], ['Fri', 'openFriday'],
['Sat', 'openSaturday'], ['Sun', 'openSunday'],
];
for (const c of clinics) { for (const c of clinics) {
const name = c.clinicName ?? c.name; const name = c.clinicName ?? c.name;
const addr = c.addressCustom const addr = c.addressCustom
@@ -584,9 +591,15 @@ export class AiChatController {
: ''; : '';
sections.push(`### ${name}`); sections.push(`### ${name}`);
if (addr) sections.push(` Address: ${addr}`); if (addr) sections.push(` Address: ${addr}`);
if (c.weekdayHours) sections.push(` MonFri: ${c.weekdayHours}`); const openDays = dayFlags.filter(([, flag]) => c[flag]).map(([label]) => label);
if (c.saturdayHours) sections.push(` Saturday: ${c.saturdayHours}`); if (openDays.length) {
sections.push(` Sunday: ${c.sundayHours ?? 'Closed'}`); const hours = c.opensAt && c.closesAt ? ` ${c.opensAt}${c.closesAt}` : '';
sections.push(` Open: ${openDays.join(', ')}${hours}`);
}
const closedDays = dayFlags.filter(([, flag]) => !c[flag]).map(([label]) => label);
if (closedDays.length) {
sections.push(` Closed: ${closedDays.join(', ')}`);
}
if (c.walkInAllowed) sections.push(` Walk-ins: Accepted`); if (c.walkInAllowed) sections.push(` Walk-ins: Accepted`);
} }
@@ -594,7 +607,8 @@ export class AiChatController {
const rules: string[] = []; const rules: string[] = [];
if (rulesClinic.cancellationWindowHours) rules.push(`Free cancellation up to ${rulesClinic.cancellationWindowHours}h before`); if (rulesClinic.cancellationWindowHours) rules.push(`Free cancellation up to ${rulesClinic.cancellationWindowHours}h before`);
if (rulesClinic.arriveEarlyMin) rules.push(`Arrive ${rulesClinic.arriveEarlyMin}min early`); if (rulesClinic.arriveEarlyMin) rules.push(`Arrive ${rulesClinic.arriveEarlyMin}min early`);
if (rulesClinic.requiredDocuments) rules.push(`First-time patients bring ${rulesClinic.requiredDocuments}`); const docs = rulesClinic.requiredDocuments?.edges?.map((e: any) => e.node?.documentType).filter(Boolean) ?? [];
if (docs.length) rules.push(`First-time patients bring: ${docs.join(', ')}`);
if (rulesClinic.walkInAllowed) rules.push('Walk-ins accepted'); if (rulesClinic.walkInAllowed) rules.push('Walk-ins accepted');
if (rulesClinic.onlineBooking) rules.push('Online booking available'); if (rulesClinic.onlineBooking) rules.push('Online booking available');
if (rules.length) { if (rules.length) {