сделал добавление пациента
This commit is contained in:
parent
44c092ecb9
commit
defe869e3e
18
web-app/src/api/patients/AddPatient.jsx
Normal file
18
web-app/src/api/patients/AddPatient.jsx
Normal file
@ -0,0 +1,18 @@
|
||||
import axios from "axios";
|
||||
import CONFIG from "../../core/Config.jsx";
|
||||
|
||||
|
||||
const AddPatient = async (token, patient) => {
|
||||
try {
|
||||
const response = await axios.post(`${CONFIG.BASE_URL}/patients/`, patient, {
|
||||
headers: {
|
||||
Authorization: `Bearer ${token}`,
|
||||
},
|
||||
});
|
||||
return response.data;
|
||||
} catch (error) {
|
||||
throw new Error(error.response.data.message);
|
||||
}
|
||||
};
|
||||
|
||||
export default AddPatient;
|
||||
@ -1,11 +1,12 @@
|
||||
import {useEffect, useState} from "react";
|
||||
import {Input, Select, List, FloatButton, Row, Col, message} from "antd";
|
||||
import {PlusOutlined} from "@ant-design/icons";
|
||||
import {Input, Select, List, FloatButton, Row, Col, message, Spin} from "antd";
|
||||
import {LoadingOutlined, PlusOutlined} from "@ant-design/icons";
|
||||
import {useAuth} from "../AuthContext.jsx";
|
||||
import getAllPatients from "../api/patients/GetAllPatients.jsx";
|
||||
import PatientListCard from "../components/PatientListCard.jsx";
|
||||
import PatientModal from "../components/PatientModal.jsx";
|
||||
import updatePatient from "../api/patients/UpdatePatient.jsx"; // Подключаем модальное окно
|
||||
import updatePatient from "../api/patients/UpdatePatient.jsx";
|
||||
import addPatient from "../api/patients/AddPatient.jsx"; // Подключаем модальное окно
|
||||
|
||||
const {Option} = Select;
|
||||
|
||||
@ -21,6 +22,7 @@ const PatientsPage = () => {
|
||||
|
||||
const [isModalVisible, setIsModalVisible] = useState(false);
|
||||
const [selectedPatient, setSelectedPatient] = useState(null);
|
||||
const [loading, setLoading] = useState(true);
|
||||
|
||||
useEffect(() => {
|
||||
if (!isModalVisible) {
|
||||
@ -39,18 +41,18 @@ const PatientsPage = () => {
|
||||
} catch (err) {
|
||||
setError(err.message);
|
||||
}
|
||||
|
||||
if (loading) {
|
||||
setLoading(false)
|
||||
}
|
||||
};
|
||||
|
||||
const filteredPatients = patients
|
||||
.filter((patient) =>
|
||||
`${patient.first_name} ${patient.last_name}`.toLowerCase().includes(searchText.toLowerCase())
|
||||
)
|
||||
.filter((patient) => `${patient.first_name} ${patient.last_name}`.toLowerCase().includes(searchText.toLowerCase()))
|
||||
.sort((a, b) => {
|
||||
const fullNameA = `${a.last_name} ${a.first_name}`;
|
||||
const fullNameB = `${b.last_name} ${b.first_name}`;
|
||||
return sortOrder === "asc"
|
||||
? fullNameA.localeCompare(fullNameB)
|
||||
: fullNameB.localeCompare(fullNameA);
|
||||
return sortOrder === "asc" ? fullNameA.localeCompare(fullNameB) : fullNameB.localeCompare(fullNameA);
|
||||
});
|
||||
|
||||
const handleAddPatient = () => {
|
||||
@ -78,19 +80,27 @@ const PatientsPage = () => {
|
||||
}
|
||||
throw new Error(error.message);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
if (!selectedPatient) {
|
||||
setPatients((prevPatients) => [...prevPatients, {id: Date.now(), ...newPatient}]);
|
||||
message.success("Пациент успешно добавлен!");
|
||||
|
||||
try {
|
||||
await addPatient(user.token, newPatient);
|
||||
} catch (error) {
|
||||
if (error.response?.status === 401) {
|
||||
throw new Error("Ошибка авторизации: пользователь неяден или токен недействителен");
|
||||
}
|
||||
throw new Error(error.message);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
setIsModalVisible(false);
|
||||
};
|
||||
|
||||
return (
|
||||
<div style={{padding: 20}}>
|
||||
return (<div style={{padding: 20}}>
|
||||
<Row gutter={[16, 16]} style={{marginBottom: 20}}>
|
||||
<Col xs={24} sm={16}>
|
||||
<Input
|
||||
@ -111,18 +121,19 @@ const PatientsPage = () => {
|
||||
</Col>
|
||||
</Row>
|
||||
|
||||
{loading ? (
|
||||
<Spin indicator={<LoadingOutlined style={{fontSize: 48}} spin/>}/>
|
||||
) : (
|
||||
<List
|
||||
grid={{gutter: 16, column: 1}}
|
||||
dataSource={filteredPatients}
|
||||
renderItem={(patient) => (
|
||||
<List.Item
|
||||
renderItem={(patient) => (<List.Item
|
||||
onClick={() => {
|
||||
handleEditPatient(patient);
|
||||
}}
|
||||
>
|
||||
<PatientListCard patient={patient}/>
|
||||
</List.Item>
|
||||
)}
|
||||
</List.Item>)}
|
||||
pagination={{
|
||||
current,
|
||||
pageSize,
|
||||
@ -134,6 +145,8 @@ const PatientsPage = () => {
|
||||
},
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
|
||||
|
||||
<FloatButton
|
||||
icon={<PlusOutlined/>}
|
||||
@ -147,9 +160,7 @@ const PatientsPage = () => {
|
||||
onSubmit={handleSubmit}
|
||||
patient={selectedPatient}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
;
|
||||
</div>);
|
||||
};
|
||||
|
||||
export default PatientsPage;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user