feat: 건조시럽 환산계수 모달 구현 - GET/POST/PUT API 추가 - PMR 약품명 더블클릭 → 모달 오픈 - 신규 등록/수정 기능

This commit is contained in:
thug0bin
2026-03-12 10:17:39 +09:00
parent 9531b74d0e
commit 98d370104b
3 changed files with 560 additions and 0 deletions

View File

@@ -3953,6 +3953,198 @@ def api_conversion_factor(sung_code):
})
@app.route('/api/drug-info/drysyrup/<sung_code>', methods=['GET'])
def api_drysyrup_get(sung_code):
"""
건조시럽 전체 정보 조회 API
PostgreSQL drysyrup 테이블에서 SUNG_CODE로 전체 정보 조회
"""
try:
session = db_manager.get_postgres_session()
if session is None:
return jsonify({
'success': True,
'exists': False,
'error': 'PostgreSQL 연결 실패'
})
query = text("""
SELECT
ingredient_code,
ingredient_name,
product_name,
conversion_factor,
post_prep_amount,
main_ingredient_amt,
storage_conditions,
expiration_date
FROM drysyrup
WHERE ingredient_code = :sung_code
LIMIT 1
""")
row = session.execute(query, {'sung_code': sung_code}).fetchone()
if not row:
return jsonify({
'success': True,
'exists': False
})
return jsonify({
'success': True,
'exists': True,
'sung_code': row[0],
'ingredient_name': row[1],
'product_name': row[2],
'conversion_factor': float(row[3]) if row[3] is not None else None,
'post_prep_amount': row[4],
'main_ingredient_amt': row[5],
'storage_conditions': row[6],
'expiration_date': row[7]
})
except Exception as e:
logging.error(f"건조시럽 조회 오류 (SUNG_CODE={sung_code}): {e}")
return jsonify({
'success': True,
'exists': False,
'error': str(e)
})
@app.route('/api/drug-info/drysyrup', methods=['POST'])
def api_drysyrup_create():
"""
건조시럽 신규 등록 API
"""
try:
data = request.get_json()
if not data or not data.get('sung_code'):
return jsonify({'success': False, 'error': '성분코드 필수'}), 400
session = db_manager.get_postgres_session()
if session is None:
return jsonify({'success': False, 'error': 'PostgreSQL 연결 실패'}), 500
# 중복 체크
check_query = text("SELECT 1 FROM drysyrup WHERE ingredient_code = :sung_code")
existing = session.execute(check_query, {'sung_code': data['sung_code']}).fetchone()
if existing:
return jsonify({'success': False, 'error': '이미 등록된 성분코드'}), 400
insert_query = text("""
INSERT INTO drysyrup (
ingredient_code, ingredient_name, product_name,
conversion_factor, post_prep_amount, main_ingredient_amt,
storage_conditions, expiration_date
) VALUES (
:sung_code, :ingredient_name, :product_name,
:conversion_factor, :post_prep_amount, :main_ingredient_amt,
:storage_conditions, :expiration_date
)
""")
session.execute(insert_query, {
'sung_code': data.get('sung_code'),
'ingredient_name': data.get('ingredient_name', ''),
'product_name': data.get('product_name', ''),
'conversion_factor': data.get('conversion_factor'),
'post_prep_amount': data.get('post_prep_amount', ''),
'main_ingredient_amt': data.get('main_ingredient_amt', ''),
'storage_conditions': data.get('storage_conditions', '실온'),
'expiration_date': data.get('expiration_date', '')
})
session.commit()
return jsonify({'success': True, 'message': '등록 완료'})
except Exception as e:
logging.error(f"건조시럽 등록 오류: {e}")
try:
session.rollback()
except:
pass
return jsonify({'success': False, 'error': str(e)}), 500
@app.route('/api/drug-info/drysyrup/<sung_code>', methods=['PUT'])
def api_drysyrup_update(sung_code):
"""
건조시럽 정보 수정 API
"""
try:
data = request.get_json()
if not data:
return jsonify({'success': False, 'error': '데이터 필수'}), 400
session = db_manager.get_postgres_session()
if session is None:
return jsonify({'success': False, 'error': 'PostgreSQL 연결 실패'}), 500
# 존재 여부 확인
check_query = text("SELECT 1 FROM drysyrup WHERE ingredient_code = :sung_code")
existing = session.execute(check_query, {'sung_code': sung_code}).fetchone()
if not existing:
# 없으면 신규 등록으로 처리
insert_query = text("""
INSERT INTO drysyrup (
ingredient_code, ingredient_name, product_name,
conversion_factor, post_prep_amount, main_ingredient_amt,
storage_conditions, expiration_date
) VALUES (
:sung_code, :ingredient_name, :product_name,
:conversion_factor, :post_prep_amount, :main_ingredient_amt,
:storage_conditions, :expiration_date
)
""")
session.execute(insert_query, {
'sung_code': sung_code,
'ingredient_name': data.get('ingredient_name', ''),
'product_name': data.get('product_name', ''),
'conversion_factor': data.get('conversion_factor'),
'post_prep_amount': data.get('post_prep_amount', ''),
'main_ingredient_amt': data.get('main_ingredient_amt', ''),
'storage_conditions': data.get('storage_conditions', '실온'),
'expiration_date': data.get('expiration_date', '')
})
else:
# 있으면 업데이트
update_query = text("""
UPDATE drysyrup SET
ingredient_name = :ingredient_name,
product_name = :product_name,
conversion_factor = :conversion_factor,
post_prep_amount = :post_prep_amount,
main_ingredient_amt = :main_ingredient_amt,
storage_conditions = :storage_conditions,
expiration_date = :expiration_date
WHERE ingredient_code = :sung_code
""")
session.execute(update_query, {
'sung_code': sung_code,
'ingredient_name': data.get('ingredient_name', ''),
'product_name': data.get('product_name', ''),
'conversion_factor': data.get('conversion_factor'),
'post_prep_amount': data.get('post_prep_amount', ''),
'main_ingredient_amt': data.get('main_ingredient_amt', ''),
'storage_conditions': data.get('storage_conditions', '실온'),
'expiration_date': data.get('expiration_date', '')
})
session.commit()
return jsonify({'success': True, 'message': '저장 완료'})
except Exception as e:
logging.error(f"건조시럽 수정 오류 (SUNG_CODE={sung_code}): {e}")
try:
session.rollback()
except:
pass
return jsonify({'success': False, 'error': str(e)}), 500
# ==================== 입고이력 API ====================
@app.route('/api/drugs/<drug_code>/purchase-history')