HH/templates/surveys/instance_list.html
2026-02-22 08:35:53 +03:00

264 lines
16 KiB
HTML

{% extends "layouts/base.html" %}
{% load i18n %}
{% load static %}
{% block title %}{% trans "Survey Instances" %} - PX360{% endblock %}
{% block content %}
<!-- Header -->
<header class="mb-6">
<div class="flex justify-between items-start">
<div>
<h1 class="text-2xl font-bold text-navy">{% trans "Survey Instances" %}</h1>
<p class="text-sm text-slate mt-1">{% trans "Monitor survey responses and scores" %}</p>
</div>
<div class="flex items-center gap-3">
<div class="relative group">
<i data-lucide="search" class="w-4 h-4 absolute left-3 top-1/2 -translate-y-1/2 text-slate group-focus-within:text-navy"></i>
<input type="text" id="searchInput" placeholder="{% trans 'Search MRN, Name...' %}"
class="pl-10 pr-4 py-2.5 bg-slate-100 border-transparent border focus:border-navy/30 focus:bg-white rounded-xl text-sm outline-none w-64 transition-all"
value="{{ filters.search|default:'' }}">
</div>
<button onclick="toggleFilters()" class="bg-white text-navy px-5 py-2.5 rounded-xl text-sm font-bold shadow-lg shadow-navy/20 hover:bg-light flex items-center gap-2 transition border border-slate-200">
<i data-lucide="filter" class="w-4 h-4"></i> {% trans "Filters" %}
</button>
</div>
</div>
</header>
<!-- Filters Panel -->
<div id="filtersPanel" class="hidden bg-slate-50 px-6 py-4 border-b border-slate-200 mb-6 rounded-2xl">
<form method="get" class="flex flex-wrap gap-4 items-end">
<div class="flex items-center gap-2">
<label class="text-xs font-bold text-slate uppercase">{% trans "Status" %}</label>
<select name="status" class="px-3 py-1.5 bg-white border border-slate-200 rounded-lg text-xs focus:outline-none focus:ring-2 focus:ring-navy">
<option value="">{% trans "All" %}</option>
<option value="sent" {% if filters.status == 'sent' %}selected{% endif %}>{% trans "Sent" %}</option>
<option value="completed" {% if filters.status == 'completed' %}selected{% endif %}>{% trans "Completed" %}</option>
<option value="pending" {% if filters.status == 'pending' %}selected{% endif %}>{% trans "Pending" %}</option>
</select>
</div>
<div class="flex items-center gap-2">
<label class="text-xs font-bold text-slate uppercase">{% trans "Type" %}</label>
<select name="survey_type" class="px-3 py-1.5 bg-white border border-slate-200 rounded-lg text-xs focus:outline-none focus:ring-2 focus:ring-navy">
<option value="">{% trans "All" %}</option>
<option value="stage" {% if filters.survey_type == 'stage' %}selected{% endif %}>{% trans "Journey Stage" %}</option>
<option value="complaint_resolution" {% if filters.survey_type == 'complaint_resolution' %}selected{% endif %}>{% trans "Complaint Resolution" %}</option>
<option value="general" {% if filters.survey_type == 'general' %}selected{% endif %}>{% trans "General" %}</option>
<option value="nps" {% if filters.survey_type == 'nps' %}selected{% endif %}>{% trans "NPS" %}</option>
</select>
</div>
<div class="flex items-center gap-2">
<label class="text-xs font-bold text-slate uppercase">{% trans "Hospital" %}</label>
<select name="hospital" class="px-3 py-1.5 bg-white border border-slate-200 rounded-lg text-xs focus:outline-none focus:ring-2 focus:ring-navy">
<option value="">{% trans "All" %}</option>
{% for hospital in hospitals %}
<option value="{{ hospital.id }}" {% if filters.hospital|add:"0" == hospital.id %}selected{% endif %}>
{{ hospital.name }}
</option>
{% endfor %}
</select>
</div>
<div class="flex items-center gap-2">
<button type="submit" class="px-4 py-1.5 bg-navy text-white rounded-lg text-xs font-bold hover:bg-blue transition">{% trans "Apply" %}</button>
<a href="{% url 'surveys:instance_list' %}" class="px-4 py-1.5 border border-slate-200 rounded-lg text-xs font-semibold text-slate hover:bg-white transition">{% trans "Clear" %}</a>
</div>
</form>
</div>
<!-- Surveys Table -->
<div class="bg-white rounded-2xl shadow-sm border border-slate-100 overflow-hidden">
<div class="flex justify-between items-center p-5 border-b border-slate-100">
<h3 class="font-bold text-navy flex items-center gap-2 text-sm">
<i data-lucide="table" class="w-4 h-4"></i>
{% trans "Survey List" %}
</h3>
<div class="text-xs text-slate font-medium">
{% trans "Showing" %} <span class="font-bold text-navy">{{ surveys.start_index|default:0 }}-{{ surveys.end_index|default:0 }}</span> {% trans "of" %} <span class="font-bold text-navy">{{ surveys.paginator.count|default:0 }}</span>
</div>
</div>
<div class="overflow-x-auto">
<table class="w-full">
<thead class="bg-slate-50 border-b border-slate-100">
<tr class="text-xs font-bold text-slate uppercase tracking-wider">
<th class="px-5 py-3 text-left">{% trans "Patient" %}</th>
<th class="px-5 py-3 text-left">{% trans "Survey Template" %}</th>
<th class="px-5 py-3 text-left">{% trans "Type" %}</th>
<th class="px-5 py-3 text-left">{% trans "Status" %}</th>
<th class="px-5 py-3 text-left">{% trans "Score" %}</th>
<th class="px-5 py-3 text-left">{% trans "Sent" %}</th>
<th class="px-5 py-3 text-left">{% trans "Completed" %}</th>
<th class="px-5 py-3 text-left">{% trans "Actions" %}</th>
</tr>
</thead>
<tbody class="text-sm divide-y divide-slate-100">
{% for survey in surveys.object_list %}
<tr class="hover:bg-light/30 transition cursor-pointer" onclick="window.location.href='{% url 'surveys:instance_detail' survey.id %}'">
<td class="px-5 py-4">
<div class="font-semibold text-navy">{{ survey.patient.get_full_name }}</div>
<div class="text-xs text-slate">MRN: {{ survey.patient.mrn }}</div>
</td>
<td class="px-5 py-4">
<div class="font-medium text-slate-800">{{ survey.survey_template.name }}</div>
{% if survey.survey_template.hospital %}
<div class="text-xs text-slate">{{ survey.survey_template.hospital.name }}</div>
{% endif %}
</td>
<td class="px-5 py-4">
<span class="px-2.5 py-1 rounded-lg text-xs font-bold bg-light text-navy">{{ survey.survey_template.get_survey_type_display }}</span>
</td>
<td class="px-5 py-4">
{% if survey.status == 'completed' %}
<span class="px-2.5 py-1 rounded-lg text-xs font-bold bg-green-100 text-green-600">{{ survey.get_status_display }}</span>
{% elif survey.status == 'sent' %}
<span class="px-2.5 py-1 rounded-lg text-xs font-bold bg-yellow-100 text-yellow-600">{{ survey.get_status_display }}</span>
{% elif survey.status == 'active' %}
<span class="px-2.5 py-1 rounded-lg text-xs font-bold bg-blue-100 text-blue-600">{{ survey.get_status_display }}</span>
{% elif survey.status == 'cancelled' %}
<span class="px-2.5 py-1 rounded-lg text-xs font-bold bg-red-100 text-red-600">{{ survey.get_status_display }}</span>
{% else %}
<span class="px-2.5 py-1 rounded-lg text-xs font-bold bg-slate-100 text-slate-600">{{ survey.get_status_display }}</span>
{% endif %}
</td>
<td class="px-5 py-4">
{% if survey.total_score %}
<div class="flex items-center gap-2">
<span class="{% if survey.is_negative %}text-red-500{% else %}text-green-500{% endif %} font-bold">
{{ survey.total_score|floatformat:1 }}/5.0
</span>
{% if survey.is_negative %}
<i data-lucide="alert-circle" class="w-4 h-4 text-red-500" title="{% trans 'Negative survey' %}"></i>
{% endif %}
</div>
{% else %}
<span class="text-slate text-xs">-</span>
{% endif %}
</td>
<td class="px-5 py-4 text-slate text-xs">
{% if survey.sent_at %}
{{ survey.sent_at|date:"M d, Y H:i" }}
{% else %}
-
{% endif %}
</td>
<td class="px-5 py-4 text-slate text-xs">
{% if survey.completed_at %}
{{ survey.completed_at|date:"M d, Y H:i" }}
{% else %}
-
{% endif %}
</td>
<td class="px-5 py-4" onclick="event.stopPropagation();">
<a href="{% url 'surveys:instance_detail' survey.id %}"
class="p-2 text-navy hover:bg-light rounded-lg transition inline-flex items-center gap-1"
title="{% trans 'View details' %}">
<i data-lucide="eye" class="w-4 h-4"></i>
</a>
</td>
</tr>
{% empty %}
<tr>
<td colspan="8" class="text-center py-12">
<i data-lucide="inbox" class="w-12 h-12 mx-auto mb-3 text-slate-300"></i>
<p class="text-slate font-medium">{% trans "No surveys found" %}</p>
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
<!-- Pagination -->
{% if surveys.has_other_pages %}
<div class="bg-slate-50 px-6 py-4 flex items-center justify-between border-t border-slate-100">
<div class="flex items-center gap-4">
<span class="text-xs text-slate font-medium">
{% trans "Showing" %} <span class="font-bold text-navy">{{ surveys.start_index }}-{{ surveys.end_index }}</span> {% trans "of" %} <span class="font-bold text-navy">{{ surveys.paginator.count }}</span> {% trans "entries" %}
</span>
<!-- Page Size Selector -->
<form method="get" class="flex items-center gap-2" id="pageSizeForm">
{% for key, value in request.GET.items %}
{% if key != 'page_size' and key != 'page' %}
<input type="hidden" name="{{ key }}" value="{{ value }}">
{% endif %}
{% endfor %}
<label class="text-xs text-slate">{% trans "Show" %}</label>
<select name="page_size" onchange="document.getElementById('pageSizeForm').submit()" class="px-2 py-1 bg-white border border-slate-200 rounded-lg text-xs focus:outline-none focus:ring-2 focus:ring-navy">
<option value="10" {% if surveys.paginator.per_page == 10 %}selected{% endif %}>10</option>
<option value="25" {% if surveys.paginator.per_page == 25 %}selected{% endif %}>25</option>
<option value="50" {% if surveys.paginator.per_page == 50 %}selected{% endif %}>50</option>
<option value="100" {% if surveys.paginator.per_page == 100 %}selected{% endif %}>100</option>
</select>
</form>
</div>
<div class="flex gap-1">
{% if surveys.has_previous %}
<a href="?page={{ surveys.previous_page_number }}{% for key, value in request.GET.items %}{% if key != 'page' %}&{{ key }}={{ value }}{% endif %}{% endfor %}"
class="w-8 h-8 flex items-center justify-center rounded-lg border border-slate-200 bg-white hover:bg-slate-50 transition">
<i data-lucide="chevron-left" class="w-4 h-4 text-slate"></i>
</a>
{% else %}
<span class="w-8 h-8 flex items-center justify-center rounded-lg border border-slate-200 bg-slate-100 text-slate-300 cursor-not-allowed">
<i data-lucide="chevron-left" class="w-4 h-4"></i>
</span>
{% endif %}
{% for num in surveys.paginator.page_range %}
{% if num == surveys.number %}
<span class="w-8 h-8 flex items-center justify-center rounded-lg bg-navy text-white text-xs font-bold">{{ num }}</span>
{% elif num > surveys.number|add:'-3' and num < surveys.number|add:'3' %}
<a href="?page={{ num }}{% for key, value in request.GET.items %}{% if key != 'page' %}&{{ key }}={{ value }}{% endif %}{% endfor %}"
class="w-8 h-8 flex items-center justify-center rounded-lg border border-slate-200 bg-white hover:bg-slate-50 text-xs font-bold text-slate transition">
{{ num }}
</a>
{% elif num == 1 or num == surveys.paginator.num_pages %}
<a href="?page={{ num }}{% for key, value in request.GET.items %}{% if key != 'page' %}&{{ key }}={{ value }}{% endif %}{% endfor %}"
class="w-8 h-8 flex items-center justify-center rounded-lg border border-slate-200 bg-white hover:bg-slate-50 text-xs font-bold text-slate transition">
{{ num }}
</a>
{% elif num == surveys.number|add:'-3' or num == surveys.number|add:'3' %}
<span class="w-8 h-8 flex items-center justify-center text-xs text-slate">...</span>
{% endif %}
{% endfor %}
{% if surveys.has_next %}
<a href="?page={{ surveys.next_page_number }}{% for key, value in request.GET.items %}{% if key != 'page' %}&{{ key }}={{ value }}{% endif %}{% endfor %}"
class="w-8 h-8 flex items-center justify-center rounded-lg border border-slate-200 bg-white hover:bg-slate-50 transition">
<i data-lucide="chevron-right" class="w-4 h-4 text-slate"></i>
</a>
{% else %}
<span class="w-8 h-8 flex items-center justify-center rounded-lg border border-slate-200 bg-slate-100 text-slate-300 cursor-not-allowed">
<i data-lucide="chevron-right" class="w-4 h-4"></i>
</span>
{% endif %}
</div>
</div>
{% endif %}
</div>
<script>
function toggleFilters() {
const filters = document.getElementById('filtersPanel');
filters.classList.toggle('hidden');
}
// Search functionality
document.getElementById('searchInput')?.addEventListener('keypress', function(e) {
if (e.key === 'Enter') {
const value = this.value;
const url = new URL(window.location.href);
if (value) {
url.searchParams.set('search', value);
} else {
url.searchParams.delete('search');
}
url.searchParams.delete('page');
window.location.href = url.toString();
}
});
</script>
{% endblock %}