-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_report_routes.py
More file actions
88 lines (79 loc) · 3.46 KB
/
Copy pathtest_report_routes.py
File metadata and controls
88 lines (79 loc) · 3.46 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
import httpx
import json
from datetime import datetime, timedelta
print('=== Testing Report Data Routes ===\n')
# Get today's date and date range for testing
today = datetime.utcnow()
from_date = (today - timedelta(days=3)).strftime("%Y-%m-%d")
to_date = today.strftime("%Y-%m-%d")
print(f'Report period: {from_date} to {to_date}\n')
# Test 1: GET /api/patients/{id}/report-data - Basic report
print('1. GET /api/patients/P001/report-data (report for P001)')
url = f'http://localhost:8000/api/patients/P001/report-data?from={from_date}&to={to_date}'
r = httpx.get(url)
print(f'Status: {r.status_code}')
if r.status_code == 200:
data = r.json()
print(f'Patient: {data["patient"]["name"]} (ID: {data["patient"]["id"]})')
print(f'Status: {data["patient"]["status"]}, Age: {data["patient"]["age"]}')
print(f'Period: {data["period"]["from"]} to {data["period"]["to"]}')
print(f'Devices: {len(data["devices"])}, Alerts: {len(data["alerts"])}')
print()
else:
print(f'Error: {r.json()}\n')
# Test 2: Verify vitals statistics
print('2. Vitals statistics for P001')
url = f'http://localhost:8000/api/patients/P001/report-data?from={from_date}&to={to_date}'
r = httpx.get(url)
if r.status_code == 200:
data = r.json()
vitals = data["vitals"]
print(f'Pulse Rate: avg={vitals["pulse_rate"]["avg"]:.1f} bpm, min={vitals["pulse_rate"]["min"]:.1f}, max={vitals["pulse_rate"]["max"]:.1f}')
print(f'SpO2: avg={vitals["spo2"]["avg"]:.1f}%, min={vitals["spo2"]["min"]:.1f}, max={vitals["spo2"]["max"]:.1f}')
print(f'Temperature: avg={vitals["temperature"]["avg"]:.1f}°C, min={vitals["temperature"]["min"]:.1f}, max={vitals["temperature"]["max"]:.1f}')
print(f'Pulse Rate data points: {len(vitals["pulse_rate"]["data"])}')
print()
else:
print(f'Error\n')
# Test 3: Report for different patient
print('3. GET /api/patients/P002/report-data (report for P002)')
url = f'http://localhost:8000/api/patients/P002/report-data?from={from_date}&to={to_date}'
r = httpx.get(url)
print(f'Status: {r.status_code}')
if r.status_code == 200:
data = r.json()
print(f'Patient: {data["patient"]["name"]} (ID: {data["patient"]["id"]})')
print(f'Devices: {len(data["devices"])}')
for device in data["devices"]:
print(f' - {device["id"]}: {device["name"]} (Status: {device["status"]})')
print()
else:
print(f'Error\n')
# Test 4: 404 for non-existent patient
print('4. GET /api/patients/P999/report-data (404 test)')
url = f'http://localhost:8000/api/patients/P999/report-data?from={from_date}&to={to_date}'
r = httpx.get(url)
print(f'Status: {r.status_code}')
if r.status_code == 404:
error = r.json()
print(f'Error message: {error["detail"]}')
print()
# Test 5: Invalid date format
print('5. GET with invalid date format (400 test)')
r = httpx.get('http://localhost:8000/api/patients/P001/report-data?from=04-29-2026&to=04-30-2026')
print(f'Status: {r.status_code}')
if r.status_code == 400:
error = r.json()
print(f'Error message: {error["detail"]}')
print()
# Test 6: Full report response format
print('6. Full report response structure:')
url = f'http://localhost:8000/api/patients/P001/report-data?from={from_date}&to={to_date}'
r = httpx.get(url)
if r.status_code == 200:
data = r.json()
print(json.dumps(data, indent=2)[:1000] + '...\n') # First 1000 chars
print('Required top-level fields:')
required_fields = ["patient", "period", "vitals", "alerts", "devices"]
for field in required_fields:
print(f' - {field}: {field in data}')