diff --git a/staff_dashboard.php b/staff_dashboard.php index 7cb0cda..5d4a48b 100644 --- a/staff_dashboard.php +++ b/staff_dashboard.php @@ -10,61 +10,54 @@ if (!isset($_SESSION['user_id']) || $_SESSION['user_role'] !== 'staff') { $pdo = db(); -// -- Analytics & Alerts -- -$total_residents = $pdo->query("SELECT count(*) FROM residents")->fetchColumn(); -$active_residents = $pdo->query("SELECT count(*) FROM residents WHERE status = 'Active'")->fetchColumn(); -$high_risk_residents = $pdo->query("SELECT count(*) FROM residents WHERE risk_level = 'High'")->fetchColumn(); - -$high_risk_alert_stmt = $pdo->query("SELECT id, first_name, last_name, program FROM residents WHERE risk_level = 'High' ORDER BY last_name, first_name LIMIT 5"); -$high_risk_alerts = $high_risk_alert_stmt->fetchAll(PDO::FETCH_ASSOC); - // -- Fetch Domains -- -$domain_stmt = $pdo->query("SELECT * FROM domains ORDER BY id"); -$domains = $domain_stmt->fetchAll(PDO::FETCH_ASSOC); +$domains = [ + ['id' => 'economic', 'name' => 'Economic Stability'], + ['id' => 'education', 'name' => 'Education Access & Quality'], + ['id' => 'healthcare', 'name' => 'Health Care Access & Quality'], + ['id' => 'neighborhood', 'name' => 'Neighborhood & Built Environment'], + ['id' => 'social', 'name' => 'Social & Community Context'], +]; // -- Get active domain -- -$active_domain_id = $_GET['domain_id'] ?? $domains[0]['id'] ?? 1; - -// -- Filtering -- -$program_filter = $_GET['program'] ?? ''; -$risk_filter = $_GET['risk_level'] ?? ''; -$status_filter = $_GET['status'] ?? ''; - -$base_sql = "SELECT r.id, r.first_name, r.last_name, r.status, r.program, r.risk_level, COALESCE(rdp.progress, 0) as progress - FROM residents r - LEFT JOIN resident_domain_progress rdp ON r.id = rdp.resident_id AND rdp.domain_id = ?"; - -$params = [$active_domain_id]; -$where_clauses = []; - -if ($program_filter) { - $where_clauses[] = "r.program = ?"; - $params[] = $program_filter; -} -if ($risk_filter) { - $where_clauses[] = "r.risk_level = ?"; - $params[] = $risk_filter; -} -if ($status_filter) { - $where_clauses[] = "r.status = ?"; - $params[] = $status_filter; +$active_domain_id = $_GET['domain'] ?? 'economic'; +$active_domain_name = ''; +foreach ($domains as $domain) { + if ($domain['id'] === $active_domain_id) { + $active_domain_name = $domain['name']; + break; + } } -$sql = $base_sql; -if (!empty($where_clauses)) { - $sql .= " WHERE " . implode(' AND ', $where_clauses); -} +// --- DATA FETCHING FOR THE ACTIVE DOMAIN --- -$sql .= " ORDER BY r.last_name, r.first_name"; +// KPI: Total Residents in this domain (placeholder) +$kpi_total_residents = $pdo->query("SELECT COUNT(DISTINCT resident_id) FROM risk_scores WHERE domain = '{$active_domain_id}'")->fetchColumn(); -$stmt = $pdo->prepare($sql); -$stmt->execute($params); -$residents = $stmt->fetchAll(PDO::FETCH_ASSOC); +// KPI: Average Risk Score +$kpi_avg_risk = $pdo->prepare("SELECT AVG(score_int) FROM risk_scores WHERE domain = ?"); +$kpi_avg_risk->execute([$active_domain_id]); +$kpi_avg_risk = round($kpi_avg_risk->fetchColumn() ?? 0); -// For filter dropdowns -$programs = $pdo->query("SELECT DISTINCT program FROM residents ORDER BY program")->fetchAll(PDO::FETCH_COLUMN); -$risk_levels = $pdo->query("SELECT DISTINCT risk_level FROM residents ORDER BY risk_level")->fetchAll(PDO::FETCH_COLUMN); -$statuses = $pdo->query("SELECT DISTINCT status FROM residents ORDER BY status")->fetchAll(PDO::FETCH_COLUMN); +// KPI: High-Risk Residents +$kpi_high_risk_count = $pdo->prepare("SELECT COUNT(*) FROM risk_scores WHERE domain = ? AND level = 'high'"); +$kpi_high_risk_count->execute([$active_domain_id]); +$kpi_high_risk_count = $kpi_high_risk_count->fetchColumn(); + +// Risk & Drivers: Top Drivers (Placeholder - requires JSON processing) +$top_drivers = [ + ['label' => 'Inconsistent employment', 'weight' => 0.8], + ['label' => 'High rent burden', 'weight' => 0.7], + ['label' => 'Lack of emergency funds', 'weight' => 0.6], +]; + +// Summary Table: Survey Responses +$survey_responses_stmt = $pdo->prepare("SELECT r.first_name, r.last_name, sr.question_label, sr.answer_value, sr.answered_at + FROM survey_responses sr + JOIN residents r ON sr.resident_id = r.id + WHERE sr.domain = ? ORDER BY sr.answered_at DESC LIMIT 10"); +$survey_responses_stmt->execute([$active_domain_id]); +$survey_responses = $survey_responses_stmt->fetchAll(PDO::FETCH_ASSOC); ?> @@ -96,206 +89,127 @@ $statuses = $pdo->query("SELECT DISTINCT status FROM residents ORDER BY status") -
+

Continuum Control Center

New Resident
- -
-
-
-
-
Total Residents
-

-
-
+
+
+
-
-
-
-
Active Residents
-

-
-
-
-
-
-
-
High Risk
-

-
-
-
-
+
+
+
+

Domain:

-
- -
-
-
- -
-
-
-
- -
- - - Export CSV - + +
+
+
+
+
Residents in Domain
+

+
-
-
- -
-
- - -
-
- - -
-
- - -
-
-
- Reset - -
-
+
+
+
+
+
Avg. Risk Score
+

%

+
- -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameProgramRisk LevelProgressStatusAction
- - - -
-
%
-
-
- - - - View -
No residents found matching your criteria.
+
+
+
+
+
High-Risk
+

+
-
-
-
- -
-
-
- High Risk Alerts -
-
- - - -
-
+ +
+ + + + +
+
+
Domain Timeline
+
+

[Placeholder for chronological stream of events: survey responses, notes, referrals, etc.]

+
+
+
+
Summary: Survey Responses
+
+
+ + + + + + + + + + + + + + + + + + +
ResidentQuestionAnswerDate
No survey responses for this domain yet.
+
+
+
+
+
+ +
- - \ No newline at end of file +