From 3fc9bbaf8ef4e6f51f3660e22e684664a15a3e6e Mon Sep 17 00:00:00 2001 From: thug0bin Date: Fri, 27 Feb 2026 17:07:41 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=EB=8C=80=EC=8B=9C=EB=B3=B4=EB=93=9C=20?= =?UTF-8?q?=EB=AA=A8=EB=8B=AC=EC=97=90=20=EC=A1=B0=EC=A0=9C=20=EC=9D=B4?= =?UTF-8?q?=EB=A0=A5=20=ED=83=AD=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - /admin/user/ API에 prescriptions 필드 추가 - 전화번호 → CD_PERSON(CUSCODE) → PS_main 연동 - 모달에 💊 조제 탭 추가 (admin_members.html 스타일 적용) - 병원명, 의사명, 투약일수, 처방품목 표시 --- backend/app.py | 67 ++++++++++++++++++++++++++++++++++-- backend/templates/admin.html | 57 ++++++++++++++++++++++++++++-- 2 files changed, 120 insertions(+), 4 deletions(-) diff --git a/backend/app.py b/backend/app.py index 6d9815d..acfcd52 100644 --- a/backend/app.py +++ b/backend/app.py @@ -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: diff --git a/backend/templates/admin.html b/backend/templates/admin.html index 8c29a67..91069ff 100644 --- a/backend/templates/admin.html +++ b/backend/templates/admin.html @@ -896,10 +896,13 @@
+
@@ -956,6 +959,56 @@ html += '

적립 이력이 없습니다.

'; } + html += ` + + + + `;