feat: 처방 사용량 페이지에 약품 위치 표시

- rx-usage API에 CD_item_position.CD_NM_sale 조인 추가
- 제품코드 옆에 위치 배지 표시 (📍A-1 형태)
- 인디고 색상 작은 배지로 UI 해치지 않게
This commit is contained in:
thug0bin 2026-03-06 13:41:39 +09:00
parent 055fad574d
commit ddba17ae08
3 changed files with 45 additions and 4 deletions

View File

@ -4085,7 +4085,7 @@ def api_rx_usage():
mssql_session = db_manager.get_session('PM_PRES')
# 전문의약품 품목별 사용량 집계 쿼리 (현재고: IM_total.IM_QT_sale_debit)
# 전문의약품 품목별 사용량 집계 쿼리 (현재고: IM_total.IM_QT_sale_debit, 위치: CD_item_position.CD_NM_sale)
rx_query = text("""
SELECT
P.DrugCode as drug_code,
@ -4096,13 +4096,15 @@ def api_rx_usage():
SUM(ISNULL(P.DRUPRICE, 0) * ISNULL(P.QUAN, 1) * ISNULL(P.Days, 1)) as total_amount,
COUNT(DISTINCT P.PreSerial) as prescription_count,
COALESCE(NULLIF(G.BARCODE, ''), '') as barcode,
ISNULL(IT.IM_QT_sale_debit, 0) as current_stock
ISNULL(IT.IM_QT_sale_debit, 0) as current_stock,
ISNULL(POS.CD_NM_sale, '') as location
FROM PS_sub_pharm P
LEFT JOIN PM_DRUG.dbo.CD_GOODS G ON P.DrugCode = G.DrugCode
LEFT JOIN PM_DRUG.dbo.IM_total IT ON P.DrugCode = IT.DrugCode
LEFT JOIN PM_DRUG.dbo.CD_item_position POS ON P.DrugCode = POS.DrugCode
WHERE P.Indate >= :start_date
AND P.Indate <= :end_date
GROUP BY P.DrugCode, G.GoodsName, G.SplName, G.BARCODE, IT.IM_QT_sale_debit
GROUP BY P.DrugCode, G.GoodsName, G.SplName, G.BARCODE, IT.IM_QT_sale_debit, POS.CD_NM_sale
ORDER BY SUM(ISNULL(P.QUAN, 1) * ISNULL(P.Days, 1)) DESC
""")
@ -4143,6 +4145,7 @@ def api_rx_usage():
'total_amount': int(amount),
'prescription_count': rx_count,
'current_stock': int(row.current_stock or 0), # 현재고
'location': row.location or '', # 약국 내 위치
'thumbnail': None
})

View File

@ -26,6 +26,7 @@ baekje_bp = Blueprint('baekje', __name__, url_prefix='/api/baekje')
# ========== 세션 관리 ==========
_baekje_session = None
_init_started = False
def get_baekje_session():
global _baekje_session
@ -34,6 +35,32 @@ def get_baekje_session():
return _baekje_session
def init_baekje_session():
"""앱 시작 시 백그라운드에서 로그인 시작"""
global _init_started
if _init_started:
return
_init_started = True
session = get_baekje_session()
# 저장된 토큰이 있으면 즉시 사용 가능
if session._logged_in:
logger.info(f"백제약품: 저장된 토큰 사용 중")
return
# 백그라운드 로그인 시작
session.start_background_login()
logger.info(f"백제약품: 백그라운드 로그인 시작됨")
# 모듈 로드 시 자동 시작
try:
init_baekje_session()
except Exception as e:
logger.warning(f"백제약품 초기화 오류: {e}")
def search_baekje_stock(keyword: str):
"""백제약품 재고 검색"""
try:

View File

@ -379,6 +379,17 @@
font-size: 11px;
color: var(--text-muted);
}
.location-badge {
display: inline-block;
background: rgba(99, 102, 241, 0.15);
color: var(--accent-indigo);
font-size: 10px;
font-weight: 500;
padding: 1px 5px;
border-radius: 4px;
margin-left: 4px;
font-family: inherit;
}
/* 수량 관련 */
.qty-cell {
@ -926,7 +937,7 @@
}
<div class="product-info">
<span class="product-name">${escapeHtml(item.product_name)}</span>
<span class="product-code">${item.drug_code}${item.supplier ? ` · ${escapeHtml(item.supplier)}` : ''}</span>
<span class="product-code">${item.drug_code}${item.supplier ? ` · ${escapeHtml(item.supplier)}` : ''}${item.location ? ` <span class="location-badge">📍${escapeHtml(item.location)}</span>` : ''}</span>
</div>
</div>
</td>