diff --git a/location_view.php b/location_view.php new file mode 100644 index 0000000..0dd8810 --- /dev/null +++ b/location_view.php @@ -0,0 +1,93 @@ +query(" + SELECT state, county, city, COUNT(id) as resident_count + FROM residents + GROUP BY state, county, city + ORDER BY state, county, city +")->fetchAll(PDO::FETCH_ASSOC); + +?> + + + + + + Resident Location View | Continuum Nexus + + + + + + + + +
+

Resident Counts by Location

+ +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + +
StateCountyCityResident Count
No location data available.
+
+
+
+
+ + + + diff --git a/partner_dashboard.php b/partner_dashboard.php index 321f51d..bf1689c 100644 --- a/partner_dashboard.php +++ b/partner_dashboard.php @@ -20,33 +20,41 @@ if (!$partner) { } else { $partner_id = $partner['id']; - // -- Performance Summary -- - $stmt = $pdo->prepare("SELECT COUNT(*) FROM residents WHERE partner_id = ?"); - $stmt->execute([$partner_id]); - $total_assigned = $stmt->fetchColumn(); - - $stmt = $pdo->prepare("SELECT COUNT(*) FROM residents WHERE partner_id = ? AND status = 'Active'"); - $stmt->execute([$partner_id]); - $active_assigned = $stmt->fetchColumn(); - - $stmt = $pdo->prepare("SELECT COUNT(*) FROM referrals WHERE partner_id = ?"); - $stmt->execute([$partner_id]); - $total_referrals = $stmt->fetchColumn(); - - // -- Resident Data -- + // -- Fetch assigned residents and their domain scores -- $resident_sql = " SELECT - r.id, r.first_name, r.last_name, r.program, r.risk_level, r.status, - (SELECT COUNT(*) FROM action_plans ap WHERE ap.resident_id = r.id AND ap.status != 'Completed') as open_plans_count, - (SELECT note FROM case_notes WHERE resident_id = r.id ORDER BY created_at DESC LIMIT 1) as last_note, - (SELECT created_at FROM case_notes WHERE resident_id = r.id ORDER BY created_at DESC LIMIT 1) as last_note_date + r.id, r.first_name, r.last_name, r.program, r.status, + GROUP_CONCAT(rs.domain, ':', rs.score_int, ':', rs.level SEPARATOR ';') as domain_data FROM residents r + LEFT JOIN risk_scores rs ON r.id = rs.resident_id WHERE r.partner_id = ? + GROUP BY r.id ORDER BY r.last_name, r.first_name "; $resident_stmt = $pdo->prepare($resident_sql); $resident_stmt->execute([$partner_id]); - $residents = $resident_stmt->fetchAll(PDO::FETCH_ASSOC); + $residents_raw = $resident_stmt->fetchAll(PDO::FETCH_ASSOC); + + $residents = array_map(function($res) { + $res['domains'] = []; + if ($res['domain_data']) { + $domains_list = explode(';', $res['domain_data']); + foreach ($domains_list as $d) { + list($domain, $score, $level) = explode(':', $d); + $res['domains'][$domain] = ['score' => $score, 'level' => $level]; + } + } + unset($res['domain_data']); + return $res; + }, $residents_raw); + + // -- Performance Summary -- + $total_assigned = count($residents); + $active_assigned = count(array_filter($residents, fn($r) => $r['status'] === 'Active')); + + $stmt = $pdo->prepare("SELECT COUNT(*) FROM referrals WHERE partner_id = ?"); + $stmt->execute([$partner_id]); + $total_referrals = $stmt->fetchColumn(); // -- Referral Data -- $referral_sql = " @@ -160,8 +168,8 @@ if (!$partner) { - -

Assigned Resident Health Cards

+ +

Assigned Resident Overview

@@ -169,43 +177,36 @@ if (!$partner) {
-
+
-
-
- - +
+

- Program: + Program:
+ Status: +

-

- Status: +

Domain Risk Levels:
+
'EC', 'education' => 'ED', 'healthcare' => 'HC', 'neighborhood' => 'NB', 'social' => 'SO']; + foreach ($domain_map as $domain_id => $abbr): + $level = $resident['domains'][$domain_id]['level'] ?? 'N/A'; + $level_class = 'bg-secondary'; + if ($level === 'High') $level_class = 'bg-danger'; + if ($level === 'Moderate') $level_class = 'bg-warning text-dark'; + if ($level === 'Low') $level_class = 'bg-success'; ?> - -

-
- Open Action Plans - +
+ +
+
-
Last Note
-

- - "..." -
on - - No notes recorded yet. - -

+
+
diff --git a/resident_dashboard.php b/resident_dashboard.php index 11562ac..1ff8768 100644 --- a/resident_dashboard.php +++ b/resident_dashboard.php @@ -2,44 +2,48 @@ session_start(); require_once 'db/config.php'; -if (!isset($_SESSION['user_id']) || $_SESSION['role'] !== 'resident') { +// Check if user is logged in and has the 'resident' role +if (!isset($_SESSION['user_id']) || $_SESSION['user_role'] !== 'resident') { header("Location: index.php"); - exit(); + exit; } $resident_id = $_SESSION['user_id']; +$pdo = db(); -// Fetch resident's name -$stmt = $pdo->prepare("SELECT name FROM residents WHERE id = ?"); +// Fetch resident's first name +$stmt = $pdo->prepare("SELECT first_name FROM residents WHERE id = ?"); $stmt->execute([$resident_id]); -$resident = $stmt->fetch(); +$resident_name = $stmt->fetchColumn(); -// Fetch resident's domain scores -$stmt = $pdo->prepare(" - SELECT d.name, rds.score - FROM resident_domain_scores rds - JOIN domains d ON rds.domain_id = d.id - WHERE rds.resident_id = ? - ORDER BY d.id +// Fetch resident's domain risk scores, levels, and drivers +$risk_scores_stmt = $pdo->prepare(" + SELECT domain, score_int, level, drivers + FROM risk_scores + WHERE resident_id = ? + ORDER BY domain "); -$stmt->execute([$resident_id]); -$domain_scores = $stmt->fetchAll(); +$risk_scores_stmt->execute([$resident_id]); +$risk_scores = $risk_scores_stmt->fetchAll(PDO::FETCH_ASSOC | PDO::FETCH_GROUP); // Fetch resident's action plans -$stmt = $pdo->prepare(" - SELECT ap.id, ap.title, ap.description, ap.status, d.name as domain_name +$action_plans_stmt = $pdo->prepare(" + SELECT ap.id, ap.title, ap.status, ap.domain FROM action_plans ap - JOIN domains d ON ap.domain_id = d.id WHERE ap.resident_id = ? ORDER BY ap.created_at DESC "); -$stmt->execute([$resident_id]); -$action_plans = $stmt->fetchAll(); +$action_plans_stmt->execute([$resident_id]); +$action_plans = $action_plans_stmt->fetchAll(PDO::FETCH_ASSOC); -// Fetch resident's case manager for messaging -$stmt = $pdo->prepare("SELECT u.id, u.name, u.email FROM users u JOIN residents r ON u.id = r.case_manager_id WHERE r.id = ?"); -$stmt->execute([$resident_id]); -$case_manager = $stmt->fetch(); +// Domain names mapping +$domains = [ + 'economic' => 'Economic Stability', + 'education' => 'Education Access & Quality', + 'healthcare' => 'Health Care Access & Quality', + 'neighborhood' => 'Neighborhood & Built Environment', + 'social' => 'Social & Community Context', +]; ?> @@ -47,87 +51,91 @@ $case_manager = $stmt->fetch(); - Resident Dashboard - Continuum Nexus - - + Resident Dashboard | Continuum Nexus + + -
-

Welcome, !

+

Welcome, !

+

Your Domain Overview

-
-

Your Progress Across the 5 Domains

-
- -
-
-
-
-
-
- % -
-
-
-
+ $domain_name): ?> + +
+
+
+
+
- +
+
+

/100

+

Risk Score

+
+ +
Key Factors:
+
    + +
  • -
  • + +
+ +

No specific risk factors identified.

+ +
+
-
+
-

Your Active Action Plans

+

Your Action Plans

- +
- + - + - - - + + @@ -138,36 +146,8 @@ $case_manager = $stmt->fetch(); -
-
-
-
-

Upcoming Appointments

-
-
- -

Your appointment calendar will be displayed here.

- View Calendar -
-
-
-
-
-
-

Resource Library

-
-
-

Access helpful documents, links, and guides.

- Browse Resources -
-
-
-
- - - - + diff --git a/staff_dashboard.php b/staff_dashboard.php index 5d4a48b..ecda992 100644 --- a/staff_dashboard.php +++ b/staff_dashboard.php @@ -29,19 +29,48 @@ foreach ($domains as $domain) { } } +// -- Get search term -- +$search_term = $_GET['search'] ?? ''; + // --- DATA FETCHING FOR THE ACTIVE DOMAIN --- -// 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(); +// Base query for residents +$resident_filter_sql = 'FROM residents r WHERE 1=1'; +$params = []; +if (!empty($search_term)) { + $resident_filter_sql .= ' AND (r.first_name LIKE ? OR r.last_name LIKE ?)'; + $params[] = "%$search_term%"; + $params[] = "%$search_term%"; +} + +// KPI: Total Residents in this domain +$kpi_total_residents_sql = "SELECT COUNT(DISTINCT r.id) $resident_filter_sql"; +$kpi_stmt = $pdo->prepare($kpi_total_residents_sql); +$kpi_stmt->execute($params); +$kpi_total_residents = $kpi_stmt->fetchColumn(); // 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_sql = "SELECT AVG(rs.score_int) FROM risk_scores rs JOIN residents r ON rs.resident_id = r.id WHERE rs.domain = ?"; +$avg_risk_params = [$active_domain_id]; +if (!empty($search_term)) { + $kpi_avg_risk_sql .= ' AND (r.first_name LIKE ? OR r.last_name LIKE ?)'; + $avg_risk_params[] = "%$search_term%"; + $avg_risk_params[] = "%$search_term%"; +} +$kpi_avg_risk = $pdo->prepare($kpi_avg_risk_sql); +$kpi_avg_risk->execute($avg_risk_params); $kpi_avg_risk = round($kpi_avg_risk->fetchColumn() ?? 0); // 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_sql = "SELECT COUNT(rs.id) FROM risk_scores rs JOIN residents r ON rs.resident_id = r.id WHERE rs.domain = ? AND rs.level = 'high'"; +$high_risk_params = [$active_domain_id]; +if (!empty($search_term)) { + $kpi_high_risk_sql .= ' AND (r.first_name LIKE ? OR r.last_name LIKE ?)'; + $high_risk_params[] = "%$search_term%"; + $high_risk_params[] = "%$search_term%"; +} +$kpi_high_risk_count = $pdo->prepare($kpi_high_risk_sql); +$kpi_high_risk_count->execute($high_risk_params); $kpi_high_risk_count = $kpi_high_risk_count->fetchColumn(); // Risk & Drivers: Top Drivers (Placeholder - requires JSON processing) @@ -52,11 +81,19 @@ $top_drivers = [ ]; // 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 +$survey_sql = "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]); + WHERE sr.domain = ?"; +$survey_params = [$active_domain_id]; +if (!empty($search_term)) { + $survey_sql .= ' AND (r.first_name LIKE ? OR r.last_name LIKE ?)'; + $survey_params[] = "%$search_term%"; + $survey_params[] = "%$search_term%"; +} +$survey_sql .= ' ORDER BY sr.answered_at DESC LIMIT 10'; +$survey_responses_stmt = $pdo->prepare($survey_sql); +$survey_responses_stmt->execute($survey_params); $survey_responses = $survey_responses_stmt->fetchAll(PDO::FETCH_ASSOC); ?> @@ -83,6 +120,9 @@ $survey_responses = $survey_responses_stmt->fetchAll(PDO::FETCH_ASSOC); + Logout @@ -95,6 +135,22 @@ $survey_responses = $survey_responses_stmt->fetchAll(PDO::FETCH_ASSOC); New Resident + +
+
+
+ +
+ + +
+
+ +
+ +
+
+
Title Domain StatusAction
You have no active action plans.You have no active action plans.
- View Details + + View