From 3f96b286d3de06ed8c473f7b0b0fd0ef2512a4a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=8B=9C=EA=B3=A8=EC=95=BD=EC=82=AC?= Date: Wed, 18 Feb 2026 05:49:00 +0000 Subject: [PATCH] =?UTF-8?q?fix:=20=ED=99=98=EC=9E=90=20=ED=8E=B8=EC=A7=91?= =?UTF-8?q?=20=EB=B2=84=ED=8A=BC=20=EA=B8=B0=EB=8A=A5=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 환자 편집 버튼 클릭 이벤트 핸들러 추가 - 편집 모드에서 환자 정보 불러오기 구현 - 마일리지 정보 표시 (현재 잔액, 총 적립, 총 사용) - 환자 정보 수정 API 연동 (PUT 메소드) - API에 마일리지 정보 포함하도록 수정 - 모달 닫힐 때 폼 초기화 처리 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- app.py | 6 +++-- static/app.js | 66 +++++++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 65 insertions(+), 7 deletions(-) diff --git a/app.py b/app.py index 5c9c372..8a5d833 100644 --- a/app.py +++ b/app.py @@ -79,7 +79,8 @@ def get_patients(): with get_db() as conn: cursor = conn.cursor() cursor.execute(""" - SELECT patient_id, name, phone, gender, birth_date, notes + SELECT patient_id, name, phone, gender, birth_date, notes, + mileage_balance, total_mileage_earned, total_mileage_used FROM patients WHERE is_active = 1 ORDER BY created_at DESC @@ -96,7 +97,8 @@ def get_patient(patient_id): with get_db() as conn: cursor = conn.cursor() cursor.execute(""" - SELECT patient_id, name, phone, jumin_no, gender, birth_date, address, notes + SELECT patient_id, name, phone, jumin_no, gender, birth_date, address, notes, + mileage_balance, total_mileage_earned, total_mileage_used FROM patients WHERE patient_id = ? AND is_active = 1 """, (patient_id,)) diff --git a/static/app.js b/static/app.js index ab69f57..e1da7e4 100644 --- a/static/app.js +++ b/static/app.js @@ -185,13 +185,55 @@ $(document).ready(function() { const patientName = $(this).data('name'); viewPatientCompounds(patientId, patientName); }); + + // 편집 버튼 이벤트 + $('.edit-patient').on('click', function() { + const patientId = $(this).data('id'); + editPatient(patientId); + }); }); } }); } - // 환자 등록 + // 환자 정보 편집 + function editPatient(patientId) { + $.get(`/api/patients/${patientId}`, function(response) { + if (response.success && response.data) { + const patient = response.data; + + // 모달 제목 변경 + $('#patientModal .modal-title').text('환자 정보 수정'); + + // 폼에 데이터 채우기 + $('#patientName').val(patient.name); + $('#patientPhone').val(patient.phone); + $('#patientJumin').val(patient.jumin_no); + $('#patientGender').val(patient.gender); + $('#patientBirth').val(patient.birth_date); + $('#patientAddress').val(patient.address); + $('#patientNotes').val(patient.notes); + + // 마일리지 섹션 표시 및 데이터 채우기 + $('#mileageSection').show(); + $('#patientMileageBalance').val(patient.mileage_balance || 0); + $('#patientMileageEarned').val(patient.total_mileage_earned || 0); + $('#patientMileageUsed').val(patient.total_mileage_used || 0); + + // 저장 버튼에 patient_id 저장 + $('#savePatientBtn').data('patient-id', patientId); + + // 모달 표시 + $('#patientModal').modal('show'); + } + }).fail(function() { + alert('환자 정보를 불러오는데 실패했습니다.'); + }); + } + + // 환자 등록/수정 $('#savePatientBtn').on('click', function() { + const patientId = $(this).data('patient-id'); // 편집 모드인지 확인 const patientData = { name: $('#patientName').val(), phone: $('#patientPhone').val(), @@ -202,25 +244,39 @@ $(document).ready(function() { notes: $('#patientNotes').val() }; + // 편집 모드인 경우 PUT, 새 등록인 경우 POST + const url = patientId ? `/api/patients/${patientId}` : '/api/patients'; + const method = patientId ? 'PUT' : 'POST'; + $.ajax({ - url: '/api/patients', - method: 'POST', + url: url, + method: method, contentType: 'application/json', data: JSON.stringify(patientData), success: function(response) { if (response.success) { - alert('환자가 등록되었습니다.'); + alert(patientId ? '환자 정보가 수정되었습니다.' : '환자가 등록되었습니다.'); $('#patientModal').modal('hide'); $('#patientForm')[0].reset(); + $('#mileageSection').hide(); // 마일리지 섹션 숨기기 + $('#savePatientBtn').removeData('patient-id'); // patient-id 데이터 제거 loadPatients(); } }, error: function(xhr) { - alert('오류: ' + xhr.responseJSON.error); + alert('오류: ' + (xhr.responseJSON?.error || '알 수 없는 오류')); } }); }); + // 환자 모달이 닫힐 때 초기화 + $('#patientModal').on('hidden.bs.modal', function() { + $('#patientForm')[0].reset(); + $('#mileageSection').hide(); + $('#savePatientBtn').removeData('patient-id'); + $('#patientModal .modal-title').text('환자 등록'); // 제목을 기본값으로 복원 + }); + // 환자 처방 내역 조회 function viewPatientCompounds(patientId, patientName) { // 환자 정보 가져오기