38960-vm/includes/layout/footer.php
2026-03-04 08:07:04 +00:00

2025 lines
107 KiB
PHP

<?php
// includes/layout/footer.php
?>
</div>
</div>
<!-- Add Patient Modal -->
<div class="modal fade" id="addPatientModal" tabindex="-1" aria-hidden="true">
<div class="modal-dialog">
<form action="<?php echo $_SERVER['PHP_SELF']; ?>?section=<?php echo $section; ?>" method="POST">
<input type="hidden" name="action" value="add_patient">
<div class="modal-content border-0 shadow">
<div class="modal-header">
<h5 class="modal-title fw-bold text-white"><?php echo __('add_patient'); ?></h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<div class="mb-3">
<label class="form-label"><?php echo __('name'); ?></label>
<input type="text" name="name" class="form-control" required>
</div>
<div class="row">
<div class="col-md-6 mb-3">
<label class="form-label"><?php echo __('phone'); ?></label>
<input type="text" name="phone" class="form-control" required>
</div>
<div class="col-md-6 mb-3">
<label class="form-label"><?php echo __('dob'); ?></label>
<input type="date" name="dob" class="form-control">
</div>
</div>
<div class="row">
<div class="col-md-6 mb-3">
<label class="form-label"><?php echo __('gender'); ?></label>
<select name="gender" class="form-select">
<option value="Male"><?php echo __('male'); ?></option>
<option value="Female"><?php echo __('female'); ?></option>
<option value="Other"><?php echo __('other'); ?></option>
</select>
</div>
<div class="col-md-6 mb-3">
<label class="form-label"><?php echo __('blood_group'); ?></label>
<input type="text" name="blood_group" class="form-control" placeholder="O+, A-, etc.">
</div>
</div>
<hr>
<h6 class="fw-bold mb-3"><?php echo __('insurance'); ?> (<?php echo __('optional'); ?>)</h6>
<div class="row">
<div class="col-md-6 mb-3">
<label class="form-label"><?php echo __('insurance_company'); ?></label>
<select name="insurance_company_id" class="form-select">
<option value=""><?php echo __('not_insured'); ?></option>
<?php foreach ($all_insurance as $i): ?>
<option value="<?php echo $i['id']; ?>"><?php echo htmlspecialchars($i['name']); ?></option>
<?php endforeach; ?>
</select>
</div>
<div class="col-md-6 mb-3">
<label class="form-label"><?php echo __('policy_number'); ?></label>
<input type="text" name="policy_number" class="form-control">
</div>
</div>
<div class="mb-3">
<label class="form-label"><?php echo __('address'); ?></label>
<textarea name="address" class="form-control" rows="2"></textarea>
</div>
</div>
<div class="modal-footer bg-light">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal"><?php echo __('cancel'); ?></button>
<button type="submit" class="btn btn-primary px-4"><?php echo __('save'); ?></button>
</div>
</div>
</form>
</div>
</div>
<!-- Edit Patient Modal -->
<div class="modal fade" id="editPatientModal" tabindex="-1" aria-hidden="true">
<div class="modal-dialog">
<form action="<?php echo $_SERVER['PHP_SELF']; ?>?section=<?php echo $section; ?>" method="POST">
<input type="hidden" name="action" value="edit_patient">
<input type="hidden" name="id" id="edit_patient_id">
<div class="modal-content border-0 shadow">
<div class="modal-header">
<h5 class="modal-title fw-bold text-white"><?php echo __('edit'); ?> <?php echo __('patient'); ?></h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<div class="mb-3">
<label class="form-label"><?php echo __('name'); ?></label>
<input type="text" name="name" id="edit_patient_name" class="form-control" required>
</div>
<div class="row">
<div class="col-md-6 mb-3">
<label class="form-label"><?php echo __('phone'); ?></label>
<input type="text" name="phone" id="edit_patient_phone" class="form-control" required>
</div>
<div class="col-md-6 mb-3">
<label class="form-label"><?php echo __('dob'); ?></label>
<input type="date" name="dob" id="edit_patient_dob" class="form-control">
</div>
</div>
<div class="row">
<div class="col-md-6 mb-3">
<label class="form-label"><?php echo __('gender'); ?></label>
<select name="gender" id="edit_patient_gender" class="form-select">
<option value="Male"><?php echo __('male'); ?></option>
<option value="Female"><?php echo __('female'); ?></option>
<option value="Other"><?php echo __('other'); ?></option>
</select>
</div>
<div class="col-md-6 mb-3">
<label class="form-label"><?php echo __('blood_group'); ?></label>
<input type="text" name="blood_group" id="edit_patient_blood_group" class="form-control" placeholder="O+, A-, etc.">
</div>
</div>
<hr>
<h6 class="fw-bold mb-3"><?php echo __('insurance'); ?> (<?php echo __('optional'); ?>)</h6>
<div class="row">
<div class="col-md-6 mb-3">
<label class="form-label"><?php echo __('insurance_company'); ?></label>
<select name="insurance_company_id" id="edit_patient_insurance_company_id" class="form-select">
<option value=""><?php echo __('not_insured'); ?></option>
<?php foreach ($all_insurance as $i): ?>
<option value="<?php echo $i['id']; ?>"><?php echo htmlspecialchars($i['name']); ?></option>
<?php endforeach; ?>
</select>
</div>
<div class="col-md-6 mb-3">
<label class="form-label"><?php echo __('policy_number'); ?></label>
<input type="text" name="policy_number" id="edit_patient_policy_number" class="form-control">
</div>
</div>
<div class="mb-3">
<label class="form-label"><?php echo __('address'); ?></label>
<textarea name="address" id="edit_patient_address" class="form-control" rows="2"></textarea>
</div>
</div>
<div class="modal-footer bg-light">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal"><?php echo __('cancel'); ?></button>
<button type="submit" class="btn btn-primary px-4"><?php echo __('save'); ?></button>
</div>
</div>
</form>
</div>
</div>
<!-- Delete Patient Modal -->
<div class="modal fade" id="deletePatientModal" tabindex="-1" aria-hidden="true">
<div class="modal-dialog">
<form action="<?php echo $_SERVER['PHP_SELF']; ?>?section=<?php echo $section; ?>" method="POST">
<input type="hidden" name="action" value="delete_patient">
<input type="hidden" name="id" id="delete_patient_id">
<div class="modal-content border-0 shadow">
<div class="modal-header">
<h5 class="modal-title fw-bold text-white"><?php echo __('delete'); ?> <?php echo __('patient'); ?></h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<p><?php echo __('confirm_delete'); ?> <strong id="delete_patient_name"></strong>?</p>
</div>
<div class="modal-footer bg-light">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal"><?php echo __('cancel'); ?></button>
<button type="submit" class="btn btn-danger px-4"><?php echo __('delete'); ?></button>
</div>
</div>
</form>
</div>
</div>
<!-- Add Doctor Modal -->
<div class="modal fade" id="addDoctorModal" tabindex="-1" aria-hidden="true">
<div class="modal-dialog">
<form action="<?php echo $_SERVER['PHP_SELF']; ?>?section=<?php echo $section; ?>" method="POST">
<input type="hidden" name="action" value="add_doctor">
<div class="modal-content border-0 shadow">
<div class="modal-header">
<h5 class="modal-title fw-bold text-white"><?php echo __('add_doctor'); ?></h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<div class="mb-3">
<label class="form-label"><?php echo __('name_en'); ?></label>
<input type="text" name="name_en" class="form-control" required>
</div>
<div class="mb-3">
<label class="form-label"><?php echo __('name_ar'); ?></label>
<input type="text" name="name_ar" class="form-control" dir="rtl" required>
</div>
<div class="row">
<div class="col-md-6 mb-3">
<label class="form-label"><?php echo __('phone'); ?></label>
<input type="text" name="tel" class="form-control">
</div>
<div class="col-md-6 mb-3">
<label class="form-label"><?php echo __('email'); ?></label>
<input type="email" name="email" class="form-control">
</div>
</div>
<div class="mb-3">
<label class="form-label"><?php echo __('specialization_en'); ?></label>
<input type="text" name="specialization_en" class="form-control">
</div>
<div class="mb-3">
<label class="form-label"><?php echo __('specialization_ar'); ?></label>
<input type="text" name="specialization_ar" class="form-control" dir="rtl">
</div>
<div class="mb-3">
<label class="form-label"><?php echo __('department'); ?></label>
<select name="department_id" class="form-select">
<option value=""><?php echo __('search'); ?>...</option>
<?php foreach ($all_departments as $dept): ?>
<option value="<?php echo $dept['id']; ?>"><?php echo htmlspecialchars($dept['name']); ?></option>
<?php endforeach; ?>
</select>
</div>
</div>
<div class="modal-footer bg-light">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal"><?php echo __('cancel'); ?></button>
<button type="submit" class="btn btn-primary px-4"><?php echo __('save'); ?></button>
</div>
</div>
</form>
</div>
</div>
<!-- Edit Doctor Modal -->
<div class="modal fade" id="editDoctorModal" tabindex="-1" aria-hidden="true">
<div class="modal-dialog">
<form action="<?php echo $_SERVER['PHP_SELF']; ?>?section=<?php echo $section; ?>" method="POST">
<input type="hidden" name="action" value="edit_doctor">
<input type="hidden" name="id" id="edit_doctor_id">
<div class="modal-content border-0 shadow">
<div class="modal-header">
<h5 class="modal-title fw-bold text-white"><?php echo __('edit'); ?> <?php echo __('doctor'); ?></h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<div class="mb-3">
<label class="form-label"><?php echo __('name_en'); ?></label>
<input type="text" name="name_en" id="edit_doctor_name_en" class="form-control" required>
</div>
<div class="mb-3">
<label class="form-label"><?php echo __('name_ar'); ?></label>
<input type="text" name="name_ar" id="edit_doctor_name_ar" class="form-control" dir="rtl" required>
</div>
<div class="row">
<div class="col-md-6 mb-3">
<label class="form-label"><?php echo __('phone'); ?></label>
<input type="text" name="tel" id="edit_doctor_tel" class="form-control">
</div>
<div class="col-md-6 mb-3">
<label class="form-label"><?php echo __('email'); ?></label>
<input type="email" name="email" id="edit_doctor_email" class="form-control">
</div>
</div>
<div class="mb-3">
<label class="form-label"><?php echo __('specialization_en'); ?></label>
<input type="text" name="specialization_en" id="edit_doctor_spec_en" class="form-control">
</div>
<div class="mb-3">
<label class="form-label"><?php echo __('specialization_ar'); ?></label>
<input type="text" name="specialization_ar" id="edit_doctor_spec_ar" class="form-control" dir="rtl">
</div>
<div class="mb-3">
<label class="form-label"><?php echo __('department'); ?></label>
<select name="department_id" id="edit_doctor_dept_id" class="form-select">
<option value=""><?php echo __('search'); ?>...</option>
<?php foreach ($all_departments as $dept): ?>
<option value="<?php echo $dept['id']; ?>"><?php echo htmlspecialchars($dept['name']); ?></option>
<?php endforeach; ?>
</select>
</div>
</div>
<div class="modal-footer bg-light">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal"><?php echo __('cancel'); ?></button>
<button type="submit" class="btn btn-primary px-4"><?php echo __('save'); ?></button>
</div>
</div>
</form>
</div>
</div>
<!-- Delete Doctor Modal -->
<div class="modal fade" id="deleteDoctorModal" tabindex="-1" aria-hidden="true">
<div class="modal-dialog">
<form action="<?php echo $_SERVER['PHP_SELF']; ?>?section=<?php echo $section; ?>" method="POST">
<input type="hidden" name="action" value="delete_doctor">
<input type="hidden" name="id" id="delete_doctor_id">
<div class="modal-content border-0 shadow">
<div class="modal-header">
<h5 class="modal-title fw-bold text-white"><?php echo __('delete'); ?> <?php echo __('doctor'); ?></h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<p><?php echo __('confirm_delete'); ?>?</p>
</div>
<div class="modal-footer bg-light">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal"><?php echo __('cancel'); ?></button>
<button type="submit" class="btn btn-danger px-4"><?php echo __('delete'); ?></button>
</div>
</div>
</form>
</div>
</div>
<!-- Add Nurse Modal -->
<div class="modal fade" id="addNurseModal" tabindex="-1" aria-hidden="true">
<div class="modal-dialog">
<form action="<?php echo $_SERVER['PHP_SELF']; ?>?section=<?php echo $section; ?>" method="POST">
<input type="hidden" name="action" value="add_nurse">
<div class="modal-content border-0 shadow">
<div class="modal-header">
<h5 class="modal-title fw-bold text-white"><?php echo __('add_nurse'); ?></h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<div class="mb-3">
<label class="form-label"><?php echo __('name_en'); ?></label>
<input type="text" name="name_en" class="form-control" required>
</div>
<div class="mb-3">
<label class="form-label"><?php echo __('name_ar'); ?></label>
<input type="text" name="name_ar" class="form-control" dir="rtl" required>
</div>
<div class="row">
<div class="col-md-6 mb-3">
<label class="form-label"><?php echo __('phone'); ?></label>
<input type="text" name="tel" class="form-control">
</div>
<div class="col-md-6 mb-3">
<label class="form-label"><?php echo __('email'); ?></label>
<input type="email" name="email" class="form-control">
</div>
</div>
<div class="mb-3">
<label class="form-label"><?php echo __('department'); ?></label>
<select name="department_id" class="form-select">
<option value=""><?php echo __('search'); ?>...</option>
<?php foreach ($all_departments as $dept): ?>
<option value="<?php echo $dept['id']; ?>"><?php echo htmlspecialchars($dept['name']); ?></option>
<?php endforeach; ?>
</select>
</div>
</div>
<div class="modal-footer bg-light">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal"><?php echo __('cancel'); ?></button>
<button type="submit" class="btn btn-primary px-4"><?php echo __('save'); ?></button>
</div>
</div>
</form>
</div>
</div>
<!-- Edit Nurse Modal -->
<div class="modal fade" id="editNurseModal" tabindex="-1" aria-hidden="true">
<div class="modal-dialog">
<form action="<?php echo $_SERVER['PHP_SELF']; ?>?section=<?php echo $section; ?>" method="POST">
<input type="hidden" name="action" value="edit_nurse">
<input type="hidden" name="id" id="edit_nurse_id">
<div class="modal-content border-0 shadow">
<div class="modal-header">
<h5 class="modal-title fw-bold text-white"><?php echo __('edit'); ?> <?php echo __('nurses'); ?></h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<div class="mb-3">
<label class="form-label"><?php echo __('name_en'); ?></label>
<input type="text" name="name_en" id="edit_nurse_name_en" class="form-control" required>
</div>
<div class="mb-3">
<label class="form-label"><?php echo __('name_ar'); ?></label>
<input type="text" name="name_ar" id="edit_nurse_name_ar" class="form-control" dir="rtl" required>
</div>
<div class="row">
<div class="col-md-6 mb-3">
<label class="form-label"><?php echo __('phone'); ?></label>
<input type="text" name="tel" id="edit_nurse_tel" class="form-control">
</div>
<div class="col-md-6 mb-3">
<label class="form-label"><?php echo __('email'); ?></label>
<input type="email" name="email" id="edit_nurse_email" class="form-control">
</div>
</div>
<div class="mb-3">
<label class="form-label"><?php echo __('department'); ?></label>
<select name="department_id" id="edit_nurse_dept_id" class="form-select">
<option value=""><?php echo __('search'); ?>...</option>
<?php foreach ($all_departments as $dept): ?>
<option value="<?php echo $dept['id']; ?>"><?php echo htmlspecialchars($dept['name']); ?></option>
<?php endforeach; ?>
</select>
</div>
</div>
<div class="modal-footer bg-light">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal"><?php echo __('cancel'); ?></button>
<button type="submit" class="btn btn-primary px-4"><?php echo __('save'); ?></button>
</div>
</div>
</form>
</div>
</div>
<!-- Delete Nurse Modal -->
<div class="modal fade" id="deleteNurseModal" tabindex="-1" aria-hidden="true">
<div class="modal-dialog">
<form action="<?php echo $_SERVER['PHP_SELF']; ?>?section=<?php echo $section; ?>" method="POST">
<input type="hidden" name="action" value="delete_nurse">
<input type="hidden" name="id" id="delete_nurse_id">
<div class="modal-content border-0 shadow">
<div class="modal-header">
<h5 class="modal-title fw-bold text-white"><?php echo __('delete'); ?> <?php echo __('nurses'); ?></h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<p><?php echo __('confirm_delete'); ?>?</p>
</div>
<div class="modal-footer bg-light">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal"><?php echo __('cancel'); ?></button>
<button type="submit" class="btn btn-danger px-4"><?php echo __('delete'); ?></button>
</div>
</div>
</form>
</div>
</div>
<!-- Add Department Modal -->
<div class="modal fade" id="addDepartmentModal" tabindex="-1" aria-hidden="true">
<div class="modal-dialog">
<form action="<?php echo $_SERVER['PHP_SELF']; ?>?section=<?php echo $section; ?>" method="POST">
<input type="hidden" name="action" value="add_department">
<div class="modal-content border-0 shadow">
<div class="modal-header">
<h5 class="modal-title fw-bold text-white"><?php echo __('add_department'); ?></h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<div class="mb-3">
<label class="form-label"><?php echo __('name_en'); ?></label>
<input type="text" name="name_en" class="form-control" required>
</div>
<div class="mb-3">
<label class="form-label"><?php echo __('name_ar'); ?></label>
<input type="text" name="name_ar" class="form-control" dir="rtl" required>
</div>
</div>
<div class="modal-footer bg-light">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal"><?php echo __('cancel'); ?></button>
<button type="submit" class="btn btn-primary px-4"><?php echo __('save'); ?></button>
</div>
</div>
</form>
</div>
</div>
<!-- Edit Department Modal -->
<div class="modal fade" id="editDepartmentModal" tabindex="-1" aria-hidden="true">
<div class="modal-dialog">
<form action="<?php echo $_SERVER['PHP_SELF']; ?>?section=<?php echo $section; ?>" method="POST">
<input type="hidden" name="action" value="edit_department">
<input type="hidden" name="id" id="edit_department_id">
<div class="modal-content border-0 shadow">
<div class="modal-header">
<h5 class="modal-title fw-bold text-white"><?php echo __('edit'); ?> <?php echo __('department'); ?></h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<div class="mb-3">
<label class="form-label"><?php echo __('name_en'); ?></label>
<input type="text" name="name_en" id="edit_department_name_en" class="form-control" required>
</div>
<div class="mb-3">
<label class="form-label"><?php echo __('name_ar'); ?></label>
<input type="text" name="name_ar" id="edit_department_name_ar" class="form-control" dir="rtl" required>
</div>
</div>
<div class="modal-footer bg-light">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal"><?php echo __('cancel'); ?></button>
<button type="submit" class="btn btn-primary px-4"><?php echo __('save'); ?></button>
</div>
</div>
</form>
</div>
</div>
<!-- Delete Department Modal -->
<div class="modal fade" id="deleteDepartmentModal" tabindex="-1" aria-hidden="true">
<div class="modal-dialog">
<form action="<?php echo $_SERVER['PHP_SELF']; ?>?section=<?php echo $section; ?>" method="POST">
<input type="hidden" name="action" value="delete_department">
<input type="hidden" name="id" id="delete_department_id">
<div class="modal-content border-0 shadow">
<div class="modal-header">
<h5 class="modal-title fw-bold text-white"><?php echo __('delete'); ?> <?php echo __('department'); ?></h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<p><?php echo __('confirm_delete'); ?>?</p>
</div>
<div class="modal-footer bg-light">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal"><?php echo __('cancel'); ?></button>
<button type="submit" class="btn btn-danger px-4"><?php echo __('delete'); ?></button>
</div>
</div>
</form>
</div>
</div>
<!-- Add Insurance Modal -->
<div class="modal fade" id="addInsuranceModal" tabindex="-1" aria-hidden="true">
<div class="modal-dialog">
<form action="<?php echo $_SERVER['PHP_SELF']; ?>?section=insurance" method="POST">
<input type="hidden" name="action" value="add_insurance">
<div class="modal-content border-0 shadow">
<div class="modal-header">
<h5 class="modal-title fw-bold text-white"><?php echo __('add_insurance'); ?></h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<div class="mb-3">
<label class="form-label"><?php echo __('name'); ?> (EN)</label>
<input type="text" name="name_en" class="form-control" required>
</div>
<div class="mb-3">
<label class="form-label"><?php echo __('name'); ?> (AR)</label>
<input type="text" name="name_ar" class="form-control" dir="rtl" required>
</div>
<div class="row">
<div class="col-md-6 mb-3">
<label class="form-label"><?php echo __('email'); ?></label>
<input type="email" name="email" class="form-control">
</div>
<div class="col-md-6 mb-3">
<label class="form-label"><?php echo __('phone'); ?></label>
<input type="text" name="phone" class="form-control">
</div>
</div>
<div class="mb-3">
<label class="form-label"><?php echo __('contact_info'); ?></label>
<textarea name="contact_info" class="form-control" rows="2"></textarea>
</div>
</div>
<div class="modal-footer bg-light">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal"><?php echo __('cancel'); ?></button>
<button type="submit" class="btn btn-primary px-4"><?php echo __('save'); ?></button>
</div>
</div>
</form>
</div>
</div>
<!-- Add Employee Modal -->
<div class="modal fade" id="addEmployeeModal" tabindex="-1" aria-hidden="true">
<div class="modal-dialog">
<form action="<?php echo $_SERVER['PHP_SELF']; ?>?section=<?php echo $section; ?>" method="POST">
<input type="hidden" name="action" value="add_employee">
<div class="modal-content border-0 shadow">
<div class="modal-header">
<h5 class="modal-title fw-bold text-white"><?php echo __('add_employee'); ?></h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<div class="mb-3">
<label class="form-label"><?php echo __('name_en'); ?></label>
<input type="text" name="name_en" class="form-control" required>
</div>
<div class="mb-3">
<label class="form-label"><?php echo __('name_ar'); ?></label>
<input type="text" name="name_ar" class="form-control" dir="rtl" required>
</div>
<div class="row">
<div class="col-md-6 mb-3">
<label class="form-label"><?php echo __('dob'); ?></label>
<input type="date" name="dob" class="form-control">
</div>
<div class="col-md-6 mb-3">
<label class="form-label"><?php echo __('mobile'); ?></label>
<input type="text" name="mobile" class="form-control">
</div>
</div>
<div class="row">
<div class="col-md-6 mb-3">
<label class="form-label"><?php echo __('email'); ?></label>
<input type="email" name="email" class="form-control">
</div>
<div class="col-md-6 mb-3">
<label class="form-label"><?php echo __('department'); ?></label>
<select name="department_id" class="form-select">
<option value=""><?php echo __('search'); ?>...</option>
<?php foreach ($all_departments as $dept): ?>
<option value="<?php echo $dept['id']; ?>"><?php echo htmlspecialchars($dept['name']); ?></option>
<?php endforeach; ?>
</select>
</div>
</div>
<div class="mb-3">
<label class="form-label"><?php echo __('passion_en'); ?></label>
<textarea name="passion_en" class="form-control" rows="2"></textarea>
</div>
<div class="mb-3">
<label class="form-label"><?php echo __('passion_ar'); ?></label>
<textarea name="passion_ar" class="form-control" rows="2" dir="rtl"></textarea>
</div>
</div>
<div class="modal-footer bg-light">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal"><?php echo __('cancel'); ?></button>
<button type="submit" class="btn btn-primary px-4"><?php echo __('save'); ?></button>
</div>
</div>
</form>
</div>
</div>
<!-- Edit Employee Modal -->
<div class="modal fade" id="editEmployeeModal" tabindex="-1" aria-hidden="true">
<div class="modal-dialog">
<form action="<?php echo $_SERVER['PHP_SELF']; ?>?section=<?php echo $section; ?>" method="POST">
<input type="hidden" name="action" value="edit_employee">
<input type="hidden" name="id" id="edit_employee_id">
<div class="modal-content border-0 shadow">
<div class="modal-header">
<h5 class="modal-title fw-bold text-white"><?php echo __('edit_employee'); ?></h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<div class="mb-3">
<label class="form-label"><?php echo __('name_en'); ?></label>
<input type="text" name="name_en" id="edit_employee_name_en" class="form-control" required>
</div>
<div class="mb-3">
<label class="form-label"><?php echo __('name_ar'); ?></label>
<input type="text" name="name_ar" id="edit_employee_name_ar" class="form-control" dir="rtl" required>
</div>
<div class="row">
<div class="col-md-6 mb-3">
<label class="form-label"><?php echo __('dob'); ?></label>
<input type="date" name="dob" id="edit_employee_dob" class="form-control">
</div>
<div class="col-md-6 mb-3">
<label class="form-label"><?php echo __('mobile'); ?></label>
<input type="text" name="mobile" id="edit_employee_mobile" class="form-control">
</div>
</div>
<div class="row">
<div class="col-md-6 mb-3">
<label class="form-label"><?php echo __('email'); ?></label>
<input type="email" name="email" id="edit_employee_email" class="form-control">
</div>
<div class="col-md-6 mb-3">
<label class="form-label"><?php echo __('department'); ?></label>
<select name="department_id" id="edit_employee_dept_id" class="form-select">
<option value=""><?php echo __('search'); ?>...</option>
<?php foreach ($all_departments as $dept): ?>
<option value="<?php echo $dept['id']; ?>"><?php echo htmlspecialchars($dept['name']); ?></option>
<?php endforeach; ?>
</select>
</div>
</div>
<div class="mb-3">
<label class="form-label"><?php echo __('passion_en'); ?></label>
<textarea name="passion_en" id="edit_employee_passion_en" class="form-control" rows="2"></textarea>
</div>
<div class="mb-3">
<label class="form-label"><?php echo __('passion_ar'); ?></label>
<textarea name="passion_ar" id="edit_employee_passion_ar" class="form-control" rows="2" dir="rtl"></textarea>
</div>
</div>
<div class="modal-footer bg-light">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal"><?php echo __('cancel'); ?></button>
<button type="submit" class="btn btn-primary px-4"><?php echo __('save'); ?></button>
</div>
</div>
</form>
</div>
</div>
<!-- Delete Employee Modal -->
<div class="modal fade" id="deleteEmployeeModal" tabindex="-1" aria-hidden="true">
<div class="modal-dialog">
<form action="<?php echo $_SERVER['PHP_SELF']; ?>?section=<?php echo $section; ?>" method="POST">
<input type="hidden" name="action" value="delete_employee">
<input type="hidden" name="id" id="delete_employee_id">
<div class="modal-content border-0 shadow">
<div class="modal-header">
<h5 class="modal-title fw-bold text-white"><?php echo __('delete_employee'); ?></h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<p><?php echo __('confirm_delete'); ?>?</p>
</div>
<div class="modal-footer bg-light">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal"><?php echo __('cancel'); ?></button>
<button type="submit" class="btn btn-danger px-4"><?php echo __('delete'); ?></button>
</div>
</div>
</form>
</div>
</div>
<!-- Add Poison Modal -->
<div class="modal fade" id="addPoisonModal" tabindex="-1" aria-hidden="true">
<div class="modal-dialog">
<form action="<?php echo $_SERVER['PHP_SELF']; ?>?section=<?php echo $section; ?>" method="POST">
<input type="hidden" name="action" value="add_poison">
<div class="modal-content border-0 shadow">
<div class="modal-header">
<h5 class="modal-title fw-bold text-white"><?php echo __('add_poison'); ?></h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<div class="mb-3">
<label class="form-label"><?php echo __('name_en'); ?></label>
<input type="text" name="name_en" class="form-control" required>
</div>
<div class="mb-3">
<label class="form-label"><?php echo __('name_ar'); ?></label>
<input type="text" name="name_ar" class="form-control" dir="rtl" required>
</div>
<div class="mb-3">
<label class="form-label"><?php echo __('description_en'); ?></label>
<textarea name="description_en" class="form-control" rows="2"></textarea>
</div>
<div class="mb-3">
<label class="form-label"><?php echo __('description_ar'); ?></label>
<textarea name="description_ar" class="form-control" rows="2" dir="rtl"></textarea>
</div>
</div>
<div class="modal-footer bg-light">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal"><?php echo __('cancel'); ?></button>
<button type="submit" class="btn btn-primary px-4"><?php echo __('save'); ?></button>
</div>
</div>
</form>
</div>
</div>
<!-- Edit Poison Modal -->
<div class="modal fade" id="editPoisonModal" tabindex="-1" aria-hidden="true">
<div class="modal-dialog">
<form action="<?php echo $_SERVER['PHP_SELF']; ?>?section=<?php echo $section; ?>" method="POST">
<input type="hidden" name="action" value="edit_poison">
<input type="hidden" name="id" id="edit_poison_id">
<div class="modal-content border-0 shadow">
<div class="modal-header">
<h5 class="modal-title fw-bold text-white"><?php echo __('edit_poison'); ?></h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<div class="mb-3">
<label class="form-label"><?php echo __('name_en'); ?></label>
<input type="text" name="name_en" id="edit_poison_name_en" class="form-control" required>
</div>
<div class="mb-3">
<label class="form-label"><?php echo __('name_ar'); ?></label>
<input type="text" name="name_ar" id="edit_poison_name_ar" class="form-control" dir="rtl" required>
</div>
<div class="mb-3">
<label class="form-label"><?php echo __('description_en'); ?></label>
<textarea name="description_en" id="edit_poison_desc_en" class="form-control" rows="2"></textarea>
</div>
<div class="mb-3">
<label class="form-label"><?php echo __('description_ar'); ?></label>
<textarea name="description_ar" id="edit_poison_desc_ar" class="form-control" rows="2" dir="rtl"></textarea>
</div>
</div>
<div class="modal-footer bg-light">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal"><?php echo __('cancel'); ?></button>
<button type="submit" class="btn btn-primary px-4"><?php echo __('save'); ?></button>
</div>
</div>
</form>
</div>
</div>
<!-- Delete Poison Modal -->
<div class="modal fade" id="deletePoisonModal" tabindex="-1" aria-hidden="true">
<div class="modal-dialog">
<form action="<?php echo $_SERVER['PHP_SELF']; ?>?section=<?php echo $section; ?>" method="POST">
<input type="hidden" name="action" value="delete_poison">
<input type="hidden" name="id" id="delete_poison_id">
<div class="modal-content border-0 shadow">
<div class="modal-header">
<h5 class="modal-title fw-bold text-white"><?php echo __('delete_poison'); ?></h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<p><?php echo __('confirm_delete'); ?>?</p>
</div>
<div class="modal-footer bg-light">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal"><?php echo __('cancel'); ?></button>
<button type="submit" class="btn btn-danger px-4"><?php echo __('delete'); ?></button>
</div>
</div>
</form>
</div>
</div>
<!-- Add Test Group Modal -->
<div class="modal fade" id="addTestGroupModal" tabindex="-1" aria-hidden="true">
<div class="modal-dialog">
<form action="<?php echo $_SERVER['PHP_SELF']; ?>?section=<?php echo $section; ?>" method="POST">
<input type="hidden" name="action" value="add_test_group">
<div class="modal-content border-0 shadow">
<div class="modal-header">
<h5 class="modal-title fw-bold text-white"><?php echo __('add_test_group'); ?></h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<div class="mb-3">
<label class="form-label"><?php echo __('name_en'); ?></label>
<input type="text" name="name_en" class="form-control" required>
</div>
<div class="mb-3">
<label class="form-label"><?php echo __('name_ar'); ?></label>
<input type="text" name="name_ar" class="form-control" dir="rtl" required>
</div>
</div>
<div class="modal-footer bg-light">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal"><?php echo __('cancel'); ?></button>
<button type="submit" class="btn btn-primary px-4"><?php echo __('save'); ?></button>
</div>
</div>
</form>
</div>
</div>
<!-- Edit Test Group Modal -->
<div class="modal fade" id="editTestGroupModal" tabindex="-1" aria-hidden="true">
<div class="modal-dialog">
<form action="<?php echo $_SERVER['PHP_SELF']; ?>?section=<?php echo $section; ?>" method="POST">
<input type="hidden" name="action" value="edit_test_group">
<input type="hidden" name="id" id="edit_test_group_id">
<div class="modal-content border-0 shadow">
<div class="modal-header">
<h5 class="modal-title fw-bold text-white"><?php echo __('edit_test_group'); ?></h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<div class="mb-3">
<label class="form-label"><?php echo __('name_en'); ?></label>
<input type="text" name="name_en" id="edit_test_group_name_en" class="form-control" required>
</div>
<div class="mb-3">
<label class="form-label"><?php echo __('name_ar'); ?></label>
<input type="text" name="name_ar" id="edit_test_group_name_ar" class="form-control" dir="rtl" required>
</div>
</div>
<div class="modal-footer bg-light">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal"><?php echo __('cancel'); ?></button>
<button type="submit" class="btn btn-primary px-4"><?php echo __('save'); ?></button>
</div>
</div>
</form>
</div>
</div>
<!-- Delete Test Group Modal -->
<div class="modal fade" id="deleteTestGroupModal" tabindex="-1" aria-hidden="true">
<div class="modal-dialog">
<form action="<?php echo $_SERVER['PHP_SELF']; ?>?section=<?php echo $section; ?>" method="POST">
<input type="hidden" name="action" value="delete_test_group">
<input type="hidden" name="id" id="delete_test_group_id">
<div class="modal-content border-0 shadow">
<div class="modal-header">
<h5 class="modal-title fw-bold text-white"><?php echo __('delete_test_group'); ?></h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<p><?php echo __('confirm_delete'); ?>?</p>
</div>
<div class="modal-footer bg-light">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal"><?php echo __('cancel'); ?></button>
<button type="submit" class="btn btn-danger px-4"><?php echo __('delete'); ?></button>
</div>
</div>
</form>
</div>
</div>
<!-- Add Test Modal -->
<div class="modal fade" id="addTestModal" tabindex="-1" aria-hidden="true">
<div class="modal-dialog">
<form action="<?php echo $_SERVER['PHP_SELF']; ?>?section=<?php echo $section; ?>" method="POST">
<input type="hidden" name="action" value="add_test">
<div class="modal-content border-0 shadow">
<div class="modal-header">
<h5 class="modal-title fw-bold text-white"><?php echo __('add_test'); ?></h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<div class="mb-3">
<label class="form-label"><?php echo __('name_en'); ?></label>
<input type="text" name="name_en" class="form-control" required>
</div>
<div class="mb-3">
<label class="form-label"><?php echo __('name_ar'); ?></label>
<input type="text" name="name_ar" class="form-control" dir="rtl" required>
</div>
<div class="mb-3">
<label class="form-label"><?php echo __('test_group'); ?></label>
<select name="group_id" class="form-select">
<option value=""><?php echo __('search'); ?>...</option>
<?php foreach ($all_test_groups as $group): ?>
<option value="<?php echo $group['id']; ?>"><?php echo htmlspecialchars($group['name']); ?></option>
<?php endforeach; ?>
</select>
</div>
<div class="mb-3">
<label class="form-label"><?php echo __("normal_range"); ?></label>
<input type="text" name="normal_range" class="form-control" placeholder="e.g. Men: 13-17, Women: 12-15 g/dL">
</div>
<div class="mb-3">
<label class="form-label"><?php echo __('price'); ?></label>
<input type="number" step="0.01" name="price" class="form-control" required placeholder="0.00">
</div>
</div>
<div class="modal-footer bg-light">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal"><?php echo __('cancel'); ?></button>
<button type="submit" class="btn btn-primary px-4"><?php echo __('save'); ?></button>
</div>
</div>
</form>
</div>
</div>
<!-- Edit Test Modal -->
<div class="modal fade" id="editTestModal" tabindex="-1" aria-hidden="true">
<div class="modal-dialog">
<form action="<?php echo $_SERVER['PHP_SELF']; ?>?section=<?php echo $section; ?>" method="POST">
<input type="hidden" name="action" value="edit_test">
<input type="hidden" name="id" id="edit_test_id">
<div class="modal-content border-0 shadow">
<div class="modal-header">
<h5 class="modal-title fw-bold text-white"><?php echo __('edit_test'); ?></h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<div class="mb-3">
<label class="form-label"><?php echo __('name_en'); ?></label>
<input type="text" name="name_en" id="edit_test_name_en" class="form-control" required>
</div>
<div class="mb-3">
<label class="form-label"><?php echo __('name_ar'); ?></label>
<input type="text" name="name_ar" id="edit_test_name_ar" class="form-control" dir="rtl" required>
</div>
<div class="mb-3">
<label class="form-label"><?php echo __('test_group'); ?></label>
<select name="group_id" id="edit_test_group_id_select" class="form-select">
<option value=""><?php echo __('search'); ?>...</option>
<?php foreach ($all_test_groups as $group): ?>
<option value="<?php echo $group['id']; ?>"><?php echo htmlspecialchars($group['name']); ?></option>
<?php endforeach; ?>
</select>
</div>
<div class="mb-3">
<label class="form-label"><?php echo __("normal_range"); ?></label>
<input type="text" name="normal_range" id="edit_test_normal_range" class="form-control" placeholder="e.g. Men: 13-17, Women: 12-15 g/dL">
</div>
<div class="mb-3">
<label class="form-label"><?php echo __('price'); ?></label>
<input type="number" step="0.01" name="price" id="edit_test_price" class="form-control" required placeholder="0.00">
</div>
</div>
<div class="modal-footer bg-light">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal"><?php echo __('cancel'); ?></button>
<button type="submit" class="btn btn-primary px-4"><?php echo __('save'); ?></button>
</div>
</div>
</form>
</div>
</div>
<!-- Delete Test Modal -->
<div class="modal fade" id="deleteTestModal" tabindex="-1" aria-hidden="true">
<div class="modal-dialog">
<form action="<?php echo $_SERVER['PHP_SELF']; ?>?section=<?php echo $section; ?>" method="POST">
<input type="hidden" name="action" value="delete_test">
<input type="hidden" name="id" id="delete_test_id">
<div class="modal-content border-0 shadow">
<div class="modal-header">
<h5 class="modal-title fw-bold text-white"><?php echo __('delete_test'); ?></h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<p><?php echo __('confirm_delete'); ?>?</p>
</div>
<div class="modal-footer bg-light">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal"><?php echo __('cancel'); ?></button>
<button type="submit" class="btn btn-danger px-4"><?php echo __('delete'); ?></button>
</div>
</div>
</form>
</div>
</div>
<!-- Add Inquiry Modal -->
<div class="modal fade" id="addInquiryModal" tabindex="-1" aria-hidden="true">
<div class="modal-dialog modal-lg">
<form action="<?php echo $_SERVER['PHP_SELF']; ?>?section=<?php echo $section; ?>" method="POST">
<input type="hidden" name="action" value="add_inquiry">
<div class="modal-content border-0 shadow">
<div class="modal-header">
<h5 class="modal-title fw-bold text-white"><?php echo __('add_inquiry'); ?></h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<div class="mb-3">
<label class="form-label"><?php echo __('patient'); ?></label>
<input type="text" name="patient_name" class="form-control" required placeholder="<?php echo __('name'); ?>">
</div>
<div class="mb-3">
<div class="d-flex justify-content-between align-items-center mb-2">
<label class="form-label mb-0"><?php echo __('tests'); ?></label>
<button type="button" class="btn btn-sm btn-outline-primary" onclick="addInquiryTestRow('add')">
<i class="bi bi-plus-circle"></i> <?php echo __('add_test'); ?>
</button>
</div>
<div id="add_inquiry_tests_container">
<div class="test-row card bg-light border-0 mb-2 p-2">
<div class="row g-2">
<div class="col-md-11">
<div class="row g-2">
<div class="col-md-12 mb-2">
<select name="test_ids[]" class="form-select select2-test" required onchange="updateNormalRange(this)">
<option value=""><?php echo __('search'); ?>...</option>
<?php foreach ($all_tests as $test): ?>
<option value="<?php echo $test['id']; ?>" data-range="<?php echo htmlspecialchars($test['normal_range']); ?>">
<?php echo htmlspecialchars($test['name']); ?>
</option>
<?php endforeach; ?>
</select>
</div>
<div class="col-md-6">
<input type="text" name="results[]" class="form-control form-control-sm" placeholder="<?php echo __('result'); ?>">
</div>
<div class="col-md-6">
<input type="text" name="normal_ranges[]" class="form-control form-control-sm" placeholder="<?php echo __('normal_range'); ?>">
</div>
</div>
</div>
<div class="col-md-1 d-flex align-items-center justify-content-center">
<button type="button" class="btn btn-link text-danger p-0" onclick="this.closest('.test-row').remove()">
<i class="bi bi-x-circle fs-5"></i>
</button>
</div>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-6 mb-3">
<label class="form-label"><?php echo __('source'); ?></label>
<select name="source" class="form-select">
<option value="Internal"><?php echo __('internal'); ?></option>
<option value="External"><?php echo __('external'); ?></option>
</select>
</div>
<div class="col-md-6 mb-3">
<label class="form-label"><?php echo __('status'); ?></label>
<select name="status" class="form-select">
<option value="Pending"><?php echo __('Pending'); ?></option>
<option value="Completed"><?php echo __('Completed'); ?></option>
<option value="Cancelled"><?php echo __('Cancelled'); ?></option>
</select>
</div>
</div>
<div class="mb-3">
<label class="form-label"><?php echo __('inquiry_date'); ?></label>
<input type="datetime-local" name="inquiry_date" class="form-control" value="<?php echo date('Y-m-d\TH:i'); ?>">
</div>
<div class="mb-3">
<label class="form-label"><?php echo __('notes'); ?></label>
<textarea name="notes" class="form-control" rows="2"></textarea>
</div>
</div>
<div class="modal-footer bg-light">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal"><?php echo __('cancel'); ?></button>
<button type="submit" class="btn btn-primary px-4"><?php echo __('save'); ?></button>
</div>
</div>
</form>
</div>
</div>
<!-- Edit Inquiry Modal -->
<div class="modal fade" id="editInquiryModal" tabindex="-1" aria-hidden="true">
<div class="modal-dialog modal-lg">
<form action="<?php echo $_SERVER['PHP_SELF']; ?>?section=<?php echo $section; ?>" method="POST">
<input type="hidden" name="action" value="edit_inquiry">
<input type="hidden" name="id" id="edit_inquiry_id">
<div class="modal-content border-0 shadow">
<div class="modal-header">
<h5 class="modal-title fw-bold text-white"><?php echo __('edit_inquiry'); ?></h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<div class="mb-3">
<label class="form-label"><?php echo __('patient'); ?></label>
<input type="text" name="patient_name" id="edit_inquiry_patient_name" class="form-control" required>
</div>
<div class="mb-3">
<div class="d-flex justify-content-between align-items-center mb-2">
<label class="form-label mb-0"><?php echo __('tests'); ?></label>
<button type="button" class="btn btn-sm btn-outline-primary" onclick="addInquiryTestRow('edit')">
<i class="bi bi-plus-circle"></i> <?php echo __('add_test'); ?>
</button>
</div>
<div id="edit_inquiry_tests_container">
<!-- Populated by JS -->
</div>
</div>
<div class="row">
<div class="col-md-6 mb-3">
<label class="form-label"><?php echo __('source'); ?></label>
<select name="source" id="edit_inquiry_source" class="form-select">
<option value="Internal"><?php echo __('internal'); ?></option>
<option value="External"><?php echo __('external'); ?></option>
</select>
</div>
<div class="col-md-6 mb-3">
<label class="form-label"><?php echo __('status'); ?></label>
<select name="status" id="edit_inquiry_status" class="form-select">
<option value="Pending"><?php echo __('Pending'); ?></option>
<option value="Completed"><?php echo __('Completed'); ?></option>
<option value="Cancelled"><?php echo __('Cancelled'); ?></option>
</select>
</div>
</div>
<div class="mb-3">
<label class="form-label"><?php echo __('inquiry_date'); ?></label>
<input type="datetime-local" name="inquiry_date" id="edit_inquiry_date" class="form-control">
</div>
<div class="mb-3">
<label class="form-label"><?php echo __('notes'); ?></label>
<textarea name="notes" id="edit_inquiry_notes" class="form-control" rows="2"></textarea>
</div>
</div>
<div class="modal-footer bg-light">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal"><?php echo __('cancel'); ?></button>
<button type="submit" class="btn btn-primary px-4"><?php echo __('save'); ?></button>
</div>
</div>
</form>
</div>
</div>
<!-- Delete Inquiry Modal -->
<div class="modal fade" id="deleteInquiryModal" tabindex="-1" aria-hidden="true">
<div class="modal-dialog">
<form action="<?php echo $_SERVER['PHP_SELF']; ?>?section=<?php echo $section; ?>" method="POST">
<input type="hidden" name="action" value="delete_inquiry">
<input type="hidden" name="id" id="delete_inquiry_id">
<div class="modal-content border-0 shadow">
<div class="modal-header">
<h5 class="modal-title fw-bold text-white"><?php echo __('delete'); ?></h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<p><?php echo __('confirm_delete'); ?>?</p>
</div>
<div class="modal-footer bg-light">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal"><?php echo __('cancel'); ?></button>
<button type="submit" class="btn btn-danger px-4"><?php echo __('delete'); ?></button>
</div>
</div>
</form>
</div>
</div>
<!-- Book Appointment Modal -->
<div class="modal fade" id="bookAppointmentModal" tabindex="-1" aria-hidden="true">
<div class="modal-dialog">
<form action="<?php echo $_SERVER['PHP_SELF']; ?>?section=<?php echo $section; ?>" method="POST">
<input type="hidden" name="action" value="book_appointment">
<div class="modal-content border-0 shadow">
<div class="modal-header">
<h5 class="modal-title fw-bold text-white"><?php echo __('book_appointment'); ?></h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<div class="mb-3">
<label class="form-label"><?php echo __('patient'); ?></label>
<select name="patient_id" class="form-select select2-modal" required>
<option value=""><?php echo __('search'); ?>...</option>
<?php foreach ($all_patients as $p): ?>
<option value="<?php echo $p['id']; ?>"><?php echo htmlspecialchars($p['name']); ?></option>
<?php endforeach; ?>
</select>
</div>
<div class="mb-3">
<label class="form-label"><?php echo __('doctor'); ?></label>
<select name="doctor_id" class="form-select select2-modal" required>
<option value=""><?php echo __('search'); ?>...</option>
<?php foreach ($all_doctors as $d): ?>
<option value="<?php echo $d['id']; ?>"><?php echo htmlspecialchars($d['name']); ?></option>
<?php endforeach; ?>
</select>
</div>
<div class="mb-3">
<label class="form-label"><?php echo __('date'); ?></label>
<input type="datetime-local" name="date" class="form-control" required>
</div>
<div class="mb-3">
<label class="form-label"><?php echo __('reason'); ?></label>
<textarea name="reason" class="form-control" rows="2"></textarea>
</div>
</div>
<div class="modal-footer bg-light">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal"><?php echo __('cancel'); ?></button>
<button type="submit" class="btn btn-success px-4"><?php echo __('book_appointment'); ?></button>
</div>
</div>
</form>
</div>
</div>
<!-- Record Visit Modal -->
<div class="modal fade" id="recordVisitModal" tabindex="-1" aria-hidden="true">
<div class="modal-dialog modal-lg">
<form action="<?php echo $_SERVER['PHP_SELF']; ?>?section=<?php echo $section; ?>" method="POST">
<input type="hidden" name="action" value="record_visit">
<div class="modal-content border-0 shadow">
<div class="modal-header">
<h5 class="modal-title fw-bold text-white"><?php echo __('add_visit'); ?></h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<div class="row">
<div class="col-md-12 mb-3">
<label class="form-label"><?php echo __('appointment'); ?> (<?php echo __('optional'); ?>)</label>
<select name="appointment_id" class="form-select select2-modal" id="visit_appointment_select" onchange="updateVisitFields()">
<option value=""><?php echo __('search'); ?>...</option>
<?php foreach ($scheduled_appointments as $sa): ?>
<option value="<?php echo $sa['id']; ?>" data-patient="<?php echo $sa['patient_id']; ?>" data-doctor="<?php echo $sa['doctor_id']; ?>">
<?php echo htmlspecialchars($sa['patient_name']); ?> - <?php echo $sa['appointment_date']; ?>
</option>
<?php endforeach; ?>
</select>
</div>
</div>
<div class="row">
<div class="col-md-6 mb-3">
<label class="form-label"><?php echo __('patient'); ?></label>
<select name="patient_id" id="visit_patient_id" class="form-select select2-modal" required>
<option value=""><?php echo __('search'); ?>...</option>
<?php foreach ($all_patients as $p): ?>
<option value="<?php echo $p['id']; ?>"><?php echo htmlspecialchars($p['name']); ?></option>
<?php endforeach; ?>
</select>
</div>
<div class="col-md-6 mb-3">
<label class="form-label"><?php echo __('doctor'); ?></label>
<select name="doctor_id" id="visit_doctor_id" class="form-select select2-modal" required>
<option value=""><?php echo __('search'); ?>...</option>
<?php foreach ($all_doctors as $d): ?>
<option value="<?php echo $d['id']; ?>"><?php echo htmlspecialchars($d['name']); ?></option>
<?php endforeach; ?>
</select>
</div>
</div>
<hr>
<h6 class="fw-bold mb-3"><?php echo __('vitals'); ?></h6>
<div class="row">
<div class="col-md-3 mb-3">
<label class="form-label"><?php echo __('weight'); ?></label>
<input type="text" name="weight" class="form-control">
</div>
<div class="col-md-3 mb-3">
<label class="form-label"><?php echo __('blood_pressure'); ?></label>
<input type="text" name="blood_pressure" class="form-control" placeholder="120/80">
</div>
<div class="col-md-3 mb-3">
<label class="form-label"><?php echo __('heart_rate'); ?></label>
<input type="text" name="heart_rate" class="form-control">
</div>
<div class="col-md-3 mb-3">
<label class="form-label"><?php echo __('temperature'); ?></label>
<input type="text" name="temperature" class="form-control">
</div>
</div>
<hr>
<div class="mb-3">
<label class="form-label"><?php echo __('symptoms'); ?></label>
<textarea name="symptoms" class="form-control" rows="2"></textarea>
</div>
<div class="mb-3">
<label class="form-label"><?php echo __('diagnosis'); ?></label>
<textarea name="diagnosis" class="form-control" rows="2"></textarea>
</div>
<div class="mb-3">
<label class="form-label"><?php echo __('treatment_plan'); ?></label>
<textarea name="treatment_plan" class="form-control" rows="2"></textarea>
</div>
</div>
<div class="modal-footer bg-light">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal"><?php echo __('cancel'); ?></button>
<button type="submit" class="btn btn-info text-white px-4"><?php echo __('save'); ?></button>
</div>
</div>
</form>
</div>
</div>
<!-- Edit Visit Modal -->
<div class="modal fade" id="editVisitModal" tabindex="-1" aria-hidden="true">
<div class="modal-dialog modal-lg">
<form action="<?php echo $_SERVER['PHP_SELF']; ?>?section=<?php echo $section; ?>" method="POST">
<input type="hidden" name="action" value="edit_visit">
<input type="hidden" name="id" id="edit_visit_id">
<div class="modal-content border-0 shadow">
<div class="modal-header">
<h5 class="modal-title fw-bold text-white"><?php echo __('edit_visit'); ?></h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<div class="row">
<div class="col-md-6 mb-3">
<label class="form-label"><?php echo __('patient'); ?></label>
<select name="patient_id" id="edit_visit_patient_id" class="form-select select2-modal" required>
<option value=""><?php echo __('search'); ?>...</option>
<?php foreach ($all_patients as $p): ?>
<option value="<?php echo $p['id']; ?>"><?php echo htmlspecialchars($p['name']); ?></option>
<?php endforeach; ?>
</select>
</div>
<div class="col-md-6 mb-3">
<label class="form-label"><?php echo __('doctor'); ?></label>
<select name="doctor_id" id="edit_visit_doctor_id" class="form-select select2-modal" required>
<option value=""><?php echo __('search'); ?>...</option>
<?php foreach ($all_doctors as $d): ?>
<option value="<?php echo $d['id']; ?>"><?php echo htmlspecialchars($d['name']); ?></option>
<?php endforeach; ?>
</select>
</div>
</div>
<hr>
<h6 class="fw-bold mb-3"><?php echo __('vitals'); ?></h6>
<div class="row">
<div class="col-md-3 mb-3">
<label class="form-label"><?php echo __('weight'); ?></label>
<input type="text" name="weight" id="edit_visit_weight" class="form-control">
</div>
<div class="col-md-3 mb-3">
<label class="form-label"><?php echo __('blood_pressure'); ?></label>
<input type="text" name="blood_pressure" id="edit_visit_blood_pressure" class="form-control" placeholder="120/80">
</div>
<div class="col-md-3 mb-3">
<label class="form-label"><?php echo __('heart_rate'); ?></label>
<input type="text" name="heart_rate" id="edit_visit_heart_rate" class="form-control">
</div>
<div class="col-md-3 mb-3">
<label class="form-label"><?php echo __('temperature'); ?></label>
<input type="text" name="temperature" id="edit_visit_temperature" class="form-control">
</div>
</div>
<hr>
<div class="mb-3">
<label class="form-label"><?php echo __('symptoms'); ?></label>
<textarea name="symptoms" id="edit_visit_symptoms" class="form-control" rows="2"></textarea>
</div>
<div class="mb-3">
<label class="form-label"><?php echo __('diagnosis'); ?></label>
<textarea name="diagnosis" id="edit_visit_diagnosis" class="form-control" rows="2"></textarea>
</div>
<div class="mb-3">
<label class="form-label"><?php echo __('treatment_plan'); ?></label>
<textarea name="treatment_plan" id="edit_visit_treatment_plan" class="form-control" rows="2"></textarea>
</div>
</div>
<div class="modal-footer bg-light">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal"><?php echo __('cancel'); ?></button>
<button type="submit" class="btn btn-primary px-4"><?php echo __('save'); ?></button>
</div>
</div>
</form>
</div>
</div>
<!-- Create Bill Modal -->
<div class="modal fade" id="createBillModal" tabindex="-1" aria-hidden="true">
<div class="modal-dialog">
<form action="<?php echo $_SERVER['PHP_SELF']; ?>?section=billing" method="POST">
<input type="hidden" name="action" value="create_bill">
<input type="hidden" name="visit_id" id="bill_visit_id">
<input type="hidden" name="patient_id" id="bill_patient_id">
<div class="modal-content border-0 shadow">
<div class="modal-header">
<h5 class="modal-title fw-bold text-white"><?php echo __('create_bill'); ?></h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<p class="mb-3"><?php echo __('patient'); ?>: <strong id="bill_patient_name"></strong></p>
<div class="alert alert-info py-2 small">
<i class="bi bi-info-circle me-1"></i> If patient has insurance, 80% coverage will be applied automatically.
</div>
<div id="bill_items_container">
<div class="row g-2 mb-2 align-items-end item-row">
<div class="col-8">
<label class="form-label small mb-1"><?php echo __('description'); ?></label>
<input type="text" name="items[]" class="form-control" required value="<?php echo __('consultation_fee'); ?>">
</div>
<div class="col-4">
<label class="form-label small mb-1"><?php echo __('amount'); ?></label>
<input type="number" step="0.01" name="amounts[]" class="form-control" required placeholder="0.00">
</div>
</div>
</div>
<button type="button" class="btn btn-link btn-sm p-0 mt-2" onclick="addBillItem()">+ <?php echo __('add_item'); ?></button>
</div>
<div class="modal-footer bg-light">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal"><?php echo __('cancel'); ?></button>
<button type="submit" class="btn btn-success px-4"><?php echo __('save'); ?></button>
</div>
</div>
</form>
</div>
</div>
<!-- Provisional Report Modal -->
<div class="modal fade" id="reportModal" tabindex="-1" aria-hidden="true">
<div class="modal-dialog">
<form action="<?php echo $_SERVER['PHP_SELF']; ?>?section=<?php echo $section; ?>" method="POST">
<input type="hidden" name="action" value="create_report">
<input type="hidden" name="visit_id" id="report_visit_id">
<div class="modal-content border-0 shadow">
<div class="modal-header">
<h5 class="modal-title fw-bold text-white"><?php echo __('new_report'); ?></h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<div class="mb-3">
<label class="form-label"><?php echo __('report_type'); ?></label>
<input type="text" name="report_type" class="form-control" required placeholder="General, Lab, X-Ray, etc.">
</div>
<div class="mb-3">
<label class="form-label"><?php echo __('findings'); ?></label>
<textarea name="findings" class="form-control" rows="3"></textarea>
</div>
<div class="mb-3">
<label class="form-label"><?php echo __('recommendations'); ?></label>
<textarea name="recommendations" class="form-control" rows="3"></textarea>
</div>
</div>
<div class="modal-footer bg-light">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal"><?php echo __('cancel'); ?></button>
<button type="submit" class="btn btn-primary px-4"><?php echo __('save'); ?></button>
</div>
</div>
</form>
</div>
</div>
<!-- jQuery (Required for Select2) -->
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<!-- Select2 JS -->
<script src="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/js/select2.min.js"></script>
<!-- Bootstrap 5 Bundle JS -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
<script>
// Global error handler to help debugging
window.onerror = function(message, source, lineno, colno, error) {
console.error("Global JS Error: " + message + " at " + source + ":" + lineno + ":" + colno);
return false;
};
$(document).ready(function() {
try {
initSelect2();
// Re-init select2 when modals are shown
$('.modal').on('shown.bs.modal', function() {
initSelect2();
});
// Initialize tooltips with improved settings
setTimeout(function() {
try {
if (typeof bootstrap !== 'undefined' && bootstrap.Tooltip) {
var tooltipTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="tooltip"]'))
tooltipTriggerList.forEach(function (tooltipTriggerEl) {
new bootstrap.Tooltip(tooltipTriggerEl, {
container: 'body',
trigger: 'hover'
});
});
}
} catch (e) {
console.error('Tooltip initialization failed:', e);
}
}, 500);
} catch (e) {
console.error('Document ready initialization failed:', e);
}
});
function initSelect2() {
if (typeof jQuery !== 'undefined' && jQuery.fn.select2) {
$('.select2-modal').each(function() {
try {
$(this).select2({
dropdownParent: $(this).closest('.modal'),
theme: 'bootstrap-5',
width: '100%'
});
} catch (e) { console.error('Select2 init failed for element:', this, e); }
});
$('.select2-test').each(function() {
try {
$(this).select2({
dropdownParent: $(this).closest('.modal'),
theme: 'bootstrap-5',
width: '100%'
});
} catch (e) { console.error('Select2 test init failed:', e); }
});
}
}
function addInquiryTestRow(type, data = null) {
const container = document.getElementById(type + '_inquiry_tests_container');
if (!container) return;
const row = document.createElement('div');
row.className = 'test-row card bg-light border-0 mb-2 p-2';
let options = '<option value=""><?php echo __('search'); ?>...</option>';
if (typeof window.ALL_TESTS_DATA !== 'undefined') {
window.ALL_TESTS_DATA.forEach(test => {
const selected = data && data.test_id == test.id ? 'selected' : '';
options += `<option value="${test.id}" data-range="${test.normal_range || ''}" ${selected}>${test.name}</option>`;
});
}
row.innerHTML = `
<div class="row g-2">
<div class="col-md-11">
<div class="row g-2">
<div class="col-md-12 mb-2">
<select name="test_ids[]" class="form-select select2-test" required onchange="updateNormalRange(this)">
${options}
</select>
</div>
<div class="col-md-6">
<input type="text" name="results[]" class="form-control form-control-sm" placeholder="<?php echo __('result'); ?>" value="${data ? (data.result || '') : ''}">
</div>
<div class="col-md-6">
<input type="text" name="normal_ranges[]" class="form-control form-control-sm" placeholder="<?php echo __('normal_range'); ?>" value="${data ? (data.normal_range || '') : ''}">
</div>
</div>
</div>
<div class="col-md-1 d-flex align-items-center justify-content-center">
<button type="button" class="btn btn-link text-danger p-0" onclick="this.closest('.test-row').remove()">
<i class="bi bi-x-circle fs-5"></i>
</button>
</div>
</div>
`;
container.appendChild(row);
initSelect2();
}
function updateNormalRange(select) {
const option = select.options[select.selectedIndex];
if (!option) return;
const range = option.dataset.range || '';
const row = select.closest('.test-row');
if (row) {
const rangeInput = row.querySelector('input[name="normal_ranges[]"]');
if (rangeInput && !rangeInput.value) {
rangeInput.value = range;
}
}
}
function updateVisitFields() {
const select = document.getElementById('visit_appointment_select');
if (!select) return;
const option = select.options[select.selectedIndex];
if (option && option.value && typeof jQuery !== 'undefined') {
$('#visit_patient_id').val(option.dataset.patient).trigger('change');
$('#visit_doctor_id').val(option.dataset.doctor).trigger('change');
}
}
function showReportModal(visitId) {
var el = document.getElementById('reportModal');
if (el) {
var input = document.getElementById('report_visit_id');
if (input) input.value = visitId;
bootstrap.Modal.getOrCreateInstance(el).show();
}
}
function showBillModal(visitId, patientId, patientName) {
var el = document.getElementById('createBillModal');
if (el) {
var vId = document.getElementById('bill_visit_id');
var pId = document.getElementById('bill_patient_id');
var pName = document.getElementById('bill_patient_name');
if (vId) vId.value = visitId || '';
if (pId) pId.value = patientId;
if (pName) pName.innerText = patientName || '';
bootstrap.Modal.getOrCreateInstance(el).show();
}
}
function showEditPatientModal(patient) {
if (!patient) return;
var el = document.getElementById('editPatientModal');
if (el) {
var fields = {
'edit_patient_id': patient.id,
'edit_patient_name': patient.name,
'edit_patient_phone': patient.phone,
'edit_patient_dob': patient.dob,
'edit_patient_gender': patient.gender,
'edit_patient_blood_group': patient.blood_group,
'edit_patient_insurance_company_id': patient.insurance_company_id || '',
'edit_patient_policy_number': patient.policy_number || '',
'edit_patient_address': patient.address || ''
};
for (var id in fields) {
var field = document.getElementById(id);
if (field) field.value = fields[id];
}
bootstrap.Modal.getOrCreateInstance(el).show();
}
}
function showDeletePatientModal(id, name) {
var el = document.getElementById('deletePatientModal');
if (el) {
var idField = document.getElementById('delete_patient_id');
var nameField = document.getElementById('delete_patient_name');
if (idField) idField.value = id || '';
if (nameField) nameField.innerText = name || '';
bootstrap.Modal.getOrCreateInstance(el).show();
}
}
function showEditDoctorModal(doc) {
if (!doc) return;
var el = document.getElementById('editDoctorModal');
if (el) {
var fields = {
'edit_doctor_id': doc.id,
'edit_doctor_name_en': doc.name_en,
'edit_doctor_name_ar': doc.name_ar,
'edit_doctor_tel': doc.tel || '',
'edit_doctor_email': doc.email || '',
'edit_doctor_spec_en': doc.specialization_en,
'edit_doctor_spec_ar': doc.specialization_ar,
'edit_doctor_dept_id': doc.department_id || ''
};
for (var id in fields) {
var field = document.getElementById(id);
if (field) field.value = fields[id];
}
bootstrap.Modal.getOrCreateInstance(el).show();
}
}
function showDeleteDoctorModal(id) {
var el = document.getElementById('deleteDoctorModal');
if (el) {
var field = document.getElementById('delete_doctor_id');
if (field) field.value = id || '';
bootstrap.Modal.getOrCreateInstance(el).show();
}
}
function showEditNurseModal(nurse) {
if (!nurse) return;
var el = document.getElementById('editNurseModal');
if (el) {
var fields = {
'edit_nurse_id': nurse.id,
'edit_nurse_name_en': nurse.name_en,
'edit_nurse_name_ar': nurse.name_ar,
'edit_nurse_tel': nurse.tel || '',
'edit_nurse_email': nurse.email || '',
'edit_nurse_dept_id': nurse.department_id || ''
};
for (var id in fields) {
var field = document.getElementById(id);
if (field) field.value = fields[id];
}
bootstrap.Modal.getOrCreateInstance(el).show();
}
}
function showDeleteNurseModal(id) {
var el = document.getElementById('deleteNurseModal');
if (el) {
var field = document.getElementById('delete_nurse_id');
if (field) field.value = id || '';
bootstrap.Modal.getOrCreateInstance(el).show();
}
}
function showEditDepartmentModal(dept) {
if (!dept) return;
var el = document.getElementById('editDepartmentModal');
if (el) {
var fields = {
'edit_department_id': dept.id,
'edit_department_name_en': dept.name_en,
'edit_department_name_ar': dept.name_ar
};
for (var id in fields) {
var field = document.getElementById(id);
if (field) field.value = fields[id];
}
bootstrap.Modal.getOrCreateInstance(el).show();
}
}
function showDeleteDepartmentModal(id) {
var el = document.getElementById('deleteDepartmentModal');
if (el) {
var field = document.getElementById('delete_department_id');
if (field) field.value = id || '';
bootstrap.Modal.getOrCreateInstance(el).show();
}
}
function showEditEmployeeModal(emp) {
if (!emp) return;
var el = document.getElementById('editEmployeeModal');
if (el) {
var fields = {
'edit_employee_id': emp.id,
'edit_employee_name_en': emp.name_en,
'edit_employee_name_ar': emp.name_ar,
'edit_employee_dob': emp.dob || '',
'edit_employee_mobile': emp.mobile || '',
'edit_employee_email': emp.email || '',
'edit_employee_dept_id': emp.department_id || '',
'edit_employee_passion_en': emp.passion_en || '',
'edit_employee_passion_ar': emp.passion_ar || ''
};
for (var id in fields) {
var field = document.getElementById(id);
if (field) field.value = fields[id];
}
bootstrap.Modal.getOrCreateInstance(el).show();
}
}
function showDeleteEmployeeModal(id) {
var el = document.getElementById('deleteEmployeeModal');
if (el) {
var field = document.getElementById('delete_employee_id');
if (field) field.value = id || '';
bootstrap.Modal.getOrCreateInstance(el).show();
}
}
function showEditPoisonModal(poison) {
if (!poison) return;
var el = document.getElementById('editPoisonModal');
if (el) {
var fields = {
'edit_poison_id': poison.id,
'edit_poison_name_en': poison.name_en,
'edit_poison_name_ar': poison.name_ar,
'edit_poison_desc_en': poison.description_en || '',
'edit_poison_desc_ar': poison.description_ar || ''
};
for (var id in fields) {
var field = document.getElementById(id);
if (field) field.value = fields[id];
}
bootstrap.Modal.getOrCreateInstance(el).show();
}
}
function showDeletePoisonModal(id) {
var el = document.getElementById('deletePoisonModal');
if (el) {
var field = document.getElementById('delete_poison_id');
if (field) field.value = id || '';
bootstrap.Modal.getOrCreateInstance(el).show();
}
}
function showEditTestGroupModal(group) {
if (!group) return;
var el = document.getElementById('editTestGroupModal');
if (el) {
var fields = {
'edit_test_group_id': group.id,
'edit_test_group_name_en': group.name_en,
'edit_test_group_name_ar': group.name_ar
};
for (var id in fields) {
var field = document.getElementById(id);
if (field) field.value = fields[id];
}
bootstrap.Modal.getOrCreateInstance(el).show();
}
}
function showDeleteTestGroupModal(id) {
var el = document.getElementById('deleteTestGroupModal');
if (el) {
var field = document.getElementById('delete_test_group_id');
if (field) field.value = id || '';
bootstrap.Modal.getOrCreateInstance(el).show();
}
}
function showEditTestModal(test) {
if (!test) return;
var el = document.getElementById('editTestModal');
if (el) {
var fields = {
'edit_test_id': test.id,
'edit_test_name_en': test.name_en,
'edit_test_name_ar': test.name_ar,
'edit_test_group_id_select': test.group_id || '',
'edit_test_normal_range': test.normal_range || '',
'edit_test_price': test.price || '0.00'
};
for (var id in fields) {
var field = document.getElementById(id);
if (field) field.value = fields[id];
}
bootstrap.Modal.getOrCreateInstance(el).show();
}
}
function showDeleteTestModal(id) {
var el = document.getElementById('deleteTestModal');
if (el) {
var field = document.getElementById('delete_test_id');
if (field) field.value = id || '';
bootstrap.Modal.getOrCreateInstance(el).show();
}
}
function showEditVisitModal(visit) {
if (!visit) return;
var el = document.getElementById('editVisitModal');
if (el) {
var vId = document.getElementById('edit_visit_id');
if (vId) vId.value = visit.id || '';
if (typeof jQuery !== 'undefined') {
$('#edit_visit_patient_id').val(visit.patient_id).trigger('change');
$('#edit_visit_doctor_id').val(visit.doctor_id).trigger('change');
}
var fields = {
'edit_visit_weight': visit.weight || '',
'edit_visit_blood_pressure': visit.blood_pressure || '',
'edit_visit_heart_rate': visit.heart_rate || '',
'edit_visit_temperature': visit.temperature || '',
'edit_visit_symptoms': visit.symptoms || '',
'edit_visit_diagnosis': visit.diagnosis || '',
'edit_visit_treatment_plan': visit.treatment_plan || ''
};
for (var id in fields) {
var field = document.getElementById(id);
if (field) field.value = fields[id];
}
bootstrap.Modal.getOrCreateInstance(el).show();
}
}
function showRecordVisitModal(patientId = null) {
if (patientId && typeof jQuery !== 'undefined') {
$('#visit_patient_id').val(patientId).trigger('change');
}
var el = document.getElementById('recordVisitModal');
if (el) {
bootstrap.Modal.getOrCreateInstance(el).show();
}
}
function showEditInquiryModal(inquiry) {
if (!inquiry) return;
var el = document.getElementById('editInquiryModal');
if (el) {
var fields = {
'edit_inquiry_id': inquiry.id || '',
'edit_inquiry_patient_name': inquiry.patient_name || '',
'edit_inquiry_source': inquiry.source || 'Internal',
'edit_inquiry_status': inquiry.status || 'Pending',
'edit_inquiry_notes': inquiry.notes || ''
};
for (var id in fields) {
var field = document.getElementById(id);
if (field) field.value = fields[id];
}
if (inquiry.inquiry_date) {
var dateField = document.getElementById('edit_inquiry_date');
if (dateField) dateField.value = inquiry.inquiry_date.replace(' ', 'T').substring(0, 16);
}
const container = document.getElementById('edit_inquiry_tests_container');
if (container) {
container.innerHTML = '';
if (inquiry.tests && inquiry.tests.length > 0) {
inquiry.tests.forEach(test => {
addInquiryTestRow('edit', test);
});
} else {
addInquiryTestRow('edit');
}
}
bootstrap.Modal.getOrCreateInstance(el).show();
}
}
function showDeleteInquiryModal(id) {
var el = document.getElementById('deleteInquiryModal');
if (el) {
var field = document.getElementById('delete_inquiry_id');
if (field) field.value = id || '';
bootstrap.Modal.getOrCreateInstance(el).show();
}
}
function printInquiry(inquiry) {
if (!inquiry) return;
try {
const printWindow = window.open('', '_blank');
if (!printWindow) return;
const date = inquiry.inquiry_date ? new Date(inquiry.inquiry_date).toLocaleString() : '';
let testsHtml = '';
if (inquiry.tests && inquiry.tests.length > 0) {
inquiry.tests.forEach(t => {
testsHtml += `
<tr>
<td style="padding: 10px; border-bottom: 1px solid #eee;">${t.test_name}</td>
<td style="padding: 10px; border-bottom: 1px solid #eee; text-align: center;"><strong>${t.result || '-'}</strong></td>
<td style="padding: 10px; border-bottom: 1px solid #eee; text-align: center;">${t.normal_range || '-'}</td>
</tr>
`;
});
}
printWindow.document.write(`
<html>
<head>
<title>Laboratory Report - ${inquiry.patient_name}</title>
<style>
body { font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; color: #333; line-height: 1.6; }
.header { text-align: center; border-bottom: 2px solid #002D62; padding-bottom: 20px; margin-bottom: 30px; }
.header h1 { margin: 0; color: #002D62; }
.info-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin-bottom: 30px; }
.info-item b { color: #555; }
table { width: 100%; border-collapse: collapse; margin-bottom: 30px; }
th { background-color: #f8f9fa; text-align: left; padding: 12px; border-bottom: 2px solid #dee2e6; }
.footer { margin-top: 50px; border-top: 1px solid #eee; padding-top: 20px; text-align: center; font-size: 0.9em; color: #777; }
</style>
</head>
<body>
<div class="header">
<h1>LABORATORY REPORT</h1>
<p>Hospital Management System</p>
</div>
<div class="info-grid">
<div class="info-item"><b>Patient Name:</b> ${inquiry.patient_name}</div>
<div class="info-item"><b>Date:</b> ${date}</div>
<div class="info-item"><b>Inquiry ID:</b> #${inquiry.id}</div>
<div class="info-item"><b>Status:</b> ${inquiry.status}</div>
</div>
<table>
<thead>
<tr>
<th>Test Name</th>
<th style="text-align: center;">Result</th>
<th style="text-align: center;">Normal Range</th>
</tr>
</thead>
<tbody>
${testsHtml}
</tbody>
</table>
${inquiry.notes ? `<div style="margin-top: 20px;"><b>Notes:</b><p>${inquiry.notes}</p></div>` : ''}
<div class="footer">
<p>This is a computer-generated report. No signature required.</p>
<p>Printed on: ${new Date().toLocaleString()}</p>
</div>
<script>
window.onload = function() { window.print(); window.close(); }
<\/script>
</body>
</html>
`);
printWindow.document.close();
} catch (e) { console.error('Print inquiry failed:', e); }
}
function addBillItem() {
const container = document.getElementById('bill_items_container');
if (!container) return;
const row = document.createElement('div');
row.className = 'row g-2 mb-2 align-items-end item-row';
row.innerHTML = `
<div class="col-8">
<input type="text" name="items[]" class="form-control" required>
</div>
<div class="col-4">
<input type="number" step="0.01" name="amounts[]" class="form-control" required placeholder="0.00">
</div>
`;
container.appendChild(row);
}
</script>
</body>
</html>