update patients form

This commit is contained in:
Flatlogic Bot 2026-03-22 04:29:56 +00:00
parent f10cdedce9
commit 5f98198b67
2 changed files with 95 additions and 30 deletions

View File

@ -1,39 +1,70 @@
document.addEventListener('DOMContentLoaded', () => {
// --- Chat Widget Logic ---
const chatForm = document.getElementById('chat-form');
const chatInput = document.getElementById('chat-input');
const chatMessages = document.getElementById('chat-messages');
const appendMessage = (text, sender) => {
const msgDiv = document.createElement('div');
msgDiv.classList.add('message', sender);
msgDiv.textContent = text;
chatMessages.appendChild(msgDiv);
chatMessages.scrollTop = chatMessages.scrollHeight;
};
if (chatForm && chatInput && chatMessages) {
const appendMessage = (text, sender) => {
const msgDiv = document.createElement('div');
msgDiv.classList.add('message', sender);
msgDiv.textContent = text;
chatMessages.appendChild(msgDiv);
chatMessages.scrollTop = chatMessages.scrollHeight;
};
chatForm.addEventListener('submit', async (e) => {
e.preventDefault();
const message = chatInput.value.trim();
if (!message) return;
chatForm.addEventListener('submit', async (e) => {
e.preventDefault();
const message = chatInput.value.trim();
if (!message) return;
appendMessage(message, 'visitor');
chatInput.value = '';
appendMessage(message, 'visitor');
chatInput.value = '';
try {
const response = await fetch('api/chat.php', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ message })
try {
const response = await fetch('api/chat.php', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ message })
});
const data = await response.json();
// Artificial delay for realism
setTimeout(() => {
appendMessage(data.reply, 'bot');
}, 500);
} catch (error) {
console.error('Error:', error);
appendMessage("Sorry, something went wrong. Please try again.", 'bot');
}
});
}
// --- Patient Form: Auto-calculate DOB from Age ---
function calculateDobFromAge(ageInputId, dobInputId) {
const ageInput = document.getElementById(ageInputId);
const dobInput = document.getElementById(dobInputId);
if (ageInput && dobInput) {
ageInput.addEventListener('input', function() {
const age = parseInt(this.value);
if (!isNaN(age) && age >= 0) {
const currentYear = new Date().getFullYear();
const birthYear = currentYear - age;
// Default to Jan 1st of the birth year
const dob = `${birthYear}-01-01`;
dobInput.value = dob;
// Trigger change event if needed (e.g. for validation or other listeners)
dobInput.dispatchEvent(new Event('change'));
dobInput.dispatchEvent(new Event('input'));
} else {
dobInput.value = '';
}
});
const data = await response.json();
// Artificial delay for realism
setTimeout(() => {
appendMessage(data.reply, 'bot');
}, 500);
} catch (error) {
console.error('Error:', error);
appendMessage("Sorry, something went wrong. Please try again.", 'bot');
}
});
});
}
calculateDobFromAge('add_patient_age', 'add_patient_dob');
calculateDobFromAge('edit_patient_age', 'edit_patient_dob');
});

View File

@ -307,6 +307,23 @@ $translations = [
'upload_failed' => 'File upload failed',
'profile_updated_successfully' => 'Profile updated successfully',
'error_updating_profile' => 'Error updating profile',
'settings_updated_successfully' => 'Settings updated successfully.',
'company_details' => 'Company Details',
'company_name' => 'Company Name',
'company_email' => 'Company Email',
'company_phone' => 'Company Phone',
'company_address' => 'Company Address',
'ctr_no' => 'CR No.',
'registration_no' => 'Registration No.',
'vat_no' => 'VAT No.',
'timezone' => 'Timezone',
'working_hours_start' => 'Working Hours Start',
'working_hours_end' => 'Working Hours End',
'currency_settings' => 'Currency Settings',
'currency_symbol' => 'Currency Symbol',
'decimal_digits' => 'Decimal Digits',
'company_logo' => 'Company Logo',
'company_favicon' => 'Company Favicon',
],
'ar' => [
'dashboard' => 'لوحة التحكم',
@ -615,5 +632,22 @@ $translations = [
'upload_failed' => 'فشل تحميل الملف',
'profile_updated_successfully' => 'تم تحديث الملف الشخصي بنجاح',
'error_updating_profile' => 'خطأ في تحديث الملف الشخصي',
'settings_updated_successfully' => 'تم تحديث الإعدادات بنجاح.',
'company_details' => 'تفاصيل الشركة',
'company_name' => 'اسم الشركة',
'company_email' => 'البريد الإلكتروني للشركة',
'company_phone' => 'هاتف الشركة',
'company_address' => 'عنوان الشركة',
'ctr_no' => 'رقم السجل التجاري',
'registration_no' => 'رقم التسجيل',
'vat_no' => 'الرقم الضريبي',
'timezone' => 'المنطقة الزمنية',
'working_hours_start' => 'بداية ساعات العمل',
'working_hours_end' => 'نهاية ساعات العمل',
'currency_settings' => 'إعدادات العملة',
'currency_symbol' => 'رمز العملة',
'decimal_digits' => 'الخانات العشرية',
'company_logo' => 'شعار الشركة',
'company_favicon' => 'أيقونة الموقع',
]
];
];