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

@ -45,6 +45,7 @@ const useAppointmentView = () => {
delete: "Удалить",
deleting: "Удаление...",
confirmDelete: "Вы уверены, что хотите удалить файл?",
printResults: "Печать результатов",
};
const visible = !!selectedAppointment;
@ -113,7 +114,6 @@ const useAppointmentView = () => {
link.click();
link.remove();
window.URL.revokeObjectURL(downloadUrl);
} catch (error) {
console.error("Error downloading file:", error);
notification.error({
@ -147,6 +147,69 @@ const useAppointmentView = () => {
}
};
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",
});
}
};
return {
modalWidth,
blockStyle,
@ -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";