박권수

feat. qrcode front -> backend api

...@@ -65,4 +65,11 @@ export default { ...@@ -65,4 +65,11 @@ export default {
65 }, 65 },
66 }); 66 });
67 }, 67 },
68 + prescribeMedicine : (token : RecoilState<any>, Data : any) => {
69 + return client.post('/doctor/prescribe', Data, {
70 + headers : {
71 + Authorization : token,
72 + },
73 + });
74 + },
68 }; 75 };
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -10,11 +10,8 @@ import * as Alert from '../../../util/alertMessage'; ...@@ -10,11 +10,8 @@ import * as Alert from '../../../util/alertMessage';
10 10
11 import { doctorApi, medicineApi } from '../../../api'; 11 import { doctorApi, medicineApi } from '../../../api';
12 12
13 -import QRCode from 'qrcode';
14 13
15 14
16 -//toDo : Generate QR Code By Medicine Id
17 -
18 type DoctorMenuProps = RouteComponentProps 15 type DoctorMenuProps = RouteComponentProps
19 16
20 const DoctorMenuContainer = (props : DoctorMenuProps) => { 17 const DoctorMenuContainer = (props : DoctorMenuProps) => {
...@@ -264,19 +261,36 @@ const DoctorMenuContainer = (props : DoctorMenuProps) => { ...@@ -264,19 +261,36 @@ const DoctorMenuContainer = (props : DoctorMenuProps) => {
264 }; 261 };
265 262
266 const onPrescribeSubmit = async() => { 263 const onPrescribeSubmit = async() => {
264 + const onPrescribeMedicine = async () => {
265 + setLoading(true);
266 + try {
267 + const res = await doctorApi.prescribeMedicine(token, {
268 + patientId : patientDetail.profile.userId,
269 + medicineId : prescribeMedicine.medicineId,
270 + dosage,
271 + });
272 +
273 + if(res.statusText === 'OK') {
274 + setQrcodeUrl(res.data.qrCode);
275 + setLoading(false);
276 + }
277 + } catch(e : any) {
278 + setLoading(false);
279 + Alert.onError(e.response.data.error, () => null);
280 + }
281 + };
282 +
267 Alert.onCheck(`${prescribeMedicine.name}(일 복용량:${dosage})\n을 처방하시겠습니까?`, async () => { 283 Alert.onCheck(`${prescribeMedicine.name}(일 복용량:${dosage})\n을 처방하시겠습니까?`, async () => {
268 - setQrcodeUrl(await QRCode.toDataURL(`${prescribeMedicine.name}/${prescribeMedicine.medicineId}/${dosage}/${userId}`, { 284 + await onPrescribeMedicine();
269 - type : "image/png",
270 - color : { dark : '#337DFF', light : '#FFF' },
271 - }));
272 Alert.onSuccess('처방 정보가 생성 되었습니다.', () => onSetNextStepPrescribe()); 285 Alert.onSuccess('처방 정보가 생성 되었습니다.', () => onSetNextStepPrescribe());
273 }, () => null); 286 }, () => null);
274 }; 287 };
275 288
276 const onPrintQrcode = async(divId : string) => { 289 const onPrintQrcode = async(divId : string) => {
277 const printContent : any = document.getElementById(divId); 290 const printContent : any = document.getElementById(divId);
278 - const windowOpen : any = window.open('', 'PrintQRCode'); 291 + const windowOpen : any = window.open('', '_blank');
279 292
293 + //toDo : 현재 인증되지 않은 사용자(=http)이기 때문에, GCS에서 signed url을 불러와도 만료되어, 이미지가 정상 표시 안됨 : 해결 필요
280 windowOpen.document.writeln(printContent.innerHTML); 294 windowOpen.document.writeln(printContent.innerHTML);
281 windowOpen.document.close(); 295 windowOpen.document.close();
282 windowOpen.focus(); 296 windowOpen.focus();
......
...@@ -242,7 +242,8 @@ const DoctorMenuPresenter = (props : DoctorMenuProps) => { ...@@ -242,7 +242,8 @@ const DoctorMenuPresenter = (props : DoctorMenuProps) => {
242 </styled.MedicineQRCodeInfo> 242 </styled.MedicineQRCodeInfo>
243 { 243 {
244 props.qrcodeUrl ? 244 props.qrcodeUrl ?
245 - <styled.MedicineQRCode src = {props.qrcodeUrl}/> : null 245 + <styled.MedicineQRCode
246 + src = {props.qrcodeUrl}/> : null
246 } 247 }
247 </styled.MedicineQRCodeWrapper> 248 </styled.MedicineQRCodeWrapper>
248 } 249 }
......