diff --git a/backend/templates/admin.html b/backend/templates/admin.html index b077eac..bf0dbf5 100644 --- a/backend/templates/admin.html +++ b/backend/templates/admin.html @@ -999,6 +999,10 @@ `; }).join(''); + // 약품 코드 배열 (상호작용 체크용) + const drugCodes = (rx.items || []).map(item => item.drug_code).filter(c => c); + const drugCodesJson = JSON.stringify(drugCodes).replace(/"/g, '"'); + html += `
@@ -1009,6 +1013,14 @@ 🏥 ${rx.hospital || ''} · ${rx.doctor || ''}
${rx.items && rx.items.length > 0 ? `
${itemsHtml}
` : ''} + ${drugCodes.length >= 2 ? ` +
+ +
+ ` : ''}
`; }); @@ -1710,6 +1722,162 @@ closeAIAnalysisModal(); } }); + + // ═══════════════════════════════════════════════════ + // KIMS 약물 상호작용 체크 + // ═══════════════════════════════════════════════════ + + async function checkDrugInteraction(drugCodes, preSerial) { + // drugCodes가 문자열로 넘어올 수 있음 + if (typeof drugCodes === 'string') { + try { drugCodes = JSON.parse(drugCodes); } catch(e) { return; } + } + + // 로딩 모달 표시 + showInteractionModal('loading'); + + try { + const response = await fetch('/api/kims/interaction-check', { + method: 'POST', + headers: {'Content-Type': 'application/json'}, + body: JSON.stringify({ + drug_codes: drugCodes, + pre_serial: preSerial + }) + }); + + const data = await response.json(); + + if (data.success) { + showInteractionModal('result', data); + } else { + showInteractionModal('error', data.error || '알 수 없는 오류'); + } + } catch (err) { + showInteractionModal('error', '서버 연결 실패: ' + err.message); + } + } + + function showInteractionModal(type, data) { + let modal = document.getElementById('interactionModal'); + if (!modal) { + modal = document.createElement('div'); + modal.id = 'interactionModal'; + modal.style.cssText = 'position:fixed;inset:0;background:rgba(0,0,0,0.5);display:flex;align-items:center;justify-content:center;z-index:9999;'; + modal.onclick = (e) => { if (e.target === modal) modal.remove(); }; + document.body.appendChild(modal); + } + + let content = ''; + + if (type === 'loading') { + content = ` +
+
🔬
+
상호작용 분석 중...
+
KIMS 데이터베이스 조회 중
+
+ `; + } else if (type === 'error') { + content = ` +
+
⚠️
+
분석 실패
+
${escapeHtml(data)}
+
+ +
+
+ `; + } else if (type === 'result') { + const interactions = data.interactions || []; + const drugsChecked = data.drugs_checked || []; + + // 약품 목록 (상호작용 여부에 따른 색상) + const drugsHtml = drugsChecked.map(d => { + const hasInteraction = d.has_interaction; + const bgColor = hasInteraction ? '#fef2f2' : '#f1f5f9'; + const borderColor = hasInteraction ? '#fca5a5' : '#e2e8f0'; + const textColor = hasInteraction ? '#dc2626' : '#334155'; + const icon = hasInteraction ? '⚠️ ' : ''; + return `${icon}${escapeHtml(d.name.slice(0,20))}`; + }).join(''); + + // 상호작용 목록 + let interactionsHtml = ''; + if (interactions.length === 0) { + interactionsHtml = ` +
+
+
상호작용 없음
+
+ ${data.total_pairs}개 약품 조합을 검사했습니다.
+ 주의가 필요한 상호작용이 발견되지 않았습니다. +
+
+ `; + } else { + interactionsHtml = interactions.map(item => ` +
+
+ + ${escapeHtml(item.drug1_name?.slice(0,20) || '')} ↔ ${escapeHtml(item.drug2_name?.slice(0,20) || '')} + + + ${item.severity_text} + +
+ ${item.description ? ` +
+ 📋 ${escapeHtml(item.description)} +
+ ` : ''} + ${item.management ? ` +
+ 💡 ${escapeHtml(item.management.slice(0, 150))}... +
+ ` : ''} +
+ `).join(''); + } + + content = ` +
+
+
+ 🔬 약물 상호작용 분석 +
+
+ ${drugsChecked.length}개 약품 · ${data.total_pairs}개 조합 검사 +
+
+
+
분석 약품
+ ${drugsHtml} +
+
+ ${interactions.length > 0 ? ` +
+ ⚠️ ${interactions.length}건의 상호작용 발견 +
+ ` : ''} + ${interactionsHtml} +
+
+ +
+
+ `; + } + + modal.innerHTML = content; + }