fix: 템플릿 완전 재작성 - 페이지당 4개 고정 영역

This commit is contained in:
청춘약국
2026-03-18 23:19:22 +09:00
parent 72ce6d9f05
commit 4fb34d5e17
2 changed files with 210 additions and 377 deletions

View File

@@ -122,14 +122,7 @@ class AnimalMedRendererV2:
await page.set_content(html_content, wait_until='networkidle')
# 콘텐츠 크기 확인
rect = await page.evaluate('''() => {
const el = document.querySelector('.container');
const rect = el.getBoundingClientRect();
return { width: rect.width, height: rect.height };
}''')
# scale 고정 (자연스러운 페이지 분할)
# scale 고정 (페이지 분할을 위해)
scale = 1.0
await page.pdf(

View File

@@ -9,8 +9,6 @@
* { margin: 0; padding: 0; box-sizing: border-box; }
html, body {
width: 210mm;
height: 297mm;
font-family: 'Noto Sans KR', sans-serif;
font-size: 9pt;
color: #333;
@@ -18,16 +16,14 @@
background: #fff;
}
.container {
width: 210mm;
padding: 5mm;
}
/* 페이지 */
.page {
width: 200mm;
height: 287mm;
width: 210mm;
height: 297mm;
padding: 5mm;
page-break-after: always;
position: relative;
box-sizing: border-box;
}
.page:last-child {
@@ -39,85 +35,79 @@
display: flex;
justify-content: space-between;
align-items: center;
border-bottom: 3px solid #1565C0;
padding-bottom: 3mm;
margin-bottom: 4mm;
border-bottom: 2px solid #1565C0;
padding-bottom: 2mm;
margin-bottom: 3mm;
height: 15mm;
}
.header-left .patient-name {
font-size: 16pt;
font-size: 14pt;
font-weight: 700;
color: #0D47A1;
}
.header-left .patient-info {
font-size: 8pt;
color: #666;
margin-top: 1mm;
}
.header-center {
text-align: center;
}
.header-center .pharmacy-name {
font-size: 14pt;
font-weight: 700;
color: #1565C0;
}
.header-center .pharmacy-slogan {
font-size: 8pt;
color: #42A5F5;
}
.header-right {
text-align: right;
font-size: 7pt;
color: #666;
}
/* 약품 카드 그리드 */
.drug-cards-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 3mm;
.header-center .pharmacy-name {
font-size: 12pt;
font-weight: 700;
color: #1565C0;
}
/* 약품 카드 공통 */
.header-right {
font-size: 7pt;
color: #666;
}
/* 카드 그리드 영역 - 고정 높이 */
.cards-area {
display: grid;
grid-template-columns: 1fr 1fr;
grid-template-rows: 1fr 1fr;
gap: 2mm;
height: 265mm; /* 297 - 5*2(패딩) - 15(헤더) - 7(푸터) */
}
.cards-area.no-header {
height: 280mm; /* 헤더 없을 때 */
}
/* 약품 카드 */
.drug-card {
border: 1px solid #E0E0E0;
border-radius: 2mm;
overflow: hidden;
page-break-inside: avoid;
display: flex;
flex-direction: column;
}
.drug-card-header {
background: linear-gradient(135deg, #1565C0, #42A5F5);
color: white;
padding: 2mm;
padding: 1.5mm;
display: flex;
align-items: center;
gap: 2mm;
flex-shrink: 0;
}
.drug-icon {
width: 8mm;
height: 8mm;
width: 7mm;
height: 7mm;
background: white;
border-radius: 1.5mm;
border-radius: 1mm;
display: flex;
align-items: center;
justify-content: center;
font-size: 12pt;
}
.drug-title-area {
flex: 1;
font-size: 10pt;
}
.drug-name {
font-size: 9pt;
font-size: 8pt;
font-weight: 700;
}
@@ -129,270 +119,193 @@
.drug-badges {
display: flex;
gap: 0.5mm;
margin-top: 0.5mm;
flex-wrap: wrap;
}
.badge {
background: rgba(255,255,255,0.2);
padding: 0.3mm 1mm;
padding: 0.2mm 1mm;
border-radius: 0.5mm;
font-size: 5pt;
font-size: 4.5pt;
}
.drug-card-body {
padding: 2mm;
font-size: 6pt;
}
/* 구충제 전용 - 커버리지 표 */
.coverage-section {
margin-bottom: 3mm;
padding: 1.5mm;
font-size: 5.5pt;
flex: 1;
overflow: hidden;
}
/* 섹션들 */
.coverage-title {
font-size: 9pt;
font-size: 6pt;
font-weight: 700;
color: #1565C0;
margin-bottom: 2mm;
display: flex;
align-items: center;
gap: 1mm;
margin-bottom: 1mm;
}
.coverage-table {
display: grid;
grid-template-columns: repeat(4, 1fr);
gap: 1mm;
gap: 0.5mm;
background: #F5F5F5;
padding: 2mm;
border-radius: 2mm;
padding: 1mm;
border-radius: 1mm;
margin-bottom: 1.5mm;
}
.coverage-item {
background: white;
padding: 1.5mm;
border-radius: 1mm;
padding: 1mm;
border-radius: 0.5mm;
text-align: center;
font-size: 7pt;
font-size: 5pt;
}
.coverage-item.covered {
border-left: 2px solid #4CAF50;
}
.coverage-item.covered { border-left: 1.5px solid #4CAF50; }
.coverage-item.not-covered { border-left: 1.5px solid #F44336; background: #FFEBEE; }
.coverage-item.not-covered {
border-left: 2px solid #F44336;
background: #FFEBEE;
}
.coverage-icon {
font-size: 10pt;
display: block;
}
.coverage-name {
font-weight: 500;
margin-top: 0.5mm;
}
.coverage-icon { font-size: 7pt; }
.coverage-name { font-weight: 500; }
/* 갭 경고 */
.gap-warning {
background: #FFF3E0;
border: 1px solid #FFB74D;
border-radius: 2mm;
padding: 2mm;
margin-top: 2mm;
font-size: 7pt;
border-radius: 1mm;
padding: 1mm;
margin-bottom: 1.5mm;
font-size: 5pt;
}
.gap-warning-title {
font-weight: 700;
color: #E65100;
}
.gap-solution {
color: #F57C00;
margin-top: 1mm;
}
.gap-warning-title { font-weight: 700; color: #E65100; }
.gap-solution { color: #F57C00; }
/* 투약 정보 */
.dosing-section {
background: #E3F2FD;
border-radius: 2mm;
padding: 2mm 3mm;
margin-bottom: 3mm;
border-radius: 1mm;
padding: 1mm 1.5mm;
margin-bottom: 1.5mm;
}
.dosing-title {
font-weight: 700;
color: #1565C0;
font-size: 8pt;
}
.dosing-main {
font-size: 11pt;
font-weight: 700;
color: #0D47A1;
margin: 1mm 0;
}
.dosing-note {
font-size: 7pt;
color: #1976D2;
}
.dosing-title { font-weight: 700; color: #1565C0; font-size: 5.5pt; }
.dosing-main { font-size: 8pt; font-weight: 700; color: #0D47A1; }
.dosing-note { font-size: 5pt; color: #1976D2; }
/* 체중별 제품 */
.weight-products {
display: flex;
gap: 1mm;
gap: 0.5mm;
flex-wrap: wrap;
margin-top: 2mm;
margin-top: 1mm;
}
.weight-product {
background: #E8F5E9;
padding: 1mm 2mm;
border-radius: 1mm;
font-size: 6pt;
border: 1px solid #A5D6A7;
}
/* NSAIDs 전용 - 용량표 */
.dosage-table-section {
margin-bottom: 3mm;
padding: 0.5mm 1mm;
border-radius: 0.5mm;
font-size: 4.5pt;
border: 0.5px solid #A5D6A7;
}
/* 용량표 */
.dosage-grid {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 1mm;
gap: 0.5mm;
background: #E3F2FD;
padding: 2mm;
border-radius: 2mm;
padding: 1mm;
border-radius: 1mm;
margin-bottom: 1.5mm;
}
.dosage-cell {
background: white;
padding: 1.5mm;
border-radius: 1mm;
padding: 1mm;
border-radius: 0.5mm;
text-align: center;
font-size: 7pt;
font-size: 5pt;
}
.dosage-weight {
font-weight: 500;
color: #1565C0;
}
.dosage-amount {
font-weight: 700;
color: #0D47A1;
font-size: 9pt;
}
.dosage-weight { font-weight: 500; color: #1565C0; }
.dosage-amount { font-weight: 700; color: #0D47A1; font-size: 6pt; }
/* 절대 금기 */
.contraindication-box {
background: #FFEBEE;
border: 2px solid #F44336;
border-radius: 2mm;
padding: 2mm 3mm;
margin-bottom: 3mm;
border: 1px solid #F44336;
border-radius: 1mm;
padding: 1mm;
margin-bottom: 1.5mm;
}
.contraindication-title {
font-weight: 900;
color: #C62828;
font-size: 9pt;
margin-bottom: 1mm;
}
.contraindication-title { font-weight: 900; color: #C62828; font-size: 6pt; }
.contraindication-list {
list-style: none;
}
.contraindication-list li {
font-size: 8pt;
font-size: 5pt;
color: #B71C1C;
padding: 1mm 0;
border-bottom: 1px dashed #FFCDD2;
display: flex;
align-items: flex-start;
gap: 1mm;
}
.contraindication-list li:last-child {
border-bottom: none;
}
.contraindication-list li { padding: 0.3mm 0; }
/* 주의사항 */
.warnings-section {
background: #FFF8E1;
border: 1px solid #FFE082;
border-radius: 2mm;
padding: 2mm 3mm;
border-radius: 1mm;
padding: 1mm;
}
.warnings-title {
font-weight: 700;
color: #F57F17;
font-size: 8pt;
margin-bottom: 1mm;
}
.warnings-title { font-weight: 700; color: #F57F17; font-size: 5.5pt; }
.warnings-list {
list-style: none;
}
.warnings-list li {
font-size: 7pt;
font-size: 5pt;
color: #795548;
padding: 0.5mm 0;
padding-left: 2mm;
position: relative;
}
.warnings-list li::before {
content: "•";
position: absolute;
left: 0;
color: #FF9800;
.warnings-list li { padding: 0.2mm 0; }
/* 외용제 용법 */
.usage-box {
background: #E8F5E9;
padding: 1mm;
border-radius: 1mm;
font-size: 5pt;
margin-bottom: 1.5mm;
}
/* 푸터 */
.footer {
position: absolute;
bottom: 4mm;
left: 6mm;
right: 6mm;
bottom: 3mm;
left: 5mm;
right: 5mm;
text-align: center;
font-size: 6pt;
font-size: 5pt;
color: #9E9E9E;
border-top: 1px solid #E0E0E0;
padding-top: 2mm;
border-top: 0.5px solid #E0E0E0;
padding-top: 1mm;
height: 7mm;
}
.footer-logo {
font-weight: 700;
color: #1565C0;
font-size: 8pt;
}
.footer-logo { font-weight: 700; color: #1565C0; font-size: 6pt; }
</style>
</head>
<body>
<div class="container">
<!-- 약품 카드들 (페이지당 4개, 2x2 그리드) -->
{% for drug in drugs %}
{% if loop.index0 % 4 == 0 %}
{% set drugs_per_page = 4 %}
{% set total_pages = ((drugs|length - 1) // drugs_per_page) + 1 %}
{% for page_num in range(total_pages) %}
<div class="page">
{% if loop.index0 == 0 %}
{% if page_num == 0 %}
<!-- 헤더 (첫 페이지만) -->
<div class="header">
<div class="header-left">
<div class="patient-name">{{ patient_name }} 보호자님</div>
<div class="patient-info">
🐾 {{ pet_name }} ({{ pet_species }}, {{ pet_age }}) | 📅 {{ issue_date }}
</div>
<div class="patient-info">🐾 {{ pet_name }} ({{ pet_species }}, {{ pet_age }}) | 📅 {{ issue_date }}</div>
</div>
<div class="header-center">
<div class="pharmacy-name">🏥 {{ pharmacy_name }}</div>
@@ -400,28 +313,28 @@
<div class="header-right">{{ pharmacy_tel }}</div>
</div>
{% endif %}
<div class="drug-cards-grid">
{% endif %}
<div class="cards-area {% if page_num > 0 %}no-header{% endif %}">
{% set start_idx = page_num * drugs_per_page %}
{% set end_idx = [start_idx + drugs_per_page, drugs|length] | min %}
{% for drug in drugs[start_idx:end_idx] %}
<div class="drug-card">
<div class="drug-card-header">
<div class="drug-icon">💊</div>
<div class="drug-title-area">
<div>
<div class="drug-name">{{ drug.name }}</div>
<div class="drug-subtitle">{{ drug.english_name }}</div>
<div class="drug-badges">
<span class="badge">{{ drug.category_display }}</span>
{% for animal in drug.target_animal %}
<span class="badge">{{ animal }}</span>
{% endfor %}
<span class="badge">{{ drug.administration }}</span>
{% for animal in drug.target_animal %}<span class="badge">{{ animal }}</span>{% endfor %}
</div>
</div>
</div>
<div class="drug-card-body">
{% if drug.category == 'antiparasitic' %}
<!-- 구충제 레이아웃 -->
<div class="coverage-section">
<!-- 구충제 -->
<div class="coverage-title">🎯 구충 범위</div>
<div class="coverage-table">
{% for item in drug.coverage_summary.covered %}
@@ -438,180 +351,107 @@
{% endfor %}
</div>
{% if drug.coverage_summary.not_covered %}
{% if drug.coverage_summary.gap_solution %}
<div class="gap-warning">
<div class="gap-warning-title">⚠️ 미커버 항목</div>
<div class="gap-solution">💡 {{ drug.coverage_summary.gap_solution }}</div>
<span class="gap-warning-title">⚠️ 보완:</span>
<span class="gap-solution">{{ drug.coverage_summary.gap_solution }}</span>
</div>
{% endif %}
</div>
<div class="dosing-section">
<div class="dosing-title">📅 투약 주기</div>
<div class="dosing-title">📅 투약</div>
<div class="dosing-main">{{ drug.dosing.interval }}</div>
<div class="dosing-note">
{{ drug.dosing.interval_reason }}<br>
최소 연령: {{ drug.dosing.minimum_age }} / 최소 체중: {{ drug.dosing.minimum_weight }}
</div>
{% if drug.weight_products %}
<div class="weight-products">
{% for wp in drug.weight_products %}
<div class="weight-product">{{ wp.size }} ({{ wp.weight_range }})</div>
{% endfor %}
{% for wp in drug.weight_products %}<div class="weight-product">{{ wp.size }}({{ wp.weight_range }})</div>{% endfor %}
</div>
{% endif %}
</div>
{% elif drug.category == 'nsaid' %}
<!-- NSAIDs 레이아웃 -->
<div class="dosage-table-section">
<div class="coverage-title">⚖️ 체중별 용량 ({{ drug.dosage.standard }})</div>
<!-- NSAIDs -->
<div class="coverage-title">⚖️ 용량 ({{ drug.dosage.standard }})</div>
<div class="dosage-grid">
{% for row in drug.dosage_table %}
{% for row in drug.dosage_table[:6] %}
<div class="dosage-cell">
<div class="dosage-weight">{{ row.weight }}</div>
<div class="dosage-amount">{{ row.tablets }}</div>
</div>
{% endfor %}
</div>
</div>
{% if drug.absolute_contraindications %}
<div class="contraindication-box">
<div class="contraindication-title">🚫 절대 금기</div>
<ul class="contraindication-list">
{% for contra in drug.absolute_contraindications %}
<li>❌ {{ contra.item }} — {{ contra.reason }}</li>
{% for c in drug.absolute_contraindications[:3] %}
<li>❌ {{ c.item }}</li>
{% endfor %}
</ul>
</div>
{% endif %}
{% elif drug.category == 'antibiotic' %}
<!-- 항생제 레이아웃 -->
<!-- 항생제 -->
<div class="dosing-section">
<div class="dosing-title">📋 적응증</div>
<div class="dosing-main">{{ drug.indication }}</div>
</div>
<div class="dosage-table-section">
<div class="coverage-title">⚖️ 체중별 용량 ({{ drug.dosage.standard }})</div>
<div class="dosage-grid">
{% for row in drug.dosage_table %}
<div class="dosage-cell">
<div class="dosage-weight">{{ row.weight }}</div>
<div class="dosage-amount">{{ row.tablets }}</div>
</div>
{% endfor %}
</div>
<div class="dosing-note" style="margin-top:2mm;">
투약 기간: {{ drug.dosage.duration }}
</div>
<div class="dosing-title">📋 {{ drug.indication[:30] }}...</div>
<div class="dosing-main">{{ drug.dosage.standard }}</div>
<div class="dosing-note">기간: {{ drug.dosage.duration }}</div>
</div>
{% if drug.cat_warning %}
<div class="contraindication-box">
<div class="contraindication-title">🐱 고양이 특별 주의</div>
<ul class="contraindication-list">
<li>❌ 최대 용량: {{ drug.cat_warning.max_dose }}</li>
<li>❌ 위험: {{ drug.cat_warning.risk }}</li>
</ul>
<div class="contraindication-title">🐱 고양이 주의</div>
<div style="font-size:5pt;">최대: {{ drug.cat_warning.max_dose }} ({{ drug.cat_warning.risk }})</div>
</div>
{% endif %}
{% elif drug.category == 'antiemetic' %}
<!-- 항구토제 레이아웃 -->
<!-- 항구토제 -->
<div class="dosing-section">
<div class="dosing-title">📋 적응증</div>
<div class="dosing-main">{{ drug.indication }}</div>
</div>
<div class="coverage-section">
<div class="coverage-title">💊 용법용량</div>
<div class="coverage-table" style="grid-template-columns: 1fr 1fr;">
<div class="coverage-item covered">
<span class="coverage-name" style="font-weight:700;">급성 구토</span>
<span style="font-size:8pt;">{{ drug.dosage.acute_vomiting.dose }}</span>
<span style="font-size:6pt;">최대 {{ drug.dosage.acute_vomiting.duration }}</span>
</div>
<div class="coverage-item covered">
<span class="coverage-name" style="font-weight:700;">멀미 예방</span>
<span style="font-size:8pt;">{{ drug.dosage.motion_sickness.dose }}</span>
<span style="font-size:6pt;">{{ drug.dosage.motion_sickness.timing }}</span>
</div>
</div>
</div>
{% if drug.clinical_notes %}
<div class="gap-warning">
<div class="gap-warning-title">💡 임상 참고</div>
{% for note in drug.clinical_notes %}
<div class="gap-solution">• {{ note }}</div>
{% endfor %}
</div>
{% endif %}
{% elif drug.category in ['otic', 'antifungal', 'topical'] %}
<!-- 외용제 레이아웃 -->
<div class="dosing-section">
<div class="dosing-title">📋 적응증</div>
<div class="dosing-main" style="font-size:7pt;">{{ drug.indication }}</div>
</div>
<div class="dosage-table-section">
<div class="coverage-title" style="font-size:7pt;">💊 용법</div>
<div style="font-size:6pt; background:#E8F5E9; padding:1.5mm; border-radius:1mm;">
{% if drug.dosage.frequency %}
<div><b>빈도:</b> {{ drug.dosage.frequency }}</div>
{% endif %}
{% if drug.dosage.duration %}
<div><b>기간:</b> {{ drug.dosage.duration }}</div>
{% endif %}
{% if drug.dosage.contact_time %}
<div><b>접촉시간:</b> {{ drug.dosage.contact_time }}</div>
{% endif %}
{% if drug.dosage.amount %}
<div><b>용량:</b> {{ drug.dosage.amount }}</div>
{% endif %}
<div class="dosing-title">📋 {{ drug.indication }}</div>
</div>
<div class="usage-box">
<b>급성구토:</b> {{ drug.dosage.acute_vomiting.dose }} ({{ drug.dosage.acute_vomiting.duration }})<br>
<b>멀미예방:</b> {{ drug.dosage.motion_sickness.dose }} ({{ drug.dosage.motion_sickness.timing }})
</div>
{% else %}
<!--본 레이아웃 -->
<!--타 (외용제 등) -->
<div class="dosing-section">
<div class="dosing-title">📋 적응증</div>
<div class="dosing-main">{{ drug.indication }}</div>
<div class="dosing-title">📋 {{ drug.indication }}</div>
</div>
{% if drug.dosage %}
<div class="usage-box">
{% if drug.dosage.frequency %}<b>빈도:</b> {{ drug.dosage.frequency }}<br>{% endif %}
{% if drug.dosage.duration %}<b>기간:</b> {{ drug.dosage.duration }}<br>{% endif %}
{% if drug.dosage.contact_time %}<b>접촉:</b> {{ drug.dosage.contact_time }}{% endif %}
</div>
{% endif %}
{% endif %}
<!-- 공통: 주의사항 -->
<!-- 주의사항 -->
{% if drug.warnings %}
<div class="warnings-section">
<div class="warnings-title">⚠️ 주의사항</div>
<div class="warnings-title">⚠️ 주의</div>
<ul class="warnings-list">
{% for warning in drug.warnings %}
<li>{{ warning }}</li>
{% endfor %}
{% for w in drug.warnings[:3] %}<li>{{ w[:40] }}{% if w|length > 40 %}...{% endif %}</li>{% endfor %}
</ul>
</div>
{% endif %}
</div>
</div>
{% if loop.index % 4 == 0 or loop.last %}
</div><!-- drug-cards-grid -->
{% endfor %}
</div>
{% if loop.last %}
<!-- 푸터 (마지막 페이지만) -->
<div class="footer">
<div class="footer-logo">🐾 동물약 복약안내 시스템 v2</div>
안내문은 참고용입니다.
<div class="footer-logo">🐾 동물약 복약안내 v2</div>
참고용 안내문입니다. 정확한 투약은 수의사 지시에 따르세요.
</div>
{% endif %}
</div><!-- page -->
{% endif %}
</div>
{% endfor %}
<!-- 푸터 제거됨 (위에서 처리) -->
</div>
</body>
</html>