272 lines
14 KiB
PHP
272 lines
14 KiB
PHP
<?php
|
|
session_start();
|
|
require_once 'db/config.php';
|
|
|
|
// Check if user is logged in and has the 'staff' role
|
|
if (!isset($_SESSION['user_id']) || $_SESSION['user_role'] !== 'staff') {
|
|
header("Location: index.php");
|
|
exit;
|
|
}
|
|
|
|
$pdo = db();
|
|
|
|
// -- Fetch Domains --
|
|
$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'] ?? 'economic';
|
|
$active_domain_name = '';
|
|
foreach ($domains as $domain) {
|
|
if ($domain['id'] === $active_domain_id) {
|
|
$active_domain_name = $domain['name'];
|
|
break;
|
|
}
|
|
}
|
|
|
|
// -- Get search term --
|
|
$search_term = $_GET['search'] ?? '';
|
|
|
|
// --- DATA FETCHING FOR THE ACTIVE DOMAIN ---
|
|
|
|
// 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_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_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)
|
|
$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_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 = ?";
|
|
$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);
|
|
|
|
?>
|
|
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Staff Dashboard | Continuum Nexus</title>
|
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
|
|
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css">
|
|
<link rel="stylesheet" href="assets/css/custom.css">
|
|
</head>
|
|
<body>
|
|
|
|
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
|
|
<div class="container-fluid">
|
|
<a class="navbar-brand" href="staff_dashboard.php">Continuum Nexus</a>
|
|
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
|
|
<span class="navbar-toggler-icon"></span>
|
|
</button>
|
|
<div class="collapse navbar-collapse" id="navbarNav">
|
|
<ul class="navbar-nav me-auto mb-2 mb-lg-0">
|
|
<li class="nav-item">
|
|
<a class="nav-link active" aria-current="page" href="staff_dashboard.php">Dashboard</a>
|
|
</li>
|
|
<li class="nav-item">
|
|
<a class="nav-link" href="location_view.php">Location View</a>
|
|
</li>
|
|
</ul>
|
|
<a href="logout.php" class="btn btn-outline-light">Logout</a>
|
|
</div>
|
|
</div>
|
|
</nav>
|
|
|
|
<div class="container-fluid mt-4">
|
|
<div class="d-flex justify-content-between align-items-center mb-4">
|
|
<h1 class="h2">Continuum Control Center</h1>
|
|
<a href="resident_intake.php" class="btn btn-primary-custom"><i class="bi bi-plus-circle me-2"></i>New Resident</a>
|
|
</div>
|
|
|
|
<!-- Search and Filter -->
|
|
<div class="card mb-4">
|
|
<div class="card-body">
|
|
<form action="staff_dashboard.php" method="get" class="row g-3 align-items-center">
|
|
<input type="hidden" name="domain" value="<?php echo htmlspecialchars($active_domain_id); ?>">
|
|
<div class="col-md-8">
|
|
<label for="search_term" class="visually-hidden">Search Residents</label>
|
|
<input type="text" class="form-control" id="search_term" name="search" placeholder="Search by name..." value="<?php echo htmlspecialchars($search_term); ?>">
|
|
</div>
|
|
<div class="col-md-4">
|
|
<button type="submit" class="btn btn-primary w-100">Search</button>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="card">
|
|
<div class="card-header">
|
|
<ul class="nav nav-tabs card-header-tabs" id="domainTabs" role="tablist">
|
|
<?php foreach ($domains as $domain): ?>
|
|
<li class="nav-item" role="presentation">
|
|
<a class="nav-link <?php echo ($domain['id'] === $active_domain_id) ? 'active' : ''; ?>" href="?domain=<?php echo $domain['id']; ?>" role="tab"><?php echo htmlspecialchars($domain['name']); ?></a>
|
|
</li>
|
|
<?php endforeach; ?>
|
|
</ul>
|
|
</div>
|
|
<div class="card-body">
|
|
<div class="tab-content" id="domainTabsContent">
|
|
<div class="tab-pane fade show active" role="tabpanel">
|
|
<h3 class="mb-4">Domain: <?php echo htmlspecialchars($active_domain_name); ?></h3>
|
|
|
|
<!-- Overview Cards (KPIs) -->
|
|
<div class="row mb-4">
|
|
<div class="col-md-4">
|
|
<div class="card text-center">
|
|
<div class="card-body">
|
|
<h5 class="card-title">Residents in Domain</h5>
|
|
<p class="card-text fs-4"><?php echo $kpi_total_residents; ?></p>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="col-md-4">
|
|
<div class="card text-center">
|
|
<div class="card-body">
|
|
<h5 class="card-title">Avg. Risk Score</h5>
|
|
<p class="card-text fs-4"><?php echo $kpi_avg_risk; ?>%</p>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="col-md-4">
|
|
<div class="card text-center text-danger">
|
|
<div class="card-body">
|
|
<h5 class="card-title">High-Risk</h5>
|
|
<p class="card-text fs-4"><?php echo $kpi_high_risk_count; ?></p>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="row">
|
|
<!-- Left Column: Risk/Drivers & Actions -->
|
|
<div class="col-lg-4">
|
|
<div class="card mb-4">
|
|
<div class="card-header">Risk & Drivers</div>
|
|
<div class="card-body">
|
|
<h5 class="card-title">Top Risk Drivers</h5>
|
|
<ul class="list-group list-group-flush">
|
|
<?php foreach ($top_drivers as $driver): ?>
|
|
<li class="list-group-item d-flex justify-content-between align-items-center">
|
|
<?php echo htmlspecialchars($driver['label']); ?>
|
|
<span class="badge bg-danger rounded-pill"><?php echo ($driver['weight'] * 100); ?>%</span>
|
|
</li>
|
|
<?php endforeach; ?>
|
|
</ul>
|
|
</div>
|
|
</div>
|
|
<div class="card">
|
|
<div class="card-header">Actions</div>
|
|
<div class="list-group list-group-flush">
|
|
<a href="#" class="list-group-item list-group-item-action"><i class="bi bi-ui-checks me-2"></i>Launch Follow-Up Survey</a>
|
|
<a href="create_referral.php" class="list-group-item list-group-item-action"><i class="bi bi-send me-2"></i>Create Referral</a>
|
|
<a href="add_case_note.php" class="list-group-item list-group-item-action"><i class="bi bi-journal-plus me-2"></i>Add Note</a>
|
|
<a href="#" class="list-group-item list-group-item-action"><i class="bi bi-check2-square me-2"></i>New Task</a>
|
|
<a href="#" class="list-group-item list-group-item-action text-success"><i class="bi bi-download me-2"></i>Export Domain Data (CSV)</a>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Right Column: Timeline & Summary Tables -->
|
|
<div class="col-lg-8">
|
|
<div class="card mb-4">
|
|
<div class="card-header">Domain Timeline</div>
|
|
<div class="card-body" style="height: 200px; overflow-y: auto;">
|
|
<p class="text-muted">[Placeholder for chronological stream of events: survey responses, notes, referrals, etc.]</p>
|
|
</div>
|
|
</div>
|
|
<div class="card">
|
|
<div class="card-header">Summary: Survey Responses</div>
|
|
<div class="card-body">
|
|
<div class="table-responsive">
|
|
<table class="table table-sm">
|
|
<thead>
|
|
<tr><th>Resident</th><th>Question</th><th>Answer</th><th>Date</th></tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php if (!empty($survey_responses)): ?>
|
|
<?php foreach ($survey_responses as $resp): ?>
|
|
<tr>
|
|
<td><?php echo htmlspecialchars($resp['first_name'] . ' ' . $resp['last_name']); ?></td>
|
|
<td><?php echo htmlspecialchars($resp['question_label']); ?></td>
|
|
<td><?php echo htmlspecialchars($resp['answer_value']); ?></td>
|
|
<td><?php echo date('M j, Y', strtotime($resp['answered_at'])); ?></td>
|
|
</tr>
|
|
<?php endforeach; ?>
|
|
<?php else: ?>
|
|
<tr><td colspan="4" class="text-center text-muted">No survey responses for this domain yet.</td></tr>
|
|
<?php endif; ?>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
|
|
</body>
|
|
</html>
|