stanlee47 Claude Sonnet 4.6 commited on
Commit
6e723dc
·
1 Parent(s): 03cf1a4

Fix column name errors breaking patients list + detail page

Browse files

- database.py get_all_users: ended_at IS NULL → is_active = 1
- database.py get_dashboard_stats: same fix
- admin_patient_detail.html: use is_active/start_time/avg_confidence
(correct column names from depression_episodes table)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

database.py CHANGED
@@ -869,7 +869,7 @@ class Database:
869
 
870
  # Check for active ML-detected risk episode
871
  active_ep = self.conn.execute(
872
- "SELECT COUNT(*) FROM depression_episodes WHERE user_id = ? AND ended_at IS NULL",
873
  (r[0],)
874
  ).fetchone()[0]
875
 
@@ -1022,7 +1022,7 @@ class Database:
1022
 
1023
  # Active ML-detected risk episodes
1024
  active_episodes = self.conn.execute(
1025
- "SELECT COUNT(*) FROM depression_episodes WHERE ended_at IS NULL"
1026
  ).fetchone()[0]
1027
 
1028
  # Wearable readings in last 24 hours
 
869
 
870
  # Check for active ML-detected risk episode
871
  active_ep = self.conn.execute(
872
+ "SELECT COUNT(*) FROM depression_episodes WHERE user_id = ? AND is_active = 1",
873
  (r[0],)
874
  ).fetchone()[0]
875
 
 
1022
 
1023
  # Active ML-detected risk episodes
1024
  active_episodes = self.conn.execute(
1025
+ "SELECT COUNT(*) FROM depression_episodes WHERE is_active = 1"
1026
  ).fetchone()[0]
1027
 
1028
  # Wearable readings in last 24 hours
templates/admin_patient_detail.html CHANGED
@@ -419,10 +419,10 @@
419
 
420
  // Risk badge in header
421
  const depStats = patientData.depression_stats || {};
422
- const activeEp = patientData.recent_episodes?.find(e => !e.ended_at);
423
  const badge = document.getElementById('risk-badge');
424
  if (activeEp) {
425
- const peakRisk = activeEp.peak_risk_level ?? activeEp.risk_level ?? 1;
426
  if (peakRisk >= 2) {
427
  badge.textContent = '⚠ HIGH STRESS';
428
  badge.className = 'px-2 py-0.5 text-xs font-semibold rounded-full bg-red-100 text-red-700';
@@ -777,11 +777,11 @@
777
  const data = resp.data || [];
778
 
779
  // Show active episode banner
780
- const activeEp = patientData.recent_episodes?.find(e => !e.ended_at);
781
- if (activeEp) {
782
- const startedAt = AdminPanel.formatTimeAgo(activeEp.started_at);
783
- const riskLabel = activeEp.peak_risk_level >= 2 ? 'High Stress' : 'Mild Stress';
784
- const confPct = activeEp.peak_confidence ? (activeEp.peak_confidence * 100).toFixed(0) + '%' : 'N/A';
785
  document.getElementById('episode-detail').textContent =
786
  `Started ${startedAt} · Peak: ${riskLabel} (${confPct} confidence)`;
787
  document.getElementById('active-episode-banner').classList.remove('hidden');
 
419
 
420
  // Risk badge in header
421
  const depStats = patientData.depression_stats || {};
422
+ const activeEp = patientData.recent_episodes?.find(e => e.is_active);
423
  const badge = document.getElementById('risk-badge');
424
  if (activeEp) {
425
+ const peakRisk = activeEp.peak_risk_level ?? 1;
426
  if (peakRisk >= 2) {
427
  badge.textContent = '⚠ HIGH STRESS';
428
  badge.className = 'px-2 py-0.5 text-xs font-semibold rounded-full bg-red-100 text-red-700';
 
777
  const data = resp.data || [];
778
 
779
  // Show active episode banner
780
+ const activeEp2 = patientData.recent_episodes?.find(e => e.is_active);
781
+ if (activeEp2) {
782
+ const startedAt = AdminPanel.formatTimeAgo(activeEp2.start_time);
783
+ const riskLabel = activeEp2.peak_risk_level >= 2 ? 'High Stress' : 'Mild Stress';
784
+ const confPct = activeEp2.avg_confidence ? (activeEp2.avg_confidence * 100).toFixed(0) + '%' : 'N/A';
785
  document.getElementById('episode-detail').textContent =
786
  `Started ${startedAt} · Peak: ${riskLabel} (${confPct} confidence)`;
787
  document.getElementById('active-episode-banner').classList.remove('hidden');