@@ -539,7 +544,7 @@ select option:disabled {
});
}
- function updateDoctorDropdowns($tbody) {
+ /* function updateDoctorDropdowns($tbody) {
let selectedDoctors = [];
$tbody.find('.doctor-select').each(function() {
@@ -574,7 +579,47 @@ select option:disabled {
});
});
}
+ */
+ function updateDoctorDropdowns() {
+ let selectedDoctors = [];
+
+ $('.doctor-select').each(function() {
+ let value = $(this).val();
+
+ if (value) {
+ selectedDoctors.push(value);
+ }
+ });
+
+ $('.doctor-select').each(function() {
+
+ let currentDropdown = $(this);
+ let currentValue = currentDropdown.val();
+
+ currentDropdown.find('option').each(function() {
+
+ let option = $(this);
+ let originalText = option.data('original-text') || option.text();
+
+ option.data('original-text', originalText);
+ option.text(originalText);
+ option.prop('disabled', false);
+
+ let optionValue = option.val();
+
+ if (
+ optionValue &&
+ optionValue !== currentValue &&
+ selectedDoctors.includes(optionValue)
+ ) {
+ option.prop('disabled', true);
+ option.text(originalText + ' (Already Added)');
+ }
+ });
+
+ });
+ }
function updateOtherMoleculeDropdowns($tbody) {
let sectionMolecule = $tbody.data('molecule-use');
@@ -663,8 +708,11 @@ select option:disabled {
return fd;
}
- $(document).on('change', '.doctor-select', function() {
+ /*$(document).on('change', '.doctor-select', function() {
updateDoctorDropdowns($(this).closest('.doctor-table-body'));
+ });*/
+ $(document).on('change', '.doctor-select', function() {
+ updateDoctorDropdowns();
});
$('.doctor-select').select2({
@@ -675,12 +723,18 @@ select option:disabled {
prefillAllDoctorTables();
- $('.doctor-table-body').each(function() {
+ /* $('.doctor-table-body').each(function() {
let $tbody = $(this);
updateOtherMoleculeDropdowns($tbody);
updateDoctorDropdowns($tbody);
+ }); */
+ $('.doctor-table-body').each(function() {
+ let $tbody = $(this);
+ updateOtherMoleculeDropdowns($tbody);
});
+ updateDoctorDropdowns();
+
$('#report-form').on('submit', function(event) {
event.preventDefault();