diff --git a/src/PagesMedico/DoctorAgendamentoManager.jsx b/src/PagesMedico/DoctorAgendamentoManager.jsx
index 567646c..70bb768 100644
--- a/src/PagesMedico/DoctorAgendamentoManager.jsx
+++ b/src/PagesMedico/DoctorAgendamentoManager.jsx
@@ -30,6 +30,7 @@ const Agendamento = () => {
const authHeader = getAuthorizationHeader();
const ID_MEDICO_ESPECIFICO = "078d2a67-b4c1-43c8-ae32-c1e75bb5b3df";
+
const [listaTodosAgendamentos, setListaTodosAgendamentos] = useState([]);
const [selectedID, setSelectedId] = useState("0");
@@ -39,12 +40,16 @@ const Agendamento = () => {
const [DictAgendamentosOrganizados, setAgendamentosOrganizados] = useState(
{}
);
+
+
const [showDeleteModal, setShowDeleteModal] = useState(false);
const [ListaDeMedicos, setListaDeMedicos] = useState([]);
const [FiltredTodosMedicos, setFiltredTodosMedicos] = useState([]);
const [searchTermDoctor, setSearchTermDoctor] = useState("");
const [MedicoFiltrado, setMedicoFiltrado] = useState({ id: "vazio" });
const [motivoCancelamento, setMotivoCancelamento] = useState("");
+ const [searchTermPatient, setSearchTermPatient] = useState("");
+ const [patientDropdownOpen, setPatientDropdownOpen] = useState(false);
const [showSpinner, setShowSpinner] = useState(true);
const [waitlistSearch, setWaitlistSearch] = useState("");
const [waitSortKey, setWaitSortKey] = useState(null);
@@ -302,6 +307,14 @@ const Agendamento = () => {
setMedicoFiltrado({ id: "vazio" });
}
};
+
+const filtrarPorPaciente = (appointments) => {
+ if (!searchTermPatient.trim()) return appointments;
+ const term = searchTermPatient.toLowerCase();
+ return appointments.filter((app) =>
+ app.paciente_nome?.toLowerCase().includes(term)
+ );
+};
const generateDateGrid = () => {
const grid = [];
@@ -411,6 +424,13 @@ const Agendamento = () => {
() => applySortingWaitlist(filaEsperaFiltrada),
[filaEsperaFiltrada, applySortingWaitlist]
);
+ const listaPacientesUnicos = useMemo(() => {
+ const pacientes = Object.values(cachePacientes || {});
+ return pacientes.sort((a, b) =>
+ (a.full_name || "").localeCompare(b.full_name || "")
+ );
+}, [cachePacientes]);
+
const waitTotalPages =
Math.ceil(filaEsperaOrdenada.length / waitPerPage) || 1;
const waitIndiceInicial = (waitPage - 1) * waitPerPage;
@@ -449,71 +469,11 @@ const Agendamento = () => {
Agendar nova consulta
{!PageNovaConsulta ? (
- {user?.role !== "doctor" && (
-
-
-
- Filtrar por Médico
-
-
-
handleSearchMedicos(e.target.value)}
- />
-
- Buscar médico para filtrar consultas
-
- {searchTermDoctor && FiltredTodosMedicos.length > 0 && (
-
- {FiltredTodosMedicos.map((medico) => (
-
- ))}
-
- )}
-
-
- {MedicoFiltrado.id !== "vazio" && (
-
-
-
- {searchTermDoctor}
-
-
-
- )}
-
- )}
+
+
+
+
+
+
+
+
Filtrar por Paciente
+
+
+
+
+
{
+ setSearchTermPatient(e.target.value);
+ setPatientDropdownOpen(true);
+ }}
+ onFocus={() => {
+ if (searchTermPatient.trim()) {
+ setPatientDropdownOpen(true);
+ }
+ }}
+ style={{ paddingLeft: "40px" }}
+ />
+
+ {patientDropdownOpen && searchTermPatient.trim() && (
+
+ {listaPacientesUnicos
+ .filter((p) => {
+ const nome = (p.full_name || "").toLowerCase();
+ const term = searchTermPatient.toLowerCase();
+ return nome.startsWith(term); // só começo do nome
+ })
+ .slice(0, 20)
+ .map((p) => (
+ {
+ setSearchTermPatient(p.full_name);
+ setPatientDropdownOpen(false);
+ }}
+ >
+ {p.full_name} - {p.cpf}
+
+ ))}
+
+ )}
+
+
+ {searchTermPatient && (
+
+ setSearchTermPatient("")}
+ >
+
+ Limpar filtro
+
+
+ )}
+
+
-
- Realizado
-
-
- Confirmado
-
-
- Agendado
-
-
- Cancelado
-
-
+
+
{currentDate.format("MMMM [de] YYYY")}
@@ -755,13 +807,17 @@ const Agendamento = () => {
))}
{dateGrid.map((day, index) => {
const dayString = day.format("YYYY-MM-DD");
- const appointmentsOnDay =
- DictAgendamentosOrganizados[dayString] || [];
- const filteredAppointments = appointmentsOnDay.filter(
- (app) =>
- MedicoFiltrado.id === "vazio" ||
- app.doctor_id === MedicoFiltrado.id
- );
+ const appointmentsOnDay =
+ DictAgendamentosOrganizados[dayString] || [];
+
+const filteredAppointments = filtrarPorPaciente(
+ appointmentsOnDay.filter(
+ (app) =>
+ MedicoFiltrado.id === "vazio" ||
+ app.doctor_id === MedicoFiltrado.id
+ )
+);
+
const cellClasses = `day-cell ${
day.isSame(currentDate, "month")
? "current-month"
diff --git a/src/PagesMedico/styleMedico/Agendamento.css b/src/PagesMedico/styleMedico/Agendamento.css
index 5f01d68..9c6277a 100644
--- a/src/PagesMedico/styleMedico/Agendamento.css
+++ b/src/PagesMedico/styleMedico/Agendamento.css
@@ -166,13 +166,20 @@
}
.container-btns-agenda-fila_esepera {
- margin-top: 30px;
display: flex;
flex-direction: row;
+ justify-content: space-between;
+ align-items: flex-end;
gap: 20px;
- margin-left: 20px;
+
+ margin-top: 0;
+ margin-bottom: 0;
+ margin-left: 0;
+ padding: 0 20px 0;
+ border-bottom: 1px solid #edf1f7;
}
+
.btn-fila-espera,
.btn-agenda {
background-color: transparent;
@@ -269,4 +276,10 @@ html[data-bs-theme="dark"] .legenda-item-agendado {
background-color: #2e2e1e;
border: 3px solid #4d4d2e;
color: #f7f7c4;
-}
\ No newline at end of file
+}
+.calendar-legend {
+ margin-top: 8px;
+ display: flex;
+ gap: 8px;
+ justify-content: center;
+}
diff --git a/src/pages/Agendamento.jsx b/src/pages/Agendamento.jsx
index 443df63..3e927b6 100644
--- a/src/pages/Agendamento.jsx
+++ b/src/pages/Agendamento.jsx
@@ -24,6 +24,7 @@ dayjs.extend(isBetween);
dayjs.extend(localeData);
const Agendamento = ({ setDictInfo }) => {
+
const navigate = useNavigate();
const [listaTodosAgendamentos, setListaTodosAgendamentos] = useState([]);
const [selectedID, setSelectedId] = useState('0');
@@ -37,6 +38,7 @@ const Agendamento = ({ setDictInfo }) => {
const [ListaDeMedicos, setListaDeMedicos] = useState([]);
const [FiltredTodosMedicos, setFiltredTodosMedicos] = useState([]);
const [searchTermDoctor, setSearchTermDoctor] = useState('');
+ const [doctorDropdownOpen, setDoctorDropdownOpen] = useState(false);
const [MedicoFiltrado, setMedicoFiltrado] = useState({ id: "vazio" });
const [cacheAgendamentos, setCacheAgendamentos] = useState([]);
const [appointmentToEdit, setAppointmentToEdit] = useState(null);
@@ -412,22 +414,11 @@ const Agendamento = ({ setDictInfo }) => {
{selectedDay.format('dddd')}
{selectedDay.format('D [de] MMMM [de] YYYY')}
-
-
- Realizado
-
-
- Confirmado
-
-
- Agendado
-
-
- Cancelado
-
+
+
Realizado
+
Confirmado
+
Agendado
+
Cancelado
@@ -440,12 +431,13 @@ const Agendamento = ({ setDictInfo }) => {
) : (() => {
const allApps =
DictAgendamentosOrganizados[selectedDay.format('YYYY-MM-DD')] || [];
- const filtered = allApps.filter(app =>
- !searchTermDoctor
- ? true
- : (app.medico_nome || '').toLowerCase()
- .includes(searchTermDoctor.toLowerCase())
- );
+ const termDoc = searchTermDoctor.toLowerCase();
+const filtered = allApps.filter(app =>
+ !termDoc
+ ? true
+ : (app.medico_nome || '').toLowerCase().startsWith(termDoc)
+);
+
return filtered.length > 0 ? (
filtered.map(app => (
@@ -494,19 +486,72 @@ const Agendamento = ({ setDictInfo }) => {
);
})()}
-
-
-
-
- setSearchTermDoctor(e.target.value)}
- />
-
+
+
+ {/* SUBSTITUIR POR ESTE BLOCO 👇 */}
+
+
+
{
+ setSearchTermDoctor(e.target.value);
+ setDoctorDropdownOpen(true);
+ }}
+ onFocus={() => {
+ if (searchTermDoctor.trim()) setDoctorDropdownOpen(true);
+ }}
+ />
+ {doctorDropdownOpen && searchTermDoctor.trim() && (
+
+ {ListaDeMedicos
+ .filter((m) => {
+ const nome = (m.nomeMedico || "").toLowerCase();
+ const term = searchTermDoctor.toLowerCase();
+ return nome.startsWith(term);
+ })
+ .slice(0, 20)
+ .map((m) => (
+ {
+ setSearchTermDoctor(m.nomeMedico);
+ setDoctorDropdownOpen(false);
+ }}
+ >
+ {m.nomeMedico}
+
+ ))}
+
+ )}
+
+
+
+
{currentDate.format('MMMM [de] YYYY')}
@@ -578,12 +623,12 @@ const Agendamento = ({ setDictInfo }) => {
{dateGrid.map((day, index) => {
const dayKey = day.format('YYYY-MM-DD');
const appointmentsOnDay = DictAgendamentosOrganizados[dayKey] || [];
- const filteredAppointments = appointmentsOnDay.filter(app =>
- !searchTermDoctor
- ? true
- : (app.medico_nome || '').toLowerCase()
- .includes(searchTermDoctor.toLowerCase())
- );
+ const termDoc = searchTermDoctor.toLowerCase();
+const filteredAppointments = appointmentsOnDay.filter(app =>
+ !termDoc
+ ? true
+ : (app.medico_nome || '').toLowerCase().startsWith(termDoc)
+);
const cellClasses = `day-cell ${
day.isSame(currentDate, 'month') ? 'current-month' : 'other-month'
} ${day.isSame(dayjs(), 'day') ? 'today' : ''} ${