kdrug-inventory-system/add_sample_herb_data.py
시골약사 ad9ac396e2 chore: 개발 파일 정리 및 구조화
- 개발/테스트 스크립트를 dev_scripts/ 폴더로 이동
- 스크린샷을 screenshots/ 폴더로 이동
- 백업 파일 보존 (.backup)
- 처방 관련 추가 스크립트 포함

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2026-02-18 04:44:48 +00:00

317 lines
11 KiB
Python

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
한약재 샘플 데이터 추가 - 십전대보탕 구성 약재
"""
import sqlite3
from datetime import datetime
def get_connection():
"""데이터베이스 연결"""
return sqlite3.connect('database/kdrug.db')
def add_herb_extended_data():
"""약재 확장 정보 추가"""
conn = get_connection()
cursor = conn.cursor()
# 십전대보탕 구성 약재들의 실제 ingredient_code 사용
herb_data = [
{
'ingredient_code': '3400H1AHM', # 인삼
'property': '온(溫)',
'taste': '감(甘), 미고(微苦)',
'meridian_tropism': '폐(肺), 비(脾), 심(心)',
'main_effects': '대보원기, 보비익폐, 생진지갈, 안신익지',
'indications': '기허증, 피로, 식욕부진, 설사, 호흡곤란, 자한, 양위, 소갈, 건망, 불면',
'dosage_range': '1~3돈(3~9g)',
'precautions': '실증, 열증자 신중 투여',
'preparation_method': '수치법: 홍삼, 백삼, 당삼 등으로 가공',
'tags': [
('보기', 5),
('보혈', 3),
('안신', 4),
]
},
{
'ingredient_code': '3007H1AHM', # 감초
'property': '평(平)',
'taste': '감(甘)',
'meridian_tropism': '심(心), 폐(肺), 비(脾), 위(胃)',
'main_effects': '화중완급, 윤폐지해, 해독',
'indications': '복통, 기침, 인후통, 소화불량, 약물중독',
'dosage_range': '1~3돈(3~9g)',
'precautions': '장기복용시 부종 주의',
'preparation_method': '자감초(炙甘草) 등',
'tags': [
('보기', 3),
('해독', 4),
('윤조', 3),
('청열', 2),
('항염', 3),
]
},
{
'ingredient_code': '3204H1AHM', # 백출
'property': '온(溫)',
'taste': '감(甘), 고(苦)',
'meridian_tropism': '비(脾), 위(胃)',
'main_effects': '건비익기, 조습이수, 지한, 안태',
'indications': '비허설사, 수종, 담음, 자한, 태동불안',
'dosage_range': '2~4돈(6~12g)',
'precautions': '음허내열자 신중',
'preparation_method': '토백출, 생백출',
'tags': [
('보기', 4),
('이수', 4),
('건비', 5),
]
},
{
'ingredient_code': '3215H1AHM', # 복령
'property': '평(平)',
'taste': '감(甘), 담(淡)',
'meridian_tropism': '심(心), 폐(肺), 비(脾), 신(腎)',
'main_effects': '이수삼습, 건비영심, 안신',
'indications': '소변불리, 수종, 설사, 불면, 심계',
'dosage_range': '3~5돈(9~15g)',
'precautions': '음허자 신중',
'preparation_method': '백복령, 적복령',
'tags': [
('이수', 5),
('안신', 3),
('건비', 3),
]
},
{
'ingredient_code': '3419H1AHM', # 작약
'property': '미한(微寒)',
'taste': '고(苦), 산(酸)',
'meridian_tropism': '간(肝), 비(脾)',
'main_effects': '양혈렴음, 유간지통, 평간양',
'indications': '혈허, 복통, 사지경련, 두훈, 월경불순',
'dosage_range': '2~4돈(6~12g)',
'precautions': '비허설사자 신중',
'preparation_method': '백작약, 적작약',
'tags': [
('보혈', 4),
('진경', 4),
('평간', 3),
]
},
{
'ingredient_code': '3475H1AHM', # 천궁
'property': '온(溫)',
'taste': '신(辛)',
'meridian_tropism': '간(肝), 담(膽), 심포(心包)',
'main_effects': '활혈행기, 거풍지통',
'indications': '혈체, 두통, 현훈, 월경불순, 복통',
'dosage_range': '1~2돈(3~6g)',
'precautions': '음허화왕자 신중',
'preparation_method': '주천궁',
'tags': [
('활혈', 5),
('거풍', 3),
('지통', 4),
]
},
{
'ingredient_code': '3105H1AHM', # 당귀
'property': '온(溫)',
'taste': '감(甘), 신(辛)',
'meridian_tropism': '간(肝), 심(心), 비(脾)',
'main_effects': '보혈활혈, 조경지통, 윤장통변',
'indications': '혈허, 월경불순, 복통, 변비, 타박상',
'dosage_range': '2~4돈(6~12g)',
'precautions': '습성설사자 신중',
'preparation_method': '주당귀, 당귀신, 당귀미',
'tags': [
('보혈', 5),
('활혈', 4),
('윤조', 3),
]
},
{
'ingredient_code': '3583H1AHM', # 황기
'property': '온(溫)',
'taste': '감(甘)',
'meridian_tropism': '폐(肺), 비(脾)',
'main_effects': '보기승양, 고표지한, 이수소종, 탈독생기',
'indications': '기허, 자한, 설사, 탈항, 수종, 창양',
'dosage_range': '3~6돈(9~18g)',
'precautions': '표실사 및 음허자 신중',
'preparation_method': '밀자황기',
'tags': [
('보기', 5),
('승양', 4),
('고표', 4),
]
},
{
'ingredient_code': '3384H1AHM', # 육계
'property': '대열(大熱)',
'taste': '감(甘), 신(辛)',
'meridian_tropism': '신(腎), 비(脾), 심(心), 간(肝)',
'main_effects': '보화조양, 산한지통, 온경통맥',
'indications': '양허, 냉증, 요통, 복통, 설사',
'dosage_range': '0.5~1돈(1.5~3g)',
'precautions': '음허화왕자, 임신부 금기',
'preparation_method': '육계심, 계피',
'tags': [
('보양', 5),
('온리', 5),
('산한', 4),
]
},
{
'ingredient_code': '3299H1AHM', # 숙지황
'property': '온(溫)',
'taste': '감(甘)',
'meridian_tropism': '간(肝), 신(腎)',
'main_effects': '자음보혈, 익정전수',
'indications': '혈허, 음허, 요슬산연, 유정, 붕루',
'dosage_range': '3~6돈(9~18g)',
'precautions': '비허설사, 담다자 신중',
'preparation_method': '숙지황 제법',
'tags': [
('보혈', 5),
('자음', 5),
('보신', 4),
]
},
]
for herb in herb_data:
# herb_master_extended 업데이트
cursor.execute("""
UPDATE herb_master_extended
SET property = ?,
taste = ?,
meridian_tropism = ?,
main_effects = ?,
indications = ?,
dosage_range = ?,
precautions = ?,
preparation_method = ?,
updated_at = CURRENT_TIMESTAMP
WHERE ingredient_code = ?
""", (
herb['property'],
herb['taste'],
herb['meridian_tropism'],
herb['main_effects'],
herb['indications'],
herb['dosage_range'],
herb['precautions'],
herb['preparation_method'],
herb['ingredient_code']
))
# 효능 태그 매핑
for tag_name, strength in herb.get('tags', []):
# 태그 ID 조회
cursor.execute("""
SELECT tag_id FROM herb_efficacy_tags
WHERE tag_name = ?
""", (tag_name,))
tag_result = cursor.fetchone()
if tag_result:
tag_id = tag_result[0]
# 기존 태그 삭제
cursor.execute("""
DELETE FROM herb_item_tags
WHERE ingredient_code = ? AND tag_id = ?
""", (herb['ingredient_code'], tag_id))
# 태그 매핑 추가
cursor.execute("""
INSERT INTO herb_item_tags
(ingredient_code, tag_id, strength)
VALUES (?, ?, ?)
""", (herb['ingredient_code'], tag_id, strength))
print(f"{herb['ingredient_code']} 데이터 추가 완료")
conn.commit()
conn.close()
def add_prescription_rules():
"""처방 배합 규칙 추가"""
conn = get_connection()
cursor = conn.cursor()
# 몇 가지 대표적인 배합 규칙 추가
rules = [
{
'herb1': '인삼',
'herb2': '황기',
'rule_type': '상수',
'description': '보기작용 상승효과',
'clinical_note': '기허증에 병용시 효과 증대'
},
{
'herb1': '당귀',
'herb2': '천궁',
'rule_type': '상수',
'description': '활혈작용 상승효과',
'clinical_note': '혈허, 혈체에 병용'
},
{
'herb1': '반하',
'herb2': '생강',
'rule_type': '상수',
'description': '반하의 독성 감소, 진토작용 증강',
'clinical_note': '구토, 오심에 병용'
},
{
'herb1': '감초',
'herb2': '감수',
'rule_type': '상반',
'description': '효능 상반',
'clinical_note': '병용 금지'
},
{
'herb1': '인삼',
'herb2': '오령지',
'rule_type': '상외',
'description': '효능 감소',
'clinical_note': '병용시 주의'
}
]
for rule in rules:
cursor.execute("""
INSERT OR IGNORE INTO prescription_rules
(herb1_name, herb2_name, rule_type, description, clinical_notes)
VALUES (?, ?, ?, ?, ?)
""", (rule['herb1'], rule['herb2'], rule['rule_type'],
rule['description'], rule['clinical_note']))
print(f"{rule['herb1']} - {rule['herb2']} 규칙 추가")
conn.commit()
conn.close()
def main():
print("=" * 80)
print("한약재 샘플 데이터 추가 - 십전대보탕 구성 약재")
print("=" * 80)
try:
print("\n1. 약재 확장 정보 추가 중...")
add_herb_extended_data()
print("\n2. 처방 배합 규칙 추가 중...")
add_prescription_rules()
print("\n✨ 모든 샘플 데이터가 성공적으로 추가되었습니다!")
except Exception as e:
print(f"\n❌ 오류 발생: {e}")
import traceback
traceback.print_exc()
if __name__ == "__main__":
main()