updating patients

This commit is contained in:
Flatlogic Bot 2026-03-06 02:52:55 +00:00
parent 2b7bb7957e
commit 230a62f266
2 changed files with 68 additions and 5 deletions

View File

@ -0,0 +1,14 @@
Plan:
1. **Fix Syntax Error:** I identified that the JavaScript code for age calculation in `includes/layout/footer.php` contained Python-style comments (`#`), causing a syntax error.
2. **Correct Comments:** I created and executed a Python script (`fix_footer_js.py` and `fix_footer_js_v2.py`) to replace these with valid JavaScript comments (`//`).
3. **Verify:** I verified the file content to ensure the syntax is now correct.
Changed:
* `includes/layout/footer.php`: Replaced invalid `#` comments with `//` in the JavaScript section at the end of the file.
Notes:
* The automatic age-to-DOB calculation (and vice-versa) should now work correctly when you type in the "Age" field.
* The script listens for input on the Age field and sets the DOB to `YYYY-01-01`.
Next: Please try entering the age again in the "Add Patient" or "Edit Patient" modal. It should now automatically populate the Date of Birth field.
Reminder: Click Save in the editor to sync changes.

View File

@ -35,13 +35,17 @@
</div>
</div>
<div class="row">
<div class="col-md-4 mb-3">
<div class="col-md-3 mb-3">
<label class="form-label"><?php echo __('phone'); ?></label>
<input type="text" name="phone" class="form-control" required>
</div>
<div class="col-md-4 mb-3">
<div class="col-md-3 mb-3">
<label class="form-label"><?php echo __('dob'); ?></label>
<input type="text" name="dob" class="form-control masked-date" placeholder="YYYY-MM-DD">
<input type="text" name="dob" id="add_patient_dob" class="form-control masked-date" placeholder="YYYY-MM-DD">
</div>
<div class="col-md-2 mb-3">
<label class="form-label"><?php echo __('age'); ?></label>
<input type="number" id="add_patient_age" class="form-control" placeholder="<?php echo __('age'); ?>" min="0" max="150">
</div>
<div class="col-md-4 mb-3">
<label class="form-label"><?php echo __('gender'); ?></label>
@ -129,14 +133,18 @@
</div>
</div>
<div class="row">
<div class="col-md-4 mb-3">
<div class="col-md-3 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-4 mb-3">
<div class="col-md-3 mb-3">
<label class="form-label"><?php echo __('dob'); ?></label>
<input type="text" name="dob" id="edit_patient_dob" class="form-control masked-date" placeholder="YYYY-MM-DD">
</div>
<div class="col-md-2 mb-3">
<label class="form-label"><?php echo __('age'); ?></label>
<input type="number" id="edit_patient_age" class="form-control" placeholder="<?php echo __('age'); ?>" min="0" max="150">
</div>
<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">
@ -3232,6 +3240,47 @@ $drug_groups_js = $db->query("SELECT * FROM drugs_groups ORDER BY name_$lang")->
modal.show();
}
// Age to DOB Calculation
function setupAgeCalculation(ageId, dobId) {
var ageInput = document.getElementById(ageId);
var dobInput = document.getElementById(dobId);
if (ageInput && dobInput) {
ageInput.addEventListener('input', function() {
var age = parseInt(this.value);
if (!isNaN(age) && age >= 0) {
var currentYear = new Date().getFullYear();
var birthYear = currentYear - age;
// Default to Jan 1st
var dob = birthYear + '-01-01';
dobInput.value = dob;
// Trigger events for masking/validation
dobInput.dispatchEvent(new Event('input', { bubbles: true }));
dobInput.dispatchEvent(new Event('change', { bubbles: true }));
}
});
dobInput.addEventListener('change', function() {
// Try to calculate age from DOB if age is empty
if (this.value && this.value.length === 10 && !ageInput.value) {
var dob = new Date(this.value);
var today = new Date();
var age = today.getFullYear() - dob.getFullYear();
var m = today.getMonth() - dob.getMonth();
if (m < 0 || (m === 0 && today.getDate() < dob.getDate())) {
age--;
}
if (!isNaN(age) && age >= 0) {
ageInput.value = age;
}
}
});
}
}
setupAgeCalculation('add_patient_age', 'add_patient_dob');
setupAgeCalculation('edit_patient_age', 'edit_patient_dob');
</script>
</body>