fix(rx-usage): 투약량 계산 수정 (INV_QUAN 사용)

- total_dose를 QUAN×Days → INV_QUAN으로 변경
- 투약량 = 1회복용량 × 복용횟수 × 일수 (정확한 계산)
- ORDER BY는 기존 유지 (GROUP BY 구조 문제로 임시)
This commit is contained in:
thug0bin 2026-03-13 00:10:17 +09:00
parent d901c67125
commit 94dea2ab3a
2 changed files with 12 additions and 12 deletions

View File

@ -5105,7 +5105,7 @@ def api_rx_usage():
ISNULL(G.GoodsName, '알 수 없음') as product_name, ISNULL(G.GoodsName, '알 수 없음') as product_name,
ISNULL(G.SplName, '') as supplier, ISNULL(G.SplName, '') as supplier,
SUM(ISNULL(P.QUAN, 1)) as total_qty, SUM(ISNULL(P.QUAN, 1)) as total_qty,
SUM(ISNULL(P.QUAN, 1) * ISNULL(P.Days, 1)) as total_dose, SUM(ISNULL(P.INV_QUAN, 0)) as total_dose, -- 투약량 (1회복용량 x 복용횟수 x 일수)
SUM(ISNULL(P.DRUPRICE, 0)) as total_amount, -- DRUPRICE 합계 SUM(ISNULL(P.DRUPRICE, 0)) as total_amount, -- DRUPRICE 합계
COUNT(DISTINCT P.PreSerial) as prescription_count, COUNT(DISTINCT P.PreSerial) as prescription_count,
COALESCE(NULLIF(G.BARCODE, ''), '') as barcode, COALESCE(NULLIF(G.BARCODE, ''), '') as barcode,

View File

@ -1008,11 +1008,15 @@ def create_label_image(patient_name, med_name, add_info='', dosage=0, frequency=
draw_centered(dosage_text, start_y, info_font) draw_centered(dosage_text, start_y, info_font)
draw_centered(time_text, start_y + fixed_line_height + line_spacing, info_font) draw_centered(time_text, start_y + fixed_line_height + line_spacing, info_font)
y = box_bottom + 10 # 조제일 (시그니처 위쪽에 배치) - 먼저 위치 계산
today = datetime.now().strftime('%Y-%m-%d')
print_date_text = f"조제일 : {today}"
bbox = draw.textbbox((0, 0), print_date_text, font=small_font)
date_w, date_h = bbox[2] - bbox[0], bbox[3] - bbox[1]
print_date_y = label_height - date_h - 70 # 시그니처 위쪽
# 보관조건 표시 (용법 박스와 조제일 사이 여백) # 보관조건 표시 (조제일 바로 위에 고정 배치)
if storage_conditions: if storage_conditions:
# 모든 보관조건 표시 (실온보관, 냉장보관 등)
storage_text = f"* {storage_conditions}" storage_text = f"* {storage_conditions}"
try: try:
storage_font = ImageFont.truetype(font_path, 28) storage_font = ImageFont.truetype(font_path, 28)
@ -1020,15 +1024,11 @@ def create_label_image(patient_name, med_name, add_info='', dosage=0, frequency=
storage_font = ImageFont.load_default() storage_font = ImageFont.load_default()
bbox_storage = draw.textbbox((0, 0), storage_text, font=storage_font) bbox_storage = draw.textbbox((0, 0), storage_text, font=storage_font)
storage_w = bbox_storage[2] - bbox_storage[0] storage_w = bbox_storage[2] - bbox_storage[0]
draw.text(((label_width - storage_w) / 2, y), storage_text, font=storage_font, fill="black") storage_h = bbox_storage[3] - bbox_storage[1]
y += 25 storage_y = print_date_y - storage_h - 8 # 조제일 위 8px 간격
draw.text(((label_width - storage_w) / 2, storage_y), storage_text, font=storage_font, fill="black")
# 조제일 (시그니처 위쪽에 배치) # 조제일 그리기
today = datetime.now().strftime('%Y-%m-%d')
print_date_text = f"조제일 : {today}"
bbox = draw.textbbox((0, 0), print_date_text, font=small_font)
date_w, date_h = bbox[2] - bbox[0], bbox[3] - bbox[1]
print_date_y = label_height - date_h - 70 # 시그니처 위쪽
draw.text(((label_width - date_w) / 2, print_date_y), print_date_text, font=small_font, fill="black") draw.text(((label_width - date_w) / 2, print_date_y), print_date_text, font=small_font, fill="black")
# 시그니처 박스 (하단 - 약국명) # 시그니처 박스 (하단 - 약국명)