Team 2 (Lung Manager Programme) Duplicate Doctor
Specific Folder FTP Upload / ftp-deploy (push) Successful in 36s
Details
Specific Folder FTP Upload / ftp-deploy (push) Successful in 36s
Details
This commit is contained in:
parent
885095ae3e
commit
8f1381d6aa
|
|
@ -356,7 +356,7 @@
|
|||
$('#field-speciality' + suffix).val(selectedOption.attr('speciality') || '');
|
||||
}
|
||||
|
||||
function preventDuplicateDoctors() {
|
||||
/* function preventDuplicateDoctors() {
|
||||
const selectedValues = [];
|
||||
|
||||
$('select[id^="field-contact_id"]').each(function () {
|
||||
|
|
@ -388,8 +388,80 @@
|
|||
$select.select2({ width: '100%', placeholder: '-- Select Doctor --' });
|
||||
$select.val(oldValue).trigger('change.select2');
|
||||
});
|
||||
} */
|
||||
|
||||
function preventDuplicateDoctors() {
|
||||
|
||||
const selectedValues = [];
|
||||
|
||||
// Get all selected doctor IDs
|
||||
$('select[id^="field-contact_id"]').each(function () {
|
||||
|
||||
const value = $(this).val();
|
||||
|
||||
if (value) {
|
||||
selectedValues.push(String(value));
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
// Disable already selected doctors in other dropdowns
|
||||
$('select[id^="field-contact_id"]').each(function () {
|
||||
|
||||
const $select = $(this);
|
||||
|
||||
const currentValue = $select.val()
|
||||
? String($select.val())
|
||||
: '';
|
||||
|
||||
$select.find('option').each(function () {
|
||||
|
||||
const $option = $(this);
|
||||
const optionValue = String($option.val() || '');
|
||||
|
||||
if (!optionValue) return;
|
||||
|
||||
const cleanText = $option.text()
|
||||
.replace(' (Already Added)', '');
|
||||
|
||||
if (
|
||||
selectedValues.includes(optionValue) &&
|
||||
optionValue !== currentValue
|
||||
) {
|
||||
|
||||
$option.prop('disabled', true);
|
||||
|
||||
$option.text(cleanText + ' (Already Added)');
|
||||
|
||||
} else {
|
||||
|
||||
$option.prop('disabled', false);
|
||||
|
||||
$option.text(cleanText);
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
// Refresh Select2
|
||||
const oldValue = $select.val();
|
||||
|
||||
if ($select.hasClass('select2-hidden-accessible')) {
|
||||
$select.select2('destroy');
|
||||
}
|
||||
|
||||
$select.select2({
|
||||
width: '100%',
|
||||
placeholder: '-- Select Doctor --'
|
||||
});
|
||||
|
||||
$select.val(oldValue).trigger('change.select2');
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
// All doctor dropdowns use the same change handler, including added wrappers.
|
||||
$(document).on('change', 'select[id^="field-contact_id"]', function () {
|
||||
updateDoctorMeta($(this));
|
||||
|
|
@ -425,7 +497,7 @@
|
|||
Promise.all(requests).then(function (responses) {
|
||||
const doctorMap = new Map();
|
||||
|
||||
responses.forEach(function (data) {
|
||||
/* responses.forEach(function (data) {
|
||||
if (!Array.isArray(data)) return;
|
||||
|
||||
data.forEach(function (doctor) {
|
||||
|
|
@ -433,8 +505,40 @@
|
|||
const key = String(doctor.value);
|
||||
if (!doctorMap.has(key)) doctorMap.set(key, doctor);
|
||||
});
|
||||
}); */
|
||||
|
||||
responses.forEach(function (data) {
|
||||
if (!Array.isArray(data)) return;
|
||||
|
||||
data.forEach(function (doctor) {
|
||||
|
||||
if (!doctor || !doctor.contact) return;
|
||||
|
||||
// Only Doctor type contacts
|
||||
const contactType = String(doctor.contact.type || '').toLowerCase();
|
||||
|
||||
if (contactType !== 'doctor') {
|
||||
return;
|
||||
}
|
||||
|
||||
if (
|
||||
doctor.value === undefined ||
|
||||
doctor.value === null ||
|
||||
doctor.value === ''
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
const key = String(doctor.value);
|
||||
|
||||
// Remove duplicate doctor records
|
||||
if (!doctorMap.has(key)) {
|
||||
doctorMap.set(key, doctor);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
const allDoctors = Array.from(doctorMap.values()).sort(function (a, b) {
|
||||
return String(a.display || '').localeCompare(String(b.display || ''), 'en', { sensitivity: 'base' });
|
||||
});
|
||||
|
|
@ -559,6 +663,28 @@
|
|||
return !!$(this).val();
|
||||
}).length;
|
||||
|
||||
|
||||
const selectedDoctorIds = [];
|
||||
|
||||
$('select[id^="field-contact_id"]').each(function () {
|
||||
|
||||
const doctorId = $(this).val();
|
||||
|
||||
if (doctorId) {
|
||||
selectedDoctorIds.push(String(doctorId));
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
const uniqueDoctorIds = [...new Set(selectedDoctorIds)];
|
||||
|
||||
if (selectedDoctorIds.length !== uniqueDoctorIds.length) {
|
||||
|
||||
alert('Duplicate doctors are not allowed.');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (!isEditMode && selectedDoctorCount !== 10) {
|
||||
alert('You must select exactly 10 doctors. Currently selected: ' + selectedDoctorCount);
|
||||
return;
|
||||
|
|
|
|||
Loading…
Reference in New Issue