-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimport_sample_data.py
More file actions
104 lines (89 loc) · 3.92 KB
/
Copy pathimport_sample_data.py
File metadata and controls
104 lines (89 loc) · 3.92 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
import os
import json
from utils.db import import_json_to_database
def main():
"""Import neural profile sample data into database"""
# Check if database URL is available
if not os.environ.get('DATABASE_URL'):
print("ERROR: DATABASE_URL environment variable not set")
return
# Import the sample data
json_path = "data/neural_profile.json"
if not os.path.exists(json_path):
print(f"ERROR: Sample data file not found at {json_path}")
return
try:
print(f"Importing neural profile data from {json_path}...")
patient_id, message = import_json_to_database(json_path)
if patient_id:
print(f"SUCCESS: Data imported with patient ID: {patient_id}")
# Verify import using direct SQL queries instead of fetch_patient_data
print("\nVerifying patient data using direct SQL queries:")
# Use SQL to verify the import
from sqlalchemy import create_engine, text
engine = create_engine(os.environ.get('DATABASE_URL'))
# Check patient
with engine.connect() as conn:
patient_result = conn.execute(
text("SELECT display_name, record_date FROM patients WHERE id = :id"),
{"id": patient_id}
)
patient = patient_result.fetchone()
if patient:
print(f"Patient Name: {patient[0]}")
print(f"Record Date: {patient[1]}")
else:
print("Patient not found!")
# Check medications
med_result = conn.execute(
text("""
SELECT m.name, m.purpose FROM medications m
JOIN treatment_plans tp ON m.treatment_plan_id = tp.id
WHERE tp.patient_id = :patient_id
"""),
{"patient_id": patient_id}
)
medications = med_result.fetchall()
if medications:
print(f"\nMedications: {len(medications)}")
for med in medications:
print(f" - {med[0]}: {med[1]}")
else:
print("\nNo medications found")
# Check referrals
ref_result = conn.execute(
text("""
SELECT r.referral_type FROM referrals r
JOIN treatment_plans tp ON r.treatment_plan_id = tp.id
WHERE tp.patient_id = :patient_id
"""),
{"patient_id": patient_id}
)
referrals = ref_result.fetchall()
if referrals:
print(f"\nReferrals: {len(referrals)}")
for ref in referrals:
print(f" - {ref[0]}")
else:
print("\nNo referrals found")
# Check diagnostic tests
test_result = conn.execute(
text("""
SELECT test_type, test_results FROM diagnostic_tests
WHERE patient_id = :patient_id
"""),
{"patient_id": patient_id}
)
tests = test_result.fetchall()
if tests:
print(f"\nDiagnostic Tests: {len(tests)}")
for test in tests:
print(f" - {test[0]}: {test[1]}")
else:
print("\nNo diagnostic tests found")
else:
print(f"ERROR: {message}")
except Exception as e:
print(f"ERROR: Failed to import sample data: {e}")
if __name__ == "__main__":
main()