feat: Добавлена фильтрация и новые функции для приемов.

Добавлены фильтрация по дате для получения приемов и запланированных приемов. Добавлены функции открытия модалок.
This commit is contained in:
Андрей Дувакин 2025-06-08 13:07:34 +05:00
parent 3f3762c066
commit 3a22fd05be
5 changed files with 83 additions and 48 deletions

View File

@ -7,7 +7,10 @@ export const appointmentsApi = createApi({
tagTypes: ['Appointment'], tagTypes: ['Appointment'],
endpoints: (builder) => ({ endpoints: (builder) => ({
getAppointments: builder.query({ getAppointments: builder.query({
query: (doctor_id) => `/appointments/doctor/${doctor_id}/`, query: ({ doctor_id, start_date, end_date }) => ({
url: `/appointments/doctor/${doctor_id}/`,
params: { start_date, end_date },
}),
providesTags: ['Appointment'], providesTags: ['Appointment'],
refetchOnMountOrArgChange: 5, refetchOnMountOrArgChange: 5,
}), }),

View File

@ -7,7 +7,10 @@ export const scheduledAppointmentsApi = createApi({
tagTypes: ['ScheduledAppointment'], tagTypes: ['ScheduledAppointment'],
endpoints: (builder) => ({ endpoints: (builder) => ({
getScheduledAppointments: builder.query({ getScheduledAppointments: builder.query({
query: (doctor_id) => `/scheduled_appointments/doctor/${doctor_id}/`, query: ({ doctor_id, start_date, end_date }) => ({
url: `/scheduled_appointments/doctor/${doctor_id}/`,
params: { start_date, end_date },
}),
providesTags: ['ScheduledAppointment'], providesTags: ['ScheduledAppointment'],
}), }),
createScheduledAppointment: builder.mutation({ createScheduledAppointment: builder.mutation({

View File

@ -6,7 +6,6 @@ import dayjs from "dayjs";
import {useGetAppointmentsQuery} from "../../../Api/appointmentsApi.js"; import {useGetAppointmentsQuery} from "../../../Api/appointmentsApi.js";
import {Grid} from "antd"; import {Grid} from "antd";
import {useUploadAppointmentFileMutation} from "../../../Api/appointmentFilesApi.js"; import {useUploadAppointmentFileMutation} from "../../../Api/appointmentFilesApi.js";
import Compressor from 'compressorjs';
const {useBreakpoint} = Grid; const {useBreakpoint} = Grid;
@ -30,9 +29,20 @@ const useAppointmentFormModalUI = (createAppointment, patients, cancelAppointmen
const [uploadAppointmentFile, {isLoading: isUploadingFile}] = useUploadAppointmentFileMutation(); const [uploadAppointmentFile, {isLoading: isUploadingFile}] = useUploadAppointmentFileMutation();
const {data: appointments = []} = useGetAppointmentsQuery(userData.id, { const startDate = appointmentDate.startOf('month').utc().format('YYYY-MM-DD');
pollingInterval: 20000, const endDate = appointmentDate.endOf('month').utc().format('YYYY-MM-DD');
});
const {
data: appointments = [],
isLoading: isLoadingAppointments,
isError: isErrorAppointments,
} = useGetAppointmentsQuery(
{doctor_id: userData.id, start_date: startDate, end_date: endDate},
{
pollingInterval: 60000,
skip: !userData.id,
}
);
const { const {
data: previousAppointments = [], data: previousAppointments = [],
@ -43,6 +53,16 @@ const useAppointmentFormModalUI = (createAppointment, patients, cancelAppointmen
skip: !selectedPatient, skip: !selectedPatient,
}); });
useEffect(() => {
if (isErrorAppointments) {
notification.error({
message: 'Ошибка',
description: 'Ошибка загрузки приемов.',
placement: 'topRight',
});
}
}, [isErrorAppointments]);
const blockStepStyle = {marginBottom: 16}; const blockStepStyle = {marginBottom: 16};
const searchInputStyle = {marginBottom: 16}; const searchInputStyle = {marginBottom: 16};
const chooseContainerStyle = {maxHeight: 400, overflowY: "auto"}; const chooseContainerStyle = {maxHeight: 400, overflowY: "auto"};
@ -180,6 +200,7 @@ const useAppointmentFormModalUI = (createAppointment, patients, cancelAppointmen
appointment_datetime: dayjs(scheduledData.appointment_datetime), appointment_datetime: dayjs(scheduledData.appointment_datetime),
results: scheduledData.results || "", results: scheduledData.results || "",
}); });
setAppointmentDate(dayjs(scheduledData.appointment_datetime));
} }
} else { } else {
form.setFieldsValue({ form.setFieldsValue({
@ -219,9 +240,14 @@ const useAppointmentFormModalUI = (createAppointment, patients, cancelAppointmen
setFormValues({}); setFormValues({});
setIsDrawerVisible(false); setIsDrawerVisible(false);
setDraftFiles([]); setDraftFiles([]);
setAppointmentDate(dayjs(new Date())); // Сбрасываем дату
};
const handleSetAppointmentDate = (date) => {
setAppointmentDate(date);
form.setFieldsValue({appointment_datetime: date}); // Синхронизируем форму
}; };
const handleSetAppointmentDate = (date) => setAppointmentDate(date);
const modalWidth = useMemo(() => (screenXS ? 700 : "90%"), [screenXS]); const modalWidth = useMemo(() => (screenXS ? 700 : "90%"), [screenXS]);
const showDrawer = () => { const showDrawer = () => {
@ -330,8 +356,8 @@ const useAppointmentFormModalUI = (createAppointment, patients, cancelAppointmen
} catch (error) { } catch (error) {
console.error("Error creating appointment:", error); console.error("Error creating appointment:", error);
notification.error({ notification.error({
message: "Ошибка загрузки файла", message: "Ошибка создания приема",
description: `Не удалось загрузить файл ${JSON.stringify(error.data?.detail || error.data || error.message || "Неизвестная ошибка", null, 2)}`, description: `Не удалось создать прием: ${JSON.stringify(error.data?.detail || error.data || error.message || "Неизвестная ошибка", null, 2)}`,
placement: "topRight", placement: "topRight",
}); });
} }
@ -405,6 +431,8 @@ const useAppointmentFormModalUI = (createAppointment, patients, cancelAppointmen
handleAddFile, handleAddFile,
handleRemoveFile, handleRemoveFile,
isUploadingFile, isUploadingFile,
isLoadingAppointments,
isErrorAppointments,
}; };
}; };

View File

@ -12,12 +12,6 @@ import useAppointments from "./useAppointments.js";
import dayjs from 'dayjs'; import dayjs from 'dayjs';
import LoadingIndicator from "../../Widgets/LoadingIndicator/LoadingIndicator.jsx"; import LoadingIndicator from "../../Widgets/LoadingIndicator/LoadingIndicator.jsx";
import AppointmentFormModal from "../../Dummies/AppointmentFormModal/AppointmentFormModal.jsx"; import AppointmentFormModal from "../../Dummies/AppointmentFormModal/AppointmentFormModal.jsx";
import { useDispatch } from "react-redux";
import {
openModal,
setSelectedAppointment,
setSelectedScheduledAppointment
} from "../../../Redux/Slices/appointmentsSlice.js";
import AppointmentViewModal from "../../Dummies/AppointmentViewModal/AppointmentViewModal.jsx"; import AppointmentViewModal from "../../Dummies/AppointmentViewModal/AppointmentViewModal.jsx";
import ScheduledAppointmentFormModal import ScheduledAppointmentFormModal
from "../../Dummies/ScheduledAppintmentFormModal/ScheduledAppointmentFormModal.jsx"; from "../../Dummies/ScheduledAppintmentFormModal/ScheduledAppointmentFormModal.jsx";
@ -48,16 +42,10 @@ const AppointmentsPage = () => {
openCreateScheduledAppointmentModal, openCreateScheduledAppointmentModal,
currentMonth, currentMonth,
handleMonthChange, handleMonthChange,
handleEventClick,
openCreateAppointmentModal,
} = useAppointments(); } = useAppointments();
const dispatch = useDispatch();
const handleEventClick = (event) => {
if (event.appointment_datetime) {
dispatch(setSelectedAppointment(event));
} else {
dispatch(setSelectedScheduledAppointment(event));
}
};
if (isError) return ( if (isError) return (
<Result <Result
@ -200,7 +188,7 @@ const AppointmentsPage = () => {
> >
<FloatButton <FloatButton
icon={<PlusOutlined/>} icon={<PlusOutlined/>}
onClick={() => dispatch(openModal())} onClick={openCreateAppointmentModal}
tooltip="Прием" tooltip="Прием"
/> />
<FloatButton <FloatButton

View File

@ -7,6 +7,7 @@ import {
} from "../../../Api/appointmentsApi.js"; } from "../../../Api/appointmentsApi.js";
import { useGetAllPatientsQuery } from "../../../Api/patientsApi.js"; import { useGetAllPatientsQuery } from "../../../Api/patientsApi.js";
import { import {
openModal,
openScheduledModal, openScheduledModal,
setHovered, setHovered,
setSelectedAppointment, setSelectedAppointment,
@ -101,10 +102,20 @@ const useAppointments = () => {
} }
}; };
const handleEventClick = (event) => {
if (event.appointment_datetime) {
dispatch(setSelectedAppointment(event));
} else {
dispatch(setSelectedScheduledAppointment(event));
}
};
const openCreateScheduledAppointmentModal = () => { const openCreateScheduledAppointmentModal = () => {
dispatch(openScheduledModal()); dispatch(openScheduledModal());
}; };
const openCreateAppointmentModal = () => dispatch(openModal());
const siderButtonText = useMemo(() => const siderButtonText = useMemo(() =>
hovered ? (collapsed ? "Показать предстоящие события" : "Скрыть предстоящие события") : "", hovered ? (collapsed ? "Показать предстоящие события" : "Скрыть предстоящие события") : "",
[collapsed, hovered] [collapsed, hovered]
@ -175,6 +186,8 @@ const useAppointments = () => {
openCreateScheduledAppointmentModal, openCreateScheduledAppointmentModal,
currentMonth, currentMonth,
handleMonthChange, handleMonthChange,
handleEventClick,
openCreateAppointmentModal,
}; };
}; };