2025-08-12 13:33:25 +03:00

306 lines
16 KiB
HTML

{% extends 'base.html' %}
{% load static %}
{% block title %}Surgical Cases{% endblock %}
{% block content %}
<div class="container-fluid">
<div class="row">
<div class="col-12">
<div class="d-flex justify-content-between align-items-center mb-4">
<h1 class="h3 mb-0">Surgical Cases</h1>
<a href="{% url 'operating_theatre:surgical_case_create' %}" class="btn btn-primary">
<i class="fas fa-plus"></i> New Case
</a>
</div>
</div>
</div>
<!-- Search and Filter Form -->
<div class="row mb-4">
<div class="col-12">
<div class="card">
<div class="card-body">
<form method="get" class="row">
<div class="col-md-3">
<input type="text" name="search" class="form-control"
placeholder="Search cases..." value="{{ request.GET.search }}">
</div>
<div class="col-md-2">
<select name="status" class="form-control">
<option value="">All Statuses</option>
{% for value, label in statuses %}
<option value="{{ value }}" {% if request.GET.status == value %}selected{% endif %}>
{{ label }}
</option>
{% endfor %}
</select>
</div>
<div class="col-md-2">
<select name="priority" class="form-control">
<option value="">All Priorities</option>
{% for value, label in priorities %}
<option value="{{ value }}" {% if request.GET.priority == value %}selected{% endif %}>
{{ label }}
</option>
{% endfor %}
</select>
</div>
<div class="col-md-2">
<select name="room" class="form-control">
<option value="">All Rooms</option>
{% for room in operating_rooms %}
<option value="{{ room.pk }}" {% if request.GET.room == room.pk|stringformat:"s" %}selected{% endif %}>
{{ room.room_number }}
</option>
{% endfor %}
</select>
</div>
<div class="col-md-3">
<button type="submit" class="btn btn-outline-primary">
<i class="fas fa-search"></i> Search
</button>
<a href="{% url 'operating_theatre:surgical_case_list' %}" class="btn btn-outline-secondary">
<i class="fas fa-times"></i> Clear
</a>
</div>
</form>
</div>
</div>
</div>
</div>
<!-- Cases Table -->
<div class="row">
<div class="col-12">
<div class="card">
<div class="card-body">
{% if surgical_cases %}
<div class="table-responsive">
<table class="table table-striped">
<thead>
<tr>
<th>Patient</th>
<th>Procedure</th>
<th>Surgeon</th>
<th>Room</th>
<th>Scheduled</th>
<th>Priority</th>
<th>Status</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
{% for case in surgical_cases %}
<tr>
<td>
<a href="{% url 'operating_theatre:surgical_case_detail' case.pk %}">
<strong>{{ case.patient.first_name }} {{ case.patient.last_name }}</strong>
</a>
<br><small class="text-muted">MRN: {{ case.patient.mrn }}</small>
</td>
<td>
{{ case.procedure_name }}
{% if case.procedure_code %}
<br><small class="text-muted">{{ case.procedure_code }}</small>
{% endif %}
</td>
<td>
{% if case.primary_surgeon %}
{{ case.primary_surgeon.first_name }} {{ case.primary_surgeon.last_name }}
{% else %}
<span class="text-muted">N/A</span>
{% endif %}
</td>
<td>
{% if case.operating_room %}
{{ case.operating_room.room_number }}
{% else %}
<span class="text-muted">TBD</span>
{% endif %}
</td>
<td>
{{ case.scheduled_start_time|date:"M d, Y H:i" }}
{% if case.estimated_duration_minutes %}
<br><small class="text-muted">Est: {{ case.estimated_duration_minutes }}min</small>
{% endif %}
</td>
<td>
<span class="badge badge-{% if case.priority == 'EMERGENCY' %}danger{% elif case.priority == 'URGENT' %}warning{% elif case.priority == 'HIGH' %}info{% else %}secondary{% endif %}">
{{ case.get_priority_display }}
</span>
</td>
<td>
<span class="badge badge-{% if case.status == 'SCHEDULED' %}info{% elif case.status == 'IN_PROGRESS' %}warning{% elif case.status == 'COMPLETED' %}success{% elif case.status == 'CANCELLED' %}danger{% else %}secondary{% endif %}">
{{ case.get_status_display }}
</span>
</td>
<td>
<div class="btn-group btn-group-sm" role="group">
<a href="{% url 'operating_theatre:surgical_case_detail' case.pk %}"
class="btn btn-outline-info" title="View Details">
<i class="fas fa-eye"></i>
</a>
{% if case.status in 'SCHEDULED,IN_PROGRESS' %}
<a href="{% url 'operating_theatre:surgical_case_update' case.pk %}"
class="btn btn-outline-primary" title="Update">
<i class="fas fa-edit"></i>
</a>
{% endif %}
{% if case.status == 'SCHEDULED' %}
<button type="button" class="btn btn-outline-success"
title="Start Case" data-toggle="modal"
data-target="#startCaseModal{{ case.pk }}">
<i class="fas fa-play"></i>
</button>
{% elif case.status == 'IN_PROGRESS' %}
<button type="button" class="btn btn-outline-warning"
title="Complete Case" data-toggle="modal"
data-target="#completeCaseModal{{ case.pk }}">
<i class="fas fa-check"></i>
</button>
{% endif %}
</div>
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
<!-- Pagination -->
{% if is_paginated %}
<nav aria-label="Page navigation">
<ul class="pagination justify-content-center">
{% if page_obj.has_previous %}
<li class="page-item">
<a class="page-link" href="?page=1{% for key, value in request.GET.items %}{% if key != 'page' %}&{{ key }}={{ value }}{% endif %}{% endfor %}">First</a>
</li>
<li class="page-item">
<a class="page-link" href="?page={{ page_obj.previous_page_number }}{% for key, value in request.GET.items %}{% if key != 'page' %}&{{ key }}={{ value }}{% endif %}{% endfor %}">Previous</a>
</li>
{% endif %}
<li class="page-item active">
<span class="page-link">
Page {{ page_obj.number }} of {{ page_obj.paginator.num_pages }}
</span>
</li>
{% if page_obj.has_next %}
<li class="page-item">
<a class="page-link" href="?page={{ page_obj.next_page_number }}{% for key, value in request.GET.items %}{% if key != 'page' %}&{{ key }}={{ value }}{% endif %}{% endfor %}">Next</a>
</li>
<li class="page-item">
<a class="page-link" href="?page={{ page_obj.paginator.num_pages }}{% for key, value in request.GET.items %}{% if key != 'page' %}&{{ key }}={{ value }}{% endif %}{% endfor %}">Last</a>
</li>
{% endif %}
</ul>
</nav>
{% endif %}
{% else %}
<div class="text-center py-4">
<i class="fas fa-user-md fa-3x text-muted mb-3"></i>
<h5 class="text-muted">No surgical cases found</h5>
<p class="text-muted">Start by creating your first surgical case.</p>
<a href="{% url 'operating_theatre:surgical_case_create' %}" class="btn btn-primary">
<i class="fas fa-plus"></i> Create First Case
</a>
</div>
{% endif %}
</div>
</div>
</div>
</div>
</div>
<!-- Start Case Modals -->
{% for case in surgical_cases %}
{% if case.status == 'SCHEDULED' %}
<div class="modal fade" id="startCaseModal{{ case.pk }}" tabindex="-1" role="dialog">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Start Surgical Case</h5>
<button type="button" class="close" data-dismiss="modal">
<span>&times;</span>
</button>
</div>
<form method="post" action="{% url 'operating_theatre:start_case' case.pk %}">
{% csrf_token %}
<div class="modal-body">
<div class="form-group">
<label>Patient:</label>
<p><strong>{{ case.patient.first_name }} {{ case.patient.last_name }}</strong></p>
</div>
<div class="form-group">
<label>Procedure:</label>
<p>{{ case.procedure_name }}</p>
</div>
<div class="form-group">
<label>Operating Room:</label>
<p>{{ case.operating_room.room_number }}</p>
</div>
<div class="alert alert-info">
<i class="fas fa-info-circle"></i>
This will mark the case as "In Progress" and update the room status.
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button>
<button type="submit" class="btn btn-success">Start Case</button>
</div>
</form>
</div>
</div>
</div>
{% endif %}
{% endfor %}
<!-- Complete Case Modals -->
{% for case in surgical_cases %}
{% if case.status == 'IN_PROGRESS' %}
<div class="modal fade" id="completeCaseModal{{ case.pk }}" tabindex="-1" role="dialog">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Complete Surgical Case</h5>
<button type="button" class="close" data-dismiss="modal">
<span>&times;</span>
</button>
</div>
<form method="post" action="{% url 'operating_theatre:complete_case' case.pk %}">
{% csrf_token %}
<div class="modal-body">
<div class="form-group">
<label>Patient:</label>
<p><strong>{{ case.patient.first_name }} {{ case.patient.last_name }}</strong></p>
</div>
<div class="form-group">
<label>Procedure:</label>
<p>{{ case.procedure_name }}</p>
</div>
{% if case.actual_start_time %}
<div class="form-group">
<label>Started:</label>
<p>{{ case.actual_start_time|date:"M d, Y H:i" }}</p>
</div>
{% endif %}
<div class="alert alert-warning">
<i class="fas fa-exclamation-triangle"></i>
This will mark the case as "Completed" and set the room to "Cleaning" status.
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button>
<button type="submit" class="btn btn-warning">Complete Case</button>
</div>
</form>
</div>
</div>
</div>
{% endif %}
{% endfor %}
{% endblock %}