feat: v2 API - 마스터 JSON 기반, 카테고리별 템플릿
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
from .renderer import AnimalMedRenderer
|
||||
from .renderer_v2 import AnimalMedRendererV2
|
||||
|
||||
__all__ = ['AnimalMedRenderer']
|
||||
__all__ = ['AnimalMedRenderer', 'AnimalMedRendererV2']
|
||||
|
||||
185
animal_med/renderer_v2.py
Normal file
185
animal_med/renderer_v2.py
Normal file
@@ -0,0 +1,185 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
동물약 복약안내 PDF 렌더러 v2
|
||||
- 마스터 JSON 구조 지원
|
||||
- 카테고리별 템플릿 분기 (구충제/NSAIDs)
|
||||
"""
|
||||
|
||||
import os
|
||||
import json
|
||||
import asyncio
|
||||
from datetime import datetime
|
||||
from typing import List, Dict, Optional
|
||||
from jinja2 import Environment, FileSystemLoader
|
||||
|
||||
|
||||
class AnimalMedRendererV2:
|
||||
"""동물약 복약안내 PDF 렌더링 API v2"""
|
||||
|
||||
def __init__(self, master_dir: str = None, template_path: str = None):
|
||||
base_dir = os.path.dirname(os.path.dirname(__file__))
|
||||
|
||||
self.master_dir = master_dir or os.path.join(base_dir, 'data', 'master')
|
||||
self.template_dir = template_path or os.path.join(base_dir, 'templates')
|
||||
|
||||
# Jinja2 템플릿 환경
|
||||
self.jinja_env = Environment(
|
||||
loader=FileSystemLoader(self.template_dir),
|
||||
autoescape=True
|
||||
)
|
||||
|
||||
# 마스터 약품 데이터 로드
|
||||
self._load_master_data()
|
||||
|
||||
def _load_master_data(self):
|
||||
"""마스터 JSON 파일들 로드"""
|
||||
self.drugs = {}
|
||||
|
||||
if not os.path.exists(self.master_dir):
|
||||
os.makedirs(self.master_dir, exist_ok=True)
|
||||
return
|
||||
|
||||
for filename in os.listdir(self.master_dir):
|
||||
if filename.endswith('.json'):
|
||||
filepath = os.path.join(self.master_dir, filename)
|
||||
with open(filepath, 'r', encoding='utf-8') as f:
|
||||
drug = json.load(f)
|
||||
self.drugs[drug['product_id']] = drug
|
||||
|
||||
def get_drug(self, product_id: str) -> Optional[Dict]:
|
||||
"""제품 ID로 약품 조회"""
|
||||
return self.drugs.get(product_id)
|
||||
|
||||
def get_drugs(self, product_ids: List[str]) -> List[Dict]:
|
||||
"""여러 제품 ID로 약품 조회"""
|
||||
result = []
|
||||
for pid in product_ids:
|
||||
drug = self.get_drug(pid)
|
||||
if drug:
|
||||
result.append(drug)
|
||||
return result
|
||||
|
||||
def render_html(
|
||||
self,
|
||||
product_ids: List[str],
|
||||
patient_name: str = "홍길동",
|
||||
pet_name: str = "뽀삐",
|
||||
pet_species: str = "개",
|
||||
pet_age: str = "3세",
|
||||
pharmacy_name: str = "청춘약국",
|
||||
pharmacy_tel: str = "033-481-7390",
|
||||
pharmacy_address: str = "강원 양구군 양구읍"
|
||||
) -> str:
|
||||
"""
|
||||
마스터 JSON 기반 HTML 복약안내문 렌더링 (v2)
|
||||
"""
|
||||
drugs = self.get_drugs(product_ids)
|
||||
|
||||
if not drugs:
|
||||
raise ValueError(f"유효한 약품을 찾을 수 없습니다: {product_ids}")
|
||||
|
||||
template = self.jinja_env.get_template('medication_guide_v2.html')
|
||||
|
||||
html = template.render(
|
||||
drugs=drugs,
|
||||
patient_name=patient_name,
|
||||
pet_name=pet_name,
|
||||
pet_species=pet_species,
|
||||
pet_age=pet_age,
|
||||
pharmacy_name=pharmacy_name,
|
||||
pharmacy_tel=pharmacy_tel,
|
||||
pharmacy_address=pharmacy_address,
|
||||
issue_date=datetime.now().strftime('%Y년 %m월 %d일')
|
||||
)
|
||||
|
||||
return html
|
||||
|
||||
def render_to_pdf(
|
||||
self,
|
||||
product_ids: List[str],
|
||||
output_path: str = None,
|
||||
**kwargs
|
||||
) -> Dict:
|
||||
"""
|
||||
마스터 JSON 기반 PDF 복약안내문 생성 (v2)
|
||||
"""
|
||||
# HTML 렌더링
|
||||
html_content = self.render_html(product_ids, **kwargs)
|
||||
|
||||
# 출력 경로
|
||||
if not output_path:
|
||||
import tempfile
|
||||
import time
|
||||
output_path = os.path.join(tempfile.gettempdir(), f'animal_med_v2_{int(time.time())}.pdf')
|
||||
|
||||
# HTML → PDF
|
||||
async def _convert():
|
||||
from playwright.async_api import async_playwright
|
||||
|
||||
async with async_playwright() as p:
|
||||
browser = await p.chromium.launch(headless=True)
|
||||
page = await browser.new_page(viewport={'width': 794, 'height': 1123})
|
||||
|
||||
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 };
|
||||
}''')
|
||||
|
||||
# A4에 맞는 scale 계산
|
||||
content_width_pt = rect['width'] * 0.75
|
||||
content_height_pt = rect['height'] * 0.75
|
||||
|
||||
scale_x = 595 / content_width_pt if content_width_pt > 0 else 1
|
||||
scale_y = 842 / content_height_pt if content_height_pt > 0 else 1
|
||||
scale = min(scale_x, scale_y, 1.0)
|
||||
|
||||
await page.pdf(
|
||||
path=output_path,
|
||||
format='A4',
|
||||
print_background=True,
|
||||
margin={'top': '0', 'right': '0', 'bottom': '0', 'left': '0'},
|
||||
scale=scale
|
||||
)
|
||||
|
||||
await browser.close()
|
||||
|
||||
try:
|
||||
try:
|
||||
loop = asyncio.get_running_loop()
|
||||
except RuntimeError:
|
||||
loop = None
|
||||
|
||||
if loop and loop.is_running():
|
||||
import concurrent.futures
|
||||
with concurrent.futures.ThreadPoolExecutor() as executor:
|
||||
future = executor.submit(asyncio.run, _convert())
|
||||
future.result()
|
||||
else:
|
||||
asyncio.run(_convert())
|
||||
|
||||
drugs = self.get_drugs(product_ids)
|
||||
|
||||
return {
|
||||
'success': True,
|
||||
'pdf_path': output_path,
|
||||
'drug_count': len(drugs),
|
||||
'drugs': [d['name'] for d in drugs]
|
||||
}
|
||||
except Exception as e:
|
||||
return {'success': False, 'error': str(e)}
|
||||
|
||||
def list_drugs(self) -> List[Dict]:
|
||||
"""마스터 약품 목록 반환"""
|
||||
return [
|
||||
{
|
||||
'product_id': d['product_id'],
|
||||
'name': d['name'],
|
||||
'category': d['category'],
|
||||
'category_display': d.get('category_display', d['category'])
|
||||
}
|
||||
for d in self.drugs.values()
|
||||
]
|
||||
504
templates/medication_guide_v2.html
Normal file
504
templates/medication_guide_v2.html
Normal file
@@ -0,0 +1,504 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="ko">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>동물약 복약안내문 v2</title>
|
||||
<style>
|
||||
@import url('https://fonts.googleapis.com/css2?family=Noto+Sans+KR:wght@300;400;500;700;900&display=swap');
|
||||
|
||||
* { 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;
|
||||
line-height: 1.4;
|
||||
background: #fff;
|
||||
}
|
||||
|
||||
.container {
|
||||
width: 210mm;
|
||||
min-height: 297mm;
|
||||
padding: 6mm;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
/* 헤더 */
|
||||
.header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
border-bottom: 3px solid #1565C0;
|
||||
padding-bottom: 3mm;
|
||||
margin-bottom: 4mm;
|
||||
}
|
||||
|
||||
.header-left .patient-name {
|
||||
font-size: 16pt;
|
||||
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-card {
|
||||
border: 1px solid #E0E0E0;
|
||||
border-radius: 3mm;
|
||||
margin-bottom: 4mm;
|
||||
overflow: hidden;
|
||||
page-break-inside: avoid;
|
||||
}
|
||||
|
||||
.drug-card-header {
|
||||
background: linear-gradient(135deg, #1565C0, #42A5F5);
|
||||
color: white;
|
||||
padding: 3mm;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 3mm;
|
||||
}
|
||||
|
||||
.drug-icon {
|
||||
width: 12mm;
|
||||
height: 12mm;
|
||||
background: white;
|
||||
border-radius: 2mm;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
font-size: 18pt;
|
||||
}
|
||||
|
||||
.drug-title-area {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.drug-name {
|
||||
font-size: 12pt;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.drug-subtitle {
|
||||
font-size: 7pt;
|
||||
opacity: 0.9;
|
||||
}
|
||||
|
||||
.drug-badges {
|
||||
display: flex;
|
||||
gap: 1mm;
|
||||
margin-top: 1mm;
|
||||
}
|
||||
|
||||
.badge {
|
||||
background: rgba(255,255,255,0.2);
|
||||
padding: 0.5mm 2mm;
|
||||
border-radius: 1mm;
|
||||
font-size: 6pt;
|
||||
}
|
||||
|
||||
.drug-card-body {
|
||||
padding: 3mm;
|
||||
}
|
||||
|
||||
/* 구충제 전용 - 커버리지 표 */
|
||||
.coverage-section {
|
||||
margin-bottom: 3mm;
|
||||
}
|
||||
|
||||
.coverage-title {
|
||||
font-size: 9pt;
|
||||
font-weight: 700;
|
||||
color: #1565C0;
|
||||
margin-bottom: 2mm;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 1mm;
|
||||
}
|
||||
|
||||
.coverage-table {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(4, 1fr);
|
||||
gap: 1mm;
|
||||
background: #F5F5F5;
|
||||
padding: 2mm;
|
||||
border-radius: 2mm;
|
||||
}
|
||||
|
||||
.coverage-item {
|
||||
background: white;
|
||||
padding: 1.5mm;
|
||||
border-radius: 1mm;
|
||||
text-align: center;
|
||||
font-size: 7pt;
|
||||
}
|
||||
|
||||
.coverage-item.covered {
|
||||
border-left: 2px solid #4CAF50;
|
||||
}
|
||||
|
||||
.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;
|
||||
}
|
||||
|
||||
/* 갭 경고 */
|
||||
.gap-warning {
|
||||
background: #FFF3E0;
|
||||
border: 1px solid #FFB74D;
|
||||
border-radius: 2mm;
|
||||
padding: 2mm;
|
||||
margin-top: 2mm;
|
||||
font-size: 7pt;
|
||||
}
|
||||
|
||||
.gap-warning-title {
|
||||
font-weight: 700;
|
||||
color: #E65100;
|
||||
}
|
||||
|
||||
.gap-solution {
|
||||
color: #F57C00;
|
||||
margin-top: 1mm;
|
||||
}
|
||||
|
||||
/* 투약 정보 */
|
||||
.dosing-section {
|
||||
background: #E3F2FD;
|
||||
border-radius: 2mm;
|
||||
padding: 2mm 3mm;
|
||||
margin-bottom: 3mm;
|
||||
}
|
||||
|
||||
.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;
|
||||
}
|
||||
|
||||
/* 체중별 제품 */
|
||||
.weight-products {
|
||||
display: flex;
|
||||
gap: 1mm;
|
||||
flex-wrap: wrap;
|
||||
margin-top: 2mm;
|
||||
}
|
||||
|
||||
.weight-product {
|
||||
background: #E8F5E9;
|
||||
padding: 1mm 2mm;
|
||||
border-radius: 1mm;
|
||||
font-size: 6pt;
|
||||
border: 1px solid #A5D6A7;
|
||||
}
|
||||
|
||||
/* NSAIDs 전용 - 용량표 */
|
||||
.dosage-table-section {
|
||||
margin-bottom: 3mm;
|
||||
}
|
||||
|
||||
.dosage-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(3, 1fr);
|
||||
gap: 1mm;
|
||||
background: #E3F2FD;
|
||||
padding: 2mm;
|
||||
border-radius: 2mm;
|
||||
}
|
||||
|
||||
.dosage-cell {
|
||||
background: white;
|
||||
padding: 1.5mm;
|
||||
border-radius: 1mm;
|
||||
text-align: center;
|
||||
font-size: 7pt;
|
||||
}
|
||||
|
||||
.dosage-weight {
|
||||
font-weight: 500;
|
||||
color: #1565C0;
|
||||
}
|
||||
|
||||
.dosage-amount {
|
||||
font-weight: 700;
|
||||
color: #0D47A1;
|
||||
font-size: 9pt;
|
||||
}
|
||||
|
||||
/* 절대 금기 */
|
||||
.contraindication-box {
|
||||
background: #FFEBEE;
|
||||
border: 2px solid #F44336;
|
||||
border-radius: 2mm;
|
||||
padding: 2mm 3mm;
|
||||
margin-bottom: 3mm;
|
||||
}
|
||||
|
||||
.contraindication-title {
|
||||
font-weight: 900;
|
||||
color: #C62828;
|
||||
font-size: 9pt;
|
||||
margin-bottom: 1mm;
|
||||
}
|
||||
|
||||
.contraindication-list {
|
||||
list-style: none;
|
||||
}
|
||||
|
||||
.contraindication-list li {
|
||||
font-size: 8pt;
|
||||
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;
|
||||
}
|
||||
|
||||
/* 주의사항 */
|
||||
.warnings-section {
|
||||
background: #FFF8E1;
|
||||
border: 1px solid #FFE082;
|
||||
border-radius: 2mm;
|
||||
padding: 2mm 3mm;
|
||||
}
|
||||
|
||||
.warnings-title {
|
||||
font-weight: 700;
|
||||
color: #F57F17;
|
||||
font-size: 8pt;
|
||||
margin-bottom: 1mm;
|
||||
}
|
||||
|
||||
.warnings-list {
|
||||
list-style: none;
|
||||
}
|
||||
|
||||
.warnings-list li {
|
||||
font-size: 7pt;
|
||||
color: #795548;
|
||||
padding: 0.5mm 0;
|
||||
padding-left: 2mm;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.warnings-list li::before {
|
||||
content: "•";
|
||||
position: absolute;
|
||||
left: 0;
|
||||
color: #FF9800;
|
||||
}
|
||||
|
||||
/* 푸터 */
|
||||
.footer {
|
||||
position: absolute;
|
||||
bottom: 4mm;
|
||||
left: 6mm;
|
||||
right: 6mm;
|
||||
text-align: center;
|
||||
font-size: 6pt;
|
||||
color: #9E9E9E;
|
||||
border-top: 1px solid #E0E0E0;
|
||||
padding-top: 2mm;
|
||||
}
|
||||
|
||||
.footer-logo {
|
||||
font-weight: 700;
|
||||
color: #1565C0;
|
||||
font-size: 8pt;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<!-- 헤더 -->
|
||||
<div class="header">
|
||||
<div class="header-left">
|
||||
<div class="patient-name">{{ patient_name }} 보호자님</div>
|
||||
<div class="patient-info">
|
||||
🐾 {{ pet_name }} ({{ pet_species }}, {{ pet_age }})<br>
|
||||
📅 {{ issue_date }}
|
||||
</div>
|
||||
</div>
|
||||
<div class="header-center">
|
||||
<div class="pharmacy-name">🏥 {{ pharmacy_name }}</div>
|
||||
<div class="pharmacy-slogan">반려동물을 위한 전문 복약안내</div>
|
||||
</div>
|
||||
<div class="header-right">
|
||||
{{ pharmacy_tel }}<br>
|
||||
{{ pharmacy_address }}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 약품 카드들 -->
|
||||
{% for drug in drugs %}
|
||||
<div class="drug-card">
|
||||
<div class="drug-card-header">
|
||||
<div class="drug-icon">💊</div>
|
||||
<div class="drug-title-area">
|
||||
<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>
|
||||
</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 %}
|
||||
<div class="coverage-item covered">
|
||||
<span class="coverage-icon">✅</span>
|
||||
<span class="coverage-name">{{ item }}</span>
|
||||
</div>
|
||||
{% endfor %}
|
||||
{% for item in drug.coverage_summary.not_covered %}
|
||||
<div class="coverage-item not-covered">
|
||||
<span class="coverage-icon">❌</span>
|
||||
<span class="coverage-name">{{ item }}</span>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
|
||||
{% if drug.coverage_summary.not_covered %}
|
||||
<div class="gap-warning">
|
||||
<div class="gap-warning-title">⚠️ 미커버 항목</div>
|
||||
<div class="gap-solution">💡 {{ drug.coverage_summary.gap_solution }}</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
<div class="dosing-section">
|
||||
<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 %}
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
{% elif drug.category == 'nsaid' %}
|
||||
<!-- NSAIDs 레이아웃 -->
|
||||
<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>
|
||||
|
||||
{% 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>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{% else %}
|
||||
<!-- 기본 레이아웃 -->
|
||||
<div class="dosing-section">
|
||||
<div class="dosing-title">📋 적응증</div>
|
||||
<div class="dosing-main">{{ drug.indication }}</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
<!-- 공통: 주의사항 -->
|
||||
{% if drug.warnings %}
|
||||
<div class="warnings-section">
|
||||
<div class="warnings-title">⚠️ 주의사항</div>
|
||||
<ul class="warnings-list">
|
||||
{% for warning in drug.warnings %}
|
||||
<li>{{ warning }}</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
|
||||
<!-- 푸터 -->
|
||||
<div class="footer">
|
||||
<div class="footer-logo">🐾 동물약 복약안내 시스템 v2</div>
|
||||
※ 본 안내문은 참고용입니다. 정확한 투약은 반드시 수의사의 지시에 따라 주세요.
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
70
test_v2.py
Normal file
70
test_v2.py
Normal file
@@ -0,0 +1,70 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
v2 API 테스트 - 마스터 JSON 기반 PDF 렌더링
|
||||
"""
|
||||
|
||||
import os
|
||||
import sys
|
||||
sys.path.insert(0, os.path.dirname(__file__))
|
||||
|
||||
from animal_med import AnimalMedRendererV2
|
||||
|
||||
|
||||
def main():
|
||||
print("=" * 60)
|
||||
print("동물약 복약안내 v2 API 테스트")
|
||||
print("=" * 60)
|
||||
|
||||
renderer = AnimalMedRendererV2()
|
||||
|
||||
# 마스터 약품 목록
|
||||
print("\n[1] 마스터 약품 목록:")
|
||||
for drug in renderer.list_drugs():
|
||||
print(f" {drug['product_id']} - {drug['name']} ({drug['category_display']})")
|
||||
|
||||
# 테스트: 넥스가드 스펙트라 (구충제) + 아시카프 (NSAIDs)
|
||||
test_ids = ["MASTER-001", "MASTER-002"]
|
||||
|
||||
print(f"\n[2] PDF 렌더링 ({len(test_ids)}개 약품)")
|
||||
for pid in test_ids:
|
||||
drug = renderer.get_drug(pid)
|
||||
if drug:
|
||||
print(f" - {drug['name']} ({drug['category']})")
|
||||
|
||||
# PDF 생성
|
||||
output_dir = os.path.join(os.path.dirname(__file__), 'output')
|
||||
os.makedirs(output_dir, exist_ok=True)
|
||||
|
||||
pdf_path = os.path.join(output_dir, 'master_v2_test.pdf')
|
||||
|
||||
print(f"\n[3] PDF 생성 중...")
|
||||
|
||||
result = renderer.render_to_pdf(
|
||||
product_ids=test_ids,
|
||||
output_path=pdf_path,
|
||||
patient_name="이보호자",
|
||||
pet_name="콩이",
|
||||
pet_species="비숑프리제",
|
||||
pet_age="4세"
|
||||
)
|
||||
|
||||
if result['success']:
|
||||
print(f" ✅ 성공!")
|
||||
print(f" 📄 PDF: {result['pdf_path']}")
|
||||
print(f" 약품: {', '.join(result['drugs'])}")
|
||||
|
||||
size = os.path.getsize(pdf_path)
|
||||
print(f" 크기: {size / 1024:.1f} KB")
|
||||
|
||||
import fitz
|
||||
doc = fitz.open(pdf_path)
|
||||
print(f" 페이지 수: {len(doc)}")
|
||||
doc.close()
|
||||
else:
|
||||
print(f" ❌ 실패: {result.get('error')}")
|
||||
|
||||
print("\n" + "=" * 60)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user