504 lines
24 KiB
HTML
504 lines
24 KiB
HTML
{% extends "base.html" %}
|
|
{% load static %}
|
|
|
|
{% block title %}Delete Operating Room - {{ object.room_number }} - {{ block.super }}{% endblock %}
|
|
|
|
{% block content %}
|
|
<div class="container-fluid">
|
|
<!-- Page Header -->
|
|
<div class="d-flex justify-content-between align-items-center mb-4">
|
|
<div>
|
|
<h1 class="h3 mb-1">
|
|
<i class="fas fa-exclamation-triangle text-danger me-2"></i>Delete Operating Room
|
|
</h1>
|
|
<nav aria-label="breadcrumb">
|
|
<ol class="breadcrumb mb-0">
|
|
<li class="breadcrumb-item"><a href="{% url 'core:dashboard' %}">Dashboard</a></li>
|
|
<li class="breadcrumb-item"><a href="{% url 'operating_theatre:dashboard' %}">Operating Theatre</a></li>
|
|
<li class="breadcrumb-item"><a href="{% url 'operating_theatre:operating_room_list' %}">Operating Rooms</a></li>
|
|
<li class="breadcrumb-item"><a href="{% url 'operating_theatre:operating_room_detail' object.pk %}">{{ object.room_number }}</a></li>
|
|
<li class="breadcrumb-item active">Delete</li>
|
|
</ol>
|
|
</nav>
|
|
</div>
|
|
<div class="btn-group">
|
|
<a href="{% url 'operating_theatre:operating_room_detail' object.pk %}" class="btn btn-outline-secondary">
|
|
<i class="fas fa-arrow-left me-2"></i>Back to Room
|
|
</a>
|
|
<a href="{% url 'operating_theatre:operating_room_list' %}" class="btn btn-outline-primary">
|
|
<i class="fas fa-list me-2"></i>All Rooms
|
|
</a>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="row justify-content-center">
|
|
<div class="col-lg-8">
|
|
<!-- Warning Alert -->
|
|
<div class="alert alert-danger mb-4">
|
|
<div class="d-flex align-items-center">
|
|
<i class="fas fa-exclamation-triangle fa-2x me-3"></i>
|
|
<div>
|
|
<h5 class="alert-heading mb-1">Critical Action Required</h5>
|
|
<p class="mb-0">You are about to permanently delete an operating room. This action cannot be undone and may have significant operational impact.</p>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Room Information -->
|
|
<div class="card mb-4">
|
|
<div class="card-header bg-light">
|
|
<h5 class="mb-0">
|
|
<i class="fas fa-procedures me-2"></i>Operating Room to be Deleted
|
|
</h5>
|
|
</div>
|
|
<div class="card-body">
|
|
<div class="row">
|
|
<div class="col-md-6">
|
|
<table class="table table-borderless">
|
|
<tr>
|
|
<td class="fw-semibold">Room Number:</td>
|
|
<td>{{ object.room_number }}</td>
|
|
</tr>
|
|
<tr>
|
|
<td class="fw-semibold">Room Name:</td>
|
|
<td>{{ object.room_name }}</td>
|
|
</tr>
|
|
<tr>
|
|
<td class="fw-semibold">Room Type:</td>
|
|
<td><span class="badge bg-info">{{ object.get_room_type_display }}</span></td>
|
|
</tr>
|
|
<tr>
|
|
<td class="fw-semibold">Current Status:</td>
|
|
<td>
|
|
<span class="badge bg-{% if object.status == 'AVAILABLE' %}success{% elif object.status == 'OCCUPIED' %}warning{% elif object.status == 'MAINTENANCE' %}danger{% else %}secondary{% endif %}">
|
|
{{ object.get_status_display }}
|
|
</span>
|
|
</td>
|
|
</tr>
|
|
</table>
|
|
</div>
|
|
<div class="col-md-6">
|
|
<table class="table table-borderless">
|
|
<tr>
|
|
<td class="fw-semibold">Floor:</td>
|
|
<td>Floor {{ object.floor_number }}</td>
|
|
</tr>
|
|
<tr>
|
|
<td class="fw-semibold">Building:</td>
|
|
<td>{{ object.building|default:"Not specified" }}</td>
|
|
</tr>
|
|
<tr>
|
|
<td class="fw-semibold">Active Status:</td>
|
|
<td>
|
|
{% if object.is_active %}
|
|
<span class="badge bg-success">Active</span>
|
|
{% else %}
|
|
<span class="badge bg-secondary">Inactive</span>
|
|
{% endif %}
|
|
</td>
|
|
</tr>
|
|
<tr>
|
|
<td class="fw-semibold">Emergency Cases:</td>
|
|
<td>
|
|
{% if object.accepts_emergency %}
|
|
<span class="badge bg-warning">Accepts</span>
|
|
{% else %}
|
|
<span class="badge bg-secondary">Does not accept</span>
|
|
{% endif %}
|
|
</td>
|
|
</tr>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Impact Assessment -->
|
|
<div class="card mb-4">
|
|
<div class="card-header bg-warning text-dark">
|
|
<h5 class="mb-0">
|
|
<i class="fas fa-exclamation-circle me-2"></i>Impact Assessment
|
|
</h5>
|
|
</div>
|
|
<div class="card-body">
|
|
<!-- Current Case Check -->
|
|
{% if object.current_case %}
|
|
<div class="alert alert-danger">
|
|
<h6 class="alert-heading">
|
|
<i class="fas fa-ban me-2"></i>Cannot Delete - Active Case
|
|
</h6>
|
|
<p class="mb-2">This operating room currently has an active surgical case:</p>
|
|
<ul class="mb-2">
|
|
<li><strong>Case:</strong> {{ object.current_case.case_number }}</li>
|
|
<li><strong>Patient:</strong> {{ object.current_case.patient.get_full_name }}</li>
|
|
<li><strong>Procedure:</strong> {{ object.current_case.primary_procedure }}</li>
|
|
<li><strong>Status:</strong> {{ object.current_case.get_status_display }}</li>
|
|
</ul>
|
|
<p class="mb-0">Please complete or transfer the current case before attempting to delete this room.</p>
|
|
</div>
|
|
{% endif %}
|
|
|
|
<!-- Future Bookings -->
|
|
{% if future_blocks %}
|
|
<div class="alert alert-warning">
|
|
<h6 class="alert-heading">
|
|
<i class="fas fa-calendar-alt me-2"></i>Future Bookings Affected
|
|
</h6>
|
|
<p class="mb-2">This room has {{ future_blocks|length }} future booking(s) that will be affected:</p>
|
|
<div class="table-responsive">
|
|
<table class="table table-sm">
|
|
<thead>
|
|
<tr>
|
|
<th>Date</th>
|
|
<th>Time</th>
|
|
<th>Surgeon</th>
|
|
<th>Service</th>
|
|
<th>Cases</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
{% for block in future_blocks %}
|
|
<tr>
|
|
<td>{{ block.date }}</td>
|
|
<td>{{ block.start_time }} - {{ block.end_time }}</td>
|
|
<td>{{ block.primary_surgeon.get_full_name }}</td>
|
|
<td>{{ block.get_service_display }}</td>
|
|
<td>{{ block.surgical_cases.count }}</td>
|
|
</tr>
|
|
{% endfor %}
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
{% endif %}
|
|
|
|
<!-- Historical Data -->
|
|
<div class="row">
|
|
<div class="col-md-4">
|
|
<div class="card bg-light">
|
|
<div class="card-body text-center">
|
|
<div class="h4 text-primary">{{ historical_stats.total_cases|default:0 }}</div>
|
|
<div class="small text-muted">Total Cases Performed</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="col-md-4">
|
|
<div class="card bg-light">
|
|
<div class="card-body text-center">
|
|
<div class="h4 text-info">{{ historical_stats.total_hours|default:0 }}</div>
|
|
<div class="small text-muted">Total Operating Hours</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="col-md-4">
|
|
<div class="card bg-light">
|
|
<div class="card-body text-center">
|
|
<div class="h4 text-success">{{ historical_stats.utilization|default:0 }}%</div>
|
|
<div class="small text-muted">Average Utilization</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Data Handling Options -->
|
|
<div class="card mb-4">
|
|
<div class="card-header bg-info text-white">
|
|
<h5 class="mb-0">
|
|
<i class="fas fa-database me-2"></i>Data Handling Options
|
|
</h5>
|
|
</div>
|
|
<div class="card-body">
|
|
<p class="mb-3">Choose how to handle the data associated with this operating room:</p>
|
|
|
|
<form method="post" id="deleteForm">
|
|
{% csrf_token %}
|
|
|
|
<div class="mb-3">
|
|
<label class="form-label fw-semibold">Future Bookings:</label>
|
|
<div class="form-check">
|
|
<input class="form-check-input" type="radio" name="future_bookings" id="cancel_bookings" value="cancel" checked>
|
|
<label class="form-check-label" for="cancel_bookings">
|
|
Cancel all future bookings (recommended)
|
|
</label>
|
|
</div>
|
|
<div class="form-check">
|
|
<input class="form-check-input" type="radio" name="future_bookings" id="transfer_bookings" value="transfer">
|
|
<label class="form-check-label" for="transfer_bookings">
|
|
Transfer bookings to another room
|
|
</label>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="mb-3" id="transferRoomSelection" style="display: none;">
|
|
<label for="transfer_room" class="form-label">Transfer to Room:</label>
|
|
<select class="form-select" id="transfer_room" name="transfer_room">
|
|
<option value="">Select a room...</option>
|
|
{% for room in available_rooms %}
|
|
<option value="{{ room.pk }}">{{ room.room_number }} - {{ room.room_name }} ({{ room.get_room_type_display }})</option>
|
|
{% endfor %}
|
|
</select>
|
|
</div>
|
|
|
|
<div class="mb-3">
|
|
<label class="form-label fw-semibold">Historical Data:</label>
|
|
<div class="form-check">
|
|
<input class="form-check-input" type="radio" name="historical_data" id="archive_data" value="archive" checked>
|
|
<label class="form-check-label" for="archive_data">
|
|
Archive historical data (recommended)
|
|
</label>
|
|
</div>
|
|
<div class="form-check">
|
|
<input class="form-check-input" type="radio" name="historical_data" id="delete_data" value="delete">
|
|
<label class="form-check-label" for="delete_data">
|
|
Permanently delete all historical data
|
|
</label>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Confirmation Requirements -->
|
|
<div class="card bg-light mb-3">
|
|
<div class="card-body">
|
|
<h6 class="card-title">Confirmation Requirements</h6>
|
|
<div class="form-check mb-2">
|
|
<input class="form-check-input" type="checkbox" id="confirm_impact" required>
|
|
<label class="form-check-label" for="confirm_impact">
|
|
I understand the impact of deleting this operating room
|
|
</label>
|
|
</div>
|
|
<div class="form-check mb-2">
|
|
<input class="form-check-input" type="checkbox" id="confirm_authority" required>
|
|
<label class="form-check-label" for="confirm_authority">
|
|
I have the authority to delete this operating room
|
|
</label>
|
|
</div>
|
|
<div class="form-check mb-3">
|
|
<input class="form-check-input" type="checkbox" id="confirm_irreversible" required>
|
|
<label class="form-check-label" for="confirm_irreversible">
|
|
I understand this action is irreversible
|
|
</label>
|
|
</div>
|
|
|
|
<div class="mb-3">
|
|
<label for="deletion_reason" class="form-label">Reason for Deletion <span class="text-danger">*</span></label>
|
|
<textarea class="form-control" id="deletion_reason" name="deletion_reason" rows="3" required
|
|
placeholder="Please provide a detailed reason for deleting this operating room..."></textarea>
|
|
</div>
|
|
|
|
<div class="mb-3">
|
|
<label for="confirmation_text" class="form-label">
|
|
Type "DELETE {{ object.room_number }}" to confirm <span class="text-danger">*</span>
|
|
</label>
|
|
<input type="text" class="form-control" id="confirmation_text" name="confirmation_text" required
|
|
placeholder="DELETE {{ object.room_number }}">
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Action Buttons -->
|
|
<div class="d-flex justify-content-between">
|
|
<div>
|
|
<a href="{% url 'operating_theatre:operating_room_detail' object.pk %}" class="btn btn-outline-secondary">
|
|
<i class="fas fa-arrow-left me-2"></i>Cancel
|
|
</a>
|
|
</div>
|
|
<div>
|
|
{% if not object.current_case %}
|
|
<button type="submit" class="btn btn-danger" id="deleteButton" disabled>
|
|
<i class="fas fa-trash me-2"></i>Delete Operating Room
|
|
</button>
|
|
{% else %}
|
|
<button type="button" class="btn btn-danger" disabled title="Cannot delete room with active case">
|
|
<i class="fas fa-ban me-2"></i>Cannot Delete
|
|
</button>
|
|
{% endif %}
|
|
</div>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Alternative Actions -->
|
|
<div class="card">
|
|
<div class="card-header bg-success text-white">
|
|
<h5 class="mb-0">
|
|
<i class="fas fa-lightbulb me-2"></i>Alternative Actions
|
|
</h5>
|
|
</div>
|
|
<div class="card-body">
|
|
<p class="mb-3">Consider these alternatives to deletion:</p>
|
|
<div class="row">
|
|
<div class="col-md-6">
|
|
<div class="d-grid">
|
|
<a href="{% url 'operating_theatre:operating_room_update' object.pk %}" class="btn btn-outline-primary">
|
|
<i class="fas fa-edit me-2"></i>Edit Room Configuration
|
|
</a>
|
|
</div>
|
|
<div class="small text-muted mt-2">Modify room settings instead of deleting</div>
|
|
</div>
|
|
<div class="col-md-6">
|
|
<div class="d-grid">
|
|
<button type="button" class="btn btn-outline-warning" onclick="deactivateRoom()">
|
|
<i class="fas fa-pause me-2"></i>Deactivate Room
|
|
</button>
|
|
</div>
|
|
<div class="small text-muted mt-2">Temporarily disable without deleting</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<script>
|
|
// Form validation and confirmation
|
|
document.addEventListener('DOMContentLoaded', function() {
|
|
const form = document.getElementById('deleteForm');
|
|
const deleteButton = document.getElementById('deleteButton');
|
|
const confirmationText = document.getElementById('confirmation_text');
|
|
const checkboxes = document.querySelectorAll('input[type="checkbox"][required]');
|
|
const transferBookings = document.getElementById('transfer_bookings');
|
|
const transferRoomSelection = document.getElementById('transferRoomSelection');
|
|
|
|
// Show/hide transfer room selection
|
|
document.querySelectorAll('input[name="future_bookings"]').forEach(radio => {
|
|
radio.addEventListener('change', function() {
|
|
if (this.value === 'transfer') {
|
|
transferRoomSelection.style.display = 'block';
|
|
document.getElementById('transfer_room').required = true;
|
|
} else {
|
|
transferRoomSelection.style.display = 'none';
|
|
document.getElementById('transfer_room').required = false;
|
|
}
|
|
});
|
|
});
|
|
|
|
// Validation function
|
|
function validateForm() {
|
|
const allChecked = Array.from(checkboxes).every(cb => cb.checked);
|
|
const confirmationValid = confirmationText.value === 'DELETE {{ object.room_number }}';
|
|
const reasonProvided = document.getElementById('deletion_reason').value.trim().length > 0;
|
|
|
|
let transferRoomValid = true;
|
|
if (transferBookings.checked) {
|
|
transferRoomValid = document.getElementById('transfer_room').value !== '';
|
|
}
|
|
|
|
deleteButton.disabled = !(allChecked && confirmationValid && reasonProvided && transferRoomValid);
|
|
}
|
|
|
|
// Add event listeners
|
|
checkboxes.forEach(cb => cb.addEventListener('change', validateForm));
|
|
confirmationText.addEventListener('input', validateForm);
|
|
document.getElementById('deletion_reason').addEventListener('input', validateForm);
|
|
document.getElementById('transfer_room').addEventListener('change', validateForm);
|
|
|
|
// Form submission confirmation
|
|
form.addEventListener('submit', function(e) {
|
|
e.preventDefault();
|
|
|
|
const confirmation = confirm(
|
|
'Are you absolutely sure you want to delete this operating room?\n\n' +
|
|
'This action will:\n' +
|
|
'- Permanently remove the room from the system\n' +
|
|
'- Handle future bookings as specified\n' +
|
|
'- Archive or delete historical data as selected\n\n' +
|
|
'This action CANNOT be undone!'
|
|
);
|
|
|
|
if (confirmation) {
|
|
// Show loading state
|
|
deleteButton.innerHTML = '<i class="fas fa-spinner fa-spin me-2"></i>Deleting...';
|
|
deleteButton.disabled = true;
|
|
|
|
// Submit form
|
|
this.submit();
|
|
}
|
|
});
|
|
});
|
|
|
|
// Alternative action functions
|
|
function deactivateRoom() {
|
|
if (confirm('Deactivate this operating room instead of deleting it?')) {
|
|
fetch(`{% url 'operating_theatre:update_room_status' object.pk %}`, {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
'X-CSRFToken': document.querySelector('[name=csrfmiddlewaretoken]').value
|
|
},
|
|
body: JSON.stringify({
|
|
status: 'CLOSED',
|
|
is_active: false
|
|
})
|
|
})
|
|
.then(response => response.json())
|
|
.then(data => {
|
|
if (data.success) {
|
|
alert('Operating room has been deactivated successfully.');
|
|
window.location.href = "{% url 'operating_theatre:operating_room_detail' object.pk %}";
|
|
} else {
|
|
alert('Error deactivating room: ' + data.error);
|
|
}
|
|
})
|
|
.catch(error => {
|
|
console.error('Error:', error);
|
|
alert('Error deactivating room');
|
|
});
|
|
}
|
|
}
|
|
|
|
// Prevent accidental navigation
|
|
window.addEventListener('beforeunload', function(e) {
|
|
const confirmationText = document.getElementById('confirmation_text').value;
|
|
if (confirmationText && confirmationText !== 'DELETE {{ object.room_number }}') {
|
|
e.preventDefault();
|
|
e.returnValue = '';
|
|
}
|
|
});
|
|
</script>
|
|
|
|
<style>
|
|
.alert-heading {
|
|
color: inherit;
|
|
}
|
|
|
|
.table-borderless td {
|
|
padding: 0.5rem 0;
|
|
}
|
|
|
|
.form-check-input:checked {
|
|
background-color: #dc3545;
|
|
border-color: #dc3545;
|
|
}
|
|
|
|
.btn-danger:disabled {
|
|
opacity: 0.65;
|
|
cursor: not-allowed;
|
|
}
|
|
|
|
.card-header h5 {
|
|
margin-bottom: 0;
|
|
}
|
|
|
|
@media (max-width: 768px) {
|
|
.d-flex.justify-content-between {
|
|
flex-direction: column;
|
|
gap: 1rem;
|
|
}
|
|
|
|
.btn-group {
|
|
display: flex;
|
|
flex-direction: column;
|
|
gap: 0.5rem;
|
|
}
|
|
|
|
.col-md-6, .col-md-4 {
|
|
margin-bottom: 1rem;
|
|
}
|
|
}
|
|
</style>
|
|
{% endblock %}
|
|
|