mirror of
https://dev.azure.com/globalhealthx/EMR/_git/helix-engage
synced 2026-05-18 20:08:19 +00:00
fix: stop auto-creating Unknown leads on every call
Caller resolver now returns empty IDs for unrecognized numbers instead of eagerly creating lead+patient records. Records are created when the agent explicitly books an appointment or logs an enquiry — per PRD. - caller-resolution.service.ts: return unresolved result, don't create - call-desk.tsx: toast changed to 'No existing records found' - appointment-form.tsx: create patient on save if none exists Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -259,6 +259,25 @@ export const AppointmentForm = ({
|
|||||||
);
|
);
|
||||||
notify.success('Appointment Updated');
|
notify.success('Appointment Updated');
|
||||||
} else {
|
} else {
|
||||||
|
// If no patient record exists yet (new caller), create one now
|
||||||
|
let resolvedPatientId = patientId;
|
||||||
|
if (!resolvedPatientId && callerNumber) {
|
||||||
|
const trimmedName = patientName.trim();
|
||||||
|
const nameParts = {
|
||||||
|
firstName: trimmedName.split(' ')[0] || 'Unknown',
|
||||||
|
lastName: trimmedName.split(' ').slice(1).join(' ') || '',
|
||||||
|
};
|
||||||
|
try {
|
||||||
|
const created = await apiClient.graphql<{ createPatient: { id: string } }>(
|
||||||
|
`mutation($data: PatientCreateInput!) { createPatient(data: $data) { id } }`,
|
||||||
|
{ data: { fullName: nameParts, phones: { primaryPhoneNumber: callerNumber }, patientType: 'NEW' } },
|
||||||
|
);
|
||||||
|
resolvedPatientId = created.createPatient.id;
|
||||||
|
} catch (err) {
|
||||||
|
console.warn('Failed to create patient:', err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Create appointment
|
// Create appointment
|
||||||
await apiClient.graphql(
|
await apiClient.graphql(
|
||||||
`mutation CreateAppointment($data: AppointmentCreateInput!) {
|
`mutation CreateAppointment($data: AppointmentCreateInput!) {
|
||||||
@@ -274,7 +293,7 @@ export const AppointmentForm = ({
|
|||||||
department: selectedDoctor?.department ?? '',
|
department: selectedDoctor?.department ?? '',
|
||||||
doctorId: doctor,
|
doctorId: doctor,
|
||||||
reasonForVisit: chiefComplaint || null,
|
reasonForVisit: chiefComplaint || null,
|
||||||
...(patientId ? { patientId } : {}),
|
...(resolvedPatientId ? { patientId: resolvedPatientId } : {}),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -91,7 +91,7 @@ export const CallDeskPage = () => {
|
|||||||
.then((result) => {
|
.then((result) => {
|
||||||
setResolvedCaller(result);
|
setResolvedCaller(result);
|
||||||
if (result.isNew) {
|
if (result.isNew) {
|
||||||
notify.info('New Caller', 'Lead and patient records created');
|
notify.info('New Caller', 'No existing records found for this number');
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user