hospital-management/templates/quality/audits/audit_confirm_delete.html
2025-08-12 13:33:25 +03:00

465 lines
23 KiB
HTML

{% extends "base.html" %}
{% load static %}
{% block title %}Delete Audit - Quality Management{% endblock %}
{% block content %}
<!-- BEGIN breadcrumb -->
<ol class="breadcrumb float-xl-end">
<li class="breadcrumb-item"><a href="{% url 'core:dashboard' %}">Dashboard</a></li>
<li class="breadcrumb-item"><a href="{% url 'quality:dashboard' %}">Quality</a></li>
<li class="breadcrumb-item"><a href="{% url 'quality:audit_list' %}">Audits</a></li>
<li class="breadcrumb-item"><a href="{% url 'quality:audit_detail' audit.pk %}">{{ audit.title|truncatechars:30 }}</a></li>
<li class="breadcrumb-item active">Delete</li>
</ol>
<!-- END breadcrumb -->
<!-- BEGIN page-header -->
<h1 class="page-header">
Delete Audit
<small>Confirm audit deletion</small>
</h1>
<!-- END page-header -->
<!-- BEGIN row -->
<div class="row">
<div class="col-xl-8">
<!-- Deletion Confirmation -->
<div class="panel panel-inverse">
<div class="panel-heading">
<h4 class="panel-title">
<i class="fa fa-exclamation-triangle text-warning me-2"></i>
Confirm Audit Deletion
</h4>
</div>
<div class="panel-body">
<div class="alert alert-danger">
<h5><i class="fa fa-exclamation-triangle me-2"></i>Warning</h5>
<p class="mb-0">
You are about to permanently delete this audit. This action cannot be undone and will remove all associated data including findings, corrective actions, and audit history.
</p>
</div>
<!-- Audit Information -->
<div class="card border-danger mb-4">
<div class="card-header bg-danger text-white">
<h6 class="mb-0">Audit to be Deleted</h6>
</div>
<div class="card-body">
<div class="row">
<div class="col-md-6">
<table class="table table-borderless mb-0">
<tr>
<td width="120"><strong>Title:</strong></td>
<td>{{ audit.title }}</td>
</tr>
<tr>
<td><strong>Type:</strong></td>
<td>
{% if audit.audit_type == 'internal' %}
<span class="badge bg-primary">Internal</span>
{% elif audit.audit_type == 'external' %}
<span class="badge bg-info">External</span>
{% elif audit.audit_type == 'regulatory' %}
<span class="badge bg-warning text-dark">Regulatory</span>
{% elif audit.audit_type == 'accreditation' %}
<span class="badge bg-success">Accreditation</span>
{% endif %}
</td>
</tr>
<tr>
<td><strong>Status:</strong></td>
<td>
{% if audit.status == 'planned' %}
<span class="badge bg-secondary">Planned</span>
{% elif audit.status == 'in_progress' %}
<span class="badge bg-info">In Progress</span>
{% elif audit.status == 'completed' %}
<span class="badge bg-success">Completed</span>
{% elif audit.status == 'cancelled' %}
<span class="badge bg-danger">Cancelled</span>
{% endif %}
</td>
</tr>
<tr>
<td><strong>Department:</strong></td>
<td>{{ audit.department.name|default:"All Departments" }}</td>
</tr>
</table>
</div>
<div class="col-md-6">
<table class="table table-borderless mb-0">
<tr>
<td width="120"><strong>Scheduled:</strong></td>
<td>{{ audit.scheduled_date|date:"F d, Y"|default:"Not scheduled" }}</td>
</tr>
<tr>
<td><strong>Lead Auditor:</strong></td>
<td>{{ audit.lead_auditor.get_full_name|default:"Not assigned" }}</td>
</tr>
<tr>
<td><strong>Created:</strong></td>
<td>{{ audit.created_at|date:"F d, Y" }}</td>
</tr>
<tr>
<td><strong>Findings:</strong></td>
<td>
{% if audit.findings_count > 0 %}
<span class="badge bg-orange">{{ audit.findings_count }} finding{{ audit.findings_count|pluralize }}</span>
{% else %}
<span class="badge bg-success">No findings</span>
{% endif %}
</td>
</tr>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- Impact Assessment -->
<div class="panel panel-inverse">
<div class="panel-heading">
<h4 class="panel-title">Impact Assessment</h4>
</div>
<div class="panel-body">
<div class="row">
<div class="col-md-6">
<h6>Data to be Deleted:</h6>
<ul class="list-unstyled">
<li><i class="fa fa-times text-danger me-2"></i>Audit information and documentation</li>
{% if audit.findings_count > 0 %}
<li><i class="fa fa-times text-danger me-2"></i>{{ audit.findings_count }} audit finding{{ audit.findings_count|pluralize }}</li>
{% endif %}
{% if audit.corrective_actions_count > 0 %}
<li><i class="fa fa-times text-danger me-2"></i>{{ audit.corrective_actions_count }} corrective action{{ audit.corrective_actions_count|pluralize }}</li>
{% endif %}
<li><i class="fa fa-times text-danger me-2"></i>Audit timeline and history</li>
<li><i class="fa fa-times text-danger me-2"></i>Team member assignments</li>
{% if audit.attachments_count > 0 %}
<li><i class="fa fa-times text-danger me-2"></i>{{ audit.attachments_count }} attachment{{ audit.attachments_count|pluralize }}</li>
{% endif %}
</ul>
</div>
<div class="col-md-6">
<h6>Potential Impact:</h6>
<ul class="list-unstyled">
{% if audit.status == 'completed' %}
<li><i class="fa fa-exclamation-triangle text-warning me-2"></i>Loss of completed audit documentation</li>
{% endif %}
{% if audit.is_regulatory %}
<li><i class="fa fa-exclamation-triangle text-warning me-2"></i>Regulatory compliance record loss</li>
{% endif %}
{% if audit.findings_count > 0 %}
<li><i class="fa fa-exclamation-triangle text-warning me-2"></i>Loss of quality improvement data</li>
{% endif %}
{% if audit.corrective_actions_count > 0 %}
<li><i class="fa fa-exclamation-triangle text-warning me-2"></i>Orphaned corrective actions</li>
{% endif %}
<li><i class="fa fa-exclamation-triangle text-warning me-2"></i>Audit trail discontinuity</li>
{% if audit.status == 'in_progress' %}
<li><i class="fa fa-exclamation-triangle text-warning me-2"></i>Interruption of ongoing audit process</li>
{% endif %}
</ul>
</div>
</div>
{% if audit.status == 'completed' or audit.is_regulatory %}
<div class="alert alert-warning mt-3">
<h6><i class="fa fa-exclamation-triangle me-2"></i>Special Considerations</h6>
<ul class="mb-0">
{% if audit.status == 'completed' %}
<li>This is a completed audit with documented findings and outcomes</li>
{% endif %}
{% if audit.is_regulatory %}
<li>This is a regulatory audit - deletion may affect compliance records</li>
{% endif %}
{% if audit.is_external %}
<li>This is an external audit - consider notifying external auditors</li>
{% endif %}
{% if audit.corrective_actions_count > 0 %}
<li>Associated corrective actions will become orphaned</li>
{% endif %}
</ul>
</div>
{% endif %}
</div>
</div>
<!-- Alternative Actions -->
<div class="panel panel-inverse">
<div class="panel-heading">
<h4 class="panel-title">Alternative Actions</h4>
</div>
<div class="panel-body">
<p>Consider these alternatives before deleting the audit:</p>
<div class="row">
<div class="col-md-6">
<div class="card border-info">
<div class="card-header bg-info text-white">
<h6 class="mb-0"><i class="fa fa-pause me-2"></i>Cancel Audit</h6>
</div>
<div class="card-body">
<p class="card-text small">
Change the audit status to "Cancelled" instead of deleting. This preserves the audit record while indicating it was not completed.
</p>
{% if audit.status != 'cancelled' %}
<button type="button" class="btn btn-info btn-sm" onclick="cancelAudit()">
<i class="fa fa-pause me-1"></i>Cancel Audit
</button>
{% else %}
<span class="text-muted small">Already cancelled</span>
{% endif %}
</div>
</div>
</div>
<div class="col-md-6">
<div class="card border-warning">
<div class="card-header bg-warning text-dark">
<h6 class="mb-0"><i class="fa fa-archive me-2"></i>Archive Audit</h6>
</div>
<div class="card-body">
<p class="card-text small">
Archive the audit to remove it from active lists while preserving all data for compliance and historical purposes.
</p>
{% if not audit.is_archived %}
<button type="button" class="btn btn-warning btn-sm" onclick="archiveAudit()">
<i class="fa fa-archive me-1"></i>Archive Audit
</button>
{% else %}
<span class="text-muted small">Already archived</span>
{% endif %}
</div>
</div>
</div>
</div>
{% if audit.status == 'in_progress' %}
<div class="alert alert-info mt-3">
<h6><i class="fa fa-info-circle me-2"></i>In-Progress Audit</h6>
<p class="mb-0">
This audit is currently in progress. Consider completing or cancelling it instead of deleting to maintain audit trail integrity.
</p>
</div>
{% endif %}
</div>
</div>
<!-- Confirmation Form -->
<div class="panel panel-inverse">
<div class="panel-heading">
<h4 class="panel-title">Final Confirmation</h4>
</div>
<div class="panel-body">
<form method="post" id="deleteForm">
{% csrf_token %}
<div class="alert alert-danger">
<div class="form-check mb-3">
<input class="form-check-input" type="checkbox" id="confirmUnderstand" required>
<label class="form-check-label" for="confirmUnderstand">
<strong>I understand that this action cannot be undone</strong>
</label>
</div>
<div class="form-check mb-3">
<input class="form-check-input" type="checkbox" id="confirmDataLoss" required>
<label class="form-check-label" for="confirmDataLoss">
<strong>I acknowledge that all audit data will be permanently lost</strong>
</label>
</div>
{% if audit.is_regulatory %}
<div class="form-check mb-3">
<input class="form-check-input" type="checkbox" id="confirmRegulatory" required>
<label class="form-check-label" for="confirmRegulatory">
<strong>I understand this may affect regulatory compliance records</strong>
</label>
</div>
{% endif %}
<div class="form-floating mb-3">
<input type="text" class="form-control" id="confirmationText" placeholder="Type DELETE to confirm" required>
<label for="confirmationText">Type "DELETE" to confirm *</label>
</div>
<div class="form-floating mb-3">
<textarea class="form-control" id="deletionReason" style="height: 80px;" placeholder="Reason for deletion" required></textarea>
<label for="deletionReason">Reason for Deletion *</label>
</div>
</div>
<div class="d-flex justify-content-between">
<div>
<a href="{% url 'quality:audit_detail' audit.pk %}" class="btn btn-secondary">
<i class="fa fa-arrow-left me-2"></i>Cancel
</a>
</div>
<div>
<button type="submit" class="btn btn-danger" id="deleteButton" disabled>
<i class="fa fa-trash me-2"></i>Delete Audit Permanently
</button>
</div>
</div>
</form>
</div>
</div>
</div>
<div class="col-xl-4">
<!-- Deletion Guidelines -->
<div class="panel panel-inverse">
<div class="panel-heading">
<h4 class="panel-title">Deletion Guidelines</h4>
</div>
<div class="panel-body">
<div class="alert alert-warning">
<h6><i class="fa fa-exclamation-triangle me-2"></i>When to Delete</h6>
<ul class="mb-0 small">
<li>Duplicate audit entries</li>
<li>Test audits created in error</li>
<li>Audits with no meaningful data</li>
<li>Audits created by mistake</li>
</ul>
</div>
<div class="alert alert-danger">
<h6><i class="fa fa-times-circle me-2"></i>When NOT to Delete</h6>
<ul class="mb-0 small">
<li>Completed audits with findings</li>
<li>Regulatory or compliance audits</li>
<li>Audits with corrective actions</li>
<li>Historical audit records</li>
<li>Audits under investigation</li>
</ul>
</div>
</div>
</div>
<!-- Contact Information -->
<div class="panel panel-inverse">
<div class="panel-heading">
<h4 class="panel-title">Need Help?</h4>
</div>
<div class="panel-body">
<p class="small">If you're unsure about deleting this audit, contact:</p>
<div class="mb-3">
<strong>Quality Management</strong><br>
<small class="text-muted">
<i class="fa fa-envelope me-1"></i>quality@hospital.com<br>
<i class="fa fa-phone me-1"></i>(555) 123-4567
</small>
</div>
<div class="mb-3">
<strong>Compliance Officer</strong><br>
<small class="text-muted">
<i class="fa fa-envelope me-1"></i>compliance@hospital.com<br>
<i class="fa fa-phone me-1"></i>(555) 123-4568
</small>
</div>
<div class="alert alert-info">
<small>
<i class="fa fa-info-circle me-1"></i>
Consider consulting with the Quality Management team before deleting completed or regulatory audits.
</small>
</div>
</div>
</div>
</div>
</div>
<!-- END row -->
{% endblock %}
{% block js %}
<script>
$(document).ready(function() {
// Enable delete button only when all confirmations are checked
function checkConfirmations() {
const allChecked = $('#confirmUnderstand').is(':checked') &&
$('#confirmDataLoss').is(':checked') &&
{% if audit.is_regulatory %}$('#confirmRegulatory').is(':checked') &&{% endif %}
$('#confirmationText').val().toUpperCase() === 'DELETE' &&
$('#deletionReason').val().trim() !== '';
$('#deleteButton').prop('disabled', !allChecked);
}
// Check confirmations on any change
$('#confirmUnderstand, #confirmDataLoss, #confirmRegulatory, #confirmationText, #deletionReason').on('change input', checkConfirmations);
// Form submission
$('#deleteForm').on('submit', function(e) {
if (!confirm('Are you absolutely sure you want to delete this audit? This action cannot be undone.')) {
e.preventDefault();
return false;
}
// Add deletion reason to form data
$('<input>').attr({
type: 'hidden',
name: 'deletion_reason',
value: $('#deletionReason').val()
}).appendTo('#deleteForm');
// Show loading state
$('#deleteButton').prop('disabled', true).html('<i class="fa fa-spinner fa-spin me-2"></i>Deleting...');
});
});
function cancelAudit() {
if (confirm('Cancel this audit? This will change the status to "Cancelled" but preserve all data.')) {
$.ajax({
url: '{% url "quality:cancel_audit" %}',
method: 'POST',
data: {
'audit_id': '{{ audit.id }}',
'csrfmiddlewaretoken': '{{ csrf_token }}'
},
success: function(response) {
if (response.success) {
toastr.success('Audit cancelled successfully');
window.location.href = '{% url "quality:audit_detail" audit.pk %}';
} else {
toastr.error(response.message || 'Failed to cancel audit');
}
},
error: function() {
toastr.error('Failed to cancel audit');
}
});
}
}
function archiveAudit() {
if (confirm('Archive this audit? This will remove it from active lists but preserve all data.')) {
$.ajax({
url: '{% url "quality:archive_audit" %}',
method: 'POST',
data: {
'audit_id': '{{ audit.id }}',
'csrfmiddlewaretoken': '{{ csrf_token }}'
},
success: function(response) {
if (response.success) {
toastr.success('Audit archived successfully');
window.location.href = '{% url "quality:audit_detail" audit.pk %}';
} else {
toastr.error(response.message || 'Failed to archive audit');
}
},
error: function() {
toastr.error('Failed to archive audit');
}
});
}
}
</script>
{% endblock %}