Repository navigation
Expand file tree
/
Copy pathcheck_database.py
More file actions
149 lines (111 loc) · 4.84 KB
/
Copy pathcheck_database.py
File metadata and controls
149 lines (111 loc) · 4.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Script kiểm tra database và các module dose calculation
"""
import os
import sys
import sqlite3
import logging
# Add project root to path
project_root = os.path.abspath(".")
sys.path.insert(0, project_root)
def check_database():
"""Kiểm tra database và dữ liệu bệnh nhân"""
db_path = "data/database/quangtps.db"
if not os.path.exists(db_path):
print(f"❌ Database không tồn tại: {db_path}")
return
print(f"✅ Database tồn tại: {db_path}")
try:
conn = sqlite3.connect(db_path)
cursor = conn.cursor()
# Kiểm tra các bảng
cursor.execute("SELECT name FROM sqlite_master WHERE type='table';")
tables = cursor.fetchall()
print(f"\n📊 Các bảng trong database ({len(tables)} bảng):")
for table in tables:
table_name = table[0]
cursor.execute(f"SELECT COUNT(*) FROM {table_name}")
count = cursor.fetchone()[0]
print(f" - {table_name}: {count} bản ghi")
# Hiển thị chi tiết cho bảng patients
if table_name == "patients" and count > 0:
cursor.execute("SELECT id, name, dob, gender FROM patients LIMIT 5")
patients = cursor.fetchall()
print(f" Mẫu dữ liệu:")
for patient in patients:
print(
f" ID: {patient[0]}, Name: {patient[1]}, DOB: {patient[2]}, Gender: {patient[3]}"
)
conn.close()
except Exception as e:
print(f"❌ Lỗi khi kiểm tra database: {e}")
def check_dose_algorithms():
"""Kiểm tra các module dose calculation"""
print("\n🧮 Kiểm tra các module dose calculation:")
try:
from quangtps.dose.dose_engine import DoseEngine, DoseCalculationAlgorithm
# Khởi tạo dose engine
engine = DoseEngine()
available_algorithms = engine.get_available_algorithms()
print(f" ✅ DoseEngine khởi tạo thành công")
print(f" 📋 Các thuật toán có sẵn ({len(available_algorithms)}):")
for algo in available_algorithms:
print(f" - {algo.name}: {algo.value}")
# Kiểm tra các module cụ thể
modules_to_check = [
("quangtps.dose.algorithms.pencil_beam", "PencilBeamImplementer"),
("quangtps.dose.algorithms.aaa", "AAAImplementer"),
("quangtps.dose.algorithms.pencil_beam", "PencilBeamAlgorithm"),
("quangtps.dose.algorithms.collapsed_cone", "CollapsedConeAlgorithm"),
("quangtps.dose.algorithms.monte_carlo", "MonteCarloAlgorithm"),
]
print(f"\n 🔍 Kiểm tra các class cụ thể:")
for module_name, class_name in modules_to_check:
try:
module = __import__(module_name, fromlist=[class_name])
if hasattr(module, class_name):
print(f" ✅ {module_name}.{class_name}")
else:
print(f" ❌ {module_name}.{class_name} - Class không tồn tại")
except ImportError as e:
print(f" ❌ {module_name}.{class_name} - Import error: {e}")
except Exception as e:
print(f" ❌ Lỗi khi kiểm tra dose algorithms: {e}")
def check_patient_service():
"""Kiểm tra patient service"""
print("\n👤 Kiểm tra Patient Service:")
try:
from quangtps.database.patient_db import PatientDB
patient_db = PatientDB()
print(f" ✅ PatientDB khởi tạo thành công")
# Thử lấy danh sách bệnh nhân
try:
patients = patient_db.get_all_patients()
print(f" 📋 Số lượng bệnh nhân trong database: {len(patients)}")
if len(patients) > 0:
print(f" 📝 Mẫu bệnh nhân:")
for i, patient in enumerate(patients[:3]): # Hiển thị 3 bệnh nhân đầu
patient_id = patient.get("id", "N/A")
patient_name = patient.get("name", "N/A")
print(f" {i + 1}. ID: {patient_id}, Name: {patient_name}")
else:
print(f" ⚠️ Không có bệnh nhân nào trong database")
except Exception as e:
print(f" ❌ Lỗi khi lấy danh sách bệnh nhân: {e}")
except Exception as e:
print(f" ❌ Lỗi khi khởi tạo PatientDB: {e}")
def main():
"""Hàm chính"""
print("🔍 Kiểm tra hệ thống QuangTPS\n" + "=" * 50)
# Kiểm tra database
check_database()
# Kiểm tra dose algorithms
check_dose_algorithms()
# Kiểm tra patient service
check_patient_service()
print("\n" + "=" * 50)
print("✅ Hoàn tất kiểm tra hệ thống")
if __name__ == "__main__":
main()