feat(pmr): 라벨 동적 폰트 + 한글 줄바꿈 + 파싱 개선
- 약품명 동적 폰트 크기 (32px→18px 자동 축소) - wrap_text_korean(): 글자 단위 줄바꿈 (한글 지원) - (2.5mg)노바스크정 → 앞의 괄호 제거 후 처리 - 파일 상단 함수 가이드 문서화 추가
This commit is contained in:
parent
7b71ea0179
commit
e6f4d5b1e7
@ -1,5 +1,33 @@
|
|||||||
# pmr_api.py - 조제관리(PMR) Blueprint API
|
# pmr_api.py - 조제관리(PMR) Blueprint API
|
||||||
# PharmaIT3000 MSSQL 연동 (192.168.0.4)
|
# PharmaIT3000 MSSQL 연동 (192.168.0.4)
|
||||||
|
#
|
||||||
|
# ═══════════════════════════════════════════════════════════════
|
||||||
|
# 📋 주요 함수 가이드
|
||||||
|
# ═══════════════════════════════════════════════════════════════
|
||||||
|
#
|
||||||
|
# 🏷️ 라벨 관련:
|
||||||
|
# - normalize_medication_name(med_name)
|
||||||
|
# 약품명 정규화: 밀리그램→mg, 언더스코어 제거 등
|
||||||
|
# 예: "케이발린캡슐75밀리그램_" → "케이발린캡슐75mg"
|
||||||
|
#
|
||||||
|
# - get_drug_unit(goods_name, sung_code) [utils/drug_unit.py]
|
||||||
|
# SUNG_CODE 기반 단위 판별
|
||||||
|
# 예: SUNG_CODE "123456TB" → "정" (TB=정제)
|
||||||
|
# FormCode: TB=정, CA/CH/CS=캡슐, SY=mL, GA/GB=포 등
|
||||||
|
#
|
||||||
|
# - create_label_image(patient_name, med_name, ...)
|
||||||
|
# PIL로 29mm 라벨 이미지 생성
|
||||||
|
# 지그재그 테두리, 동적 폰트, 복용량 박스 등
|
||||||
|
#
|
||||||
|
# 📊 SUNG_CODE FormCode 참조 (마지막 2자리):
|
||||||
|
# 정제류: TA, TB, TC, TD, TE, TH, TJ, TR → "정"
|
||||||
|
# 캡슐류: CA, CB, CH, CI, CJ, CS → "캡슐"
|
||||||
|
# 액제류: SS, SY, LQ → "mL" (시럽)
|
||||||
|
# 산제류: GA, GB, GC, GN, PD → "포"
|
||||||
|
# 점안제: EY, OS → "병" 또는 "개"
|
||||||
|
# 외용제: XT, XO, XL → "g" 또는 "개"
|
||||||
|
#
|
||||||
|
# ═══════════════════════════════════════════════════════════════
|
||||||
|
|
||||||
from flask import Blueprint, jsonify, request, render_template, send_file
|
from flask import Blueprint, jsonify, request, render_template, send_file
|
||||||
import pyodbc
|
import pyodbc
|
||||||
@ -708,6 +736,25 @@ def create_label_image(patient_name, med_name, add_info='', dosage=0, frequency=
|
|||||||
return y + bbox[3] - bbox[1] + 5
|
return y + bbox[3] - bbox[1] + 5
|
||||||
|
|
||||||
# 약품명 줄바꿈 처리
|
# 약품명 줄바꿈 처리
|
||||||
|
def wrap_text_korean(text, font, max_width, draw):
|
||||||
|
"""한글/영문 혼합 텍스트 줄바꿈 (글자 단위)"""
|
||||||
|
if not text:
|
||||||
|
return [text]
|
||||||
|
lines = []
|
||||||
|
current_line = ""
|
||||||
|
for char in text:
|
||||||
|
test_line = current_line + char
|
||||||
|
bbox = draw.textbbox((0, 0), test_line, font=font)
|
||||||
|
if bbox[2] - bbox[0] <= max_width:
|
||||||
|
current_line = test_line
|
||||||
|
else:
|
||||||
|
if current_line:
|
||||||
|
lines.append(current_line)
|
||||||
|
current_line = char
|
||||||
|
if current_line:
|
||||||
|
lines.append(current_line)
|
||||||
|
return lines if lines else [text]
|
||||||
|
|
||||||
def wrap_text(text, font, max_width):
|
def wrap_text(text, font, max_width):
|
||||||
lines = []
|
lines = []
|
||||||
words = text.split()
|
words = text.split()
|
||||||
@ -734,16 +781,22 @@ def create_label_image(patient_name, med_name, add_info='', dosage=0, frequency=
|
|||||||
y += 5
|
y += 5
|
||||||
|
|
||||||
# 약품명 (줄바꿈)
|
# 약품명 (줄바꿈)
|
||||||
# 괄호 앞에서 분리
|
# 앞에 있는 (숫자mg) 패턴 제거 후, 뒤의 괄호 앞에서 분리
|
||||||
if '(' in med_name:
|
import re
|
||||||
main_name = med_name.split('(')[0].strip()
|
# (2.5mg)노바스크정 → 노바스크정
|
||||||
else:
|
main_name = re.sub(r'^\([^)]+\)', '', med_name).strip()
|
||||||
|
# 노바스크정(고혈압) → 노바스크정
|
||||||
|
if '(' in main_name:
|
||||||
|
main_name = main_name.split('(')[0].strip()
|
||||||
|
# 빈 문자열이면 원본 사용
|
||||||
|
if not main_name:
|
||||||
main_name = med_name
|
main_name = med_name
|
||||||
|
|
||||||
# 약품명 줄바꿈
|
# 약품명 - 동적 폰트 크기 적용 (긴 이름 자동 축소)
|
||||||
name_lines = wrap_text(main_name, drug_font, label_width - 30)
|
adaptive_drug_font = get_adaptive_font(main_name, label_width - 30, 32, 18)
|
||||||
|
name_lines = wrap_text_korean(main_name, adaptive_drug_font, label_width - 30, draw)
|
||||||
for line in name_lines:
|
for line in name_lines:
|
||||||
y = draw_centered(line, y, drug_font)
|
y = draw_centered(line, y, adaptive_drug_font)
|
||||||
|
|
||||||
# 효능효과 (add_info) - 동적 폰트 크기 적용
|
# 효능효과 (add_info) - 동적 폰트 크기 적용
|
||||||
if add_info:
|
if add_info:
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user