730 lines
31 KiB
HTML
730 lines
31 KiB
HTML
{% extends 'base.html' %}
|
|
{% load static %}
|
|
|
|
{% block title %}{% if claim %}Edit Claim {{ claim.claim_number }}{% else %}New Insurance Claim{% endif %}{% endblock %}
|
|
|
|
{% block extra_css %}
|
|
<link href="{% static 'assets/plugins/select2/dist/css/select2.min.css' %}" rel="stylesheet" />
|
|
<style>
|
|
.form-section {
|
|
background: #fff;
|
|
border-radius: 15px;
|
|
box-shadow: 0 5px 15px rgba(0, 0, 0, 0.08);
|
|
margin-bottom: 2rem;
|
|
overflow: hidden;
|
|
}
|
|
.form-section-header {
|
|
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
|
color: white;
|
|
padding: 1.5rem;
|
|
margin: 0;
|
|
}
|
|
.form-section-body {
|
|
padding: 2rem;
|
|
}
|
|
.form-floating > label {
|
|
color: #6c757d;
|
|
}
|
|
.form-floating > .form-control:focus ~ label,
|
|
.form-floating > .form-control:not(:placeholder-shown) ~ label {
|
|
color: #007bff;
|
|
}
|
|
.btn-add-item {
|
|
border: 2px dashed #007bff;
|
|
color: #007bff;
|
|
background: transparent;
|
|
transition: all 0.3s ease;
|
|
}
|
|
.btn-add-item:hover {
|
|
background: #007bff;
|
|
color: white;
|
|
border-color: #007bff;
|
|
}
|
|
.dynamic-item {
|
|
border: 1px solid #e9ecef;
|
|
border-radius: 10px;
|
|
padding: 1rem;
|
|
margin-bottom: 1rem;
|
|
background: #f8f9fa;
|
|
position: relative;
|
|
}
|
|
.remove-item {
|
|
position: absolute;
|
|
top: 10px;
|
|
right: 10px;
|
|
background: #dc3545;
|
|
color: white;
|
|
border: none;
|
|
border-radius: 50%;
|
|
width: 30px;
|
|
height: 30px;
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
font-size: 12px;
|
|
}
|
|
.priority-indicator {
|
|
width: 12px;
|
|
height: 12px;
|
|
border-radius: 50%;
|
|
display: inline-block;
|
|
margin-right: 8px;
|
|
}
|
|
.priority-low { background-color: #28a745; }
|
|
.priority-normal { background-color: #17a2b8; }
|
|
.priority-high { background-color: #ffc107; }
|
|
.priority-urgent { background-color: #fd7e14; }
|
|
.priority-emergency { background-color: #dc3545; }
|
|
.auto-save-indicator {
|
|
position: fixed;
|
|
top: 20px;
|
|
right: 20px;
|
|
z-index: 1050;
|
|
display: none;
|
|
}
|
|
.form-help {
|
|
font-size: 0.875rem;
|
|
color: #6c757d;
|
|
margin-top: 0.25rem;
|
|
}
|
|
.required-field::after {
|
|
content: " *";
|
|
color: #dc3545;
|
|
}
|
|
</style>
|
|
{% endblock %}
|
|
|
|
{% block content %}
|
|
<div id="content" class="app-content">
|
|
<!-- Auto-save indicator -->
|
|
<div class="auto-save-indicator">
|
|
<div class="alert alert-success alert-dismissible fade show" role="alert" id="autoSaveAlert">
|
|
<i class="fas fa-check-circle me-2"></i>
|
|
<span id="autoSaveMessage">Draft saved automatically</span>
|
|
<button type="button" class="btn-close" data-bs-dismiss="alert"></button>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Breadcrumb -->
|
|
<ol class="breadcrumb">
|
|
<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:insurance_claims_list' %}">Claims</a></li>
|
|
<li class="breadcrumb-item active">{% if claim %}Edit Claim{% else %}New Claim{% endif %}</li>
|
|
</ol>
|
|
|
|
<!-- Page Header -->
|
|
<div class="d-flex align-items-center justify-content-between mb-4">
|
|
<div>
|
|
<h1 class="page-header mb-0">
|
|
<i class="fas fa-file-medical me-3"></i>
|
|
{% if claim %}Edit Claim {{ claim.claim_number }}{% else %}New Insurance Claim{% endif %}
|
|
</h1>
|
|
<p class="text-muted mb-0">
|
|
{% if claim %}Update the insurance claim details{% else %}Create a new insurance claim for patient services{% endif %}
|
|
</p>
|
|
</div>
|
|
<div>
|
|
<a href="{% if claim %}{% url 'patients:insurance_claim_detail' claim.id %}{% else %}{% url 'patients:insurance_claims_list' %}{% endif %}"
|
|
class="btn btn-outline-secondary me-2">
|
|
<i class="fas fa-arrow-left me-2"></i>Cancel
|
|
</a>
|
|
<button type="button" class="btn btn-info me-2" onclick="saveDraft()">
|
|
<i class="fas fa-save me-2"></i>Save Draft
|
|
</button>
|
|
</div>
|
|
</div>
|
|
|
|
<form method="post" id="claimForm" novalidate>
|
|
{% csrf_token %}
|
|
|
|
<!-- Basic Information -->
|
|
<div class="form-section">
|
|
<h4 class="form-section-header">
|
|
<i class="fas fa-info-circle me-2"></i>Basic Information
|
|
</h4>
|
|
<div class="form-section-body">
|
|
<div class="row g-3">
|
|
<div class="col-md-6">
|
|
<div class="form-floating">
|
|
<select class="form-select" id="patient" name="patient" required onchange="loadPatientInsurance()">
|
|
<option value="">Select Patient</option>
|
|
{% for patient in patients %}
|
|
<option value="{{ patient.id }}"
|
|
{% if claim and claim.patient.id == patient.id %}selected{% endif %}>
|
|
{{ patient.get_full_name }} ({{ patient.mrn }})
|
|
</option>
|
|
{% endfor %}
|
|
</select>
|
|
<label for="patient" class="required-field">Patient</label>
|
|
</div>
|
|
<div class="form-help">Select the patient for this claim</div>
|
|
</div>
|
|
|
|
<div class="col-md-6">
|
|
<div class="form-floating">
|
|
<select class="form-select" id="insurance_info" name="insurance_info" required>
|
|
<option value="">Select Insurance Policy</option>
|
|
{% if claim %}
|
|
<option value="{{ claim.insurance_info.id }}" selected>
|
|
{{ claim.insurance_info.insurance_company }} - {{ claim.insurance_info.policy_number }}
|
|
</option>
|
|
{% endif %}
|
|
</select>
|
|
<label for="insurance_info" class="required-field">Insurance Policy</label>
|
|
</div>
|
|
<div class="form-help">Select the insurance policy to use for this claim</div>
|
|
</div>
|
|
|
|
<div class="col-md-4">
|
|
<div class="form-floating">
|
|
<select class="form-select" id="claim_type" name="claim_type" required>
|
|
<option value="">Select Claim Type</option>
|
|
{% for value, label in type_choices %}
|
|
<option value="{{ value }}"
|
|
{% if claim and claim.claim_type == value %}selected{% endif %}>
|
|
{{ label }}
|
|
</option>
|
|
{% endfor %}
|
|
</select>
|
|
<label for="claim_type" class="required-field">Claim Type</label>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="col-md-4">
|
|
<div class="form-floating">
|
|
<select class="form-select" id="priority" name="priority" onchange="updatePriorityIndicator()">
|
|
{% for value, label in priority_choices %}
|
|
<option value="{{ value }}"
|
|
{% if claim and claim.priority == value %}selected{% elif not claim and value == 'NORMAL' %}selected{% endif %}>
|
|
{{ label }}
|
|
</option>
|
|
{% endfor %}
|
|
</select>
|
|
<label for="priority">Priority</label>
|
|
</div>
|
|
<div class="form-help">
|
|
<span class="priority-indicator priority-normal" id="priorityIndicator"></span>
|
|
<span id="priorityText">Normal priority claim</span>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="col-md-4">
|
|
<div class="form-floating">
|
|
<input type="date" class="form-control" id="service_date" name="service_date"
|
|
value="{% if claim %}{{ claim.service_date|date:'Y-m-d' }}{% endif %}" required>
|
|
<label for="service_date" class="required-field">Service Date</label>
|
|
</div>
|
|
<div class="form-help">Date when the service was provided</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Service Provider Information -->
|
|
<div class="form-section">
|
|
<h4 class="form-section-header">
|
|
<i class="fas fa-user-md me-2"></i>Service Provider Information
|
|
</h4>
|
|
<div class="form-section-body">
|
|
<div class="row g-3">
|
|
<div class="col-md-6">
|
|
<div class="form-floating">
|
|
<input type="text" class="form-control" id="service_provider" name="service_provider"
|
|
value="{% if claim %}{{ claim.service_provider }}{% endif %}" required>
|
|
<label for="service_provider" class="required-field">Service Provider Name</label>
|
|
</div>
|
|
<div class="form-help">Name of the healthcare provider</div>
|
|
</div>
|
|
|
|
<div class="col-md-6">
|
|
<div class="form-floating">
|
|
<input type="text" class="form-control" id="service_provider_license" name="service_provider_license"
|
|
value="{% if claim %}{{ claim.service_provider_license }}{% endif %}"
|
|
placeholder="SML12345">
|
|
<label for="service_provider_license">Provider License Number</label>
|
|
</div>
|
|
<div class="form-help">Saudi Medical License number (optional)</div>
|
|
</div>
|
|
|
|
<div class="col-md-6">
|
|
<div class="form-floating">
|
|
<input type="text" class="form-control" id="facility_name" name="facility_name"
|
|
value="{% if claim %}{{ claim.facility_name }}{% endif %}">
|
|
<label for="facility_name">Healthcare Facility</label>
|
|
</div>
|
|
<div class="form-help">Name of the healthcare facility</div>
|
|
</div>
|
|
|
|
<div class="col-md-6">
|
|
<div class="form-floating">
|
|
<input type="text" class="form-control" id="facility_license" name="facility_license"
|
|
value="{% if claim %}{{ claim.facility_license }}{% endif %}"
|
|
placeholder="MOH123456">
|
|
<label for="facility_license">Facility License Number</label>
|
|
</div>
|
|
<div class="form-help">MOH facility license number (optional)</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Medical Information -->
|
|
<div class="form-section">
|
|
<h4 class="form-section-header">
|
|
<i class="fas fa-stethoscope me-2"></i>Medical Information
|
|
</h4>
|
|
<div class="form-section-body">
|
|
<div class="row g-3">
|
|
<div class="col-md-6">
|
|
<div class="form-floating">
|
|
<input type="text" class="form-control" id="primary_diagnosis_code" name="primary_diagnosis_code"
|
|
value="{% if claim %}{{ claim.primary_diagnosis_code }}{% endif %}"
|
|
placeholder="E11.9" required>
|
|
<label for="primary_diagnosis_code" class="required-field">Primary Diagnosis Code</label>
|
|
</div>
|
|
<div class="form-help">ICD-10 diagnosis code</div>
|
|
</div>
|
|
|
|
<div class="col-md-6">
|
|
<div class="form-floating">
|
|
<input type="text" class="form-control" id="primary_diagnosis_description" name="primary_diagnosis_description"
|
|
value="{% if claim %}{{ claim.primary_diagnosis_description }}{% endif %}" required>
|
|
<label for="primary_diagnosis_description" class="required-field">Primary Diagnosis Description</label>
|
|
</div>
|
|
<div class="form-help">Description of the primary diagnosis</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Secondary Diagnoses -->
|
|
<div class="mt-4">
|
|
<div class="d-flex justify-content-between align-items-center mb-3">
|
|
<h6 class="mb-0">Secondary Diagnoses</h6>
|
|
<button type="button" class="btn btn-sm btn-add-item" onclick="addSecondaryDiagnosis()">
|
|
<i class="fas fa-plus me-2"></i>Add Secondary Diagnosis
|
|
</button>
|
|
</div>
|
|
<div id="secondaryDiagnoses">
|
|
{% if claim and claim.secondary_diagnosis_codes %}
|
|
{% for diagnosis in claim.secondary_diagnosis_codes %}
|
|
<div class="dynamic-item">
|
|
<button type="button" class="remove-item" onclick="removeItem(this)">
|
|
<i class="fas fa-times"></i>
|
|
</button>
|
|
<div class="row g-2">
|
|
<div class="col-md-4">
|
|
<div class="form-floating">
|
|
<input type="text" class="form-control secondary-diagnosis-code"
|
|
value="{{ diagnosis.code }}" placeholder="ICD-10 Code">
|
|
<label>Diagnosis Code</label>
|
|
</div>
|
|
</div>
|
|
<div class="col-md-8">
|
|
<div class="form-floating">
|
|
<input type="text" class="form-control secondary-diagnosis-desc"
|
|
value="{{ diagnosis.description }}" placeholder="Description">
|
|
<label>Description</label>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
{% endfor %}
|
|
{% endif %}
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Procedures -->
|
|
<div class="mt-4">
|
|
<div class="d-flex justify-content-between align-items-center mb-3">
|
|
<h6 class="mb-0">Procedures</h6>
|
|
<button type="button" class="btn btn-sm btn-add-item" onclick="addProcedure()">
|
|
<i class="fas fa-plus me-2"></i>Add Procedure
|
|
</button>
|
|
</div>
|
|
<div id="procedures">
|
|
{% if claim and claim.procedure_codes %}
|
|
{% for procedure in claim.procedure_codes %}
|
|
<div class="dynamic-item">
|
|
<button type="button" class="remove-item" onclick="removeItem(this)">
|
|
<i class="fas fa-times"></i>
|
|
</button>
|
|
<div class="row g-2">
|
|
<div class="col-md-3">
|
|
<div class="form-floating">
|
|
<input type="text" class="form-control procedure-code"
|
|
value="{{ procedure.code }}" placeholder="CPT Code">
|
|
<label>Procedure Code</label>
|
|
</div>
|
|
</div>
|
|
<div class="col-md-6">
|
|
<div class="form-floating">
|
|
<input type="text" class="form-control procedure-desc"
|
|
value="{{ procedure.description }}" placeholder="Description">
|
|
<label>Description</label>
|
|
</div>
|
|
</div>
|
|
<div class="col-md-3">
|
|
<div class="form-floating">
|
|
<input type="number" class="form-control procedure-cost"
|
|
value="{{ procedure.cost|default:'' }}" step="0.01" placeholder="0.00">
|
|
<label>Cost (SAR)</label>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
{% endfor %}
|
|
{% endif %}
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Financial Information -->
|
|
<div class="form-section">
|
|
<h4 class="form-section-header">
|
|
<i class="fas fa-calculator me-2"></i>Financial Information
|
|
</h4>
|
|
<div class="form-section-body">
|
|
<div class="row g-3">
|
|
<div class="col-md-6">
|
|
<div class="form-floating">
|
|
<input type="number" class="form-control" id="billed_amount" name="billed_amount"
|
|
value="{% if claim %}{{ claim.billed_amount }}{% endif %}"
|
|
step="0.01" min="0" required>
|
|
<label for="billed_amount" class="required-field">Billed Amount (SAR)</label>
|
|
</div>
|
|
<div class="form-help">Total amount billed for services</div>
|
|
</div>
|
|
|
|
<div class="col-md-6">
|
|
<div class="form-floating">
|
|
<input type="text" class="form-control" id="authorization_number" name="authorization_number"
|
|
value="{% if claim %}{{ claim.authorization_number }}{% endif %}"
|
|
placeholder="AUTH123456">
|
|
<label for="authorization_number">Prior Authorization Number</label>
|
|
</div>
|
|
<div class="form-help">Required for certain procedures (optional)</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Saudi-specific Information -->
|
|
<div class="form-section">
|
|
<h4 class="form-section-header">
|
|
<i class="fas fa-id-card me-2"></i>Saudi-specific Information
|
|
</h4>
|
|
<div class="form-section-body">
|
|
<div class="row g-3">
|
|
<div class="col-md-6">
|
|
<div class="form-floating">
|
|
<input type="text" class="form-control" id="saudi_id_number" name="saudi_id_number"
|
|
value="{% if claim %}{{ claim.saudi_id_number }}{% endif %}"
|
|
placeholder="1234567890" maxlength="10">
|
|
<label for="saudi_id_number">Saudi ID/Iqama Number</label>
|
|
</div>
|
|
<div class="form-help">10-digit Saudi National ID or Iqama number</div>
|
|
</div>
|
|
|
|
<div class="col-md-6">
|
|
<div class="form-floating">
|
|
<input type="text" class="form-control" id="insurance_card_number" name="insurance_card_number"
|
|
value="{% if claim %}{{ claim.insurance_card_number }}{% endif %}"
|
|
placeholder="IC123456789">
|
|
<label for="insurance_card_number">Insurance Card Number</label>
|
|
</div>
|
|
<div class="form-help">Insurance card number from physical card</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Additional Information -->
|
|
<div class="form-section">
|
|
<h4 class="form-section-header">
|
|
<i class="fas fa-sticky-note me-2"></i>Additional Information
|
|
</h4>
|
|
<div class="form-section-body">
|
|
<div class="form-floating">
|
|
<textarea class="form-control" id="notes" name="notes" style="height: 120px"
|
|
placeholder="Enter any additional notes or comments about this claim...">{% if claim %}{{ claim.notes }}{% endif %}</textarea>
|
|
<label for="notes">Notes</label>
|
|
</div>
|
|
<div class="form-help">Additional notes or comments about this claim</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Form Actions -->
|
|
<div class="d-flex justify-content-between align-items-center">
|
|
<div>
|
|
<a href="{% if claim %}{% url 'patients:insurance_claim_detail' claim.id %}{% else %}{% url 'patients:insurance_claims_list' %}{% endif %}"
|
|
class="btn btn-outline-secondary">
|
|
<i class="fas fa-times me-2"></i>Cancel
|
|
</a>
|
|
</div>
|
|
<div>
|
|
<button type="button" class="btn btn-info me-2" onclick="saveDraft()">
|
|
<i class="fas fa-save me-2"></i>Save as Draft
|
|
</button>
|
|
<button type="submit" class="btn btn-primary">
|
|
<i class="fas fa-check me-2"></i>
|
|
{% if claim %}Update Claim{% else %}Create Claim{% endif %}
|
|
</button>
|
|
</div>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
|
|
<!-- Hidden fields for JSON data -->
|
|
<input type="hidden" id="secondary_diagnosis_codes" name="secondary_diagnosis_codes">
|
|
<input type="hidden" id="procedure_codes" name="procedure_codes">
|
|
{% endblock %}
|
|
|
|
{% block extra_js %}
|
|
<script src="{% static 'assets/plugins/select2/dist/js/select2.min.js' %}"></script>
|
|
|
|
<script>
|
|
$(document).ready(function() {
|
|
// Initialize Select2
|
|
$('#patient, #insurance_info').select2({
|
|
theme: 'bootstrap-5',
|
|
width: '100%'
|
|
});
|
|
|
|
// Auto-save every 30 seconds
|
|
setInterval(saveDraft, 30000);
|
|
|
|
// Update priority indicator on load
|
|
updatePriorityIndicator();
|
|
});
|
|
|
|
function loadPatientInsurance() {
|
|
const patientId = $('#patient').val();
|
|
if (!patientId) {
|
|
$('#insurance_info').empty().append('<option value="">Select Insurance Policy</option>');
|
|
return;
|
|
}
|
|
|
|
$.ajax({
|
|
url: `/patients/ajax/patient/${patientId}/insurance/`,
|
|
method: 'GET',
|
|
success: function(response) {
|
|
if (response.success) {
|
|
const insuranceSelect = $('#insurance_info');
|
|
insuranceSelect.empty().append('<option value="">Select Insurance Policy</option>');
|
|
|
|
response.insurance_policies.forEach(function(policy) {
|
|
insuranceSelect.append(`
|
|
<option value="${policy.id}">
|
|
${policy.insurance_company} - ${policy.policy_number} (${policy.insurance_type})
|
|
</option>
|
|
`);
|
|
});
|
|
}
|
|
},
|
|
error: function() {
|
|
alert('Error loading insurance policies. Please try again.');
|
|
}
|
|
});
|
|
}
|
|
|
|
function updatePriorityIndicator() {
|
|
const priority = $('#priority').val().toLowerCase();
|
|
const indicator = $('#priorityIndicator');
|
|
const text = $('#priorityText');
|
|
|
|
// Remove all priority classes
|
|
indicator.removeClass('priority-low priority-normal priority-high priority-urgent priority-emergency');
|
|
|
|
// Add appropriate class and update text
|
|
indicator.addClass(`priority-${priority}`);
|
|
|
|
const priorityTexts = {
|
|
'low': 'Low priority claim',
|
|
'normal': 'Normal priority claim',
|
|
'high': 'High priority claim',
|
|
'urgent': 'Urgent priority claim',
|
|
'emergency': 'Emergency priority claim'
|
|
};
|
|
|
|
text.text(priorityTexts[priority] || 'Normal priority claim');
|
|
}
|
|
|
|
function addSecondaryDiagnosis() {
|
|
const container = $('#secondaryDiagnoses');
|
|
const item = $(`
|
|
<div class="dynamic-item">
|
|
<button type="button" class="remove-item" onclick="removeItem(this)">
|
|
<i class="fas fa-times"></i>
|
|
</button>
|
|
<div class="row g-2">
|
|
<div class="col-md-4">
|
|
<div class="form-floating">
|
|
<input type="text" class="form-control secondary-diagnosis-code" placeholder="ICD-10 Code">
|
|
<label>Diagnosis Code</label>
|
|
</div>
|
|
</div>
|
|
<div class="col-md-8">
|
|
<div class="form-floating">
|
|
<input type="text" class="form-control secondary-diagnosis-desc" placeholder="Description">
|
|
<label>Description</label>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
`);
|
|
container.append(item);
|
|
}
|
|
|
|
function addProcedure() {
|
|
const container = $('#procedures');
|
|
const item = $(`
|
|
<div class="dynamic-item">
|
|
<button type="button" class="remove-item" onclick="removeItem(this)">
|
|
<i class="fas fa-times"></i>
|
|
</button>
|
|
<div class="row g-2">
|
|
<div class="col-md-3">
|
|
<div class="form-floating">
|
|
<input type="text" class="form-control procedure-code" placeholder="CPT Code">
|
|
<label>Procedure Code</label>
|
|
</div>
|
|
</div>
|
|
<div class="col-md-6">
|
|
<div class="form-floating">
|
|
<input type="text" class="form-control procedure-desc" placeholder="Description">
|
|
<label>Description</label>
|
|
</div>
|
|
</div>
|
|
<div class="col-md-3">
|
|
<div class="form-floating">
|
|
<input type="number" class="form-control procedure-cost" step="0.01" placeholder="0.00">
|
|
<label>Cost (SAR)</label>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
`);
|
|
container.append(item);
|
|
}
|
|
|
|
function removeItem(button) {
|
|
$(button).closest('.dynamic-item').remove();
|
|
}
|
|
|
|
function collectSecondaryDiagnoses() {
|
|
const diagnoses = [];
|
|
$('#secondaryDiagnoses .dynamic-item').each(function() {
|
|
const code = $(this).find('.secondary-diagnosis-code').val();
|
|
const description = $(this).find('.secondary-diagnosis-desc').val();
|
|
if (code && description) {
|
|
diagnoses.push({ code, description });
|
|
}
|
|
});
|
|
return diagnoses;
|
|
}
|
|
|
|
function collectProcedures() {
|
|
const procedures = [];
|
|
$('#procedures .dynamic-item').each(function() {
|
|
const code = $(this).find('.procedure-code').val();
|
|
const description = $(this).find('.procedure-desc').val();
|
|
const cost = $(this).find('.procedure-cost').val();
|
|
if (code && description) {
|
|
procedures.push({
|
|
code,
|
|
description,
|
|
cost: cost ? parseFloat(cost) : null
|
|
});
|
|
}
|
|
});
|
|
return procedures;
|
|
}
|
|
|
|
function saveDraft() {
|
|
// Collect dynamic data
|
|
const secondaryDiagnoses = collectSecondaryDiagnoses();
|
|
const procedures = collectProcedures();
|
|
|
|
// Update hidden fields
|
|
$('#secondary_diagnosis_codes').val(JSON.stringify(secondaryDiagnoses));
|
|
$('#procedure_codes').val(JSON.stringify(procedures));
|
|
|
|
// Prepare form data
|
|
const formData = new FormData($('#claimForm')[0]);
|
|
|
|
$.ajaxSetup({
|
|
beforeSend: function(xhr, settings) {
|
|
if (!this.crossDomain) {
|
|
xhr.setRequestHeader("X-CSRFToken", $('[name=csrfmiddlewaretoken]').val());
|
|
}
|
|
}
|
|
});
|
|
|
|
// Save draft via AJAX
|
|
$.ajax({
|
|
url: '{% url "patients:save_insurance_draft" %}',
|
|
method: 'POST',
|
|
data: formData,
|
|
processData: false,
|
|
contentType: false,
|
|
success: function(response) {
|
|
if (response.success) {
|
|
showAutoSaveIndicator('Draft saved successfully');
|
|
}
|
|
},
|
|
error: function() {
|
|
console.log('Auto-save failed');
|
|
}
|
|
});
|
|
}
|
|
|
|
function showAutoSaveIndicator(message) {
|
|
$('#autoSaveMessage').text(message);
|
|
$('.auto-save-indicator').show();
|
|
setTimeout(function() {
|
|
$('.auto-save-indicator').hide();
|
|
}, 3000);
|
|
}
|
|
|
|
// Form submission
|
|
$('#claimForm').submit(function(e) {
|
|
// Collect dynamic data before submission
|
|
const secondaryDiagnoses = collectSecondaryDiagnoses();
|
|
const procedures = collectProcedures();
|
|
|
|
// Update hidden fields
|
|
$('#secondary_diagnosis_codes').val(JSON.stringify(secondaryDiagnoses));
|
|
$('#procedure_codes').val(JSON.stringify(procedures));
|
|
|
|
// Validate required fields
|
|
const requiredFields = ['patient', 'insurance_info', 'claim_type', 'service_date',
|
|
'service_provider', 'primary_diagnosis_code', 'primary_diagnosis_description',
|
|
'billed_amount'];
|
|
|
|
let isValid = true;
|
|
requiredFields.forEach(function(fieldName) {
|
|
const field = $(`[name="${fieldName}"]`);
|
|
if (!field.val()) {
|
|
field.addClass('is-invalid');
|
|
isValid = false;
|
|
} else {
|
|
field.removeClass('is-invalid');
|
|
}
|
|
});
|
|
|
|
if (!isValid) {
|
|
e.preventDefault();
|
|
alert('Please fill in all required fields.');
|
|
return false;
|
|
}
|
|
});
|
|
|
|
// Remove validation errors on input
|
|
$('input, select, textarea').on('input change', function() {
|
|
$(this).removeClass('is-invalid');
|
|
});
|
|
</script>
|
|
{% endblock %}
|
|
|