105 lines
2.9 KiB
Python
105 lines
2.9 KiB
Python
#!/usr/bin/env python3
|
|
# -*- coding: utf-8 -*-
|
|
"""
|
|
初始化测试数据脚本
|
|
"""
|
|
|
|
import sys
|
|
import os
|
|
sys.path.append(os.path.join(os.path.dirname(__file__), 'backend'))
|
|
|
|
from backend.database import DatabaseManager
|
|
import uuid
|
|
from datetime import datetime
|
|
|
|
def init_test_data():
|
|
"""初始化测试数据"""
|
|
# 初始化数据库
|
|
db_manager = DatabaseManager('backend/data/body_balance.db')
|
|
db_manager.init_database()
|
|
|
|
print("数据库初始化完成")
|
|
|
|
# 检查是否已有患者数据
|
|
patients_count = db_manager.get_patients_count()
|
|
print(f"当前患者数量: {patients_count}")
|
|
|
|
if patients_count > 0:
|
|
print("数据库中已有患者数据,跳过插入")
|
|
return
|
|
|
|
# 插入测试患者数据
|
|
test_patients = [
|
|
{
|
|
'name': '张三',
|
|
'gender': 'male',
|
|
'age': 35,
|
|
'height': 175,
|
|
'weight': 70,
|
|
'phone': '13800138001',
|
|
'medical_history': '无特殊病史',
|
|
'notes': '测试患者1'
|
|
},
|
|
{
|
|
'name': '李四',
|
|
'gender': 'female',
|
|
'age': 28,
|
|
'height': 165,
|
|
'weight': 55,
|
|
'phone': '13800138002',
|
|
'medical_history': '轻微腰椎间盘突出',
|
|
'notes': '测试患者2'
|
|
},
|
|
{
|
|
'name': '王五',
|
|
'gender': 'male',
|
|
'age': 42,
|
|
'height': 180,
|
|
'weight': 80,
|
|
'phone': '13800138003',
|
|
'medical_history': '高血压',
|
|
'notes': '测试患者3'
|
|
},
|
|
{
|
|
'name': '赵六',
|
|
'gender': 'female',
|
|
'age': 31,
|
|
'height': 160,
|
|
'weight': 50,
|
|
'phone': '13800138004',
|
|
'medical_history': '无',
|
|
'notes': '测试患者4'
|
|
},
|
|
{
|
|
'name': '钱七',
|
|
'gender': 'male',
|
|
'age': 55,
|
|
'height': 170,
|
|
'weight': 75,
|
|
'phone': '13800138005',
|
|
'medical_history': '糖尿病',
|
|
'notes': '测试患者5'
|
|
}
|
|
]
|
|
|
|
print("开始插入测试患者数据...")
|
|
|
|
for i, patient_data in enumerate(test_patients, 1):
|
|
try:
|
|
patient_id = db_manager.create_patient(patient_data)
|
|
print(f"插入患者 {i}: {patient_data['name']} (ID: {patient_id})")
|
|
except Exception as e:
|
|
print(f"插入患者 {i} 失败: {e}")
|
|
|
|
# 验证插入结果
|
|
final_count = db_manager.get_patients_count()
|
|
print(f"\n插入完成,当前患者总数: {final_count}")
|
|
|
|
# 显示患者列表
|
|
patients = db_manager.get_patients(page=1, size=10)
|
|
print("\n患者列表:")
|
|
for patient in patients:
|
|
print(f"- {patient['name']} ({patient['gender']}, {patient['age']}岁) - {patient['phone']}")
|
|
|
|
if __name__ == '__main__':
|
|
init_test_data() |