Commit ab5d6adb by luoqi

feat: update data export and patient detail templates with new fields and…

feat: update data export and patient detail templates with new fields and drag-and-drop functionality
parent 162d4220
Pipeline #3224 passed with stage
in 3 minutes 4 seconds
......@@ -38,8 +38,6 @@ Thumbs.db
# Database files
*.db
*.sqlite
*.sqlite3
# Logs
*.log
......
......@@ -52,7 +52,7 @@ class DataExporter:
# 获取所有回访记录,同时关联患者表获取诊所信息
cursor.execute("""
SELECT
SELECT
cr.case_number,
cr.callback_methods,
cr.callback_result,
......@@ -60,6 +60,14 @@ class DataExporter:
cr.operator,
cr.create_time,
cr.update_time,
cr.next_appointment_time,
cr.failure_reason,
cr.abandon_reason,
cr.ai_feedback_type,
cr.failure_reason_note,
cr.abandon_reason_note,
cr.ai_feedback_note,
cr.callback_status,
p.clinic_name
FROM callback_records cr
LEFT JOIN patients p ON cr.case_number = p.case_number
......@@ -74,8 +82,8 @@ class DataExporter:
for record in records:
case_number = record[0]
clinic_name = record[7] or '未知门诊' # 从patients表获取诊所名称
clinic_name = record[15] or '未知门诊' # 从patients表获取诊所名称(索引更新为15)
if clinic_name not in clinic_data:
clinic_data[clinic_name] = {
'records': [],
......@@ -86,16 +94,35 @@ class DataExporter:
'failed_count': 0,
'pending_count': 0
}
# 处理callback_methods字段 - 解析JSON字符串
callback_methods_raw = record[1]
try:
if isinstance(callback_methods_raw, str):
callback_methods = json.loads(callback_methods_raw)
else:
callback_methods = callback_methods_raw if callback_methods_raw else []
except (json.JSONDecodeError, TypeError):
# 如果解析失败,尝试直接使用原始值
callback_methods = [str(callback_methods_raw)] if callback_methods_raw else []
# 添加记录
clinic_data[clinic_name]['records'].append({
'case_number': case_number,
'callback_methods': record[1],
'callback_methods': callback_methods,
'callback_result': record[2],
'callback_record': record[3],
'operator': record[4],
'create_time': record[5],
'update_time': record[6]
'update_time': record[6],
'next_appointment_time': record[7],
'failure_reason': record[8],
'abandon_reason': record[9],
'ai_feedback_type': record[10],
'failure_reason_note': record[11],
'abandon_reason_note': record[12],
'ai_feedback_note': record[13],
'callback_status': record[14]
})
# 统计唯一患者数
......@@ -294,7 +321,7 @@ class DataExporter:
# 设置标题
title = f"{clinic_name} - 回访记录详情"
ws['A1'] = title
ws.merge_cells('A1:H1')
ws.merge_cells('A1:M1')
# 设置标题样式
title_font = Font(size=14, bold=True)
......@@ -306,7 +333,8 @@ class DataExporter:
ws['A1'].alignment = title_alignment
# 设置列标题
headers = ["序号", "病例号", "回访方式", "回访结果", "操作员", "创建时间", "更新时间", "详细记录"]
headers = ["序号", "病例号", "回访方式", "回访结果", "操作员", "创建时间", "更新时间", "详细记录",
"下次预约时间", "不成功备注", "放弃回访备注", "AI反馈类型", "AI反馈备注"]
for col, header in enumerate(headers, 1):
cell = ws.cell(row=3, column=col, value=header)
cell.font = Font(bold=True)
......@@ -323,6 +351,21 @@ class DataExporter:
ws.cell(row=row_idx, column=6, value=record['create_time'].strftime("%Y-%m-%d %H:%M:%S") if record['create_time'] else "")
ws.cell(row=row_idx, column=7, value=record['update_time'].strftime("%Y-%m-%d %H:%M:%S") if record['update_time'] else "")
ws.cell(row=row_idx, column=8, value=record['callback_record'])
# 新增字段
ws.cell(row=row_idx, column=9, value=record.get('next_appointment_time', '') or '')
# 备注字段:根据回访结果显示相应的备注
failure_note = record.get('failure_reason_note', '') or ''
abandon_note = record.get('abandon_reason_note', '') or ''
ws.cell(row=row_idx, column=10, value=failure_note)
ws.cell(row=row_idx, column=11, value=abandon_note)
# AI反馈:分别显示AI反馈类型和备注
ai_feedback_type = record.get('ai_feedback_type', '') or ''
ai_feedback_note = record.get('ai_feedback_note', '') or ''
ws.cell(row=row_idx, column=12, value=ai_feedback_type)
ws.cell(row=row_idx, column=13, value=ai_feedback_note)
# 根据回访结果设置颜色
if record['callback_result'] == '成功':
......@@ -334,16 +377,16 @@ class DataExporter:
else:
fill_color = "FFFFFF" # 白色
for col in range(1, 9):
for col in range(1, 14): # 更新为13列
ws.cell(row=row_idx, column=col).fill = PatternFill(start_color=fill_color, end_color=fill_color, fill_type="solid")
# 调整列宽
column_widths = [8, 15, 20, 12, 15, 20, 20, 50]
column_widths = [8, 15, 20, 12, 15, 20, 20, 50, 18, 25, 25, 25, 30] # 新增5列的宽度
for col, width in enumerate(column_widths, 1):
ws.column_dimensions[get_column_letter(col)].width = width
# 设置边框
self._add_borders(ws, 3, len(data['records']) + 3, 8)
self._add_borders(ws, 3, len(data['records']) + 3, 13) # 更新为13列
def _add_borders(self, ws, start_row: int, end_row: int, end_col: int):
"""添加边框"""
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment