import {useEffect, useState} from "react"; import { Modal, Input, Button, notification, Typography, Collapse, Steps, Row, Alert, Col, DatePicker, Spin, Grid } from "antd"; import PropTypes from "prop-types"; import getAllPatients from "../../api/patients/GetAllPatients.jsx"; import {useAuth} from "../../AuthContext.jsx"; import dayjs from "dayjs"; import getNotIssuedLenses from "../../api/lenses/GetNotIssuedLenses.jsx"; const {useBreakpoint} = Grid; const LensIssueFormModal = ({visible, onCancel, onSubmit}) => { const {user} = useAuth(); const screens = useBreakpoint(); const [patients, setPatients] = useState([]); const [lenses, setLenses] = useState([]); const [searchPatientString, setSearchPatientString] = useState(""); const [searchLensString, setSearchLensString] = useState(""); const [issueDate, setIssueDate] = useState(dayjs(new Date())); const [selectedPatient, setSelectedPatient] = useState(null); const [selectedLens, setSelectedLens] = useState(null); const [loading, setLoading] = useState(false); const [currentStep, setCurrentStep] = useState(0); useEffect(() => { if (visible) { fetchPatients(); fetchLenses(); } }, [visible]); const fetchPatients = async () => { try { const data = await getAllPatients(user.token); setPatients(data); } catch (error) { console.error(error); notification.error({ message: "Ошибка загрузки пациентов", description: "Проверьте подключение к сети.", }); } }; const fetchLenses = async () => { try { const data = await getNotIssuedLenses(user.token); setLenses(data); } catch (error) { console.error(error); notification.error({ message: "Ошибка загрузки линз", description: "Проверьте подключение к сети.", }); } }; const handleOk = async () => { try { setLoading(true); setCurrentStep(0); onSubmit(issueDate.format("YYYY-MM-DD"), selectedPatient.id, selectedLens.id); setSelectedPatient(null); setSelectedLens(null); setIssueDate(dayjs(new Date())); setLoading(false); } catch (errorInfo) { console.error("Validation Failed:", errorInfo); } }; const filteredPatients = patients .filter((patient) => { const searchLower = searchPatientString.toLowerCase(); return Object.values(patient) .filter(value => typeof value === "string") .some(value => value.toLowerCase().includes(searchLower)); }); const patientsItems = filteredPatients.map((patient) => ({ key: patient.id, label: `${patient.last_name} ${patient.first_name} (${new Date(patient.birthday).toLocaleDateString("ru-RU")})`, children:
Пациент: {patient.last_name} {patient.first_name}
Дата рождения: {new Date(patient.birthday).toLocaleDateString("ru-RU")}
Диагноз: {patient.diagnosis}
Email: {patient.email}
Телефон: {patient.phone}
Диаметр: {lens.diameter}
Тор: {lens.tor}
Пресетная рефракция: {lens.preset_refraction}
Диаметр: {lens.diameter}
FVC: {lens.fvc}
Острота зрения (Trial): {lens.trial}
Периферийная торичность: {lens.periphery_toricity}
Сторона: {lens.side}
Esa: {lens.esa}
Дата рождения: {new Date(selectedPatient.birthday).toLocaleDateString("ru-RU")}
Email: {selectedPatient.email}
Телефон: {selectedPatient.phone}
Диаметр: {selectedLens.diameter}
Тор: {selectedLens.tor}
Пресетная рефракция: {selectedLens.preset_refraction}
Диаметр: {selectedLens.diameter}
FVC: {selectedLens.fvc}
Острота зрения (Trial): {selectedLens.trial}
Периферийная торичность: {selectedLens.periphery_toricity}
Сторона: {selectedLens.side}
Esa: {selectedLens.esa}
Дата рождения: {new Date(selectedPatient.birthday).toLocaleDateString("ru-RU")}
Email: {selectedPatient.email}
Телефон: {selectedPatient.phone}
Линза: {selectedLens.diameter} {selectedLens.tor} {selectedLens.preset_refraction}
Диаметр: {selectedLens.diameter}
Тор: {selectedLens.tor}
Пресетная рефракция: {selectedLens.preset_refraction}
Диаметр: {selectedLens.diameter}
FVC: {selectedLens.fvc}
Острота зрения (Trial): {selectedLens.trial}
Периферийная торичность: {selectedLens.periphery_toricity}
Сторона: {selectedLens.side}
Esa: {selectedLens.esa}