78 lines
2.2 KiB
Python
78 lines
2.2 KiB
Python
![]() |
from database import DatabaseManager
|
||
|
import os
|
||
|
import uuid
|
||
|
from datetime import datetime
|
||
|
|
||
|
# 使用backend/data目录下的数据库路径
|
||
|
db_path = os.path.join(os.path.dirname(__file__), 'data', 'body_balance.db')
|
||
|
db = DatabaseManager(db_path)
|
||
|
db.init_database()
|
||
|
|
||
|
# 添加一些测试患者数据
|
||
|
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'
|
||
|
}
|
||
|
]
|
||
|
|
||
|
print('添加测试患者数据...')
|
||
|
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"]}岁)')
|
||
|
|
||
|
# 测试关键字查询
|
||
|
patients = db.get_patients(page=1, size=10, keyword='张')
|
||
|
print(f'\n关键字"张"查询结果: {len(patients)}条记录')
|
||
|
for p in patients:
|
||
|
print(f' - {p["name"]} ({p["gender"]}, {p["age"]}岁)')
|
||
|
|
||
|
# 测试电话号码查询
|
||
|
patients = db.get_patients(page=1, size=10, keyword='13800138002')
|
||
|
print(f'\n电话号码查询结果: {len(patients)}条记录')
|
||
|
for p in patients:
|
||
|
print(f' - {p["name"]} ({p["phone"]})')
|
||
|
|
||
|
print('\n测试完成!')
|