mirror of
https://dev.azure.com/globalhealthx/EMR/_git/helix-engage
synced 2026-05-18 20:08:19 +00:00
fix(appointment-form): keep saved doctor visible on edit when department filter mismatches
Edit mode prefilled clinic + department + doctorId, but the doctor Select rendered blank because the doctor-list filter (doctors where department === selectedDept) excluded the saved doctor. Root cause: the Appointment.department string doesn't always match the doctor's current department enum value. Fix: doctorSelectItems now always includes the currently-selected doctor as the first item, even when the department filter would exclude them. Once the user changes department or doctor, the filter behaves normally. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { useState, useEffect } from 'react';
|
||||
import { useState, useEffect, useMemo } from 'react';
|
||||
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
|
||||
import { faUserPen } from '@fortawesome/pro-duotone-svg-icons';
|
||||
import { Input } from '@/components/base/input/input';
|
||||
@@ -242,7 +242,19 @@ export const AppointmentForm = ({
|
||||
const filteredDoctors = department
|
||||
? doctors.filter(d => d.department === department)
|
||||
: doctors;
|
||||
const doctorSelectItems = filteredDoctors.map(d => ({ id: d.id, label: d.name }));
|
||||
// Always include the currently-selected doctor even if the department
|
||||
// filter would exclude them. Needed for edit mode: the saved
|
||||
// Appointment.department may be stored as a display string ("ENT") or
|
||||
// a legacy value that doesn't match the doctor's current department
|
||||
// enum — without this, the Select renders blank.
|
||||
const doctorSelectItems = useMemo(() => {
|
||||
const items = filteredDoctors.map(d => ({ id: d.id, label: d.name }));
|
||||
if (doctor && !items.some(i => i.id === doctor)) {
|
||||
const selected = doctors.find(d => d.id === doctor);
|
||||
if (selected) items.unshift({ id: selected.id, label: selected.name });
|
||||
}
|
||||
return items;
|
||||
}, [filteredDoctors, doctors, doctor]);
|
||||
|
||||
const timeSlotSelectItems = timeSlotItems.map(slot => ({
|
||||
...slot,
|
||||
|
||||
Reference in New Issue
Block a user