fix: 환자 편집 버튼 기능 수정

- 환자 편집 버튼 클릭 이벤트 핸들러 추가
- 편집 모드에서 환자 정보 불러오기 구현
- 마일리지 정보 표시 (현재 잔액, 총 적립, 총 사용)
- 환자 정보 수정 API 연동 (PUT 메소드)
- API에 마일리지 정보 포함하도록 수정
- 모달 닫힐 때 폼 초기화 처리

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

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
시골약사 2026-02-18 05:49:00 +00:00
parent ee15d8e45e
commit 3f96b286d3
2 changed files with 65 additions and 7 deletions

6
app.py
View File

@ -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,))

View File

@ -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) {
// 환자 정보 가져오기