from database import DatabaseManager import os # 检查backend/data目录下的数据库 db_path = os.path.join(os.path.dirname(__file__), 'data', 'body_balance.db') db = DatabaseManager(db_path) db.init_database() conn = db.get_connection() cursor = conn.cursor() # 检查患者总数 cursor.execute('SELECT COUNT(*) FROM patients') count = cursor.fetchone()[0] print(f'body_balance.db中的患者总数: {count}') # 查看前5条患者数据 cursor.execute('SELECT * FROM patients LIMIT 5') rows = cursor.fetchall() print('前5条患者数据:') for row in rows: print(dict(row)) conn.close() # 如果没有数据,添加测试数据 if count == 0: print('\n数据库中没有患者数据,添加测试数据...') test_patients = [ { 'name': '张三', 'gender': '男', 'age': 30, 'birth_date': '1994-01-15', 'nationality': '汉族', 'height': 175.0, 'weight': 70.0, 'phone': '13800138001', 'shoe_size': '42', 'medical_history': '无', 'notes': '测试患者1' }, { 'name': '李四', 'gender': '女', 'age': 25, 'birth_date': '1999-03-22', 'nationality': '汉族', 'height': 165.0, 'weight': 55.0, 'phone': '13800138002', 'shoe_size': '37', 'medical_history': '高血压', 'notes': '测试患者2' }, { 'name': '王五', 'gender': '男', 'age': 35, 'birth_date': '1989-07-08', 'nationality': '回族', 'height': 180.0, 'weight': 80.0, 'phone': '13800138003', 'shoe_size': '44', 'medical_history': '糖尿病', 'notes': '测试患者3' } ] for patient in test_patients: patient_id = db.create_patient(patient) print(f'添加患者: {patient["name"]}, ID: {patient_id}') print('\n重新测试get_patients方法:') patients = db.get_patients(page=1, size=10, keyword='') print(f'查询结果: {len(patients)}条记录') for p in patients: print(f' - {p["name"]} ({p["gender"]}, {p["age"]}岁)') else: print('\n数据库中已有患者数据,测试get_patients方法:') patients = db.get_patients(page=1, size=10, keyword='') print(f'查询结果: {len(patients)}条记录') for p in patients: print(f' - {p["name"]} ({p["gender"]}, {p["age"]}岁)')