Team 4 (Mother Forum )Load doctors for ABM
Specific Folder FTP Upload / ftp-deploy (push) Successful in 37s Details

This commit is contained in:
zeeshan 2026-10-09 16:57:59 +05:30
parent 60247d13b8
commit 9fe098ec0b
1 changed files with 185 additions and 162 deletions

View File

@ -6,11 +6,10 @@
<link href="{{asset('assets/libs/sweetalert2/sweetalert2.min.css')}}" rel="stylesheet" type="text/css" />
<link href="{{ asset('assets/libs/select2/select2.min.css') }}" rel="stylesheet" type="text/css" />
</head>
<body class="loading">
<div id="pageloader">
<div id="pageloader">
<img src="http://cdnjs.cloudflare.com/ajax/libs/semantic-ui/0.16.1/images/loader-large.gif" alt="processing..." />
</div>
<body class="loading">
<div class="account-pages">
<div class="container">
<div class="row justify-content-center">
@ -48,7 +47,7 @@
@endphp
@if(count($submissions) ==0 || !empty($id) )
@if(count($submissions) ==0)
<form method="POST" action="/form/submit" id="report-form" enctype="multipart/form-data">
<input type="hidden" name="form_id" value="{{$form_id}}">
<input type="hidden" name="user_id" value="{{$form->user_id}}">
@ -57,20 +56,7 @@
@if($id)
<input type="hidden" name="id" value="{{$id}}">
@endif
{{-- @if(isset($form->manager_can_submit) && $form->manager_can_submit == true)
<div class="col-md-12 mb-2">
<label for="field-user_id" class="form-label"> Select User / Territory <span class="text-danger">*</span> </label>
<select class="form-control" id="field-user_id" name="user_id" required>
<option value=""> -- Select -- </option>
@foreach($form->users as $option)
<option value="{{$option->value}}" hierarchy="{{$option->hierarchy_id}}" {{isset($question->value) && $question->value == $option->value ? 'selected':''}}>{{$option->display}}</option>
@endforeach
</select>
<input type="hidden" id="field-hierarchy_id" name="hierarchy_id" value="">
</div>
@endif --}}
@foreach($questions as $question)
<div class="col-md-12 mb-2">
<label for="field-{{$question->code}}" class="form-label">{{$question->question}} {!!$question->required == 'yes' ? '<span class="text-danger">*</span>':''!!} </label>
@ -90,26 +76,21 @@
@case('textarea')
<textarea id="field-{{$question->code}}" name="{{$question->code}}" class="form-control" {{$question->required == 'yes'?'required':'' }}>{{isset($question->value)?$question->value:''}}</textarea>
@break
{{-- @case('dropdown')
@php
$isContact = str_starts_with($question->code, 'contact_id');
$options = collect($question->options)->sortBy('display', SORT_NATURAL | SORT_FLAG_CASE);
@endphp
<select class="form-control" {!!($isContact)?'data-toggle="select2"':'' !!} id="field-{{ $question->code }}" name="{{ $question->code }}" {{ $question->required == 'yes' ? 'required' : '' }}>
@case('dropdown')
<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' )
@if($question->code == 'contact_id' && isset($option->contact->type) && $option->contact->type == 'doctor' )
<option value="{{ $option->value }}"
@if(isset($question->value) && $question->value == $option->value) selected @endif
@if($isContact)
@if($question->code == 'contact_id')
msl_code="{{ (isset($option->contact->msl_code) ? $option->contact->msl_code : '') }}"
speciality="{{ (isset($option->contact->speciality) ? $option->contact->speciality : '') }}"
@endif
>
{{ $option->display }}
</option>
@elseif(!$isContact)
@elseif($question->code != 'contact_id')
<option value="{{ $option->value }}" {{ isset($question->value) && $question->value == $option->value ? 'selected' : '' }} {{ $question->code == 'contact_id' ? 'pcode= ' . (isset($option->contact->pcode)?$option->contact->pcode:'') . ' ' : '' }} {{ isset($question->value) && $question->value == $option->value ? 'selected' : '' }} {{ $question->code == 'contact_id' ? 'speciality= ' . (isset($option->contact->speciality) ? $option->contact->speciality :'') . ' ' : '' }} >
{{ $option->display }}
</option>
@ -118,44 +99,9 @@
@endforeach
</select>
@break --}}
@case('dropdown')
@php
$isContact = str_starts_with($question->code, 'contact_id');
// जर options collection किंवा array असेल तर display field नुसार alphabetize करा
$options = collect($question->options)->sortBy('display', SORT_NATURAL | SORT_FLAG_CASE);
@endphp
<select class="form-control" {!!($isContact)?'data-toggle="select2"':'' !!} id="field-{{ $question->code }}" name="{{ $question->code }}" data-selected="{{ isset($question->value) ? $question->value : '' }}" {{ $question->required == 'yes' ? 'required' : '' }}>
<option value=""> -- Select -- </option>
{{-- $question->options ऐवजी $options वापरा --}}
@foreach ($options as $option)
@if($isContact && isset($option->contact->type) && $option->contact->type == 'doctor' )
<option value="{{ $option->value }}"
@if(isset($question->value) && $question->value == $option->value) selected @endif
@if($isContact)
msl_code="{{ (isset($option->contact->msl_code) ? $option->contact->msl_code : '') }}"
speciality="{{ (isset($option->contact->speciality) ? $option->contact->speciality : '') }}"
@endif
>
{{ $option->display }}
</option>
@elseif(!$isContact)
<option value="{{ $option->value }}"
{{ isset($question->value) && $question->value == $option->value ? 'selected' : '' }}
{{ $question->code == 'contact_id' ? 'pcode= ' . (isset($option->contact->pcode)?$option->contact->pcode:'') . ' ' : '' }}
{{ $question->code == 'contact_id' ? 'speciality= ' . (isset($option->contact->speciality) ? $option->contact->speciality :'') . ' ' : '' }}>
{{ $option->display }}
</option>
@endif
@endforeach
</select>
@break
@break
@case('checkbox')
@foreach($question->options as $option)
<div class="form-check mb-2 form-check-primary">
@ -201,9 +147,8 @@
</div>
@endif
</form>
@else
<h4 class="text-center" >You have submitted the doctor tagging. Please Edit through View History option if any changes are to be done.</h4>
<h4 class="text-center" >You have already submitted 10 Doctors</h4>
@endif
</div> <!-- end card-body -->
@ -269,18 +214,13 @@
// All contacts loaded for each hierarchy
// Example usage: console.log(contacts);
// Filter out contacts where value == 'sample'
contacts = contacts.filter(function(itm) { return itm.value !== 'sample' && itm.contact && itm.contact.type === 'doctor' });
contacts.sort(function(a, b) {
return (a.display || '').localeCompare(b.display || '', undefined, { sensitivity: 'base' });
});
contacts = contacts.filter(function(itm) { return itm.value !== 'sample'; });
console.log(contacts);
// Loop through contacts and append options to select elements whose id starts with 'field-contact_id'
// We assume contact_id fields may be suffixed, e.g. field-contact_id_1, field-contact_id, etc.
function applySelect2ToDoctorDropdowns() {
$("select[id^='field-contact_id']").each(function () {
$("[id^='field-contact_id']").each(function () {
var select = $(this);
// Avoid re-initializing select2
if (select.data("select2")) return;
@ -292,26 +232,23 @@
});
}
$('input[id^="field-msl_code"], input[id^="field-speciality"]').prop('readonly', true);
function enforceUniqueDoctorSelections() {
var selectedValues = [];
$("select[id^='field-contact_id']").each(function () {
// Collect selected values (ignore empty)
$("[id^='field-contact_id']").each(function () {
var v = $(this).val();
if (v) selectedValues.push(String(v));
});
$("select[id^='field-contact_id']").each(function () {
// Reset all option disabled states, then disable duplicates across selects
$("[id^='field-contact_id']").each(function () {
var currentSelect = $(this);
var currentVal = currentSelect.val() ? String(currentSelect.val()) : "";
currentSelect.find("option").prop("disabled", false);
// Disable values selected in OTHER selects (keep current selection enabled)
selectedValues.forEach(function (v) {
if (v && v !== currentVal) {
currentSelect
@ -320,54 +257,37 @@
}
});
if (currentSelect.hasClass("select2-hidden-accessible")) {
currentSelect.select2({
width: "100%",
placeholder: "-- Select --",
allowClear: true
});
// Refresh select2 UI if present
if (currentSelect.data("select2")) {
currentSelect.trigger("change.select2");
}
});
}
}
$("select[id^='field-contact_id']").each(function() {
var select = $(this);
// Clear previous options
var savedValue = select.attr('data-selected') || select.data('selected') || select.val() || '';
select.empty();
// 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);
}
if (savedValue && String(savedValue) === String(itm.value)) {
option.prop('selected', true);
}
select.append(option);
});
$("[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:
@ -375,49 +295,153 @@
// - 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') || '');
}
// Prevent selecting the same doctor across multiple dropdowns
enforceUniqueDoctorSelections();
});
if (savedValue) {
select.val(savedValue).trigger('change');
if (mslCodeField.length) {
mslCodeField.val(selected.attr('msl_code') || '');
}
if (specialityField.length) {
specialityField.val(selected.attr('speciality') || '');
}
});
// Ensure unique selection is enforced after initial render
// Prevent selecting the same doctor across multiple dropdowns
enforceUniqueDoctorSelections();
// Enable search on doctor dropdowns
applySelect2ToDoctorDropdowns();
$("#pageloader").fadeOut();
});
// Ensure unique selection is enforced after initial render
enforceUniqueDoctorSelections();
});
// Enable search on doctor dropdowns
applySelect2ToDoctorDropdowns();
$("#pageloader").fadeOut();
});
@endif
for (let i = 1; i <= 10; i++) {
$(`#field-mobile_number_${i}`).on('input', function () {
// Remove non-numeric characters
this.value = this.value.replace(/\D/g, '');
// Limit to 10 digits
if (this.value.length > 10) {
this.value = this.value.slice(0, 10);
}
});
}
for (let i = 1; i <= 10; i++) {
$(`#field-email_id_${i}`).on('input', function () {
// Remove spaces
this.value = this.value.replace(/\s/g, '');
});
$(`#field-email_id_${i}`).on('blur', function () {
let email = $(this).val().trim();
let emailPattern = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
if (email !== '' && !emailPattern.test(email)) {
alert('Please enter a valid email address');
$(this).focus();
}
});
}
// 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();
@ -463,8 +487,7 @@
var plandateField = document.getElementById('field-record_date');
plandateField.setAttribute('max', today);
});
</script>