feat: PAAI 피드백 루프 시스템 구현 (1-2단계)
- paai_feedback.py: 피드백 API + SQLite 저장
- PMR 화면: 👎 클릭 시 코멘트 입력 모달
- 카테고리: 약물상호작용/적응증/용법용량/기타
- 피드백 규칙 자동 정제 (기본 버전)
This commit is contained in:
@@ -117,7 +117,7 @@
|
||||
|
||||
/* 왼쪽: 환자 목록 */
|
||||
.patient-list {
|
||||
width: 380px;
|
||||
width: clamp(250px, 22vw, 380px);
|
||||
background: #fff;
|
||||
border-radius: 12px;
|
||||
box-shadow: 0 4px 20px rgba(0,0,0,0.15);
|
||||
@@ -125,6 +125,12 @@
|
||||
flex-direction: column;
|
||||
overflow: hidden;
|
||||
}
|
||||
/* 세로 모니터 최적화 */
|
||||
@media (orientation: portrait) {
|
||||
.patient-list {
|
||||
width: clamp(220px, 18vw, 300px);
|
||||
}
|
||||
}
|
||||
.patient-list-header {
|
||||
background: #4c1d95;
|
||||
color: #fff;
|
||||
@@ -415,11 +421,99 @@
|
||||
}
|
||||
.paai-feedback button:hover { border-color: #10b981; }
|
||||
.paai-feedback button.selected { background: #d1fae5; border-color: #10b981; }
|
||||
.paai-feedback button.selected-bad { background: #fee2e2; border-color: #ef4444; }
|
||||
.paai-timing {
|
||||
font-size: 0.8rem;
|
||||
color: #9ca3af;
|
||||
}
|
||||
|
||||
/* 피드백 코멘트 모달 */
|
||||
.feedback-modal {
|
||||
display: none;
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
background: rgba(0,0,0,0.5);
|
||||
z-index: 1200;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
}
|
||||
.feedback-modal.show { display: flex; }
|
||||
.feedback-modal-content {
|
||||
background: #fff;
|
||||
border-radius: 16px;
|
||||
width: 90%;
|
||||
max-width: 500px;
|
||||
box-shadow: 0 20px 40px rgba(0,0,0,0.3);
|
||||
}
|
||||
.feedback-modal-header {
|
||||
background: linear-gradient(135deg, #ef4444, #dc2626);
|
||||
color: #fff;
|
||||
padding: 18px 24px;
|
||||
border-radius: 16px 16px 0 0;
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
}
|
||||
.feedback-modal-header h3 { font-size: 1.1rem; margin: 0; }
|
||||
.feedback-modal-close {
|
||||
background: rgba(255,255,255,0.2);
|
||||
border: none;
|
||||
color: #fff;
|
||||
width: 32px;
|
||||
height: 32px;
|
||||
border-radius: 50%;
|
||||
font-size: 1.3rem;
|
||||
cursor: pointer;
|
||||
}
|
||||
.feedback-modal-body { padding: 24px; }
|
||||
.feedback-categories {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 8px;
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
.feedback-category {
|
||||
padding: 6px 14px;
|
||||
border: 2px solid #e5e7eb;
|
||||
border-radius: 20px;
|
||||
background: #fff;
|
||||
cursor: pointer;
|
||||
font-size: 0.85rem;
|
||||
transition: all 0.2s;
|
||||
}
|
||||
.feedback-category:hover { border-color: #ef4444; }
|
||||
.feedback-category.selected { background: #fee2e2; border-color: #ef4444; color: #dc2626; }
|
||||
.feedback-textarea {
|
||||
width: 100%;
|
||||
min-height: 100px;
|
||||
padding: 12px;
|
||||
border: 2px solid #e5e7eb;
|
||||
border-radius: 10px;
|
||||
font-size: 0.95rem;
|
||||
resize: vertical;
|
||||
font-family: inherit;
|
||||
}
|
||||
.feedback-textarea:focus { outline: none; border-color: #ef4444; }
|
||||
.feedback-modal-footer {
|
||||
padding: 16px 24px;
|
||||
border-top: 1px solid #e5e7eb;
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
gap: 10px;
|
||||
}
|
||||
.feedback-btn {
|
||||
padding: 10px 20px;
|
||||
border-radius: 8px;
|
||||
font-size: 0.95rem;
|
||||
cursor: pointer;
|
||||
border: none;
|
||||
}
|
||||
.feedback-btn-cancel { background: #f3f4f6; color: #374151; }
|
||||
.feedback-btn-submit { background: #ef4444; color: #fff; font-weight: 600; }
|
||||
|
||||
/* PAAI 토스트 알림 */
|
||||
.paai-toast-container {
|
||||
position: fixed;
|
||||
@@ -1169,6 +1263,29 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 피드백 코멘트 모달 -->
|
||||
<div class="feedback-modal" id="feedbackModal">
|
||||
<div class="feedback-modal-content">
|
||||
<div class="feedback-modal-header">
|
||||
<h3>📝 어떤 점이 문제였나요?</h3>
|
||||
<button class="feedback-modal-close" onclick="closeFeedbackModal()">×</button>
|
||||
</div>
|
||||
<div class="feedback-modal-body">
|
||||
<div class="feedback-categories">
|
||||
<button class="feedback-category" data-cat="interaction">💊 약물 상호작용</button>
|
||||
<button class="feedback-category" data-cat="indication">🎯 적응증/용도</button>
|
||||
<button class="feedback-category" data-cat="dosage">📏 용법용량</button>
|
||||
<button class="feedback-category" data-cat="other">📋 기타</button>
|
||||
</div>
|
||||
<textarea class="feedback-textarea" id="feedbackComment" placeholder="잘못된 점이나 개선할 내용을 적어주세요... 예: NSAID와 아세트아미노펜은 병용 가능합니다."></textarea>
|
||||
</div>
|
||||
<div class="feedback-modal-footer">
|
||||
<button class="feedback-btn feedback-btn-cancel" onclick="closeFeedbackModal()">취소</button>
|
||||
<button class="feedback-btn feedback-btn-submit" onclick="submitFeedbackComment()">제출</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 특이사항 모달 -->
|
||||
<div class="cusetc-modal" id="cusetcModal">
|
||||
<div class="cusetc-modal-content">
|
||||
@@ -2201,6 +2318,7 @@
|
||||
}
|
||||
|
||||
currentPaaiLogId = cached.result.log_id;
|
||||
currentPaaiResponse = JSON.stringify(cached.result.analysis || {});
|
||||
displayPaaiResult(cached.result);
|
||||
modal.classList.add('show');
|
||||
}
|
||||
@@ -2325,28 +2443,93 @@
|
||||
document.getElementById('paaiModal').classList.remove('show');
|
||||
}
|
||||
|
||||
// 피드백 관련 변수
|
||||
let currentPaaiResponse = '';
|
||||
let currentFeedbackCategory = 'other';
|
||||
|
||||
async function sendPaaiFeedback(useful) {
|
||||
if (!currentPaaiLogId) return;
|
||||
|
||||
// 버튼 즉시 반영
|
||||
document.getElementById('paaiUseful').classList.toggle('selected', useful);
|
||||
document.getElementById('paaiNotUseful').classList.toggle('selected', !useful);
|
||||
document.getElementById('paaiNotUseful').classList.toggle('selected-bad', !useful);
|
||||
document.getElementById('paaiNotUseful').classList.remove('selected');
|
||||
|
||||
if (useful) {
|
||||
// 👍 좋아요: 바로 저장하고 닫기
|
||||
try {
|
||||
await fetch('/api/paai/feedback', {
|
||||
method: 'POST',
|
||||
headers: {'Content-Type': 'application/json'},
|
||||
body: JSON.stringify({
|
||||
prescription_id: currentPrescriptionId,
|
||||
patient_name: document.querySelector('.patient-name')?.textContent || '',
|
||||
paai_response: currentPaaiResponse,
|
||||
rating: 'good'
|
||||
})
|
||||
});
|
||||
} catch (err) {
|
||||
console.error('Feedback error:', err);
|
||||
}
|
||||
setTimeout(() => closePaaiModal(), 500);
|
||||
} else {
|
||||
// 👎 아니요: 코멘트 모달 열기
|
||||
openFeedbackModal();
|
||||
}
|
||||
}
|
||||
|
||||
function openFeedbackModal() {
|
||||
document.getElementById('feedbackModal').classList.add('show');
|
||||
document.getElementById('feedbackComment').value = '';
|
||||
document.getElementById('feedbackComment').focus();
|
||||
|
||||
// 카테고리 버튼 이벤트
|
||||
document.querySelectorAll('.feedback-category').forEach(btn => {
|
||||
btn.classList.remove('selected');
|
||||
btn.onclick = () => {
|
||||
document.querySelectorAll('.feedback-category').forEach(b => b.classList.remove('selected'));
|
||||
btn.classList.add('selected');
|
||||
currentFeedbackCategory = btn.dataset.cat;
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
function closeFeedbackModal() {
|
||||
document.getElementById('feedbackModal').classList.remove('show');
|
||||
}
|
||||
|
||||
async function submitFeedbackComment() {
|
||||
const comment = document.getElementById('feedbackComment').value.trim();
|
||||
|
||||
if (!comment) {
|
||||
alert('코멘트를 입력해주세요.');
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
await fetch('/pmr/api/paai/feedback', {
|
||||
const res = await fetch('/api/paai/feedback', {
|
||||
method: 'POST',
|
||||
headers: {'Content-Type': 'application/json'},
|
||||
body: JSON.stringify({
|
||||
log_id: currentPaaiLogId,
|
||||
useful: useful
|
||||
prescription_id: currentPrescriptionId,
|
||||
patient_name: document.querySelector('.patient-name')?.textContent || '',
|
||||
paai_response: currentPaaiResponse,
|
||||
rating: 'bad',
|
||||
category: currentFeedbackCategory,
|
||||
pharmacist_comment: comment
|
||||
})
|
||||
});
|
||||
|
||||
const data = await res.json();
|
||||
if (data.success) {
|
||||
closeFeedbackModal();
|
||||
closePaaiModal();
|
||||
showPaaiToast('피드백이 저장되었습니다. 감사합니다! 🙏', 'success');
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('Feedback error:', err);
|
||||
alert('피드백 저장 실패');
|
||||
}
|
||||
|
||||
// 0.5초 후 모달 닫기
|
||||
setTimeout(() => closePaaiModal(), 500);
|
||||
}
|
||||
|
||||
// ─────────────────────────────────────────────────────────────
|
||||
|
||||
Reference in New Issue
Block a user