feat: 대시보드 모달에 조제 이력 탭 추가

- /admin/user/<id> API에 prescriptions 필드 추가
- 전화번호 → CD_PERSON(CUSCODE) → PS_main 연동
- 모달에 💊 조제 탭 추가 (admin_members.html 스타일 적용)
- 병원명, 의사명, 투약일수, 처방품목 표시
This commit is contained in:
thug0bin
2026-02-27 17:07:41 +09:00
parent c33d857fa6
commit 3fc9bbaf8e
2 changed files with 120 additions and 4 deletions

View File

@@ -1387,7 +1387,68 @@ def admin_user_detail(user_id):
print(f"[WARNING] MSSQL 조회 실패 (user {user_id}): {mssql_error}")
purchases = []
# 6. 응답 생성
# 6. 조제 이력 조회 (전화번호 → CUSCODE → PS_main)
prescriptions = []
pos_customer = None
if user['phone']:
try:
phone_clean = user['phone'].replace('-', '').replace(' ', '')
base_session = db_manager.get_session('PM_BASE')
pres_session = db_manager.get_session('PM_PRES')
# 전화번호로 CUSCODE 조회
cuscode_query = text("""
SELECT TOP 1 CUSCODE, PANAME
FROM CD_PERSON
WHERE REPLACE(REPLACE(PHONE, '-', ''), ' ', '') = :phone
OR REPLACE(REPLACE(TEL_NO, '-', ''), ' ', '') = :phone
OR REPLACE(REPLACE(PHONE2, '-', ''), ' ', '') = :phone
""")
cus_row = base_session.execute(cuscode_query, {'phone': phone_clean}).fetchone()
if cus_row:
cuscode = cus_row.CUSCODE
pos_customer = {'cuscode': cuscode, 'name': cus_row.PANAME}
# 조제 이력 조회
rx_query = text("""
SELECT TOP 30
P.PreSerial, P.Indate, P.Paname, P.Drname, P.OrderName, P.TDAYS
FROM PS_main P
WHERE P.CusCode = :cuscode
ORDER BY P.Indate DESC, P.PreSerial DESC
""")
rxs = pres_session.execute(rx_query, {'cuscode': cuscode}).fetchall()
for rx in rxs:
# 처방 품목 조회
items_query = text("""
SELECT S.DrugCode, G.GoodsName, S.Days, S.QUAN, S.QUAN_TIME
FROM PS_sub_pharm S
LEFT JOIN PM_DRUG.dbo.CD_GOODS G ON S.DrugCode = G.DrugCode
WHERE S.PreSerial = :pre_serial
""")
items = pres_session.execute(items_query, {'pre_serial': rx.PreSerial}).fetchall()
prescriptions.append({
'pre_serial': rx.PreSerial,
'date': rx.Indate,
'patient_name': rx.Paname,
'doctor': rx.Drname,
'hospital': rx.OrderName,
'total_days': rx.TDAYS,
'items': [{
'drug_code': item.DrugCode,
'name': item.GoodsName or '알 수 없음',
'days': float(item.Days) if item.Days else 0,
'quantity': float(item.QUAN) if item.QUAN else 0,
'times_per_day': float(item.QUAN_TIME) if item.QUAN_TIME else 0
} for item in items]
})
except Exception as rx_error:
logging.warning(f"조제 이력 조회 실패 (user {user_id}): {rx_error}")
# 7. 응답 생성
return jsonify({
'success': True,
'user': {
@@ -1409,7 +1470,9 @@ def admin_user_detail(user_id):
}
for ml in mileage_history
],
'purchases': purchases
'purchases': purchases,
'prescriptions': prescriptions,
'pos_customer': pos_customer
})
except Exception as e: