Marwan Alwali 84c1fb798e update
2025-09-08 19:52:52 +03:00

441 lines
19 KiB
HTML

{% extends "base.html" %}
{% load static %}
{% block title %}
{% if object %}Edit Emergency Contact{% else %}Add Emergency Contact{% endif %} - {{ patient.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">
<i class="fas fa-user-friends me-2"></i>
{% if object %}Edit Emergency Contact{% else %}Add Emergency Contact{% endif %}
</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="">{{ patient.get_full_name }}</a></li>
<li class="breadcrumb-item active">
{% if object %}Edit Contact{% else %}Add Contact{% endif %}
</li>
</ol>
</nav>
</div>
<div class="btn-group">
<a href="" 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">
<!-- Patient Info Card -->
<div class="card mb-4">
<div class="card-header bg-primary text-white">
<h5 class="mb-0">
<i class="fas fa-user me-2"></i>Patient Information
</h5>
</div>
<div class="card-body">
<div class="row align-items-center">
<div class="col-auto">
{% if patient.photo %}
<img src="{{ patient.photo.url }}" alt="Patient Photo" class="rounded-circle" style="width: 60px; height: 60px; object-fit: cover;">
{% else %}
<div class="bg-light rounded-circle d-flex align-items-center justify-content-center" style="width: 60px; height: 60px;">
<i class="fas fa-user fa-2x text-muted"></i>
</div>
{% endif %}
</div>
<div class="col">
<h6 class="mb-1">{{ patient.get_full_name }}</h6>
<div class="text-muted">
<small>MRN: {{ patient.mrn }} | DOB: {{ patient.date_of_birth|date:"M d, Y" }}</small>
</div>
</div>
</div>
</div>
</div>
<!-- Emergency Contact Form -->
<div class="card">
<div class="card-header">
<h5 class="mb-0">
<i class="fas fa-address-book me-2"></i>Contact Information
</h5>
</div>
<div class="card-body">
<form method="post" id="emergencyContactForm" novalidate>
{% csrf_token %}
<!-- Basic Information -->
<div class="row">
<div class="col-md-6 mb-3">
<label for="{{ form.first_name.id_for_label }}" class="form-label">
First Name <span class="text-danger">*</span>
</label>
{{ form.first_name }}
{% if form.first_name.errors %}
<div class="invalid-feedback d-block">
{{ form.first_name.errors.0 }}
</div>
{% endif %}
</div>
<div class="col-md-6 mb-3">
<label for="{{ form.last_name.id_for_label }}" class="form-label">
Last Name <span class="text-danger">*</span>
</label>
{{ form.last_name }}
{% if form.last_name.errors %}
<div class="invalid-feedback d-block">
{{ form.last_name.errors.0 }}
</div>
{% endif %}
</div>
</div>
<div class="row">
<div class="col-md-6 mb-3">
<label for="{{ form.relationship.id_for_label }}" class="form-label">
Relationship <span class="text-danger">*</span>
</label>
{{ form.relationship }}
{% if form.relationship.errors %}
<div class="invalid-feedback d-block">
{{ form.relationship.errors.0 }}
</div>
{% endif %}
</div>
<div class="col-md-6 mb-3">
<label for="{{ form.priority.id_for_label }}" class="form-label">
Priority <span class="text-danger">*</span>
</label>
{{ form.priority }}
{% if form.priority.errors %}
<div class="invalid-feedback d-block">
{{ form.priority.errors.0 }}
</div>
{% endif %}
<div class="form-text">1 = Highest priority, 2 = Second priority, etc.</div>
</div>
</div>
<!-- Contact Details -->
<h6 class="mt-4 mb-3">
<i class="fas fa-phone me-2"></i>Contact Details
</h6>
<div class="row">
<div class="col-md-6 mb-3">
<label for="{{ form.phone_number.id_for_label }}" class="form-label">
Primary Phone <span class="text-danger">*</span>
</label>
{{ form.phone_number }}
{% if form.phone_number.errors %}
<div class="invalid-feedback d-block">
{{ form.phone_number.errors.0 }}
</div>
{% endif %}
</div>
<div class="col-md-6 mb-3">
<label for="{{ form.mobile_number.id_for_label }}" class="form-label">Mobile Phone</label>
{{ form.mobile_number }}
{% if form.mobile_number.errors %}
<div class="invalid-feedback d-block">
{{ form.mobile_number.errors.0 }}
</div>
{% endif %}
</div>
</div>
<div class="mb-3">
<label for="{{ form.email.id_for_label }}" class="form-label">Email Address</label>
{{ form.email }}
{% if form.email.errors %}
<div class="invalid-feedback d-block">
{{ form.email.errors.0 }}
</div>
{% endif %}
</div>
<!-- Address Information -->
<h6 class="mt-4 mb-3">
<i class="fas fa-map-marker-alt me-2"></i>Address Information
</h6>
<div class="row">
<div class="col-md-6 mb-3">
<label for="{{ form.address_line_1.id_for_label }}" class="form-label">Address Line 1</label>
{{ form.address_line_1 }}
{% if form.address_line_1.errors %}
<div class="invalid-feedback d-block">
{{ form.address_line_1.errors.0 }}
</div>
{% endif %}
</div>
<div class="col-md-6 mb-3">
<label for="{{ form.address_line_2.id_for_label }}" class="form-label">Address Line 2</label>
{{ form.address_line_2 }}
{% if form.address_line_2.errors %}
<div class="invalid-feedback d-block">
{{ form.address_line_2.errors.0 }}
</div>
{% endif %}
</div>
</div>
<div class="row">
<div class="col-md-4 mb-3">
<label for="{{ form.city.id_for_label }}" class="form-label">City</label>
{{ form.city }}
{% if form.city.errors %}
<div class="invalid-feedback d-block">
{{ form.city.errors.0 }}
</div>
{% endif %}
</div>
<div class="col-md-4 mb-3">
<label for="{{ form.state.id_for_label }}" class="form-label">State</label>
{{ form.state }}
{% if form.state.errors %}
<div class="invalid-feedback d-block">
{{ form.state.errors.0 }}
</div>
{% endif %}
</div>
<div class="col-md-4 mb-3">
<label for="{{ form.zip_code.id_for_label }}" class="form-label">ZIP Code</label>
{{ form.zip_code }}
{% if form.zip_code.errors %}
<div class="invalid-feedback d-block">
{{ form.zip_code.errors.0 }}
</div>
{% endif %}
</div>
</div>
<!-- Authorization Settings -->
<h6 class="mt-4 mb-3">
<i class="fas fa-shield-alt me-2"></i>Authorization Settings
</h6>
<div class="row">
<div class="col-md-4 mb-3">
<div class="form-check">
{{ form.is_authorized_for_medical_decisions }}
<label class="form-check-label" for="{{ form.is_authorized_for_medical_decisions.id_for_label }}">
<strong>Medical Decisions</strong><br>
<small class="text-muted">Can make medical decisions for patient</small>
</label>
</div>
</div>
<div class="col-md-4 mb-3">
<div class="form-check">
{{ form.is_authorized_for_financial_decisions }}
<label class="form-check-label" for="{{ form.is_authorized_for_financial_decisions.id_for_label }}">
<strong>Financial Decisions</strong><br>
<small class="text-muted">Can make financial decisions for patient</small>
</label>
</div>
</div>
<div class="col-md-4 mb-3">
<div class="form-check">
{{ form.is_authorized_for_information }}
<label class="form-check-label" for="{{ form.is_authorized_for_information.id_for_label }}">
<strong>Medical Information</strong><br>
<small class="text-muted">Can receive medical information</small>
</label>
</div>
</div>
</div>
<!-- Additional Notes -->
<div class="mb-3">
<label for="{{ form.notes.id_for_label }}" class="form-label">
<i class="fas fa-sticky-note me-2"></i>Additional Notes
</label>
{{ form.notes }}
{% if form.notes.errors %}
<div class="invalid-feedback d-block">
{{ form.notes.errors.0 }}
</div>
{% endif %}
<div class="form-text">Any additional information about this emergency contact</div>
</div>
<!-- Status -->
<div class="mb-4">
<div class="form-check">
{{ form.is_active }}
<label class="form-check-label" for="{{ form.is_active.id_for_label }}">
<strong>Active Contact</strong>
<br><small class="text-muted">Uncheck to deactivate this emergency contact</small>
</label>
</div>
</div>
<!-- Form Actions -->
<hr>
<div class="d-flex justify-content-between align-items-center">
<div>
<a href="" class="btn btn-secondary">
<i class="fas fa-times me-2"></i>Cancel
</a>
</div>
<div class="btn-group">
<button type="button" class="btn btn-outline-secondary" onclick="resetForm()">
<i class="fas fa-undo me-2"></i>Reset
</button>
<button type="submit" class="btn btn-primary">
<i class="fas fa-save me-2"></i>
{% if object %}Update Contact{% else %}Add Contact{% endif %}
</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
<script>
document.addEventListener('DOMContentLoaded', function() {
// Form validation
const form = document.getElementById('emergencyContactForm');
form.addEventListener('submit', function(event) {
if (!form.checkValidity()) {
event.preventDefault();
event.stopPropagation();
}
form.classList.add('was-validated');
});
// Auto-format phone numbers
const phoneInputs = document.querySelectorAll('input[type="tel"]');
phoneInputs.forEach(function(input) {
input.addEventListener('input', function(e) {
let value = e.target.value.replace(/\D/g, '');
if (value.length >= 6) {
value = value.replace(/(\d{3})(\d{3})(\d{4})/, '($1) $2-$3');
} else if (value.length >= 3) {
value = value.replace(/(\d{3})(\d{3})/, '($1) $2');
}
e.target.value = value;
});
});
// Priority validation
const priorityInput = document.querySelector('input[name="priority"]');
if (priorityInput) {
priorityInput.addEventListener('input', function(e) {
const value = parseInt(e.target.value);
if (value < 1) {
e.target.value = 1;
} else if (value > 10) {
e.target.value = 10;
}
});
}
});
// Reset form function
function resetForm() {
if (confirm('Are you sure you want to reset the form? All unsaved changes will be lost.')) {
document.getElementById('emergencyContactForm').reset();
document.getElementById('emergencyContactForm').classList.remove('was-validated');
}
}
// Auto-save functionality (optional)
let autoSaveTimer;
function autoSave() {
clearTimeout(autoSaveTimer);
autoSaveTimer = setTimeout(function() {
// Implement auto-save logic here if needed
console.log('Auto-saving emergency contact...');
}, 30000); // Auto-save every 30 seconds
}
// Trigger auto-save on form changes
document.getElementById('emergencyContactForm').addEventListener('input', autoSave);
</script>
<style>
.form-control, .form-select {
border-radius: 0.375rem;
border: 1px solid #ced4da;
transition: border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
}
.form-control:focus, .form-select:focus {
border-color: #86b7fe;
outline: 0;
box-shadow: 0 0 0 0.25rem rgba(13, 110, 253, 0.25);
}
.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 {
background-color: rgba(13, 110, 253, 0.1);
border-bottom: 1px solid rgba(0, 0, 0, 0.125);
}
.card-header.bg-primary {
background-color: #0d6efd !important;
}
.btn {
border-radius: 0.375rem;
transition: all 0.15s ease-in-out;
}
.btn:hover {
transform: translateY(-1px);
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}
.form-check-input:checked {
background-color: #0d6efd;
border-color: #0d6efd;
}
.invalid-feedback {
font-size: 0.875rem;
}
.form-text {
font-size: 0.875rem;
color: #6c757d;
}
h6 {
color: #495057;
font-weight: 600;
}
@media (max-width: 768px) {
.btn-group {
display: flex;
flex-direction: column;
gap: 0.5rem;
}
.d-flex.justify-content-between {
flex-direction: column;
gap: 1rem;
}
}
</style>
{% endblock %}