refactor: Перенос AppointmentViewModal в папку Dummies
Перемещены компоненты и хуки для AppointmentViewModal. Обновлены импорты в HomePage и AppointmentsPage. Добавлено вывод на печать результатов приема
This commit is contained in:
parent
6cfa2dcca2
commit
01a27978e6
@ -22,6 +22,7 @@ const AppointmentViewModal = () => {
|
|||||||
downloadFile,
|
downloadFile,
|
||||||
deletingFiles,
|
deletingFiles,
|
||||||
deleteFile,
|
deleteFile,
|
||||||
|
printResults,
|
||||||
} = useAppointmentView();
|
} = useAppointmentView();
|
||||||
|
|
||||||
if (!selectedAppointment) {
|
if (!selectedAppointment) {
|
||||||
@ -103,7 +104,6 @@ const AppointmentViewModal = () => {
|
|||||||
{deletingFiles[file.id] ? labels.deleting : labels.delete}
|
{deletingFiles[file.id] ? labels.deleting : labels.delete}
|
||||||
</Button>
|
</Button>
|
||||||
</Popconfirm>
|
</Popconfirm>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
<Divider/>
|
<Divider/>
|
||||||
</Row>
|
</Row>
|
||||||
@ -113,6 +113,13 @@ const AppointmentViewModal = () => {
|
|||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
<Row justify="end" style={footerRowStyle}>
|
<Row justify="end" style={footerRowStyle}>
|
||||||
|
<Button
|
||||||
|
style={footerButtonStyle}
|
||||||
|
onClick={printResults}
|
||||||
|
disabled={!selectedAppointment.results || selectedAppointment.results === labels.resultsNotSpecified}
|
||||||
|
>
|
||||||
|
{labels.printResults}
|
||||||
|
</Button>
|
||||||
<Button style={footerButtonStyle} onClick={onCancel}>
|
<Button style={footerButtonStyle} onClick={onCancel}>
|
||||||
{labels.closeButton}
|
{labels.closeButton}
|
||||||
</Button>
|
</Button>
|
||||||
@ -1,29 +1,29 @@
|
|||||||
import {useDispatch, useSelector} from "react-redux";
|
import { useDispatch, useSelector } from "react-redux";
|
||||||
import {setSelectedAppointment} from "../../../Redux/Slices/appointmentsSlice.js";
|
import { setSelectedAppointment } from "../../../Redux/Slices/appointmentsSlice.js";
|
||||||
import dayjs from "dayjs";
|
import dayjs from "dayjs";
|
||||||
import {useState} from "react";
|
import { useState } from "react";
|
||||||
import {useGetAppointmentFilesQuery, useDeleteAppointmentFileMutation} from "../../../Api/appointmentFilesApi.js";
|
import { useGetAppointmentFilesQuery, useDeleteAppointmentFileMutation } from "../../../Api/appointmentFilesApi.js";
|
||||||
import {baseQueryWithAuth} from "../../../Api/baseQuery.js";
|
import { baseQueryWithAuth } from "../../../Api/baseQuery.js";
|
||||||
import {notification} from "antd";
|
import { notification } from "antd";
|
||||||
|
|
||||||
const useAppointmentView = () => {
|
const useAppointmentView = () => {
|
||||||
const dispatch = useDispatch();
|
const dispatch = useDispatch();
|
||||||
const {selectedAppointment} = useSelector((state) => state.appointmentsUI);
|
const { selectedAppointment } = useSelector((state) => state.appointmentsUI);
|
||||||
|
|
||||||
const {data: files = [], isLoading: isFilesLoading} = useGetAppointmentFilesQuery(
|
const { data: files = [], isLoading: isFilesLoading } = useGetAppointmentFilesQuery(
|
||||||
selectedAppointment?.id,
|
selectedAppointment?.id,
|
||||||
{skip: !selectedAppointment?.id}
|
{ skip: !selectedAppointment?.id }
|
||||||
);
|
);
|
||||||
|
|
||||||
const [deleteAppointmentFile, {isLoading: isDeletingFile}] = useDeleteAppointmentFileMutation();
|
const [deleteAppointmentFile, { isLoading: isDeletingFile }] = useDeleteAppointmentFileMutation();
|
||||||
|
|
||||||
const [downloadingFiles, setDownloadingFiles] = useState({});
|
const [downloadingFiles, setDownloadingFiles] = useState({});
|
||||||
const [deletingFiles, setDeletingFiles] = useState({});
|
const [deletingFiles, setDeletingFiles] = useState({});
|
||||||
|
|
||||||
const modalWidth = 700;
|
const modalWidth = 700;
|
||||||
const blockStyle = {marginBottom: 16};
|
const blockStyle = { marginBottom: 16 };
|
||||||
const footerRowStyle = {marginTop: 16};
|
const footerRowStyle = { marginTop: 16 };
|
||||||
const footerButtonStyle = {marginRight: 8};
|
const footerButtonStyle = { marginRight: 8 };
|
||||||
|
|
||||||
const labels = {
|
const labels = {
|
||||||
title: "Просмотр приема",
|
title: "Просмотр приема",
|
||||||
@ -45,6 +45,7 @@ const useAppointmentView = () => {
|
|||||||
delete: "Удалить",
|
delete: "Удалить",
|
||||||
deleting: "Удаление...",
|
deleting: "Удаление...",
|
||||||
confirmDelete: "Вы уверены, что хотите удалить файл?",
|
confirmDelete: "Вы уверены, что хотите удалить файл?",
|
||||||
|
printResults: "Печать результатов",
|
||||||
};
|
};
|
||||||
|
|
||||||
const visible = !!selectedAppointment;
|
const visible = !!selectedAppointment;
|
||||||
@ -79,8 +80,8 @@ const useAppointmentView = () => {
|
|||||||
|
|
||||||
const downloadFile = async (fileId, fileName) => {
|
const downloadFile = async (fileId, fileName) => {
|
||||||
try {
|
try {
|
||||||
setDownloadingFiles((prev) => ({...prev, [fileId]: true}));
|
setDownloadingFiles((prev) => ({ ...prev, [fileId]: true }));
|
||||||
const {url, ...options} = await baseQueryWithAuth(
|
const { url, ...options } = await baseQueryWithAuth(
|
||||||
{
|
{
|
||||||
url: `/appointment_files/${fileId}/file/`,
|
url: `/appointment_files/${fileId}/file/`,
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
@ -113,7 +114,6 @@ const useAppointmentView = () => {
|
|||||||
link.click();
|
link.click();
|
||||||
link.remove();
|
link.remove();
|
||||||
window.URL.revokeObjectURL(downloadUrl);
|
window.URL.revokeObjectURL(downloadUrl);
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Error downloading file:", error);
|
console.error("Error downloading file:", error);
|
||||||
notification.error({
|
notification.error({
|
||||||
@ -122,13 +122,13 @@ const useAppointmentView = () => {
|
|||||||
placement: "topRight",
|
placement: "topRight",
|
||||||
});
|
});
|
||||||
} finally {
|
} finally {
|
||||||
setDownloadingFiles((prev) => ({...prev, [fileId]: false}));
|
setDownloadingFiles((prev) => ({ ...prev, [fileId]: false }));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const deleteFile = async (fileId, fileName) => {
|
const deleteFile = async (fileId, fileName) => {
|
||||||
try {
|
try {
|
||||||
setDeletingFiles((prev) => ({...prev, [fileId]: true}));
|
setDeletingFiles((prev) => ({ ...prev, [fileId]: true }));
|
||||||
await deleteAppointmentFile(fileId).unwrap();
|
await deleteAppointmentFile(fileId).unwrap();
|
||||||
notification.success({
|
notification.success({
|
||||||
message: "Файл удален",
|
message: "Файл удален",
|
||||||
@ -143,7 +143,70 @@ const useAppointmentView = () => {
|
|||||||
placement: "topRight",
|
placement: "topRight",
|
||||||
});
|
});
|
||||||
} finally {
|
} finally {
|
||||||
setDeletingFiles((prev) => ({...prev, [fileId]: false}));
|
setDeletingFiles((prev) => ({ ...prev, [fileId]: false }));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const printResults = () => {
|
||||||
|
if (!selectedAppointment?.results || selectedAppointment.results === labels.resultsNotSpecified) {
|
||||||
|
notification.error({
|
||||||
|
message: "Ошибка печати",
|
||||||
|
description: "Результаты приема отсутствуют.",
|
||||||
|
placement: "topRight",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const results = getResults(selectedAppointment.results);
|
||||||
|
const patientName = getPatientName(selectedAppointment.patient);
|
||||||
|
const appointmentTime = getAppointmentTime(selectedAppointment.appointment_datetime);
|
||||||
|
|
||||||
|
const printWindow = window.open('', '_blank', 'width=800,height=600');
|
||||||
|
if (!printWindow) {
|
||||||
|
notification.error({
|
||||||
|
message: "Ошибка печати",
|
||||||
|
description: "Не удалось открыть окно для печати. Проверьте настройки блокировки всплывающих окон.",
|
||||||
|
placement: "topRight",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
printWindow.document.write(`
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>Результаты приема - ${patientName}</title>
|
||||||
|
<style>
|
||||||
|
body { font-family: Arial, sans-serif; margin: 20px; }
|
||||||
|
h1 { font-size: 24px; }
|
||||||
|
h2 { font-size: 18px; margin-bottom: 10px; }
|
||||||
|
.results { font-size: 16px; line-height: 1.5; }
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h1>Результаты приема</h1>
|
||||||
|
<h2>Пациент: ${patientName}</h2>
|
||||||
|
<h2>Дата и время приема: ${appointmentTime}</h2>
|
||||||
|
<div class="results">${results}</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
`);
|
||||||
|
printWindow.document.close();
|
||||||
|
|
||||||
|
printWindow.onload = () => {
|
||||||
|
printWindow.focus();
|
||||||
|
printWindow.print();
|
||||||
|
setTimeout(() => {
|
||||||
|
printWindow.close();
|
||||||
|
}, 500);
|
||||||
|
};
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error printing results:", error);
|
||||||
|
notification.error({
|
||||||
|
message: "Ошибка печати",
|
||||||
|
description: "Не удалось выполнить печать. Попробуйте снова.",
|
||||||
|
placement: "topRight",
|
||||||
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -168,6 +231,7 @@ const useAppointmentView = () => {
|
|||||||
deletingFiles,
|
deletingFiles,
|
||||||
deleteFile,
|
deleteFile,
|
||||||
isDeletingFile,
|
isDeletingFile,
|
||||||
|
printResults,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -19,7 +19,7 @@ import {
|
|||||||
setSelectedAppointment,
|
setSelectedAppointment,
|
||||||
setSelectedScheduledAppointment
|
setSelectedScheduledAppointment
|
||||||
} from "../../../Redux/Slices/appointmentsSlice.js";
|
} from "../../../Redux/Slices/appointmentsSlice.js";
|
||||||
import AppointmentViewModal from "../../Widgets/AppointmentViewModal/AppointmentViewModal.jsx";
|
import AppointmentViewModal from "../../Dummies/AppointmentViewModal/AppointmentViewModal.jsx";
|
||||||
import ScheduledAppointmentFormModal
|
import ScheduledAppointmentFormModal
|
||||||
from "../../Dummies/ScheduledAppintmentFormModal/ScheduledAppointmentFormModal.jsx";
|
from "../../Dummies/ScheduledAppintmentFormModal/ScheduledAppointmentFormModal.jsx";
|
||||||
import ScheduledAppointmentsViewModal
|
import ScheduledAppointmentsViewModal
|
||||||
|
|||||||
@ -22,7 +22,7 @@ import {
|
|||||||
import AppointmentFormModal from "../../Dummies/AppointmentFormModal/AppointmentFormModal.jsx";
|
import AppointmentFormModal from "../../Dummies/AppointmentFormModal/AppointmentFormModal.jsx";
|
||||||
import ScheduledAppointmentFormModal
|
import ScheduledAppointmentFormModal
|
||||||
from "../../Dummies/ScheduledAppintmentFormModal/ScheduledAppointmentFormModal.jsx";
|
from "../../Dummies/ScheduledAppintmentFormModal/ScheduledAppointmentFormModal.jsx";
|
||||||
import AppointmentViewModal from "../../Widgets/AppointmentViewModal/AppointmentViewModal.jsx";
|
import AppointmentViewModal from "../../Dummies/AppointmentViewModal/AppointmentViewModal.jsx";
|
||||||
import ScheduledAppointmentsViewModal
|
import ScheduledAppointmentsViewModal
|
||||||
from "../../Widgets/ScheduledAppointmentsViewModal/ScheduledAppointmentsViewModal.jsx";
|
from "../../Widgets/ScheduledAppointmentsViewModal/ScheduledAppointmentsViewModal.jsx";
|
||||||
import PatientFormModal from "../../Dummies/PatientFormModal/PatientFormModal.jsx";
|
import PatientFormModal from "../../Dummies/PatientFormModal/PatientFormModal.jsx";
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user