fix: update patient name on new callers — prevents 'Unknown' patients

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) <noreply@anthropic.com>
This commit is contained in:
2026-04-13 11:05:26 +05:30
parent d8f9174a55
commit d24945a3af

View File

@@ -286,13 +286,17 @@ export const AppointmentForm = ({
const trimmedName = patientName.trim(); const trimmedName = patientName.trim();
const nameChanged = isNameEditable && trimmedName.length > 0 && trimmedName !== initialLeadName; const nameChanged = isNameEditable && trimmedName.length > 0 && trimmedName !== initialLeadName;
// DO NOT update the shared Patient entity when name changes // Update patient name only when it was empty (new caller with no name).
// during appointment creation. The Patient record is shared // Don't overwrite an existing patient name — that would
// across all appointments — modifying it here would
// retroactively change the name on all past appointments. // retroactively change the name on all past appointments.
// The patient name for THIS appointment is stored on the // Bug #527: only set name on patients with no existing name.
// Appointment entity itself (via doctorName/department). if (nameChanged && patientId && initialLeadName.length === 0) {
// Bug #527: removed updatePatient() call. 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 // Update lead status/lastContacted on every appointment book
// (those are genuinely about this appointment), but only // (those are genuinely about this appointment), but only