439 lines
21 KiB
HTML
439 lines
21 KiB
HTML
{% extends "base.html" %}
|
|
{% load static %}
|
|
|
|
{% block title %}Delete Ward - {{ ward.name }} - {{ 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 Ward
|
|
</h1>
|
|
<nav aria-label="breadcrumb">
|
|
<ol class="breadcrumb mb-0">
|
|
<li class="breadcrumb-item"><a href="{% url 'inpatients:dashboard' %}">Inpatients</a></li>
|
|
<li class="breadcrumb-item"><a href="{% url 'inpatients:ward_list' %}">Wards</a></li>
|
|
<li class="breadcrumb-item"><a href="{% url 'inpatients:ward_detail' ward.pk %}">{{ ward.name }}</a></li>
|
|
<li class="breadcrumb-item active">Delete</li>
|
|
</ol>
|
|
</nav>
|
|
</div>
|
|
<div class="btn-group">
|
|
<a href="{% url 'inpatients:ward_detail' ward.pk %}" class="btn btn-outline-secondary">
|
|
<i class="fas fa-arrow-left me-2"></i>Back to Ward
|
|
</a>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="row justify-content-center">
|
|
<div class="col-lg-8">
|
|
<!-- Warning Card -->
|
|
<div class="card border-danger mb-4">
|
|
<div class="card-header bg-danger text-white">
|
|
<h5 class="mb-0">
|
|
<i class="fas fa-exclamation-triangle me-2"></i>Confirm Ward Deletion
|
|
</h5>
|
|
</div>
|
|
<div class="card-body">
|
|
<div class="alert alert-danger" role="alert">
|
|
<h6 class="alert-heading">
|
|
<i class="fas fa-warning me-2"></i>Warning: This action cannot be undone!
|
|
</h6>
|
|
<p class="mb-0">
|
|
You are about to permanently delete the ward <strong>"{{ ward.name }}"</strong>.
|
|
This will affect all associated data including beds, admissions, and patient records.
|
|
</p>
|
|
</div>
|
|
|
|
<!-- Ward Information -->
|
|
<div class="card bg-light mb-4">
|
|
<div class="card-body">
|
|
<h6 class="card-title">Ward Details</h6>
|
|
<div class="row">
|
|
<div class="col-md-6">
|
|
<dl class="row mb-0">
|
|
<dt class="col-sm-4">Ward ID:</dt>
|
|
<dd class="col-sm-8">{{ ward.ward_id }}</dd>
|
|
|
|
<dt class="col-sm-4">Name:</dt>
|
|
<dd class="col-sm-8">{{ ward.name }}</dd>
|
|
|
|
<dt class="col-sm-4">Type:</dt>
|
|
<dd class="col-sm-8">{{ ward.get_ward_type_display }}</dd>
|
|
</dl>
|
|
</div>
|
|
<div class="col-md-6">
|
|
<dl class="row mb-0">
|
|
<dt class="col-sm-4">Specialty:</dt>
|
|
<dd class="col-sm-8">{{ ward.get_specialty_display }}</dd>
|
|
|
|
<dt class="col-sm-4">Total Beds:</dt>
|
|
<dd class="col-sm-8">{{ ward.total_beds }}</dd>
|
|
|
|
<dt class="col-sm-4">Status:</dt>
|
|
<dd class="col-sm-8">
|
|
<span class="badge bg-{% if ward.is_active %}success{% else %}secondary{% endif %}">
|
|
{% if ward.is_active %}Active{% else %}Inactive{% endif %}
|
|
</span>
|
|
</dd>
|
|
</dl>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Impact Assessment -->
|
|
<div class="card border-warning mb-4">
|
|
<div class="card-header bg-warning text-dark">
|
|
<h6 class="mb-0">
|
|
<i class="fas fa-exclamation-circle me-2"></i>Deletion Impact Assessment
|
|
</h6>
|
|
</div>
|
|
<div class="card-body">
|
|
<div class="row">
|
|
<div class="col-md-6">
|
|
<h6 class="text-danger">Will be permanently deleted:</h6>
|
|
<ul class="list-group list-group-flush">
|
|
<li class="list-group-item d-flex justify-content-between align-items-center px-0">
|
|
<span><i class="fas fa-bed me-2"></i>Beds</span>
|
|
<span class="badge bg-danger rounded-pill">{{ ward.beds.count }}</span>
|
|
</li>
|
|
<li class="list-group-item d-flex justify-content-between align-items-center px-0">
|
|
<span><i class="fas fa-user-injured me-2"></i>Current Admissions</span>
|
|
<span class="badge bg-danger rounded-pill">{{ current_admissions.count }}</span>
|
|
</li>
|
|
<li class="list-group-item d-flex justify-content-between align-items-center px-0">
|
|
<span><i class="fas fa-history me-2"></i>Historical Admissions</span>
|
|
<span class="badge bg-warning rounded-pill">{{ historical_admissions.count }}</span>
|
|
</li>
|
|
<li class="list-group-item d-flex justify-content-between align-items-center px-0">
|
|
<span><i class="fas fa-exchange-alt me-2"></i>Transfer Records</span>
|
|
<span class="badge bg-warning rounded-pill">{{ transfer_records.count }}</span>
|
|
</li>
|
|
</ul>
|
|
</div>
|
|
<div class="col-md-6">
|
|
<h6 class="text-info">Will be preserved:</h6>
|
|
<ul class="list-group list-group-flush">
|
|
<li class="list-group-item d-flex justify-content-between align-items-center px-0">
|
|
<span><i class="fas fa-user me-2"></i>Patient Records</span>
|
|
<span class="badge bg-success rounded-pill">Preserved</span>
|
|
</li>
|
|
<li class="list-group-item d-flex justify-content-between align-items-center px-0">
|
|
<span><i class="fas fa-file-medical me-2"></i>Medical Records</span>
|
|
<span class="badge bg-success rounded-pill">Preserved</span>
|
|
</li>
|
|
<li class="list-group-item d-flex justify-content-between align-items-center px-0">
|
|
<span><i class="fas fa-receipt me-2"></i>Billing Records</span>
|
|
<span class="badge bg-success rounded-pill">Preserved</span>
|
|
</li>
|
|
<li class="list-group-item d-flex justify-content-between align-items-center px-0">
|
|
<span><i class="fas fa-users me-2"></i>Staff Assignments</span>
|
|
<span class="badge bg-info rounded-pill">Reassigned</span>
|
|
</li>
|
|
</ul>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Deletion Restrictions -->
|
|
{% if current_admissions.count > 0 %}
|
|
<div class="alert alert-danger" role="alert">
|
|
<h6 class="alert-heading">
|
|
<i class="fas fa-ban me-2"></i>Deletion Blocked
|
|
</h6>
|
|
<p class="mb-2">
|
|
This ward cannot be deleted because it has <strong>{{ current_admissions.count }}</strong>
|
|
active patient admission(s). You must:
|
|
</p>
|
|
<ol class="mb-0">
|
|
<li>Transfer all current patients to other wards</li>
|
|
<li>Complete all pending discharges</li>
|
|
<li>Ensure no active admissions remain</li>
|
|
</ol>
|
|
</div>
|
|
|
|
<div class="card border-info">
|
|
<div class="card-header bg-info text-white">
|
|
<h6 class="mb-0">Current Patients</h6>
|
|
</div>
|
|
<div class="card-body p-0">
|
|
<div class="table-responsive">
|
|
<table class="table table-sm mb-0">
|
|
<thead class="table-light">
|
|
<tr>
|
|
<th>Bed</th>
|
|
<th>Patient</th>
|
|
<th>Admission Date</th>
|
|
<th>Action Required</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
{% for admission in current_admissions %}
|
|
<tr>
|
|
<td>{{ admission.bed.bed_number }}</td>
|
|
<td>{{ admission.patient.get_full_name }}</td>
|
|
<td>{{ admission.admission_date|date:"M d, Y" }}</td>
|
|
<td>
|
|
<a href="{% url 'inpatients:transfer_patient' admission.pk %}"
|
|
class="btn btn-sm btn-outline-primary">
|
|
<i class="fas fa-exchange-alt me-1"></i>Transfer
|
|
</a>
|
|
</td>
|
|
</tr>
|
|
{% endfor %}
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
{% endif %}
|
|
|
|
<!-- Data Handling Options -->
|
|
{% if current_admissions.count == 0 %}
|
|
<div class="card border-info mb-4">
|
|
<div class="card-header bg-info text-white">
|
|
<h6 class="mb-0">
|
|
<i class="fas fa-database me-2"></i>Data Handling Options
|
|
</h6>
|
|
</div>
|
|
<div class="card-body">
|
|
<div class="form-check mb-3">
|
|
<input class="form-check-input" type="radio" name="data_handling" id="archive_data" value="archive" checked>
|
|
<label class="form-check-label" for="archive_data">
|
|
<strong>Archive historical data</strong>
|
|
<br><small class="text-muted">Move historical admissions and transfers to archive (recommended)</small>
|
|
</label>
|
|
</div>
|
|
<div class="form-check mb-3">
|
|
<input class="form-check-input" type="radio" name="data_handling" id="export_data" value="export">
|
|
<label class="form-check-label" for="export_data">
|
|
<strong>Export data before deletion</strong>
|
|
<br><small class="text-muted">Generate export file of all ward data for backup</small>
|
|
</label>
|
|
</div>
|
|
<div class="form-check">
|
|
<input class="form-check-input" type="radio" name="data_handling" id="delete_all" value="delete">
|
|
<label class="form-check-label" for="delete_all">
|
|
<strong>Permanently delete all data</strong>
|
|
<br><small class="text-muted text-danger">This cannot be undone - use with extreme caution</small>
|
|
</label>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Confirmation Requirements -->
|
|
<div class="card border-dark">
|
|
<div class="card-header bg-dark text-white">
|
|
<h6 class="mb-0">
|
|
<i class="fas fa-shield-alt me-2"></i>Confirmation Required
|
|
</h6>
|
|
</div>
|
|
<div class="card-body">
|
|
<div class="mb-3">
|
|
<label for="confirmation_text" class="form-label">
|
|
Type <code>DELETE {{ ward.name }}</code> to confirm:
|
|
</label>
|
|
<input type="text" class="form-control" id="confirmation_text"
|
|
placeholder="DELETE {{ ward.name }}" autocomplete="off">
|
|
</div>
|
|
|
|
<div class="form-check mb-3">
|
|
<input class="form-check-input" type="checkbox" id="understand_consequences">
|
|
<label class="form-check-label" for="understand_consequences">
|
|
I understand that this action cannot be undone and will permanently delete the ward and associated data
|
|
</label>
|
|
</div>
|
|
|
|
<div class="form-check">
|
|
<input class="form-check-input" type="checkbox" id="have_backup">
|
|
<label class="form-check-label" for="have_backup">
|
|
I confirm that I have appropriate backups or have exported necessary data
|
|
</label>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
{% endif %}
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Action Buttons -->
|
|
<div class="card">
|
|
<div class="card-body">
|
|
<div class="d-flex justify-content-between align-items-center">
|
|
<div>
|
|
<a href="{% url 'inpatients:ward_detail' ward.pk %}" class="btn btn-secondary">
|
|
<i class="fas fa-arrow-left me-2"></i>Cancel
|
|
</a>
|
|
</div>
|
|
<div>
|
|
{% if current_admissions.count == 0 %}
|
|
<form method="post" class="d-inline" id="deleteForm">
|
|
{% csrf_token %}
|
|
<input type="hidden" name="data_handling" id="selected_data_handling" value="archive">
|
|
<button type="submit" class="btn btn-danger" id="deleteButton" disabled>
|
|
<i class="fas fa-trash me-2"></i>Delete Ward Permanently
|
|
</button>
|
|
</form>
|
|
{% else %}
|
|
<button type="button" class="btn btn-danger" disabled title="Cannot delete ward with active admissions">
|
|
<i class="fas fa-ban me-2"></i>Deletion Blocked
|
|
</button>
|
|
{% endif %}
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<script>
|
|
// Ward deletion confirmation functionality
|
|
document.addEventListener('DOMContentLoaded', function() {
|
|
const confirmationText = document.getElementById('confirmation_text');
|
|
const understandCheckbox = document.getElementById('understand_consequences');
|
|
const backupCheckbox = document.getElementById('have_backup');
|
|
const deleteButton = document.getElementById('deleteButton');
|
|
const dataHandlingRadios = document.querySelectorAll('input[name="data_handling"]');
|
|
const selectedDataHandling = document.getElementById('selected_data_handling');
|
|
|
|
if (confirmationText && deleteButton) {
|
|
function checkFormValidity() {
|
|
const textValid = confirmationText.value === 'DELETE {{ ward.name }}';
|
|
const understandChecked = understandCheckbox.checked;
|
|
const backupChecked = backupCheckbox.checked;
|
|
|
|
deleteButton.disabled = !(textValid && understandChecked && backupChecked);
|
|
|
|
if (textValid) {
|
|
confirmationText.classList.remove('is-invalid');
|
|
confirmationText.classList.add('is-valid');
|
|
} else {
|
|
confirmationText.classList.remove('is-valid');
|
|
if (confirmationText.value.length > 0) {
|
|
confirmationText.classList.add('is-invalid');
|
|
}
|
|
}
|
|
}
|
|
|
|
// Event listeners
|
|
confirmationText.addEventListener('input', checkFormValidity);
|
|
understandCheckbox.addEventListener('change', checkFormValidity);
|
|
backupCheckbox.addEventListener('change', checkFormValidity);
|
|
|
|
// Data handling selection
|
|
dataHandlingRadios.forEach(radio => {
|
|
radio.addEventListener('change', function() {
|
|
selectedDataHandling.value = this.value;
|
|
});
|
|
});
|
|
|
|
// Form submission confirmation
|
|
document.getElementById('deleteForm').addEventListener('submit', function(e) {
|
|
if (!confirm('Are you absolutely sure you want to delete this ward? This action cannot be undone.')) {
|
|
e.preventDefault();
|
|
return false;
|
|
}
|
|
|
|
// Show loading state
|
|
deleteButton.innerHTML = '<i class="fas fa-spinner fa-spin me-2"></i>Deleting...';
|
|
deleteButton.disabled = true;
|
|
});
|
|
}
|
|
});
|
|
|
|
// Export data function
|
|
function exportWardData() {
|
|
const form = document.createElement('form');
|
|
form.method = 'POST';
|
|
form.action = '{% url "inpatients:export_ward_data" ward.pk %}';
|
|
|
|
const csrfToken = document.createElement('input');
|
|
csrfToken.type = 'hidden';
|
|
csrfToken.name = 'csrfmiddlewaretoken';
|
|
csrfToken.value = document.querySelector('[name=csrfmiddlewaretoken]').value;
|
|
|
|
form.appendChild(csrfToken);
|
|
document.body.appendChild(form);
|
|
form.submit();
|
|
document.body.removeChild(form);
|
|
}
|
|
</script>
|
|
|
|
<style>
|
|
.is-valid {
|
|
border-color: #28a745;
|
|
}
|
|
|
|
.is-invalid {
|
|
border-color: #dc3545;
|
|
}
|
|
|
|
.alert-heading {
|
|
margin-bottom: 0.5rem;
|
|
}
|
|
|
|
.list-group-item {
|
|
border: none;
|
|
padding: 0.5rem 0;
|
|
}
|
|
|
|
.list-group-item:first-child {
|
|
border-top: none;
|
|
}
|
|
|
|
.list-group-item:last-child {
|
|
border-bottom: none;
|
|
}
|
|
|
|
.form-check-label {
|
|
cursor: pointer;
|
|
}
|
|
|
|
.badge {
|
|
font-size: 0.75em;
|
|
}
|
|
|
|
code {
|
|
color: #e83e8c;
|
|
background-color: #f8f9fa;
|
|
padding: 0.2rem 0.4rem;
|
|
border-radius: 0.25rem;
|
|
}
|
|
|
|
.card-header.bg-danger,
|
|
.card-header.bg-warning,
|
|
.card-header.bg-info,
|
|
.card-header.bg-dark {
|
|
border-bottom: 1px solid rgba(255, 255, 255, 0.2);
|
|
}
|
|
|
|
.table-sm th,
|
|
.table-sm td {
|
|
padding: 0.5rem;
|
|
}
|
|
|
|
@media (max-width: 768px) {
|
|
.d-flex.justify-content-between {
|
|
flex-direction: column;
|
|
gap: 1rem;
|
|
}
|
|
|
|
.btn-group {
|
|
display: flex;
|
|
flex-direction: column;
|
|
gap: 0.5rem;
|
|
}
|
|
|
|
.row .col-md-6 {
|
|
margin-bottom: 1rem;
|
|
}
|
|
}
|
|
</style>
|
|
{% endblock %}
|
|
|