- 개발/테스트 스크립트를 dev_scripts/ 폴더로 이동 - 스크린샷을 screenshots/ 폴더로 이동 - 백업 파일 보존 (.backup) - 처방 관련 추가 스크립트 포함 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
109 lines
3.1 KiB
Python
109 lines
3.1 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
삼소음에 사용되는 약재들의 성분 코드 확인
|
|
"""
|
|
|
|
import sqlite3
|
|
|
|
def check_herb_codes():
|
|
"""약재 성분 코드 확인"""
|
|
|
|
# 삼소음에 사용되는 약재들
|
|
herbs_to_check = [
|
|
"인삼",
|
|
"소엽", # 자소엽
|
|
"전호",
|
|
"반하",
|
|
"갈근",
|
|
"적복령", # 적복령 또는 복령
|
|
"대조", # 대추
|
|
"진피",
|
|
"길경",
|
|
"지각",
|
|
"감초",
|
|
"건강"
|
|
]
|
|
|
|
conn = sqlite3.connect('database/kdrug.db')
|
|
cursor = conn.cursor()
|
|
|
|
herb_codes = {}
|
|
|
|
print("🌿 삼소음 약재 성분 코드 확인")
|
|
print("="*60)
|
|
|
|
for herb in herbs_to_check:
|
|
# 정확한 이름으로 먼저 검색
|
|
cursor.execute("""
|
|
SELECT ingredient_code, herb_name, herb_name_hanja
|
|
FROM herb_masters
|
|
WHERE herb_name = ?
|
|
""", (herb,))
|
|
|
|
result = cursor.fetchone()
|
|
|
|
# 정확한 이름이 없으면 포함된 이름으로 검색
|
|
if not result:
|
|
# 특수 케이스 처리
|
|
if herb == "소엽":
|
|
search_term = "자소엽"
|
|
elif herb == "대조":
|
|
search_term = "대추"
|
|
elif herb == "적복령":
|
|
search_term = "적복령"
|
|
else:
|
|
search_term = herb
|
|
|
|
cursor.execute("""
|
|
SELECT ingredient_code, herb_name, herb_name_hanja
|
|
FROM herb_masters
|
|
WHERE herb_name LIKE ? OR herb_name = ?
|
|
ORDER BY
|
|
CASE WHEN herb_name = ? THEN 0 ELSE 1 END,
|
|
LENGTH(herb_name)
|
|
LIMIT 1
|
|
""", (f'%{search_term}%', search_term, search_term))
|
|
result = cursor.fetchone()
|
|
|
|
if result:
|
|
herb_codes[herb] = result[0]
|
|
print(f"✅ {herb}: {result[0]} ({result[1]})")
|
|
else:
|
|
print(f"❌ {herb}: 찾을 수 없음")
|
|
|
|
# 유사한 이름 검색
|
|
cursor.execute("""
|
|
SELECT herb_name
|
|
FROM herb_masters
|
|
WHERE herb_name LIKE ?
|
|
LIMIT 5
|
|
""", (f'%{herb[:2]}%',))
|
|
similar = cursor.fetchall()
|
|
if similar:
|
|
print(f" 유사한 약재: {', '.join([s[0] for s in similar])}")
|
|
|
|
# 복령 관련 추가 확인
|
|
if "적복령" not in herb_codes or not herb_codes.get("적복령"):
|
|
print("\n📌 복령 관련 약재 추가 검색:")
|
|
cursor.execute("""
|
|
SELECT ingredient_code, herb_name
|
|
FROM herb_masters
|
|
WHERE herb_name LIKE '%복령%'
|
|
ORDER BY herb_name
|
|
""")
|
|
bokryung_list = cursor.fetchall()
|
|
for code, name in bokryung_list:
|
|
print(f" - {code}: {name}")
|
|
|
|
conn.close()
|
|
|
|
return herb_codes
|
|
|
|
if __name__ == "__main__":
|
|
herb_codes = check_herb_codes()
|
|
|
|
print("\n📊 약재 코드 매핑 결과:")
|
|
print("-"*60)
|
|
for herb, code in herb_codes.items():
|
|
if code:
|
|
print(f'"{herb}": "{code}",') |