feat: 용법용량 체중별 투여량 HTML 테이블 렌더링
- 표 형식(─ 문자) 감지 시 HTML <table> 변환 - 파란색 헤더, 굵은 숫자 스타일 - 미리보기 API에서 strip_html 개선 (표 형식 줄바꿈 유지)
This commit is contained in:
parent
71c35433fc
commit
1054a9ed17
@ -6691,14 +6691,22 @@ def api_animal_drug_info_preview():
|
||||
except Exception as e:
|
||||
return jsonify({'success': False, 'error': f'DB 오류: {str(e)}'}), 500
|
||||
|
||||
# HTML 태그 제거
|
||||
# HTML 태그 제거 (표 형식은 줄바꿈 유지)
|
||||
def strip_html(html_text):
|
||||
if not html_text:
|
||||
return ''
|
||||
text = re.sub(r'<[^>]+>', '', html_text)
|
||||
# <p>, </div> → 줄바꿈
|
||||
text = re.sub(r'</p>|</div>', '\n', html_text)
|
||||
text = re.sub(r'<[^>]+>', '', text)
|
||||
text = unescape(text)
|
||||
text = re.sub(r'\s+', ' ', text).strip()
|
||||
return text
|
||||
|
||||
# 표 형식 감지
|
||||
if '─' in text or '━' in text:
|
||||
lines = [l.strip() for l in text.split('\n') if l.strip()]
|
||||
return '\n'.join(lines)
|
||||
else:
|
||||
text = re.sub(r'\s+', ' ', text).strip()
|
||||
return text
|
||||
|
||||
# 항목별 줄바꿈 처리 (가. 나. 다. 라. / 1) 2) 3) 등)
|
||||
def format_items(text):
|
||||
@ -6710,6 +6718,53 @@ def api_animal_drug_info_preview():
|
||||
text = re.sub(r'\s+(\d+)\)\s*', r'\n \1) ', text)
|
||||
return text.strip()
|
||||
|
||||
# 표 형식을 HTML 테이블로 변환
|
||||
def format_table_html(text):
|
||||
if not text:
|
||||
return ''
|
||||
|
||||
# 표가 없으면 일반 처리
|
||||
if '─' not in text and '━' not in text:
|
||||
return format_items(text)
|
||||
|
||||
# 표 형식: 체중별 투여량 테이블 생성
|
||||
lines = [l.strip() for l in text.split('\n') if l.strip() and '─' not in l and '━' not in l]
|
||||
|
||||
# 체중 행과 투여정수 행 찾기
|
||||
header_line = None
|
||||
data_line = None
|
||||
other_lines = []
|
||||
|
||||
for line in lines:
|
||||
if '체중' in line and 'kg' in line.lower():
|
||||
header_line = line
|
||||
elif '투여' in line and '정수' in line:
|
||||
data_line = line
|
||||
else:
|
||||
other_lines.append(line)
|
||||
|
||||
result = '\n'.join(other_lines)
|
||||
|
||||
# HTML 테이블 생성
|
||||
if header_line and data_line:
|
||||
headers = re.split(r'\s{2,}', header_line)
|
||||
values = re.split(r'\s{2,}', data_line)
|
||||
|
||||
html = '<table style="width:100%;border-collapse:collapse;margin:10px 0;font-size:13px;">'
|
||||
html += '<tr style="background:#dbeafe;">'
|
||||
for h in headers:
|
||||
html += f'<th style="border:1px solid #93c5fd;padding:8px;text-align:center;">{h}</th>'
|
||||
html += '</tr>'
|
||||
html += '<tr style="background:#fff;">'
|
||||
for v in values:
|
||||
html += f'<td style="border:1px solid #93c5fd;padding:8px;text-align:center;font-weight:bold;color:#1e40af;">{v}</td>'
|
||||
html += '</tr>'
|
||||
html += '</table>'
|
||||
|
||||
result = result + '\n' + html if result else html
|
||||
|
||||
return result
|
||||
|
||||
# 투약주기 조합
|
||||
dosing_interval = None
|
||||
if row.dosing_interval_adult:
|
||||
@ -6728,7 +6783,8 @@ def api_animal_drug_info_preview():
|
||||
'company_name': row.company_name,
|
||||
'main_ingredient': row.main_ingredient if row.main_ingredient != 'NaN' else None,
|
||||
'efficacy_effect': format_items(strip_html(row.efficacy_effect)),
|
||||
'dosage_instructions': format_items(strip_html(row.dosage_instructions)),
|
||||
'dosage_instructions': format_table_html(strip_html(row.dosage_instructions)),
|
||||
'dosage_has_table': '─' in (row.dosage_instructions or ''),
|
||||
'precautions': format_items(strip_html(row.precautions)),
|
||||
# 성분 가이드 (component_guide JOIN)
|
||||
'component_code': row.component_code,
|
||||
|
||||
@ -1156,7 +1156,7 @@
|
||||
${info.dosage_instructions ? `
|
||||
<div style="margin-bottom:12px;background:#eff6ff;padding:12px;border-radius:8px;">
|
||||
<h5 style="margin:0 0 6px;color:#0284c7;">▶ 용법용량</h5>
|
||||
<p style="margin:0;font-size:13px;line-height:1.7;color:#334155;white-space:pre-line;">${escapeHtml(info.dosage_instructions)}</p>
|
||||
<div style="margin:0;font-size:13px;line-height:1.7;color:#334155;white-space:pre-line;">${info.dosage_has_table ? info.dosage_instructions : escapeHtml(info.dosage_instructions)}</div>
|
||||
</div>` : ''}
|
||||
|
||||
${info.dosing_interval ? `
|
||||
|
||||
Loading…
Reference in New Issue
Block a user