enhancing patient form

This commit is contained in:
Flatlogic Bot 2026-03-06 02:23:44 +00:00
parent 6439167fd2
commit 2b7bb7957e
8 changed files with 328 additions and 99 deletions

13
cities.php Normal file
View File

@ -0,0 +1,13 @@
<?php
$section = 'cities';
require_once __DIR__ . '/db/config.php';
require_once __DIR__ . '/helpers.php';
$db = db();
$lang = $_SESSION['lang'] ?? 'en';
require_once __DIR__ . '/includes/actions.php';
require_once __DIR__ . '/includes/common_data.php';
require_once __DIR__ . '/includes/layout/header.php';
require_once __DIR__ . '/includes/pages/cities.php';
require_once __DIR__ . '/includes/layout/footer.php';

View File

@ -0,0 +1,20 @@
CREATE TABLE IF NOT EXISTS cities (
id INT AUTO_INCREMENT PRIMARY KEY,
name_en VARCHAR(100) NOT NULL,
name_ar VARCHAR(100) NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
INSERT INTO cities (name_en, name_ar) VALUES
('Muscat', 'مسقط'),
('Salalah', 'صلالة'),
('Sohar', 'صحار'),
('Nizwa', 'نزوى'),
('Sur', 'صور'),
('Al Buraimi', 'البريمي'),
('Seeb', 'السيب'),
('Bawshar', 'بوشر'),
('Ibri', 'عبري'),
('Rustaq', 'الرستاق'),
('Khasab', 'خصب'),
('Bahla', 'بهلاء');

View File

@ -222,6 +222,33 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$_SESSION['flash_message'] = __('delete') . ' ' . __('successfully');
$redirect = true;
}
} elseif ($_POST['action'] === 'add_city') {
$name_en = $_POST['name_en'] ?? '';
$name_ar = $_POST['name_ar'] ?? '';
if ($name_en && $name_ar) {
$stmt = $db->prepare("INSERT INTO cities (name_en, name_ar) VALUES (?, ?)");
$stmt->execute([$name_en, $name_ar]);
$_SESSION['flash_message'] = __('add_city') . ' ' . __('successfully');
$redirect = true;
}
} elseif ($_POST['action'] === 'edit_city') {
$id = $_POST['id'] ?? '';
$name_en = $_POST['name_en'] ?? '';
$name_ar = $_POST['name_ar'] ?? '';
if ($id && $name_en && $name_ar) {
$stmt = $db->prepare("UPDATE cities SET name_en = ?, name_ar = ? WHERE id = ?");
$stmt->execute([$name_en, $name_ar, $id]);
$_SESSION['flash_message'] = __('edit_city') . ' ' . __('successfully');
$redirect = true;
}
} elseif ($_POST['action'] === 'delete_city') {
$id = $_POST['id'] ?? '';
if ($id) {
$stmt = $db->prepare("DELETE FROM cities WHERE id = ?");
$stmt->execute([$id]);
$_SESSION['flash_message'] = __('delete') . ' ' . __('successfully');
$redirect = true;
}
} elseif ($_POST['action'] === 'book_appointment') {
$patient_id = $_POST['patient_id'] ?? '';
$doctor_id = $_POST['doctor_id'] ?? '';

View File

@ -20,3 +20,5 @@ $scheduled_appointments = $db->query("
JOIN patients p ON a.patient_id = p.id
WHERE a.status = 'Scheduled'
ORDER BY a.start_time ASC")->fetchAll();$all_countries = require __DIR__ . "/countries.php";
$all_cities = $db->query("SELECT id, name_$lang as name FROM cities")->fetchAll();

View File

@ -6,7 +6,7 @@
<!-- Add Patient Modal -->
<div class="modal fade" id="addPatientModal" tabindex="-1" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-dialog modal-lg">
<form action="<?php echo $_SERVER['PHP_SELF']; ?>?section=<?php echo $section; ?>" method="POST" enctype="multipart/form-data">
<input type="hidden" name="action" value="add_patient">
<div class="modal-content border-0 shadow">
@ -15,15 +15,16 @@
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<div class="mb-3">
<div class="row">
<div class="col-md-4 mb-3">
<label class="form-label"><?php echo __('name'); ?></label>
<input type="text" name="name" class="form-control" required>
</div>\1\n <div class="row">
<div class="col-md-6 mb-3">
</div>
<div class="col-md-4 mb-3">
<label class="form-label"><?php echo __('civil_id'); ?></label>
<input type="text" name="civil_id" class="form-control">
</div>
<div class="col-md-6 mb-3">
<div class="col-md-4 mb-3">
<label class="form-label"><?php echo __('nationality'); ?></label>
<select name="nationality" class="form-select select2-modal">
<option value=""><?php echo __('search'); ?>...</option>
@ -33,22 +34,16 @@
</select>
</div>
</div>
<div class="mb-3">
<label class="form-label"><?php echo __('city'); ?></label>
<input type="text" name="city" class="form-control">
</div>
<div class="row">
<div class="col-md-6 mb-3">
<div class="col-md-4 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">
<div class="col-md-4 mb-3">
<label class="form-label"><?php echo __('dob'); ?></label>
<input type="date" name="dob" class="form-control">
<input type="text" name="dob" class="form-control masked-date" placeholder="YYYY-MM-DD">
</div>
</div>
<div class="row">
<div class="col-md-6 mb-3">
<div class="col-md-4 mb-3">
<label class="form-label"><?php echo __('gender'); ?></label>
<select name="gender" class="form-select">
<option value="Male"><?php echo __('male'); ?></option>
@ -56,15 +51,23 @@
<option value="Other"><?php echo __('other'); ?></option>
</select>
</div>
<div class="col-md-6 mb-3">
</div>
<div class="row">
<div class="col-md-4 mb-3">
<label class="form-label"><?php echo __('city'); ?></label>
<select name="city" class="form-select select2-modal">
<option value=""><?php echo __('select'); ?>...</option>
<?php foreach ($all_cities as $city):
?><option value="<?php echo htmlspecialchars($city['name']); ?>"><?php echo htmlspecialchars($city['name']); ?></option>
<?php endforeach;
?></select>
</div>
<div class="col-md-4 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">
<div class="col-md-4 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>
@ -73,14 +76,16 @@
<?php endforeach; ?>
</select>
</div>
<div class="col-md-6 mb-3">
</div>
<div class="row">
<div class="col-md-4 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">
<div class="col-md-8 mb-3">
<label class="form-label"><?php echo __('address'); ?></label>
<textarea name="address" class="form-control" rows="2"></textarea>
<textarea name="address" class="form-control" rows="1"></textarea>
</div>
</div>
</div>
<div class="modal-footer bg-light">
@ -94,7 +99,7 @@
<!-- Edit Patient Modal -->
<div class="modal fade" id="editPatientModal" tabindex="-1" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-dialog modal-lg">
<form action="<?php echo $_SERVER['PHP_SELF']; ?>?section=<?php echo $section; ?>" method="POST" enctype="multipart/form-data">
<input type="hidden" name="action" value="edit_patient">
<input type="hidden" name="id" id="edit_patient_id">
@ -104,16 +109,16 @@
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<div class="mb-3">
<div class="row">
<div class="col-md-4 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">
<div class="col-md-4 mb-3">
<label class="form-label"><?php echo __('civil_id'); ?></label>
<input type="text" name="civil_id" id="edit_patient_civil_id" class="form-control">
</div>
<div class="col-md-6 mb-3">
<div class="col-md-4 mb-3">
<label class="form-label"><?php echo __('nationality'); ?></label>
<select name="nationality" id="edit_patient_nationality" class="form-select select2-modal">
<option value=""><?php echo __('search'); ?>...</option>
@ -123,22 +128,16 @@
</select>
</div>
</div>
<div class="mb-3">
<label class="form-label"><?php echo __('city'); ?></label>
<input type="text" name="city" id="edit_patient_city" class="form-control">
</div>
<div class="row">
<div class="col-md-6 mb-3">
<div class="col-md-4 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">
<div class="col-md-4 mb-3">
<label class="form-label"><?php echo __('dob'); ?></label>
<input type="date" name="dob" id="edit_patient_dob" class="form-control">
<input type="text" name="dob" id="edit_patient_dob" class="form-control masked-date" placeholder="YYYY-MM-DD">
</div>
</div>
<div class="row">
<div class="col-md-6 mb-3">
<div class="col-md-4 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>
@ -146,15 +145,23 @@
<option value="Other"><?php echo __('other'); ?></option>
</select>
</div>
<div class="col-md-6 mb-3">
</div>
<div class="row">
<div class="col-md-4 mb-3">
<label class="form-label"><?php echo __('city'); ?></label>
<select name="city" id="edit_patient_city" class="form-select select2-modal">
<option value=""><?php echo __('select'); ?>...</option>
<?php foreach ($all_cities as $city):
?><option value="<?php echo htmlspecialchars($city['name']); ?>"><?php echo htmlspecialchars($city['name']); ?></option>
<?php endforeach;
?></select>
</div>
<div class="col-md-4 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">
<div class="col-md-4 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>
@ -163,14 +170,16 @@
<?php endforeach; ?>
</select>
</div>
<div class="col-md-6 mb-3">
</div>
<div class="row">
<div class="col-md-4 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">
<div class="col-md-8 mb-3">
<label class="form-label"><?php echo __('address'); ?></label>
<textarea name="address" id="edit_patient_address" class="form-control" rows="2"></textarea>
<textarea name="address" id="edit_patient_address" class="form-control" rows="1"></textarea>
</div>
</div>
</div>
<div class="modal-footer bg-light">
@ -608,7 +617,7 @@
<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">
<input type="text" name="dob" class="form-control masked-date" placeholder="YYYY-MM-DD">
</div>
<div class="col-md-6 mb-3">
<label class="form-label"><?php echo __('mobile'); ?></label>
@ -671,7 +680,7 @@
<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">
<input type="text" name="dob" id="edit_employee_dob" class="form-control masked-date" placeholder="YYYY-MM-DD">
</div>
<div class="col-md-6 mb-3">
<label class="form-label"><?php echo __('mobile'); ?></label>
@ -1971,10 +1980,94 @@
</div>
</div>
<!-- Add City Modal -->
<div class="modal fade" id="addCityModal" 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_city">
<div class="modal-content border-0 shadow">
<div class="modal-header">
<h5 class="modal-title fw-bold text-white"><?php echo __('add_city'); ?></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 City Modal -->
<div class="modal fade" id="editCityModal" 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_city">
<input type="hidden" name="id" id="edit_city_id">
<div class="modal-content border-0 shadow">
<div class="modal-header">
<h5 class="modal-title fw-bold text-white"><?php echo __('edit_city'); ?></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_city_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_city_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 City Modal -->
<div class="modal fade" id="deleteCityModal" 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_city">
<input type="hidden" name="id" id="delete_city_id">
<div class="modal-content border-0 shadow">
<div class="modal-header">
<h5 class="modal-title fw-bold text-white"><?php echo __('delete_city'); ?></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>
<!-- Scripts -->
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/js/select2.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.inputmask/5.0.8/jquery.inputmask.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/summernote@0.8.18/dist/summernote-lite.min.js"></script>
<script>
@ -1990,11 +2083,17 @@
$(document).ready(function() {
try {
initSelect2();
// Initialize Inputmask
$('.masked-date').inputmask('9999-99-99', { placeholder: "YYYY-MM-DD" });
initRichEditor();
// Re-init select2 when modals are shown
$('.modal').on('shown.bs.modal', function() {
initSelect2();
// Initialize Inputmask
$('.masked-date').inputmask('9999-99-99', { placeholder: "YYYY-MM-DD" });
// Ensure rich editor is initialized if needed
$(this).find('.rich-editor').each(function() {
if (!$(this).next().hasClass('note-editor')) {
@ -2142,6 +2241,9 @@
container.appendChild(row);
initSelect2();
// Initialize Inputmask
$('.masked-date').inputmask('9999-99-99', { placeholder: "YYYY-MM-DD" });
}
function updateNormalRange(select) {
@ -2212,9 +2314,10 @@
var field = document.getElementById(id);
if (field) {
field.value = fields[id];
if (id === 'edit_patient_nationality') {
if (id === 'edit_patient_nationality' || id === 'edit_patient_city') {
$(field).val(fields[id]).trigger('change');
}
}
}
bootstrap.Modal.getOrCreateInstance(el).show();
@ -2335,7 +2438,10 @@
};
for (var id in fields) {
var field = document.getElementById(id);
if (field) field.value = fields[id];
if (field) {
field.value = fields[id];
}
}
bootstrap.Modal.getOrCreateInstance(el).show();
}
@ -2599,6 +2705,9 @@
`;
container.appendChild(row);
initSelect2();
// Initialize Inputmask
$('.masked-date').inputmask('9999-99-99', { placeholder: "YYYY-MM-DD" });
}
function showEditXrayInquiryModal(inquiry) {
@ -3093,5 +3202,37 @@ $drug_groups_js = $db->query("SELECT * FROM drugs_groups ORDER BY name_$lang")->
currentPrescriptionRowTarget = null;
}
</script>
<!-- Flatpickr JS -->
<script src="https://cdn.jsdelivr.net/npm/flatpickr"></script>
<script>
document.addEventListener('DOMContentLoaded', function() {
flatpickr(".flatpickr-dob", {
dateFormat: "Y-m-d",
maxDate: "today",
disableMobile: true,
allowInput: true,
altInput: true,
altFormat: "F j, Y",
yearSelectorType: 'dropdown'
});
});
function showEditCityModal(city) {
document.getElementById('edit_city_id').value = city.id;
document.getElementById('edit_city_name_en').value = city.name_en;
document.getElementById('edit_city_name_ar').value = city.name_ar;
var modal = new bootstrap.Modal(document.getElementById('editCityModal'));
modal.show();
}
function showDeleteCityModal(id) {
document.getElementById('delete_city_id').value = id;
var modal = new bootstrap.Modal(document.getElementById('deleteCityModal'));
modal.show();
}
</script>
</body>
</html>

View File

@ -45,6 +45,8 @@ $site_favicon = !empty($site_settings['company_favicon']) ? $site_settings['comp
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/select2-bootstrap-5-theme@1.3.0/dist/select2-bootstrap-5-theme.min.css" />
<!-- Summernote Lite CSS -->
<link href="https://cdn.jsdelivr.net/npm/summernote@0.8.18/dist/summernote-lite.min.css" rel="stylesheet">
<!-- Flatpickr CSS -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/flatpickr/dist/flatpickr.min.css">
<style>
body { font-family: 'Inter', 'Tajawal', sans-serif; background-color: #f4f7f6; }
@ -144,6 +146,7 @@ $site_favicon = !empty($site_settings['company_favicon']) ? $site_settings['comp
<a href="doctors.php" class="sidebar-link <?php echo $section === 'doctors' ? 'active' : ''; ?>"><i class="bi bi-person-badge me-2"></i> <?php echo __('doctors'); ?></a>
<a href="nurses.php" class="sidebar-link <?php echo $section === 'nurses' ? 'active' : ''; ?>"><i class="bi bi-person-heart me-2"></i> <?php echo __('nurses'); ?></a>
<a href="departments.php" class="sidebar-link <?php echo $section === 'departments' ? 'active' : ''; ?>"><i class="bi bi-diagram-3 me-2"></i> <?php echo __('departments'); ?></a>
<a href="cities.php" class="sidebar-link <?php echo $section === 'cities' ? 'active' : ''; ?>"><i class="bi bi-building me-2"></i> <?php echo __('cities'); ?></a>
<a href="#settingsSubmenu" data-bs-toggle="collapse" class="sidebar-link <?php echo in_array($section, ['employees', 'poisons', 'company_profile']) ? 'active' : ''; ?> d-flex justify-content-between align-items-center">
<span><i class="bi bi-gear me-2"></i> <?php echo __('settings'); ?></span>

61
includes/pages/cities.php Normal file
View File

@ -0,0 +1,61 @@
<?php
$query = "SELECT * FROM cities ORDER BY id DESC";
$stmt = $db->query($query);
$cities = $stmt->fetchAll();
?>
<div class="d-flex justify-content-between align-items-center mb-4">
<h3 class="fw-bold text-secondary"><?php echo __('cities'); ?></h3>
<button class="btn btn-primary shadow-sm" data-bs-toggle="modal" data-bs-target="#addCityModal">
<i class="bi bi-plus-lg me-1"></i> <?php echo __('add_city'); ?>
</button>
</div>
<div class="card shadow-sm border-0">
<div class="card-body p-0">
<div class="table-responsive">
<table class="table table-hover align-middle mb-0">
<thead class="table-light text-secondary">
<tr>
<th class="px-4 py-3">#</th>
<th class="py-3"><?php echo __('name_en'); ?></th>
<th class="py-3"><?php echo __('name_ar'); ?></th>
<th class="py-3 text-end px-4"><?php echo __('actions'); ?></th>
</tr>
</thead>
<tbody>
<?php if (empty($cities)): ?>
<tr>
<td colspan="4" class="text-center py-5 text-muted">
<i class="bi bi-building display-4 d-block mb-3"></i>
No cities found.
</td>
</tr>
<?php else: ?>
<?php foreach ($cities as $city): ?>
<tr>
<td class="px-4 text-secondary"><?php echo $city['id']; ?></td>
<td class="fw-semibold text-dark"><?php echo htmlspecialchars($city['name_en']); ?></td>
<td class="text-secondary"><?php echo htmlspecialchars($city['name_ar']); ?></td>
<td class="text-end px-4">
<div class="btn-group shadow-sm border rounded bg-white">
<button class="btn btn-link text-primary py-1 px-2 border-end"
onclick="showEditCityModal(<?php echo htmlspecialchars(json_encode($city, JSON_UNESCAPED_UNICODE)); ?>)"
data-bs-toggle="tooltip" title="<?php echo __('edit'); ?>">
<i class="bi bi-pencil-square"></i>
</button>
<button class="btn btn-link text-danger py-1 px-2"
onclick="showDeleteCityModal(<?php echo $city['id']; ?>)"
data-bs-toggle="tooltip" title="<?php echo __('delete'); ?>">
<i class="bi bi-trash3"></i>
</button>
</div>
</td>
</tr>
<?php endforeach; ?>
<?php endif; ?>
</tbody>
</table>
</div>
</div>
</div>

View File

@ -1,38 +0,0 @@
import re
file_path = 'includes/actions.php'
with open(file_path, 'r') as f:
content = f.read()
# 1. Update variable assignments
# This is safe to replace globally as it adds variables where address is defined.
content = content.replace(
"$address = $_POST['address'] ?? '';",
"$address = $_POST['address'] ?? '';\n $civil_id = $_POST['civil_id'] ?? '';\n $nationality = $_POST['nationality'] ?? '';\n $city = $_POST['city'] ?? '';"
)
# 2. Update INSERT query (Add Patient)
old_insert = '"INSERT INTO patients (name, phone, dob, gender, blood_group, insurance_company_id, policy_number, address) VALUES (?, ?, ?, ?, ?, ?, ?, ?)"'
new_insert = '"INSERT INTO patients (name, phone, dob, gender, blood_group, insurance_company_id, policy_number, address, civil_id, nationality, city) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"'
content = content.replace(old_insert, new_insert)
# Update INSERT execution array
old_exec_insert = '[$name, $phone, $dob, $gender, $blood_group, $insurance_company_id, $policy_number, $address]'
new_exec_insert = '[$name, $phone, $dob, $gender, $blood_group, $insurance_company_id, $policy_number, $address, $civil_id, $nationality, $city]'
content = content.replace(old_exec_insert, new_exec_insert)
# 3. Update UPDATE query (Edit Patient)
old_update = '"UPDATE patients SET name = ?, phone = ?, dob = ?, gender = ?, blood_group = ?, insurance_company_id = ?, policy_number = ?, address = ? WHERE id = ?"'
new_update = '"UPDATE patients SET name = ?, phone = ?, dob = ?, gender = ?, blood_group = ?, insurance_company_id = ?, policy_number = ?, address = ?, civil_id = ?, nationality = ?, city = ? WHERE id = ?"'
content = content.replace(old_update, new_update)
# Update UPDATE execution array
old_exec_update = '[$name, $phone, $dob, $gender, $blood_group, $insurance_company_id, $policy_number, $address, $id]'
new_exec_update = '[$name, $phone, $dob, $gender, $blood_group, $insurance_company_id, $policy_number, $address, $civil_id, $nationality, $city, $id]'
content = content.replace(old_exec_update, new_exec_update)
with open(file_path, 'w') as f:
f.write(content)
print("Updated actions.php")