hospital-management/templates/patients/profiles/patient_confirm_delete.html
2025-08-12 13:33:25 +03:00

447 lines
21 KiB
HTML

{% extends "base.html" %}
{% load static %}
{% block title %}Delete Patient - {{ object.get_full_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 text-danger">
<i class="fas fa-user-times me-2"></i>Delete Patient Record
</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 'patients:patient_list' %}">Patients</a></li>
<li class="breadcrumb-item"><a href="{% url 'patients:patient_detail' object.pk %}">{{ object.get_full_name }}</a></li>
<li class="breadcrumb-item active">Delete</li>
</ol>
</nav>
</div>
<div class="btn-group">
<a href="{% url 'patients:patient_detail' object.pk %}" class="btn btn-outline-secondary">
<i class="fas fa-arrow-left me-2"></i>Back to Patient
</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>
Critical Action Required
</h5>
</div>
<div class="card-body">
<div class="alert alert-danger d-flex align-items-center" role="alert">
<i class="fas fa-exclamation-triangle fa-2x me-3"></i>
<div>
<h6 class="alert-heading mb-1">Permanent Data Deletion</h6>
<p class="mb-0">
You are about to permanently delete the patient record for <strong>{{ object.get_full_name }}</strong> (MRN: {{ object.mrn }}).
This action cannot be undone and will result in the loss of all associated medical data.
</p>
</div>
</div>
</div>
</div>
<!-- Patient Information -->
<div class="card mb-4">
<div class="card-header">
<h5 class="mb-0">
<i class="fas fa-user me-2"></i>Patient Information
</h5>
</div>
<div class="card-body">
<div class="row">
<div class="col-md-3 text-center">
{% if object.photo %}
<img src="{{ object.photo.url }}" alt="Patient Photo" class="img-fluid rounded-circle mb-3" style="width: 120px; height: 120px; object-fit: cover;">
{% else %}
<div class="bg-light rounded-circle d-inline-flex align-items-center justify-content-center mb-3" style="width: 120px; height: 120px;">
<i class="fas fa-user fa-3x text-muted"></i>
</div>
{% endif %}
</div>
<div class="col-md-9">
<div class="row">
<div class="col-sm-6">
<strong>Full Name:</strong><br>
{{ object.get_full_name }}
</div>
<div class="col-sm-6">
<strong>Medical Record Number:</strong><br>
{{ object.mrn }}
</div>
</div>
<hr>
<div class="row">
<div class="col-sm-6">
<strong>Date of Birth:</strong><br>
{{ object.date_of_birth|date:"F d, Y" }}
{% if object.age %}(Age: {{ object.age }}){% endif %}
</div>
<div class="col-sm-6">
<strong>Gender:</strong><br>
{{ object.get_gender_display }}
</div>
</div>
<hr>
<div class="row">
<div class="col-sm-6">
<strong>Phone:</strong><br>
{{ object.phone_number|default:"Not provided" }}
</div>
<div class="col-sm-6">
<strong>Email:</strong><br>
{{ object.email|default:"Not provided" }}
</div>
</div>
</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>Deletion Impact Assessment
</h5>
</div>
<div class="card-body">
<div class="alert alert-warning">
<h6 class="alert-heading">The following data will be permanently deleted:</h6>
<ul class="mb-0">
<li><strong>Patient Profile:</strong> All demographic and contact information</li>
<li><strong>Emergency Contacts:</strong> {{ object.emergency_contacts.count }} contact(s)</li>
<li><strong>Insurance Information:</strong> {{ object.insurance_info.count }} insurance record(s)</li>
<li><strong>Patient Notes:</strong> {{ object.patient_notes.count }} note(s)</li>
<li><strong>Consent Forms:</strong> {{ object.consent_forms.count }} consent form(s)</li>
<li><strong>Medical History:</strong> All associated medical records</li>
<li><strong>Appointments:</strong> All past and future appointments</li>
<li><strong>Billing Records:</strong> All financial and billing information</li>
</ul>
</div>
{% if object.emergency_contacts.exists or object.insurance_info.exists or object.patient_notes.exists %}
<div class="alert alert-info">
<h6 class="alert-heading">Related Records Summary:</h6>
<div class="row">
{% if object.emergency_contacts.exists %}
<div class="col-md-4">
<strong>Emergency Contacts:</strong>
<ul class="small mb-0">
{% for contact in object.emergency_contacts.all|slice:":3" %}
<li>{{ contact.get_full_name }} ({{ contact.relationship }})</li>
{% endfor %}
{% if object.emergency_contacts.count > 3 %}
<li><em>... and {{ object.emergency_contacts.count|add:"-3" }} more</em></li>
{% endif %}
</ul>
</div>
{% endif %}
{% if object.insurance_info.exists %}
<div class="col-md-4">
<strong>Insurance Plans:</strong>
<ul class="small mb-0">
{% for insurance in object.insurance_info.all|slice:":3" %}
<li>{{ insurance.insurance_company }} ({{ insurance.get_insurance_type_display }})</li>
{% endfor %}
{% if object.insurance_info.count > 3 %}
<li><em>... and {{ object.insurance_info.count|add:"-3" }} more</em></li>
{% endif %}
</ul>
</div>
{% endif %}
{% if object.patient_notes.exists %}
<div class="col-md-4">
<strong>Recent Notes:</strong>
<ul class="small mb-0">
{% for note in object.patient_notes.all|slice:":3" %}
<li>{{ note.created_at|date:"M d, Y" }} - {{ note.note_type }}</li>
{% endfor %}
{% if object.patient_notes.count > 3 %}
<li><em>... and {{ object.patient_notes.count|add:"-3" }} more</em></li>
{% endif %}
</ul>
</div>
{% endif %}
</div>
</div>
{% endif %}
</div>
</div>
<!-- Alternative Actions -->
<div class="card mb-4">
<div class="card-header bg-info 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 before proceeding with deletion:</p>
<div class="row">
<div class="col-md-6 mb-3">
<div class="card border-success">
<div class="card-body">
<h6 class="card-title text-success">
<i class="fas fa-user-slash me-2"></i>Deactivate Patient
</h6>
<p class="card-text small">
Mark the patient as inactive instead of deleting. This preserves all data while preventing new activities.
</p>
<button type="button" class="btn btn-sm btn-success" onclick="deactivatePatient()">
Deactivate Instead
</button>
</div>
</div>
</div>
<div class="col-md-6 mb-3">
<div class="card border-warning">
<div class="card-body">
<h6 class="card-title text-warning">
<i class="fas fa-archive me-2"></i>Archive Patient
</h6>
<p class="card-text small">
Archive the patient record for long-term storage while removing from active lists.
</p>
<button type="button" class="btn btn-sm btn-warning" onclick="archivePatient()">
Archive Instead
</button>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- Confirmation Form -->
<div class="card border-danger">
<div class="card-header bg-danger text-white">
<h5 class="mb-0">
<i class="fas fa-shield-alt me-2"></i>Deletion Confirmation
</h5>
</div>
<div class="card-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 is permanent and cannot be undone</strong>
</label>
</div>
<div class="form-check mb-3">
<input class="form-check-input" type="checkbox" id="confirmBackup" required>
<label class="form-check-label" for="confirmBackup">
<strong>I confirm that any required data has been backed up or exported</strong>
</label>
</div>
<div class="form-check mb-3">
<input class="form-check-input" type="checkbox" id="confirmAuthorization" required>
<label class="form-check-label" for="confirmAuthorization">
<strong>I have the necessary authorization to delete this patient record</strong>
</label>
</div>
</div>
<div class="mb-3">
<label for="deletionReason" class="form-label">
<strong>Reason for Deletion <span class="text-danger">*</span></strong>
</label>
<select class="form-select" id="deletionReason" name="deletion_reason" required>
<option value="">Select a reason...</option>
<option value="DUPLICATE_RECORD">Duplicate Record</option>
<option value="TEST_PATIENT">Test Patient</option>
<option value="DATA_ERROR">Data Entry Error</option>
<option value="PATIENT_REQUEST">Patient Request</option>
<option value="LEGAL_REQUIREMENT">Legal Requirement</option>
<option value="OTHER">Other (specify below)</option>
</select>
</div>
<div class="mb-3">
<label for="deletionNotes" class="form-label">
<strong>Additional Notes</strong>
</label>
<textarea class="form-control" id="deletionNotes" name="deletion_notes" rows="3"
placeholder="Provide additional details about the deletion reason..."></textarea>
</div>
<div class="mb-3">
<label for="confirmationText" class="form-label">
<strong>Type "DELETE {{ object.mrn }}" to confirm <span class="text-danger">*</span></strong>
</label>
<input type="text" class="form-control" id="confirmationText" name="confirmation_text"
placeholder="DELETE {{ object.mrn }}" required>
<div class="form-text">This helps prevent accidental deletions</div>
</div>
<hr>
<div class="d-flex justify-content-between align-items-center">
<div>
<a href="{% url 'patients:patient_detail' object.pk %}" class="btn btn-secondary">
<i class="fas fa-times me-2"></i>Cancel
</a>
</div>
<div>
<button type="submit" class="btn btn-danger" id="deleteButton" disabled>
<i class="fas fa-trash-alt me-2"></i>
Permanently Delete Patient
</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
<script>
document.addEventListener('DOMContentLoaded', function() {
const form = document.getElementById('deleteForm');
const deleteButton = document.getElementById('deleteButton');
const checkboxes = form.querySelectorAll('input[type="checkbox"]');
const confirmationText = document.getElementById('confirmationText');
const deletionReason = document.getElementById('deletionReason');
function validateForm() {
const allChecked = Array.from(checkboxes).every(cb => cb.checked);
const textMatches = confirmationText.value === 'DELETE {{ object.mrn }}';
const reasonSelected = deletionReason.value !== '';
deleteButton.disabled = !(allChecked && textMatches && reasonSelected);
}
// Add event listeners
checkboxes.forEach(cb => cb.addEventListener('change', validateForm));
confirmationText.addEventListener('input', validateForm);
deletionReason.addEventListener('change', validateForm);
// Form submission confirmation
form.addEventListener('submit', function(event) {
if (!confirm('Are you absolutely sure you want to delete this patient record? This action cannot be undone.')) {
event.preventDefault();
}
});
});
// Alternative action functions
function deactivatePatient() {
if (confirm('Deactivate this patient instead of deleting?')) {
fetch(`{% url 'patients:patient_detail' object.pk %}deactivate/`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-CSRFToken': document.querySelector('[name=csrfmiddlewaretoken]').value
}
})
.then(response => response.json())
.then(data => {
if (data.success) {
window.location.href = `{% url 'patients:patient_detail' object.pk %}`;
} else {
alert('Error deactivating patient: ' + data.error);
}
})
.catch(error => {
console.error('Error:', error);
alert('Error deactivating patient');
});
}
}
function archivePatient() {
if (confirm('Archive this patient instead of deleting?')) {
fetch(`{% url 'patients:patient_detail' object.pk %}archive/`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-CSRFToken': document.querySelector('[name=csrfmiddlewaretoken]').value
}
})
.then(response => response.json())
.then(data => {
if (data.success) {
window.location.href = `{% url 'patients:patient_detail' object.pk %}`;
} else {
alert('Error archiving patient: ' + data.error);
}
})
.catch(error => {
console.error('Error:', error);
alert('Error archiving patient');
});
}
}
</script>
<style>
.card {
box-shadow: 0 0.125rem 0.25rem rgba(0, 0, 0, 0.075);
border: 1px solid rgba(0, 0, 0, 0.125);
}
.card-header {
border-bottom: 1px solid rgba(0, 0, 0, 0.125);
}
.btn {
border-radius: 0.375rem;
transition: all 0.15s ease-in-out;
}
.btn:hover:not(:disabled) {
transform: translateY(-1px);
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}
.btn:disabled {
opacity: 0.6;
cursor: not-allowed;
}
.form-check-input:checked {
background-color: #dc3545;
border-color: #dc3545;
}
.alert {
border-radius: 0.375rem;
}
@media (max-width: 768px) {
.d-flex.justify-content-between {
flex-direction: column;
gap: 1rem;
}
.btn-group {
display: flex;
flex-direction: column;
gap: 0.5rem;
}
}
</style>
{% endblock %}