доелал выдачу линзы пациенту

This commit is contained in:
Андрей Дувакин 2025-03-10 07:20:06 +05:00
parent 9f432a4314
commit 9190723abd
3 changed files with 94 additions and 54 deletions

View File

@ -0,0 +1,20 @@
import axios from "axios";
import CONFIG from "../../core/Config.jsx";
const getNotIssuedLenses = async (token) => {
try {
const response = await axios.get(`${CONFIG.BASE_URL}/lenses/not_issued/`, {
headers: {
Authorization: `Bearer ${token}`,
},
});
return response.data;
} catch (error) {
if (error.response?.status === 403) {
throw Error("Ошибка авторизации: пользователь неяден или токен недействителен");
}
throw Error(error.message);
}
};
export default getNotIssuedLenses;

View File

@ -1,9 +1,10 @@
import {useEffect, useState} from "react";
import {Modal, Input, Button, notification, Typography, Collapse, Steps, Row, Alert, Col} from "antd";
import {Modal, Input, Button, notification, Typography, Collapse, Steps, Row, Alert, Col, DatePicker, Spin} from "antd";
import PropTypes from "prop-types";
import getAllPatients from "../../api/patients/GetAllPatients.jsx";
import getAllLenses from "../../api/lenses/GetAllLenses.jsx";
import {useAuth} from "../../AuthContext.jsx";
import dayjs from "dayjs";
import getNotIssuedLenses from "../../api/lenses/GetNotIssuedLenses.jsx";
const LensIssueFormModal = ({visible, onCancel, onSubmit}) => {
@ -13,11 +14,13 @@ const LensIssueFormModal = ({visible, onCancel, onSubmit}) => {
const [searchPatientString, setSearchPatientString] = useState("");
const [searchLensString, setSearchLensString] = useState("");
const [issueDate, setIssueDate] = useState(null);
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(() => {
@ -32,7 +35,7 @@ const LensIssueFormModal = ({visible, onCancel, onSubmit}) => {
const data = await getAllPatients(user.token);
setPatients(data);
} catch (error) {
console.log(error);
console.error(error);
notification.error({
message: "Ошибка загрузки пациентов",
description: "Проверьте подключение к сети.",
@ -42,10 +45,10 @@ const LensIssueFormModal = ({visible, onCancel, onSubmit}) => {
const fetchLenses = async () => {
try {
const data = await getAllLenses(user.token);
const data = await getNotIssuedLenses(user.token);
setLenses(data);
} catch (error) {
console.log(error);
console.error(error);
notification.error({
message: "Ошибка загрузки линз",
description: "Проверьте подключение к сети.",
@ -55,11 +58,15 @@ const LensIssueFormModal = ({visible, onCancel, onSubmit}) => {
const handleOk = async () => {
try {
// const values = await form.validateFields();
onSubmit({...values, patient: selectedPatient});
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.log("Validation Failed:", errorInfo);
console.error("Validation Failed:", errorInfo);
}
};
@ -198,40 +205,25 @@ const LensIssueFormModal = ({visible, onCancel, onSubmit}) => {
return (
<>
<Alert
type={"warning"}
message={
"Внимание! После подтверждения линза будет считаться выданной, данное действие нельзя будет отменить."
}
type="warning"
message="Внимание! После подтверждения линза будет считаться выданной, данное действие нельзя будет отменить."
style={{marginBottom: 15}}
/>
<Row
style={{padding: "10px", background: "#f5f5f5", borderRadius: 5, marginBottom: 15}}
gutter={[16, 16]}
>
<Col
xs={24}
md={16}
style={{display: "flex", alignItems: "center"}}
>
<Typography.Text
strong
>
Дата выдачи будет установлена автоматически: {issueDate.toLocaleDateString("ru-RU")}
<Row style={{padding: "10px", background: "#f5f5f5", borderRadius: 5, marginBottom: 15}}
gutter={[16, 16]}>
<Col xs={24} md={16} style={{display: "flex", alignItems: "center"}}>
<Typography.Text strong>
Дата выдачи: {issueDate?.toDate().toLocaleDateString("ru-RU")}
</Typography.Text>
</Col>
<Col
xs={24}
md={8}
>
<Button
type="primary"
onClick={}
block
>
Установить дату вручную
</Button>
<Col xs={24} md={8}>
<DatePicker
value={issueDate}
onChange={(date) => setIssueDate(date)}
format="DD.MM.YYYY"
style={{width: "100%"}}
/>
</Col>
</Row>
@ -260,7 +252,7 @@ const LensIssueFormModal = ({visible, onCancel, onSubmit}) => {
<p><b>Esa:</b> {selectedLens.esa}</p>
</div>
</>
)
);
};
const steps = [
@ -302,6 +294,7 @@ const LensIssueFormModal = ({visible, onCancel, onSubmit}) => {
setSelectedPatient(null);
setSelectedLens(null);
setCurrentStep(0);
setIssueDate(dayjs(new Date()));
onCancel();
}}
footer={null}
@ -309,10 +302,16 @@ const LensIssueFormModal = ({visible, onCancel, onSubmit}) => {
width={window.innerWidth > 768 ? 700 : "90%"}
centered
>
{loading ? (
<div style={{display: "flex", justifyContent: "center", alignItems: "center", height: "70vh"}}>
<Spin size="large"/>
</div>
) : (
<div style={{maxHeight: "70vh", overflowY: "auto", padding: "10px"}}>
{steps[currentStep].content}
</div>
)}
<div style={{maxHeight: "60vh", overflowY: "auto", padding: "10px"}}>
{steps[currentStep].content}
</div>
{window.innerWidth > 768 && (
<Steps
@ -329,21 +328,26 @@ const LensIssueFormModal = ({visible, onCancel, onSubmit}) => {
gutter={[8, 8]}
>
<Button
type="primary"
onClick={() => setCurrentStep(currentStep + 1)}
disabled={!isActiveNextButton() && !isActiveFinishButton()}
>
{isActiveFinishButton() ? "Завершить" : "Далее"}
</Button>
<Button
style={{marginLeft: 8}}
style={{marginRight: 8}}
onClick={() => setCurrentStep(currentStep - 1)}
disabled={!isActivePrevButton()}
>
Назад
</Button>
<Button
type="primary"
onClick={async () => {
if (isActiveFinishButton()) {
await handleOk();
} else {
setCurrentStep(currentStep + 1);
}
}}
disabled={!isActiveNextButton() && !isActiveFinishButton()}
>
{isActiveFinishButton() ? "Завершить" : "Далее"}
</Button>
</Row>
</Modal>
);
};

View File

@ -6,6 +6,7 @@ import {DatabaseOutlined, LoadingOutlined, PlusOutlined} from "@ant-design/icons
import LensIssueViewModal from "../components/lens_issues/LensIssueViewModal.jsx";
import dayjs from "dayjs";
import LensIssueFormModal from "../components/lens_issues/LensIssueFormModal.jsx";
import addLensIssue from "../api/lens_issues/AddLensIssue.jsx";
const {Title} = Typography;
@ -61,8 +62,24 @@ const IssuesPage = () => {
setIsModalVisible(false);
};
const handleSubmitFormModal = () => {
const handleSubmitFormModal = async (issue_date, patient_id, lens_id) => {
try {
await addLensIssue(user.token, {issue_date, patient_id, lens_id});
setIsModalVisible(false);
notification.success({
message: "Линза выдана",
description: "Линза успешно выдана пациенту.",
placement: "topRight",
});
await fetchLensIssues();
} catch (error) {
console.log(error);
notification.error({
message: "Ошибка добавления",
description: "Не удалось выдать линзу пациенту.",
placement: "topRight",
});
}
};
const fetchLensIssues = async () => {
@ -85,7 +102,6 @@ const IssuesPage = () => {
setSearchTerm(e.target.value.toLowerCase());
};
const filteredIssues = lensIssues.filter(issue => {
let dateFilter = true;