DoctorMenuContainer.tsx
11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
import React, { useState, useEffect } from 'react';
import { RouteComponentProps} from 'react-router-dom';
import DoctorMenuPresenter from './DoctorMenuPresenter';
import { useRecoilState, useRecoilValue } from 'recoil';
import * as recoilUtil from '../../../util/recoilUtil';
import * as Alert from '../../../util/alertMessage';
import { doctorApi, medicineApi } from '../../../api';
//toDo : Generate QR Code By Medicine Id
type DoctorMenuProps = RouteComponentProps
const DoctorMenuContainer = (props : DoctorMenuProps) => {
const token = useRecoilValue(recoilUtil.token);
const [loading, setLoading] = useRecoilState(recoilUtil.loading);
const [doctorInfo, setDoctorInfo] = useState<any>({
doctorNm : '',
doctorType : '',
hospitalNm : '',
hospitalAddr : '',
contact : '',
});
const [patientList, setPatientList] = useState<any>([]);
const [info, setInfo] = useState<any>({
infoType : 'DOCTOR',
userNm : '',
userAge : 0,
contact : '',
doctorType : '',
patientInfo : '',
});
const [searchPatientKeyword, setSearchPatientKeyword] = useState<string>('');
const [filteringPatientList, setFilteringPatientList] = useState<any>([]);
const [patientDetail, setPatientDetail] = useState<any>(null);
const [editModal, setEditModal] = useState<boolean>(false);
const [editPatientInfo, setEditPatientInfo] = useState<string>('');
const [newPatientRegisterModal, setNewPatientRegisterModal] = useState<boolean>(false);
const [newPatientSearchId, setNewPatientSearchId] = useState<string>('');
const [newPatientSearchResult, setNewPatientSearchResult] = useState<any | null>(null);
const [prescribeModal, setPrescribeModal] = useState<boolean>(false);
const [searchMedicineKeyword, setSearchMedicineKeyword] = useState<string>('');
const [medicineList, setMedicineList] = useState<any>([]);
const [prescribeMedicine, setPrescribeMedicine] = useState<any>(null);
const fetchData = async() => {
try {
setLoading(true);
const res = await doctorApi.getDoctorsInfo(token);
if(res.statusText === 'OK') {
const { doctorInfo } = res.data;
setDoctorInfo(doctorInfo);
setInfo({
infoType : 'DOCTOR',
userNm : doctorInfo.doctorNm,
doctorType : doctorInfo.doctorType,
contact : doctorInfo.contact,
userAge : null,
patientInfo : '',
});
//로그인한 환자의 리스트를 가져옴 : 프론트에서 필터로 검색
await doctorApi.getPatientList(token).then(res => {
setPatientList(res.data.patientList);
}).catch(error => console.log(error));
}
setLoading(false);
} catch(e) {
console.log(e);
setLoading(false);
}
};
const onSetKeyword = (e : React.ChangeEvent<HTMLInputElement>) => {
setSearchPatientKeyword(e.target.value);
};
const onFetchPatientDetail = async (patientId : string) => {
try {
setLoading(true);
await doctorApi.getPatientDetail(token, patientId).then(res => {
setPatientDetail(res.data);
setInfo({
infoType : 'PATIENT',
userNm : res.data.profile.userNm,
userAge : res.data.profile.userAge,
contact : res.data.profile.contact,
doctorType : null,
patientInfo : res.data.info,
});
}).catch(err => console.log(err));
setLoading(false);
} catch(e) {
console.log(e);
setLoading(false);
}
};
const onInitialize = async () => {
await fetchData();
setPatientDetail(null);
setInfo({
infoType : 'DOCTOR',
userNm : doctorInfo.doctorNm,
doctorType : doctorInfo.doctorType,
contact : doctorInfo.contact,
userAge : null,
patientInfo : '',
});
setFilteringPatientList([]);
setSearchPatientKeyword('');
onCloseModal();
};
const onEditPatientInfo = (e : React.ChangeEvent<HTMLTextAreaElement>) => {
setEditPatientInfo(e.target.value);
};
const onSubmitPatientInfo = () => {
if(editPatientInfo.length && patientDetail) {
const onSubmit = async () => {
try {
const result = await doctorApi.writePatientInfo(token, {
patientId : patientDetail.profile.userId,
info : editPatientInfo,
});
if(result.statusText === 'OK') {
Alert.onSuccess('환자의 특이사항을 업데이트했습니다.', () => onInitialize());
} else {
Alert.onError('특이사항을 기록하는데 실패했습니다.', () => null);
}
} catch(e : any) {
Alert.onError(e.response.data.error, () => null);
}
};
Alert.onCheck('환자의 특이사항을 업데이트하시겠습니까?', onSubmit, () => null);
} else {
Alert.onError('환자의 특이사항을 기록하세요.', () => null);
}
};
const onSetNewPatientSearchId = (e : React.ChangeEvent<HTMLInputElement>) => {
setNewPatientSearchId(e.target.value);
};
const onSearchNewPatientByEmail = async () => {
try {
setLoading(true);
await doctorApi.searchPatientById(token, newPatientSearchId).then(res => {
setNewPatientSearchResult(res.data);
setLoading(false);
}).catch(err => {
console.log(err);
setLoading(false);
Alert.onError('검색 결과가 없습니다.', () => null);
setNewPatientSearchResult(null);
});
} catch(e : any) {
setLoading(false);
Alert.onError(e.response.data.error, () => null);
}
};
const onRegisterNewPatient = () => {
if(newPatientSearchResult) {
const { patientId, patientNm } = newPatientSearchResult;
const onRegisterReq = async () => {
try {
const result = await doctorApi.registerPatient(token, {
patientId,
});
if(result.statusText === 'OK') {
Alert.onSuccess('환자에게 담당의 등록 요청을 전송했습니다.', () => null);
} else {
Alert.onError('환자에게 담당의 등록 요청을 실패했습니다.', () => null);
}
} catch(e : any) {
Alert.onError(e.response.data.error, () => null);
}
};
Alert.onCheck(`${patientNm} 환자에게 담당의 등록 요청을 전송하시겠습니까?`, onRegisterReq, () => null);
} else {
Alert.onError('환자를 먼저 검색해주세요.', () => null);
}
};
const onCloseModal = async () => {
setNewPatientRegisterModal(false);
setNewPatientSearchId('');
setNewPatientSearchResult(null);
setEditModal(false);
setEditPatientInfo('');
setPrescribeModal(false);
setSearchMedicineKeyword('');
setMedicineList([]);
setPrescribeMedicine(null);
};
const onGoBottleDetail = (bottleId : number) => {
props.history.push(`/bottle/${bottleId}`);
};
const onSetSearchMedicineKeyword = (e : React.ChangeEvent<HTMLInputElement>) => {
setSearchMedicineKeyword(e.target.value);
};
const searchMedicine = async() => {
setMedicineList([]);
setPrescribeMedicine(null);
try {
setLoading(true);
const res = await medicineApi.searchMedicine(token, searchMedicineKeyword);
if(res.statusText === 'OK') {
console.log(res.data.medicineList)
setMedicineList(res.data.medicineList);
}
setLoading(false);
} catch(e : any) {
Alert.onError(e.response.data.error, () => null);
}
};
const onPrescribeSubmit = async() => {
//toDo : 처방해서, QR코드 생성
Alert.onWarning('작업 중입니다.', () => null);
};
const onPrescribeCancel = () => {
Alert.onCheck('취소하시면 작업중인 내용이 사라집니다.', () => {
onCloseModal();
}, () => null)
};
useEffect(() => {
if(!token || !token.length) {
props.history.push('/login');
} else fetchData();
}, []);
useEffect(() => {
setFilteringPatientList(searchPatientKeyword === '' ? [] :
patientList.filter((patient : any) =>
patient.contact.includes(searchPatientKeyword)
|| patient.userNm.includes(searchPatientKeyword)
|| patient.userId.includes(searchPatientKeyword)
)
);
}, [searchPatientKeyword]);
return (
<DoctorMenuPresenter
info = {info}
searchPatientKeyword = {searchPatientKeyword}
onSetKeyword = {onSetKeyword}
filteringPatientList = {filteringPatientList}
patientDetail = {patientDetail}
onFetchPatientDetail = {onFetchPatientDetail}
onInitialize = {onInitialize}
onGoBottleDetail = {onGoBottleDetail}
editModal = {editModal}
setEditModal = {setEditModal}
editPatientInfo = {editPatientInfo}
onEditPatientInfo = {onEditPatientInfo}
onSubmitPatientInfo = {onSubmitPatientInfo}
newPatientRegisterModal = {newPatientRegisterModal}
setNewPatientRegisterModal = {setNewPatientRegisterModal}
newPatientSearchId = {newPatientSearchId}
onSetNewPatientSearchId = {onSetNewPatientSearchId}
onSearchNewPatientByEmail = {onSearchNewPatientByEmail}
onRegisterNewPatient = {onRegisterNewPatient}
onCloseModal = {onCloseModal}
prescribeModal = {prescribeModal}
setPrescribeModal = {setPrescribeModal}
searchMedicineKeyword = {searchMedicineKeyword}
onSetSearchMedicineKeyword = {onSetSearchMedicineKeyword}
medicineList = {medicineList}
searchMedicine = {searchMedicine}
prescribeMedicine = {prescribeMedicine}
setPrescribeMedicine = {setPrescribeMedicine}
onPrescribeSubmit = {onPrescribeSubmit}
onPrescribeCancel = {onPrescribeCancel}
newPatientSearchResult = {newPatientSearchResult}
/>
);
};
export default DoctorMenuContainer;