Team 2 (Purview Doctor Tagging)
Specific Folder FTP Upload / ftp-deploy (push) Successful in 1m45s Details

This commit is contained in:
zeeshan 2026-10-08 13:26:03 +05:30
parent 9a90988556
commit 914a319b3f
1 changed files with 183 additions and 157 deletions

View File

@ -94,7 +94,7 @@
$isContact = str_starts_with($question->code, 'contact_id'); $isContact = str_starts_with($question->code, 'contact_id');
@endphp @endphp
<select class="form-control" {!!($isContact)?'data-toggle="select2"':'' !!} id="field-{{ $question->code }}" name="{{ $question->code }}" {{ $question->required == 'yes' ? 'required' : '' }}> <select class="form-control" id="field-{{ $question->code }}" name="{{ $question->code }}" {{ $question->required == 'yes' ? 'required' : '' }}>
<option value=""> -- Select -- </option> <option value=""> -- Select -- </option>
@foreach ($question->options as $option) @foreach ($question->options as $option)
@if($isContact && isset($option->contact->type) && $option->contact->type == 'doctor' ) @if($isContact && isset($option->contact->type) && $option->contact->type == 'doctor' )
@ -282,180 +282,206 @@
} */ } */
function enforceUniqueDoctorSelections() { /* function enforceUniqueDoctorSelections() {
var selectedValues = []; var selectedValues = [];
// Collect selected values from select dropdowns only // Collect selected values from select dropdowns only
$("select[id^='field-contact_id']").each(function () { $("select[id^='field-contact_id']").each(function () {
var v = $(this).val(); var v = $(this).val();
if (v) selectedValues.push(String(v)); if (v) selectedValues.push(String(v));
});
// Reset all option disabled states, then disable duplicates across selects
$("select[id^='field-contact_id']").each(function () {
var currentSelect = $(this);
var currentVal = currentSelect.val() ? String(currentSelect.val()) : "";
currentSelect.find("option").prop("disabled", false);
selectedValues.forEach(function (v) {
if (v && v !== currentVal) {
currentSelect
.find("option[value=\"" + v.replace(/"/g, '\\"') + "\"]")
.prop("disabled", true);
}
});
if (currentSelect.data("select2")) {
currentSelect.trigger("change.select2");
}
});
}
$("select[id^='field-contact_id']").each(function() {
var select = $(this);
// Clear previous options
select.html('');
// Add a default 'Select' option
select.append(
$("<option></option>")
.attr("value", '')
.text('-- Select --')
);
// Append options from contacts
contacts.forEach(function(itm) {
var option = $("<option></option>")
.attr("value", itm.value)
.text(itm.display);
// If doctor options have extra attributes
if (itm.contact && itm.contact.msl_code) {
option.attr("msl_code", itm.contact.msl_code);
}
if (itm.contact && itm.contact.speciality) {
option.attr("speciality", itm.contact.speciality);
}
select.append(option);
}); });
// Reset all option disabled states, then disable duplicates across selects
$("select[id^='field-contact_id']").each(function () {
var currentSelect = $(this);
var currentVal = currentSelect.val() ? String(currentSelect.val()) : "";
currentSelect.find("option").prop("disabled", false);
selectedValues.forEach(function (v) {
if (v && v !== currentVal) {
currentSelect
.find("option[value=\"" + v.replace(/"/g, '\\"') + "\"]")
.prop("disabled", true);
}
});
if (currentSelect.data("select2")) {
currentSelect.trigger("change.select2");
}
});
} */
function enforceUniqueDoctorSelections() {
var selectedValues = [];
$("select[id^='field-contact_id']").each(function () {
var v = $(this).val();
if (v) selectedValues.push(String(v));
});
$("select[id^='field-contact_id']").each(function () {
var currentSelect = $(this);
var currentVal = currentSelect.val() ? String(currentSelect.val()) : "";
currentSelect.find("option").prop("disabled", false);
selectedValues.forEach(function (v) {
if (v && v !== currentVal) {
currentSelect
.find("option[value=\"" + v.replace(/"/g, '\\"') + "\"]")
.prop("disabled", true);
}
});
if (currentSelect.hasClass("select2-hidden-accessible")) {
currentSelect.select2({
width: "100%",
placeholder: "-- Select --",
allowClear: true
});
}
});
}
/* $("select[id^='field-contact_id']").each(function() {
var select = $(this);
// Clear previous options
select.html('');
// Add a default 'Select' option
select.append(
$("<option></option>")
.attr("value", '')
.text('-- Select --')
);
// Append options from contacts
contacts.forEach(function(itm) {
var option = $("<option></option>")
.attr("value", itm.value)
.text(itm.display);
// If doctor options have extra attributes
if (itm.contact && itm.contact.msl_code) {
option.attr("msl_code", itm.contact.msl_code);
}
if (itm.contact && itm.contact.speciality) {
option.attr("speciality", itm.contact.speciality);
}
select.append(option);
});
// For each select element, add a change event handler to populate `msl_code` and `speciality` // For each select element, add a change event handler to populate `msl_code` and `speciality`
// We assume dropdowns and targets follow the pattern: // We assume dropdowns and targets follow the pattern:
// - select: field-contact_id_1, field-contact_id_2, ..., field-contact_id // - select: field-contact_id_1, field-contact_id_2, ..., field-contact_id
// - result: field-msl_code_1, field-speciality_1, etc. // - result: field-msl_code_1, field-speciality_1, etc.
// Remove any old event handlers first to prevent duplicate bindings // Remove any old event handlers first to prevent duplicate bindings
select.off('change').on('change', function () { select.off('change').on('change', function () {
var selected = $(this).find(':selected'); var selected = $(this).find(':selected');
var selectId = $(this).attr('id'); // e.g., field-contact_id_1 var selectId = $(this).attr('id'); // e.g., field-contact_id_1
// Extract the suffix (e.g., _1 or empty) // Extract the suffix (e.g., _1 or empty)
var match = selectId.match(/^field-contact_id(_\d+)?$/); var match = selectId.match(/^field-contact_id(_\d+)?$/);
var suffix = match && match[1] ? match[1] : ''; var suffix = match && match[1] ? match[1] : '';
// Build the target msl_code and speciality field ids // Build the target msl_code and speciality field ids
var mslCodeField = $('#field-msl_code' + suffix); var mslCodeField = $('#field-msl_code' + suffix);
var specialityField = $('#field-speciality' + suffix); var specialityField = $('#field-speciality' + suffix);
if (mslCodeField.length) { if (mslCodeField.length) {
mslCodeField.val(selected.attr('msl_code') || ''); mslCodeField.val(selected.attr('msl_code') || '');
} }
if (specialityField.length) { if (specialityField.length) {
specialityField.val(selected.attr('speciality') || ''); specialityField.val(selected.attr('speciality') || '');
} }
// Prevent selecting the same doctor across multiple dropdowns // Prevent selecting the same doctor across multiple dropdowns
enforceUniqueDoctorSelections();
});
// Ensure unique selection is enforced after initial render
enforceUniqueDoctorSelections(); enforceUniqueDoctorSelections();
}); });
// Ensure unique selection is enforced after initial render // Enable search on doctor dropdowns
enforceUniqueDoctorSelections(); applySelect2ToDoctorDropdowns();
}); $("#pageloader").fadeOut();
}); */
// Enable search on doctor dropdowns // contacts लोड झाल्यानंतर:
applySelect2ToDoctorDropdowns(); contacts = contacts.filter(function(itm) { return itm.value !== 'sample'; });
$("#pageloader").fadeOut();
});
@endif
$("select[id^='field-contact_id']").each(function() {
var select = $(this);
// Loop through hierarcies and fetch contacts for each hierarchy, store in contacts variable // जर आधी Select2 लागलेले असेल तर ते आधी नष्ट (destroy) करा
if (select.hasClass("select2-hidden-accessible")) {
select.select2('destroy');
}
// $('#field-user_id').change(function(){ // जुने ऑप्शन्स रिकामे करा
// let hierarchy = $('option:selected', this).attr('hierarchy'); select.empty();
// $('#field-hierarchy_id').val(hierarchy)
// event.preventDefault();
// $("#pageloader").fadeIn();
// $.ajax({
// type: "GET",
// url: '/form/getdoctorlist?partition={{$form->partition}}&hierarchy='+hierarchy,
// processData: false,
// contentType: false,
// success: function( data ) {
// $("#pageloader").fadeOut();
// for (let i = 1; i <= 10; i++) {
// let contactField = $('#field-contact_id_' + i); // डिफॉल्ट सिलेक्ट पर्याय जोडा
select.append($("<option></option>").attr("value", '').text('-- Select --'));
// // Skip if field does not exist // डॉक्टरांची यादी जोडा
// if (!contactField.length) continue; contacts.forEach(function(itm) {
var option = $("<option></option>")
.attr("value", itm.value)
.text(itm.display);
// contactField.html(''); if (itm.contact && itm.contact.msl_code) {
// contactField.append( option.attr("msl_code", itm.contact.msl_code);
// $("<option></option>") }
// .attr("value", '') if (itm.contact && itm.contact.speciality) {
// .text('-- Select --') option.attr("speciality", itm.contact.speciality);
// ); }
select.append(option);
});
// for (let itm of data) { // आता Select2 लागू करा
// contactField.append( select.select2({
// $("<option></option>") width: "100%",
// .attr("value", itm.value) placeholder: "-- Select --",
// .text(itm.display) allowClear: true
// .attr("msl_code", itm.contact.msl_code) });
// .attr("speciality", itm.contact.speciality)
// ); // Change event बांधा
// } select.off('change').on('change', function () {
var selected = $(this).find(':selected');
var selectId = $(this).attr('id');
var match = selectId.match(/^field-contact_id(_\d+)?$/);
var suffix = match && match[1] ? match[1] : '';
var mslCodeField = $('#field-msl_code' + suffix);
var specialityField = $('#field-speciality' + suffix);
if (mslCodeField.length) {
mslCodeField.val(selected.attr('msl_code') || '');
}
if (specialityField.length) {
specialityField.val(selected.attr('speciality') || '');
}
// डुप्लिकेट डॉक्टर निवडणे थांबवा
enforceUniqueDoctorSelections();
});
});
$("#pageloader").fadeOut();
// // Remove old change events before binding again @endif
// contactField.off('change').on('change', function () {
// let selected = $(this).find(':selected');
// $('#field-msl_code_' + i).val(selected.attr('msl_code') || '');
// $('#field-speciality_' + i).val(selected.attr('speciality') || '');
// console.log(selected.text()); // selected doctor name
// });
// contactField.select2({
// placeholder: "-- Select --",
// allowClear: true,
// width: '100%'
// });
// }
// },
// });
// console.log(hierarchy)
// })
// for (let i = 1; i <= 10; i++) {
// $('#field-msl_code_' + i).attr('readonly',true);
// $('#field-speciality_' + i).attr('readonly',true);
// }
$('#report-form').on('submit', function(event){ $('#report-form').on('submit', function(event){
event.preventDefault(); event.preventDefault();