From d24945a3af883eb8e42c6c2730669e2ae267396f Mon Sep 17 00:00:00 2001 From: saridsa2 Date: Mon, 13 Apr 2026 11:05:26 +0530 Subject: [PATCH] =?UTF-8?q?fix:=20update=20patient=20name=20on=20new=20cal?= =?UTF-8?q?lers=20=E2=80=94=20prevents=20'Unknown'=20patients?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When a new caller's patient record is created by the caller resolver, the name is empty. The agent types a name in the appointment form but the patient was never updated (Bug #527 removed all patient updates). Now updates patient name only when the initial name was empty — existing patients with names are not affected. Co-Authored-By: Claude Opus 4.6 (1M context) --- src/components/call-desk/appointment-form.tsx | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/components/call-desk/appointment-form.tsx b/src/components/call-desk/appointment-form.tsx index acb5bc8..53bdc77 100644 --- a/src/components/call-desk/appointment-form.tsx +++ b/src/components/call-desk/appointment-form.tsx @@ -286,13 +286,17 @@ export const AppointmentForm = ({ const trimmedName = patientName.trim(); const nameChanged = isNameEditable && trimmedName.length > 0 && trimmedName !== initialLeadName; - // DO NOT update the shared Patient entity when name changes - // during appointment creation. The Patient record is shared - // across all appointments — modifying it here would + // Update patient name only when it was empty (new caller with no name). + // Don't overwrite an existing patient name — that would // retroactively change the name on all past appointments. - // The patient name for THIS appointment is stored on the - // Appointment entity itself (via doctorName/department). - // Bug #527: removed updatePatient() call. + // Bug #527: only set name on patients with no existing name. + if (nameChanged && patientId && initialLeadName.length === 0) { + const nameParts = { firstName: trimmedName.split(' ')[0], lastName: trimmedName.split(' ').slice(1).join(' ') || '' }; + apiClient.graphql( + `mutation($id: UUID!, $data: PatientUpdateInput!) { updatePatient(id: $id, data: $data) { id } }`, + { id: patientId, data: { fullName: nameParts } }, + ).catch((err: unknown) => console.warn('Failed to update patient name:', err)); + } // Update lead status/lastContacted on every appointment book // (those are genuinely about this appointment), but only