From a4ff052fefc4fb9bc847b109a2f36b477a54ce3a Mon Sep 17 00:00:00 2001 From: saridsa2 Date: Mon, 13 Apr 2026 11:23:22 +0530 Subject: [PATCH] fix: stop auto-creating Unknown leads on caller resolve MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Return empty IDs for unrecognized numbers instead of creating lead+patient. Per PRD: 'System will not identify the patient — no summary shown.' Records are created when agent books appointment or logs enquiry. Co-Authored-By: Claude Opus 4.6 (1M context) --- src/caller/caller-resolution.service.ts | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/caller/caller-resolution.service.ts b/src/caller/caller-resolution.service.ts index 719786b..5bc9675 100644 --- a/src/caller/caller-resolution.service.ts +++ b/src/caller/caller-resolution.service.ts @@ -23,7 +23,12 @@ export class CallerResolutionService { private readonly cache: SessionService, ) {} - // Resolve a caller by phone number. Always returns a paired lead + patient. + // Resolve a caller by phone number. + // Looks up existing lead + patient by phone. If neither exists, returns + // isNew: true with no IDs — records are NOT created automatically. + // Record creation happens when the agent explicitly books an appointment + // or logs an enquiry (per PRD: "System will not identify the patient — + // no summary shown" for unregistered numbers). async resolve(phone: string, auth: string): Promise { const normalized = phone.replace(/\D/g, '').slice(-10); if (normalized.length < 10) { @@ -85,13 +90,12 @@ export class CallerResolutionService { isNew: false, }; } else { - // Neither exists — create both - const newPatient = await this.createPatient('', '', normalized, auth); - const newLead = await this.createLead('', '', normalized, newPatient.id, auth); - this.logger.log(`[RESOLVE] Created new lead ${newLead.id} + patient ${newPatient.id} for ${normalized}`); + // Neither exists — return empty result, don't create records. + // Agent will create records when they book an appointment or log an enquiry. + this.logger.log(`[RESOLVE] No existing records for ${normalized} — returning unresolved`); result = { - leadId: newLead.id, - patientId: newPatient.id, + leadId: '', + patientId: '', firstName: '', lastName: '', phone: normalized,