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');
@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>
@foreach ($question->options as $option)
@if($isContact && isset($option->contact->type) && $option->contact->type == 'doctor' )
@ -282,180 +282,206 @@
} */
function enforceUniqueDoctorSelections() {
var selectedValues = [];
/* function enforceUniqueDoctorSelections() {
var selectedValues = [];
// Collect selected values from select dropdowns only
$("select[id^='field-contact_id']").each(function () {
var v = $(this).val();
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);
// Collect selected values from select dropdowns only
$("select[id^='field-contact_id']").each(function () {
var v = $(this).val();
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");
}
});
} */
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`
// We assume dropdowns and targets follow the pattern:
// - select: field-contact_id_1, field-contact_id_2, ..., field-contact_id
// - result: field-msl_code_1, field-speciality_1, etc.
// Remove any old event handlers first to prevent duplicate bindings
select.off('change').on('change', function () {
var selected = $(this).find(':selected');
var selectId = $(this).attr('id'); // e.g., field-contact_id_1
// Extract the suffix (e.g., _1 or empty)
var match = selectId.match(/^field-contact_id(_\d+)?$/);
var suffix = match && match[1] ? match[1] : '';
select.off('change').on('change', function () {
var selected = $(this).find(':selected');
var selectId = $(this).attr('id'); // e.g., field-contact_id_1
// Extract the suffix (e.g., _1 or empty)
var match = selectId.match(/^field-contact_id(_\d+)?$/);
var suffix = match && match[1] ? match[1] : '';
// Build the target msl_code and speciality field ids
var mslCodeField = $('#field-msl_code' + suffix);
var specialityField = $('#field-speciality' + suffix);
// Build the target msl_code and speciality field ids
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') || '');
}
if (mslCodeField.length) {
mslCodeField.val(selected.attr('msl_code') || '');
}
if (specialityField.length) {
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();
});
});
// Ensure unique selection is enforced after initial render
enforceUniqueDoctorSelections();
});
// Enable search on doctor dropdowns
applySelect2ToDoctorDropdowns();
$("#pageloader").fadeOut();
}); */
// contacts लोड झाल्यानंतर:
contacts = contacts.filter(function(itm) { return itm.value !== 'sample'; });
// Enable search on doctor dropdowns
applySelect2ToDoctorDropdowns();
$("#pageloader").fadeOut();
});
@endif
$("select[id^='field-contact_id']").each(function() {
var select = $(this);
// जर आधी Select2 लागलेले असेल तर ते आधी नष्ट (destroy) करा
if (select.hasClass("select2-hidden-accessible")) {
select.select2('destroy');
}
// जुने ऑप्शन्स रिकामे करा
select.empty();
// डिफॉल्ट सिलेक्ट पर्याय जोडा
select.append($("<option></option>").attr("value", '').text('-- Select --'));
// डॉक्टरांची यादी जोडा
contacts.forEach(function(itm) {
var option = $("<option></option>")
.attr("value", itm.value)
.text(itm.display);
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);
});
// आता Select2 लागू करा
select.select2({
width: "100%",
placeholder: "-- Select --",
allowClear: true
});
// 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();
@endif
// Loop through hierarcies and fetch contacts for each hierarchy, store in contacts variable
// $('#field-user_id').change(function(){
// let hierarchy = $('option:selected', this).attr('hierarchy');
// $('#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);
// // Skip if field does not exist
// if (!contactField.length) continue;
// contactField.html('');
// contactField.append(
// $("<option></option>")
// .attr("value", '')
// .text('-- Select --')
// );
// for (let itm of data) {
// contactField.append(
// $("<option></option>")
// .attr("value", itm.value)
// .text(itm.display)
// .attr("msl_code", itm.contact.msl_code)
// .attr("speciality", itm.contact.speciality)
// );
// }
// // Remove old change events before binding again
// 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){
event.preventDefault();