refactor: Перенос AppointmentViewModal в папку Dummies

Перемещены компоненты и хуки для AppointmentViewModal.
Обновлены импорты в HomePage и AppointmentsPage.

Добавлено вывод на печать результатов приема
This commit is contained in:
Андрей Дувакин 2025-06-06 19:40:59 +05:00
parent 6cfa2dcca2
commit 01a27978e6
4 changed files with 93 additions and 22 deletions

View File

@ -22,6 +22,7 @@ const AppointmentViewModal = () => {
downloadFile,
deletingFiles,
deleteFile,
printResults,
} = useAppointmentView();
if (!selectedAppointment) {
@ -103,7 +104,6 @@ const AppointmentViewModal = () => {
{deletingFiles[file.id] ? labels.deleting : labels.delete}
</Button>
</Popconfirm>
</div>
<Divider/>
</Row>
@ -113,6 +113,13 @@ const AppointmentViewModal = () => {
)}
</div>
<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}>
{labels.closeButton}
</Button>

View File

@ -1,29 +1,29 @@
import {useDispatch, useSelector} from "react-redux";
import {setSelectedAppointment} from "../../../Redux/Slices/appointmentsSlice.js";
import { useDispatch, useSelector } from "react-redux";
import { setSelectedAppointment } from "../../../Redux/Slices/appointmentsSlice.js";
import dayjs from "dayjs";
import {useState} from "react";
import {useGetAppointmentFilesQuery, useDeleteAppointmentFileMutation} from "../../../Api/appointmentFilesApi.js";
import {baseQueryWithAuth} from "../../../Api/baseQuery.js";
import {notification} from "antd";
import { useState } from "react";
import { useGetAppointmentFilesQuery, useDeleteAppointmentFileMutation } from "../../../Api/appointmentFilesApi.js";
import { baseQueryWithAuth } from "../../../Api/baseQuery.js";
import { notification } from "antd";
const useAppointmentView = () => {
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,
{skip: !selectedAppointment?.id}
{ skip: !selectedAppointment?.id }
);
const [deleteAppointmentFile, {isLoading: isDeletingFile}] = useDeleteAppointmentFileMutation();
const [deleteAppointmentFile, { isLoading: isDeletingFile }] = useDeleteAppointmentFileMutation();
const [downloadingFiles, setDownloadingFiles] = useState({});
const [deletingFiles, setDeletingFiles] = useState({});
const modalWidth = 700;
const blockStyle = {marginBottom: 16};
const footerRowStyle = {marginTop: 16};
const footerButtonStyle = {marginRight: 8};
const blockStyle = { marginBottom: 16 };
const footerRowStyle = { marginTop: 16 };
const footerButtonStyle = { marginRight: 8 };
const labels = {
title: "Просмотр приема",
@ -45,6 +45,7 @@ const useAppointmentView = () => {
delete: "Удалить",
deleting: "Удаление...",
confirmDelete: "Вы уверены, что хотите удалить файл?",
printResults: "Печать результатов",
};
const visible = !!selectedAppointment;
@ -79,8 +80,8 @@ const useAppointmentView = () => {
const downloadFile = async (fileId, fileName) => {
try {
setDownloadingFiles((prev) => ({...prev, [fileId]: true}));
const {url, ...options} = await baseQueryWithAuth(
setDownloadingFiles((prev) => ({ ...prev, [fileId]: true }));
const { url, ...options } = await baseQueryWithAuth(
{
url: `/appointment_files/${fileId}/file/`,
method: 'GET',
@ -113,7 +114,6 @@ const useAppointmentView = () => {
link.click();
link.remove();
window.URL.revokeObjectURL(downloadUrl);
} catch (error) {
console.error("Error downloading file:", error);
notification.error({
@ -122,13 +122,13 @@ const useAppointmentView = () => {
placement: "topRight",
});
} finally {
setDownloadingFiles((prev) => ({...prev, [fileId]: false}));
setDownloadingFiles((prev) => ({ ...prev, [fileId]: false }));
}
};
const deleteFile = async (fileId, fileName) => {
try {
setDeletingFiles((prev) => ({...prev, [fileId]: true}));
setDeletingFiles((prev) => ({ ...prev, [fileId]: true }));
await deleteAppointmentFile(fileId).unwrap();
notification.success({
message: "Файл удален",
@ -143,7 +143,70 @@ const useAppointmentView = () => {
placement: "topRight",
});
} 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,
deleteFile,
isDeletingFile,
printResults,
};
};

View File

@ -19,7 +19,7 @@ import {
setSelectedAppointment,
setSelectedScheduledAppointment
} from "../../../Redux/Slices/appointmentsSlice.js";
import AppointmentViewModal from "../../Widgets/AppointmentViewModal/AppointmentViewModal.jsx";
import AppointmentViewModal from "../../Dummies/AppointmentViewModal/AppointmentViewModal.jsx";
import ScheduledAppointmentFormModal
from "../../Dummies/ScheduledAppintmentFormModal/ScheduledAppointmentFormModal.jsx";
import ScheduledAppointmentsViewModal

View File

@ -22,7 +22,7 @@ import {
import AppointmentFormModal from "../../Dummies/AppointmentFormModal/AppointmentFormModal.jsx";
import ScheduledAppointmentFormModal
from "../../Dummies/ScheduledAppintmentFormModal/ScheduledAppointmentFormModal.jsx";
import AppointmentViewModal from "../../Widgets/AppointmentViewModal/AppointmentViewModal.jsx";
import AppointmentViewModal from "../../Dummies/AppointmentViewModal/AppointmentViewModal.jsx";
import ScheduledAppointmentsViewModal
from "../../Widgets/ScheduledAppointmentsViewModal/ScheduledAppointmentsViewModal.jsx";
import PatientFormModal from "../../Dummies/PatientFormModal/PatientFormModal.jsx";