416 lines
18 KiB
HTML
416 lines
18 KiB
HTML
{% extends "base.html" %}
|
|
{% load static %}
|
|
|
|
{% block title %}Delete Encounter - {{ 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-exclamation-triangle me-2"></i>Delete Encounter
|
|
</h1>
|
|
<nav aria-label="breadcrumb">
|
|
<ol class="breadcrumb mb-0">
|
|
<li class="breadcrumb-item"><a href="{% url 'emr:dashboard' %}">EMR</a></li>
|
|
<li class="breadcrumb-item"><a href="{% url 'emr:encounter_list' %}">Encounters</a></li>
|
|
<li class="breadcrumb-item"><a href="{% url 'emr:encounter_detail' object.pk %}">{{ object.encounter_id|truncatechars:8 }}</a></li>
|
|
<li class="breadcrumb-item active">Delete</li>
|
|
</ol>
|
|
</nav>
|
|
</div>
|
|
<div class="btn-group">
|
|
<a href="{% url 'emr:encounter_detail' object.pk %}" class="btn btn-outline-secondary">
|
|
<i class="fas fa-arrow-left me-2"></i>Back to Encounter
|
|
</a>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="row">
|
|
<div class="col-lg-8">
|
|
<!-- Warning Alert -->
|
|
<div class="alert alert-danger border-0 shadow-sm 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">Permanent Deletion Warning</h5>
|
|
<p class="mb-0">You are about to permanently delete this encounter and all associated data. This action cannot be undone.</p>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Encounter Information -->
|
|
<div class="card mb-4">
|
|
<div class="card-header bg-light">
|
|
<h5 class="mb-0">
|
|
<i class="fas fa-info-circle me-2"></i>Encounter Information
|
|
</h5>
|
|
</div>
|
|
<div class="card-body">
|
|
<div class="row">
|
|
<div class="col-md-6">
|
|
<dl class="row">
|
|
<dt class="col-sm-5">Encounter ID:</dt>
|
|
<dd class="col-sm-7"><code>{{ object.encounter_id }}</code></dd>
|
|
|
|
<dt class="col-sm-5">Patient:</dt>
|
|
<dd class="col-sm-7">
|
|
<strong>{{ object.patient.get_full_name }}</strong><br>
|
|
<small class="text-muted">MRN: {{ object.patient.mrn }}</small>
|
|
</dd>
|
|
|
|
<dt class="col-sm-5">Provider:</dt>
|
|
<dd class="col-sm-7">{{ object.provider.get_full_name }}</dd>
|
|
|
|
<dt class="col-sm-5">Type:</dt>
|
|
<dd class="col-sm-7">
|
|
<span class="badge bg-primary">{{ object.get_encounter_type_display }}</span>
|
|
</dd>
|
|
</dl>
|
|
</div>
|
|
<div class="col-md-6">
|
|
<dl class="row">
|
|
<dt class="col-sm-5">Start Date:</dt>
|
|
<dd class="col-sm-7">{{ object.start_datetime|date:"M d, Y H:i" }}</dd>
|
|
|
|
<dt class="col-sm-5">End Date:</dt>
|
|
<dd class="col-sm-7">
|
|
{% if object.end_datetime %}
|
|
{{ object.end_datetime|date:"M d, Y H:i" }}
|
|
{% else %}
|
|
<em class="text-muted">Ongoing</em>
|
|
{% endif %}
|
|
</dd>
|
|
|
|
<dt class="col-sm-5">Status:</dt>
|
|
<dd class="col-sm-7">
|
|
<span class="badge bg-{% if object.status == 'FINISHED' %}success{% elif object.status == 'CANCELLED' %}danger{% else %}warning{% endif %}">
|
|
{{ object.get_status_display }}
|
|
</span>
|
|
</dd>
|
|
|
|
<dt class="col-sm-5">Location:</dt>
|
|
<dd class="col-sm-7">{{ object.location|default:"Not specified" }}</dd>
|
|
</dl>
|
|
</div>
|
|
</div>
|
|
|
|
{% if object.chief_complaint %}
|
|
<div class="mt-3">
|
|
<dt>Chief Complaint:</dt>
|
|
<dd class="mt-1">{{ object.chief_complaint }}</dd>
|
|
</div>
|
|
{% endif %}
|
|
</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-impact me-2"></i>Deletion Impact Assessment
|
|
</h5>
|
|
</div>
|
|
<div class="card-body">
|
|
<div class="row">
|
|
<div class="col-md-6">
|
|
<h6 class="text-danger">Data That Will Be Deleted:</h6>
|
|
<ul class="list-unstyled">
|
|
<li><i class="fas fa-times text-danger me-2"></i>Encounter record and metadata</li>
|
|
<li><i class="fas fa-times text-danger me-2"></i>Associated vital signs ({{ object.vital_signs.count }})</li>
|
|
<li><i class="fas fa-times text-danger me-2"></i>Clinical notes ({{ object.clinical_notes.count }})</li>
|
|
<li><i class="fas fa-times text-danger me-2"></i>Procedure records</li>
|
|
<li><i class="fas fa-times text-danger me-2"></i>Medication orders</li>
|
|
<li><i class="fas fa-times text-danger me-2"></i>Lab orders and results</li>
|
|
<li><i class="fas fa-times text-danger me-2"></i>Imaging orders and results</li>
|
|
<li><i class="fas fa-times text-danger me-2"></i>Billing information</li>
|
|
</ul>
|
|
</div>
|
|
<div class="col-md-6">
|
|
<h6 class="text-success">Data That Will Be Preserved:</h6>
|
|
<ul class="list-unstyled">
|
|
<li><i class="fas fa-check text-success me-2"></i>Patient demographic information</li>
|
|
<li><i class="fas fa-check text-success me-2"></i>Patient medical history</li>
|
|
<li><i class="fas fa-check text-success me-2"></i>Other encounters for this patient</li>
|
|
<li><i class="fas fa-check text-success me-2"></i>Provider information</li>
|
|
<li><i class="fas fa-check text-success me-2"></i>Audit logs (deletion will be recorded)</li>
|
|
</ul>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Deletion Restrictions -->
|
|
{% if deletion_restrictions %}
|
|
<div class="card mb-4">
|
|
<div class="card-header bg-danger text-white">
|
|
<h5 class="mb-0">
|
|
<i class="fas fa-ban me-2"></i>Deletion Restrictions
|
|
</h5>
|
|
</div>
|
|
<div class="card-body">
|
|
<div class="alert alert-danger">
|
|
<h6 class="alert-heading">Cannot Delete Encounter</h6>
|
|
<p class="mb-0">This encounter cannot be deleted due to the following restrictions:</p>
|
|
</div>
|
|
<ul class="list-unstyled">
|
|
{% for restriction in deletion_restrictions %}
|
|
<li class="mb-2">
|
|
<i class="fas fa-exclamation-circle text-danger me-2"></i>
|
|
<strong>{{ restriction.type }}:</strong> {{ restriction.message }}
|
|
</li>
|
|
{% endfor %}
|
|
</ul>
|
|
<div class="alert alert-info mt-3">
|
|
<i class="fas fa-lightbulb me-2"></i>
|
|
<strong>Suggestion:</strong> Consider marking the encounter as cancelled instead of deleting it to maintain data integrity.
|
|
</div>
|
|
</div>
|
|
</div>
|
|
{% endif %}
|
|
</div>
|
|
|
|
<!-- Sidebar -->
|
|
<div class="col-lg-4">
|
|
<!-- Deletion Confirmation -->
|
|
{% if not deletion_restrictions %}
|
|
<div class="card mb-4">
|
|
<div class="card-header bg-danger text-white">
|
|
<h5 class="mb-0">
|
|
<i class="fas fa-trash me-2"></i>Confirm Deletion
|
|
</h5>
|
|
</div>
|
|
<div class="card-body">
|
|
<form method="post">
|
|
{% csrf_token %}
|
|
|
|
<div class="mb-3">
|
|
<label for="deletion_reason" class="form-label">
|
|
Reason for Deletion <span class="text-danger">*</span>
|
|
</label>
|
|
<select class="form-select" id="deletion_reason" name="deletion_reason" required>
|
|
<option value="">Select a reason...</option>
|
|
<option value="DUPLICATE">Duplicate encounter</option>
|
|
<option value="ERROR">Data entry error</option>
|
|
<option value="TEST">Test data</option>
|
|
<option value="PATIENT_REQUEST">Patient request</option>
|
|
<option value="LEGAL">Legal requirement</option>
|
|
<option value="OTHER">Other</option>
|
|
</select>
|
|
</div>
|
|
|
|
<div class="mb-3">
|
|
<label for="deletion_notes" class="form-label">
|
|
Additional Notes
|
|
</label>
|
|
<textarea class="form-control" id="deletion_notes" name="deletion_notes" rows="3"
|
|
placeholder="Provide additional context for this deletion..."></textarea>
|
|
</div>
|
|
|
|
<div class="mb-3">
|
|
<div class="form-check">
|
|
<input class="form-check-input" type="checkbox" id="confirm_deletion" name="confirm_deletion" required>
|
|
<label class="form-check-label" for="confirm_deletion">
|
|
I understand this action is permanent and cannot be undone
|
|
</label>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="mb-3">
|
|
<div class="form-check">
|
|
<input class="form-check-input" type="checkbox" id="confirm_authority" name="confirm_authority" required>
|
|
<label class="form-check-label" for="confirm_authority">
|
|
I have the authority to delete this encounter
|
|
</label>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="d-grid gap-2">
|
|
<button type="submit" class="btn btn-danger" id="deleteBtn" disabled>
|
|
<i class="fas fa-trash me-2"></i>Delete Encounter
|
|
</button>
|
|
<a href="{% url 'emr:encounter_detail' object.pk %}" class="btn btn-outline-secondary">
|
|
<i class="fas fa-times me-2"></i>Cancel
|
|
</a>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
{% else %}
|
|
<div class="card mb-4">
|
|
<div class="card-header bg-secondary text-white">
|
|
<h5 class="mb-0">
|
|
<i class="fas fa-ban me-2"></i>Deletion Blocked
|
|
</h5>
|
|
</div>
|
|
<div class="card-body">
|
|
<p class="text-muted">This encounter cannot be deleted due to system restrictions.</p>
|
|
<div class="d-grid gap-2">
|
|
<a href="{% url 'emr:encounter_detail' object.pk %}" class="btn btn-primary">
|
|
<i class="fas fa-arrow-left me-2"></i>Return to Encounter
|
|
</a>
|
|
<button type="button" class="btn btn-outline-warning" onclick="markAsCancelled()">
|
|
<i class="fas fa-ban me-2"></i>Mark as Cancelled
|
|
</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
{% endif %}
|
|
|
|
<!-- Audit Information -->
|
|
<div class="card">
|
|
<div class="card-header">
|
|
<h5 class="mb-0">
|
|
<i class="fas fa-history me-2"></i>Audit Information
|
|
</h5>
|
|
</div>
|
|
<div class="card-body">
|
|
<dl class="row mb-0">
|
|
<dt class="col-sm-6">Created:</dt>
|
|
<dd class="col-sm-6">{{ object.created_at|date:"M d, Y H:i" }}</dd>
|
|
|
|
<dt class="col-sm-6">Created By:</dt>
|
|
<dd class="col-sm-6">{{ object.created_by.get_full_name|default:object.created_by.username }}</dd>
|
|
|
|
<dt class="col-sm-6">Last Modified:</dt>
|
|
<dd class="col-sm-6">{{ object.updated_at|date:"M d, Y H:i" }}</dd>
|
|
|
|
<dt class="col-sm-6">Modified By:</dt>
|
|
<dd class="col-sm-6">{{ object.updated_by.get_full_name|default:object.updated_by.username }}</dd>
|
|
</dl>
|
|
|
|
<div class="alert alert-info mt-3 mb-0">
|
|
<i class="fas fa-info-circle me-2"></i>
|
|
<small>Deletion will be logged in the audit trail with your user information and timestamp.</small>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<script>
|
|
document.addEventListener('DOMContentLoaded', function() {
|
|
const deleteBtn = document.getElementById('deleteBtn');
|
|
const confirmDeletion = document.getElementById('confirm_deletion');
|
|
const confirmAuthority = document.getElementById('confirm_authority');
|
|
const deletionReason = document.getElementById('deletion_reason');
|
|
|
|
function checkFormValidity() {
|
|
if (confirmDeletion && confirmAuthority && deletionReason) {
|
|
const isValid = confirmDeletion.checked && confirmAuthority.checked && deletionReason.value;
|
|
if (deleteBtn) {
|
|
deleteBtn.disabled = !isValid;
|
|
}
|
|
}
|
|
}
|
|
|
|
// Add event listeners
|
|
[confirmDeletion, confirmAuthority, deletionReason].forEach(element => {
|
|
if (element) {
|
|
element.addEventListener('change', checkFormValidity);
|
|
}
|
|
});
|
|
|
|
// Form submission confirmation
|
|
const form = document.querySelector('form');
|
|
if (form) {
|
|
form.addEventListener('submit', function(e) {
|
|
const confirmed = confirm(
|
|
'Are you absolutely sure you want to delete this encounter?\n\n' +
|
|
'This action is PERMANENT and cannot be undone.\n\n' +
|
|
'Click OK to proceed with deletion, or Cancel to abort.'
|
|
);
|
|
|
|
if (!confirmed) {
|
|
e.preventDefault();
|
|
return false;
|
|
}
|
|
|
|
// Show loading state
|
|
if (deleteBtn) {
|
|
deleteBtn.innerHTML = '<i class="fas fa-spinner fa-spin me-2"></i>Deleting...';
|
|
deleteBtn.disabled = true;
|
|
}
|
|
});
|
|
}
|
|
});
|
|
|
|
function markAsCancelled() {
|
|
if (confirm('Mark this encounter as cancelled instead of deleting it?')) {
|
|
// Implementation would depend on your encounter status update endpoint
|
|
fetch(`{% url 'emr:update_encounter_status' object.id %}`, {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
'X-CSRFToken': getCsrfToken()
|
|
},
|
|
body: JSON.stringify({
|
|
status: 'CANCELLED',
|
|
reason: 'Marked as cancelled instead of deletion'
|
|
})
|
|
})
|
|
.then(response => response.json())
|
|
.then(data => {
|
|
if (data.success) {
|
|
window.location.href = "{% url 'emr:encounter_detail' object.pk %}";
|
|
} else {
|
|
alert('Error updating encounter status: ' + data.error);
|
|
}
|
|
})
|
|
.catch(error => {
|
|
console.error('Error:', error);
|
|
alert('Error updating encounter status');
|
|
});
|
|
}
|
|
}
|
|
|
|
function getCsrfToken() {
|
|
return document.querySelector('[name=csrfmiddlewaretoken]').value;
|
|
}
|
|
</script>
|
|
|
|
<style>
|
|
.alert-danger {
|
|
border-left: 4px solid #dc3545;
|
|
}
|
|
|
|
.alert-warning {
|
|
border-left: 4px solid #ffc107;
|
|
}
|
|
|
|
.alert-info {
|
|
border-left: 4px solid #0dcaf0;
|
|
}
|
|
|
|
.card-header.bg-danger {
|
|
border-bottom: 1px solid rgba(255, 255, 255, 0.2);
|
|
}
|
|
|
|
.card-header.bg-warning {
|
|
border-bottom: 1px solid rgba(0, 0, 0, 0.1);
|
|
}
|
|
|
|
.form-check-input:checked {
|
|
background-color: #dc3545;
|
|
border-color: #dc3545;
|
|
}
|
|
|
|
.btn-danger:disabled {
|
|
opacity: 0.5;
|
|
cursor: not-allowed;
|
|
}
|
|
|
|
dl.row dt {
|
|
font-weight: 600;
|
|
color: #495057;
|
|
}
|
|
|
|
dl.row dd {
|
|
color: #6c757d;
|
|
}
|
|
</style>
|
|
{% endblock %}
|
|
|