diff --git a/backend/pmr_api.py b/backend/pmr_api.py index 06d6326..4361388 100644 --- a/backend/pmr_api.py +++ b/backend/pmr_api.py @@ -188,7 +188,10 @@ def get_prescription_detail(prescription_id): return jsonify({'success': False, 'error': '처방전을 찾을 수 없습니다'}), 404 # 처방 약품 목록 (PS_sub_pharm + CD_GOODS + CD_MC JOIN) + # PS_Type: 0,1=일반, 4=대체조제(실제), 9=대체조제(원본) medications = [] + original_prescriptions = {} # PS_Type=9인 원본 처방 저장 + cursor.execute(""" SELECT s.DrugCode, @@ -197,6 +200,7 @@ def get_prescription_detail(prescription_id): s.QUAN_TIME, s.PS_Type, s.INV_QUAN, + s.SUB_SERIAL, g.GoodsName, g.SUNG_CODE, m.PRINT_TYPE, @@ -208,10 +212,30 @@ def get_prescription_detail(prescription_id): ORDER BY s.SUB_SERIAL """, (prescription_id,)) - for row in cursor.fetchall(): + all_rows = cursor.fetchall() + + # 1차: PS_Type=9 (원본 처방) 수집 - 인덱스로 저장 + for i, row in enumerate(all_rows): + if row.PS_Type == '9': + original_prescriptions[i] = { + 'drug_code': row.DrugCode or '', + 'drug_name': row.GoodsName or row.DrugCode or '', + 'add_info': row.PRINT_TYPE or row.SIM_EFFECT or '' + } + + # 2차: 실제 조제약만 추가 (PS_Type != 9) + for i, row in enumerate(all_rows): + if row.PS_Type == '9': + continue # 원본 처방은 스킵 + # 효능: PRINT_TYPE > SIM_EFFECT > 없음 add_info = row.PRINT_TYPE or row.SIM_EFFECT or '' + # 대체조제 여부 확인: PS_Type=4이고 바로 다음이 PS_Type=9 + # 순서: 4(대체) → 9(원본) + is_substituted = row.PS_Type == '4' and (i + 1) in original_prescriptions + original_drug = original_prescriptions.get(i + 1) if is_substituted else None + medications.append({ 'medication_code': row.DrugCode or '', 'med_name': row.GoodsName or row.DrugCode or '', @@ -221,7 +245,10 @@ def get_prescription_detail(prescription_id): 'duration': row.Days or 0, 'total_qty': float(row.INV_QUAN) if row.INV_QUAN else 0, 'type': '급여' if row.PS_Type in ['0', '4'] else '비급여' if row.PS_Type == '1' else row.PS_Type, - 'sung_code': row.SUNG_CODE or '' + 'sung_code': row.SUNG_CODE or '', + 'ps_type': row.PS_Type or '0', + 'is_substituted': is_substituted, + 'original_drug': original_drug }) # 나이/성별 계산 diff --git a/backend/templates/pmr.html b/backend/templates/pmr.html index cce6b7f..15d3e93 100644 --- a/backend/templates/pmr.html +++ b/backend/templates/pmr.html @@ -942,6 +942,47 @@ tr.row-removed { background: #fef2f2 !important; opacity: 0.7; } tr.row-changed { background: #fffbeb !important; } + /* 대체조제 표시 */ + .subst-badge { + display: inline-block; + background: linear-gradient(135deg, #f59e0b, #d97706); + color: white; + padding: 1px 5px; + border-radius: 4px; + font-size: 0.65rem; + font-weight: 700; + margin-right: 4px; + vertical-align: middle; + } + .original-rx { + margin-top: 4px; + font-size: 0.75rem; + } + .original-rx summary { + cursor: pointer; + color: #6b7280; + user-select: none; + } + .original-rx summary:hover { + color: #4b5563; + } + .original-drug-info { + margin-top: 4px; + padding: 6px 10px; + background: #fef3c7; + border-radius: 4px; + border-left: 3px solid #f59e0b; + } + .orig-name { + display: block; + font-weight: 500; + color: #92400e; + } + .orig-code { + font-size: 0.7rem; + color: #b45309; + } + .change-arrow { color: #94a3b8; margin: 0 4px; @@ -1362,12 +1403,23 @@ ${data.medications.map(m => ` - + -
${m.med_name || m.medication_code}
+
+ ${m.is_substituted ? '대) ' : ''}${m.med_name || m.medication_code} +
${m.medication_code}
${m.add_info ? `
${escapeHtml(m.add_info)}
` : ''} + ${m.is_substituted && m.original_drug ? ` +
+ 원처방 보기 +
+ ${escapeHtml(m.original_drug.drug_name)} + ${m.original_drug.drug_code} +
+
+ ` : ''} ${m.formulation ? `${m.formulation}` : '-'} ${m.dosage || '-'}