pharmacy-pos-qr-system/backend/scripts/check_basecode_usage.py

75 lines
2.2 KiB
Python

# -*- coding: utf-8 -*-
import sys
sys.path.insert(0, 'c:\\Users\\청춘약국\\source\\pharmacy-pos-qr-system\\backend')
from db.dbsetup import get_db_session
from sqlalchemy import text
# PM_DRUG, PM_PRES, PM_BASE 모든 DB 확인
databases = ['PM_DRUG', 'PM_PRES', 'PM_BASE']
for db_name in databases:
print(f'\n{"="*50}')
print(f'=== {db_name} 데이터베이스 ===')
print(f'{"="*50}')
try:
session = get_db_session(db_name)
# 1. BaseCode 컬럼이 있는 테이블 찾기
result = session.execute(text("""
SELECT TABLE_NAME, COLUMN_NAME
FROM INFORMATION_SCHEMA.COLUMNS
WHERE COLUMN_NAME LIKE '%BaseCode%'
OR COLUMN_NAME LIKE '%BASECODE%'
OR COLUMN_NAME LIKE '%basecode%'
ORDER BY TABLE_NAME
"""))
tables = list(result)
if tables:
print(f'\nBaseCode 관련 컬럼 발견:')
for row in tables:
print(f' - {row.TABLE_NAME}.{row.COLUMN_NAME}')
else:
print(f'\nBaseCode 관련 컬럼 없음')
# 2. 표준코드 관련 컬럼 찾기 (Stand, Standard 등)
result2 = session.execute(text("""
SELECT TABLE_NAME, COLUMN_NAME
FROM INFORMATION_SCHEMA.COLUMNS
WHERE COLUMN_NAME LIKE '%Stand%'
OR COLUMN_NAME LIKE '%Standard%'
OR COLUMN_NAME LIKE '%KD%'
ORDER BY TABLE_NAME
"""))
tables2 = list(result2)
if tables2:
print(f'\n표준코드 관련 컬럼:')
for row in tables2:
print(f' - {row.TABLE_NAME}.{row.COLUMN_NAME}')
session.close()
except Exception as e:
print(f'Error: {e}')
# 3. CD_GOODS의 BaseCode가 실제로 어떤 값인지 상위 10개 확인
print(f'\n{"="*50}')
print('=== CD_GOODS.BaseCode 샘플 데이터 ===')
print(f'{"="*50}')
session = get_db_session('PM_DRUG')
result = session.execute(text("""
SELECT TOP 10 DrugCode, GoodsName, BaseCode
FROM CD_GOODS
ORDER BY DrugCode
"""))
for row in result:
bc = row.BaseCode if row.BaseCode else '(NULL/빈값)'
print(f'{row.DrugCode}: BaseCode=[{bc}]')
session.close()