-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_working.py
More file actions
233 lines (189 loc) · 7.01 KB
/
test_working.py
File metadata and controls
233 lines (189 loc) · 7.01 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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
#!/usr/bin/env python
"""
Working Test Script for MediSafeAI
Tests with the ACTUAL existing code API
"""
import sys
from pathlib import Path
# Add src to path
sys.path.insert(0, str(Path(__file__).parent / 'src'))
def test_patient_generator():
"""Test patient data generation"""
print("=" * 60)
print("TEST 1: Patient Generator")
print("=" * 60)
try:
from src.data_generator.patient_generator import PatientGenerator
# Use actual API: PatientGenerator(seed)
gen = PatientGenerator(seed=42)
df = gen.generate_demographics(n_patients=10) # Actual method name
print(f"✓ Generated {len(df)} patients")
print(f"✓ Columns: {', '.join(df.columns)}")
print(f"\nSample data:")
print(df.head(3))
return True
except Exception as e:
print(f"✗ Error: {e}")
import traceback
traceback.print_exc()
return False
def test_vitals_generator():
"""Test vitals generation"""
print("\n" + "=" * 60)
print("TEST 2: Vitals Generator")
print("=" * 60)
try:
from src.data_generator.patient_generator import PatientGenerator
from src.data_generator.vitals_generator import VitalsGenerator
# Generate patients first
gen = PatientGenerator(seed=42)
patients_df = gen.generate_demographics(n_patients=5)
# Generate vitals
vitals_gen = VitalsGenerator()
vitals_df = vitals_gen.generate_vitals(patients_df)
print(f"✓ Generated vitals for {len(vitals_df)} patients")
print(f"✓ Vital signs columns present")
print(f"\nSample vitals:")
print(vitals_df[['patient_id', 'blood_pressure_systolic', 'heart_rate']].head(3))
return True
except Exception as e:
print(f"✗ Error: {e}")
import traceback
traceback.print_exc()
return False
def test_differential_privacy():
"""Test differential privacy"""
print("\n" + "=" * 60)
print("TEST 3: Differential Privacy")
print("=" * 60)
try:
import pandas as pd
from src.privacy.differential_privacy import DifferentialPrivacy
# Create test data
test_df = pd.DataFrame({
'patient_id': ['PT001', 'PT002', 'PT003'],
'age': [25, 45, 65],
'income': [50000, 75000, 100000]
})
print("Original data:")
print(test_df)
# Apply privacy using actual API
dp = DifferentialPrivacy(epsilon=1.0, delta=1e-5)
private_df = dp.privatize_dataframe(
test_df,
numeric_columns=['age', 'income']
)
print("\nPrivatized data:")
print(private_df)
print(f"\n✓ Privacy applied with ε={dp.epsilon}, δ={dp.delta}")
print(f"✓ Noise added to protect patient data")
return True
except Exception as e:
print(f"✗ Error: {e}")
import traceback
traceback.print_exc()
return False
def test_disease_progression():
"""Test disease progression simulation"""
print("\n" + "=" * 60)
print("TEST 4: Disease Progression")
print("=" * 60)
try:
from src.data_generator.patient_generator import PatientGenerator
from src.data_generator.disease_progression import DiseaseProgressionModel
# Generate a patient
gen = PatientGenerator(seed=42)
patients_df = gen.generate_demographics(n_patients=1)
patient = patients_df.iloc[0]
print(f"Patient: {patient['patient_id']}, Age: {patient['age']}")
# Simulate progression
model = DiseaseProgressionModel()
progression_df = model.simulate_progression(
patient,
num_visits=6,
time_interval_days=30
)
print(f"\n✓ Simulated {len(progression_df)} visits over 6 months")
print(f"\nProgression summary:")
print(progression_df[['visit_number', 'blood_glucose']].head())
return True
except Exception as e:
print(f"✗ Error: {e}")
import traceback
traceback.print_exc()
return False
def test_treatment_generator():
"""Test treatment generation"""
print("\n" + "=" * 60)
print("TEST 5: Treatment Generator")
print("=" * 60)
try:
from src.data_generator.patient_generator import PatientGenerator
from src.data_generator.treatment_generator import TreatmentGenerator
# Generate patients
gen = PatientGenerator(seed=42)
patients_df = gen.generate_demographics(n_patients=5)
# Generate treatments
treatment_gen = TreatmentGenerator()
treatments_df = treatment_gen.generate_treatments(patients_df)
print(f"✓ Generated treatments for {len(treatments_df)} patients")
print(f"\nSample treatments:")
for idx, row in treatments_df.head(3).iterrows():
print(f" {row['patient_id']}: {', '.join(row['treatments'])}")
return True
except Exception as e:
print(f"✗ Error: {e}")
import traceback
traceback.print_exc()
return False
def test_configuration():
"""Test configuration module"""
print("\n" + "=" * 60)
print("TEST 6: Configuration")
print("=" * 60)
try:
from src.config.settings import settings
print(f"✓ App Name: {settings.APP_NAME}")
print(f"✓ Version: {settings.APP_VERSION}")
print(f"✓ Environment: {settings.APP_ENV}")
print(f"✓ Default Epsilon: {settings.DEFAULT_EPSILON}")
print(f"✓ Data Directory: {settings.DATA_DIR}")
return True
except Exception as e:
print(f"✗ Error: {e}")
import traceback
traceback.print_exc()
return False
def main():
"""Run all tests"""
print("\n" + "=" * 60)
print("MediSafeAI - Working Test Suite")
print("Testing with ACTUAL existing code")
print("=" * 60)
results = []
results.append(("Patient Generator", test_patient_generator()))
results.append(("Vitals Generator", test_vitals_generator()))
results.append(("Differential Privacy", test_differential_privacy()))
results.append(("Disease Progression", test_disease_progression()))
results.append(("Treatment Generator", test_treatment_generator()))
results.append(("Configuration Module", test_configuration()))
# Summary
print("\n" + "=" * 60)
print("TEST SUMMARY")
print("=" * 60)
for name, result in results:
status = "✓ PASS" if result else "✗ FAIL"
print(f"{status}: {name}")
passed = sum(1 for _, result in results if result)
total = len(results)
print(f"\nTotal: {passed}/{total} tests passed")
if passed == total:
print("\n🎉 All tests passed! MediSafeAI core features are working!")
elif passed > 0:
print(f"\n⚡ {passed} features working! {total - passed} need attention.")
else:
print(f"\n⚠️ All tests failed. Check dependencies and setup.")
return passed == total
if __name__ == '__main__':
success = main()
sys.exit(0 if success else 1)