Team4 - Molecule Identification Form - New Changes (15 submission at a time)
Specific Folder FTP Upload / ftp-deploy (push) Successful in 1m38s Details

This commit is contained in:
Farhan Pathan 2026-06-17 09:48:58 +05:30
parent aa64f54f0e
commit 66e0038543
1 changed files with 228 additions and 254 deletions

View File

@ -33,6 +33,12 @@
'nac + acebrophylline' => 'nac_acebrophylline', 'nac + acebrophylline' => 'nac_acebrophylline',
]; ];
$categoryMoleculeUse = [
'erdosteine' => 'Erdosteine Prescriber',
'erdosteine + acebrophylline' => 'Erdosteine + Acebrophylline',
'nac + acebrophylline' => 'NAC + Acebrophylline',
];
$moleculeUseToCategory = [ $moleculeUseToCategory = [
'erdosteine prescriber' => 'erdosteine', 'erdosteine prescriber' => 'erdosteine',
'erdosteine' => 'erdosteine', 'erdosteine' => 'erdosteine',
@ -183,10 +189,10 @@
@php @php
$hideFields = [ $hideFields = [
'contact_id', 'contact_id',
'rx_support', 'rx_support',
'other_molecule_use' 'other_molecule_use',
'molecule_use',
]; ];
@endphp @endphp
@ -328,117 +334,72 @@
@endforeach @endforeach
@if(!isset($form->is_approval) || (isset($form->is_approval) && $form->is_approval != 'yes' ) ) @if(!isset($form->is_approval) || (isset($form->is_approval) && $form->is_approval != 'yes' ) )
<div class="text-center d-gri mt-3"> <div class="text-center d-gri mt-3">
@php $globalRowIndex = 0; @endphp
@foreach($categoryAttributes as $categoryLabel => $categoryPrefix)
<div class="col-md-12 mt-3"> <div class="col-md-12 mt-3">
<div class="card"> <div class="card">
{{-- <div class="card-header"> <div class="card-header">
<h5 class="mb-0">Tagged Doctors</h5> <h5 class="mb-0">{{ ucwords($categoryLabel) }}</h5>
</div> --}} </div>
<div class="card-body p-0"> <div class="card-body p-0">
<div class="table-responsive"> <div class="table-responsive">
@php <table class="table table-bordered mb-0">
$doctors = []; <thead>
<tr>
foreach($questions as $question){ <th>Doctor Name</th>
if($question->code == 'contact_id'){ <th>Rxn/Week Support</th>
$doctors = $question->options ?? []; <th>Other Molecule Use</th>
break; </tr>
} </thead>
} <tbody
@endphp class="doctor-table-body"
<table class="table table-bordered mb-0"> data-category="{{ $categoryPrefix }}"
<thead> data-molecule-use="{{ $categoryMoleculeUse[$categoryLabel] }}"
<tr> >
<th>Doctor Name</th> @for($i = 1; $i <= 5; $i++)
<tr class="doctor-row" data-row-index="{{ $globalRowIndex }}">
<th>Rxn/Week Support</th> <td>
<select
<th>Other Molecule Use</th> class="form-control doctor-select"
</tr> required
</thead> >
<tbody id="doctor-table-body"> <option value="">-- Select Doctor --</option>
@foreach($doctors as $doctor)
@for($i=1; $i<=5; $i++) <option value="{{ $doctor->value }}">{{ $doctor->display }}</option>
<tr>
<td>
<select
name="contact_id[]"
class="form-control doctor-select"
required
>
<option value="">-- Select Doctor --</option>
@foreach($questions as $question)
@if($question->code == 'contact_id')
@foreach($question->options as $doctor)
<option value="{{$doctor->value}}">
{{$doctor->display}}
</option>
@endforeach @endforeach
</select>
@endif </td>
<td>
@endforeach <select class="form-control rx-support-select" required>
<option value="">-- Select --</option>
</select> <option value="1-3 Rxn/Week">1-3 Rxn/Week</option>
</td> <option value="4-7 Rxn/Week">4-7 Rxn/Week</option>
<option value="8-11 Rxn/Week">8-11 Rxn/Week</option>
<td> <option value=">11 Rxn/Week">&gt;11 Rxn/Week</option>
</select>
<select </td>
name="rx_support[]" <td>
class="form-control" <select class="form-control other-molecule-select" required>
required <option value="">-- Select --</option>
> <option value="Erdosteine Prescriber">Erdosteine Prescriber</option>
<option value="">-- Select --</option> <option value="Erdosteine + Acebrophylline">Erdosteine + Acebrophylline</option>
<option value="1-3 Rxn/Week">1-3 Rxn/Week</option> <option value="NAC + Acebrophylline">NAC + Acebrophylline</option>
<option value="4-7 Rxn/Week">4-7 Rxn/Week</option> <option value="No">No</option>
<option value="8-11 Rxn/Week">8-11 Rxn/Week</option> </select>
<option value=">11 Rxn/Week">&gt;11 Rxn/Week</option> </td>
</select> </tr>
</td> @php $globalRowIndex++; @endphp
@endfor
<td> </tbody>
</table>
<select </div>
name="other_molecule_use[]"
class="form-control"
required
>
<option value="">-- Select --</option>
<option value="Erdosteine Prescriber">
Erdosteine Prescriber
</option>
<option value="Erdosteine + Acebrophylline">
Erdosteine + Acebrophylline Prescriber
</option>
<option value="NAC + Acebrophylline">
NAC + Acebrophylline Prescriber
</option>
<option value="No">
No
</option>
</select>
</td>
</tr>
@endfor
</tbody>
</table>
</div> </div>
</div> </div>
</div> </div>
</div> @endforeach
<button class="btn btn-primary" type="submit" id="submit-btn"> Submit </button> <button class="btn btn-primary" type="submit" id="submit-btn"> Submit </button>
</div> </div>
@endif @endif
</form> </form>
<!-- SAMPLE FORM MODAL --> <!-- SAMPLE FORM MODAL -->
@ -500,78 +461,61 @@ select option:disabled {
<script src="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/js/select2.min.js"></script> <script src="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/js/select2.min.js"></script>
<script src="{{asset('assets/libs/sweetalert2/sweetalert2.min.js')}}"></script> <script src="{{asset('assets/libs/sweetalert2/sweetalert2.min.js')}}"></script>
<script type="text/javascript"> <script type="text/javascript">
var allDoctors = {!! json_encode($doctors) !!};
var categoryAttributes = {!! json_encode($categoryAttributes) !!};
var moleculeUseToCategory = {!! json_encode($moleculeUseToCategory) !!};
var categorySubmissions = {!! json_encode($categorySubmissions) !!};
var categoryDoctorSubmissions = {!! json_encode($categoryDoctorSubmissions) !!}; var categoryDoctorSubmissions = {!! json_encode($categoryDoctorSubmissions) !!};
jQuery(document).ready(function($){ jQuery(document).ready(function($){
function resolveCategoryIndex(moleculeUse) { function getDoctorRows() {
if (!moleculeUse) { let rows = [];
return null;
}
let normalized = moleculeUse.toLowerCase().trim(); $('.doctor-table-body').each(function() {
let categoryKey = moleculeUseToCategory[normalized] || normalized; let $tbody = $(this);
let moleculeUse = $tbody.data('molecule-use');
return categoryAttributes[categoryKey] || null; $tbody.find('tr.doctor-row').each(function() {
rows.push({
$row: $(this),
moleculeUse: moleculeUse,
rowIndex: $(this).data('row-index')
});
});
});
return rows;
} }
function removeSubmissionId($row) { function removeSubmissionId($row) {
$row.removeAttr('data-submission-id');
$row.find('.submission-id').remove(); $row.find('.submission-id').remove();
} }
function setSubmissionId($row, submissionId) { function setSubmissionId($row, submissionId) {
let $input = $row.find('.submission-id'); if (submissionId) {
$row.attr('data-submission-id', submissionId);
if (!$input.length) {
$input = $('<input>', {
type: 'hidden',
class: 'submission-id',
name: 'id[]'
});
$row.find('td').first().prepend($input);
} else { } else {
$input.attr('name', 'id[]'); removeSubmissionId($row);
} }
$input.val(submissionId || '');
} }
function clearDoctorTableRow($row) { function clearDoctorTableRow($row) {
removeSubmissionId($row); removeSubmissionId($row);
$row.find('.doctor-select').val('').trigger('change'); $row.find('.doctor-select').val('').trigger('change');
$row.find('select[name="rx_support[]"]').val(''); $row.find('.rx-support-select').val('');
$row.find('select[name="other_molecule_use[]"]').val(''); $row.find('.other-molecule-select').val('');
} }
function clearDoctorTable() { function prefillDoctorTableSection($tbody, categoryPrefix) {
$('#doctor-table-body tr').each(function() { let categoryDoctors = categoryDoctorSubmissions[categoryPrefix] || {};
clearDoctorTableRow($(this));
});
$('#field-record_date').val('');
}
function prefillDoctorTableFromCategory(categoryIndex) {
clearDoctorTable();
if (!categoryIndex) {
return;
}
let categoryDoctors = categoryDoctorSubmissions[categoryIndex] || {};
let submissions = Object.values(categoryDoctors); let submissions = Object.values(categoryDoctors);
if (!submissions.length) { if (!submissions.length) {
return; return;
} }
if (submissions[0].record_date) { if (submissions[0].record_date && !$('#field-record_date').val()) {
$('#field-record_date').val(submissions[0].record_date); $('#field-record_date').val(submissions[0].record_date);
} }
$('#doctor-table-body tr').each(function(index) { $tbody.find('tr.doctor-row').each(function(index) {
let submission = submissions[index]; let submission = submissions[index];
if (!submission) { if (!submission) {
return false; return false;
@ -581,137 +525,175 @@ select option:disabled {
$row.find('.doctor-select') $row.find('.doctor-select')
.val(submission.doctor_id) .val(submission.doctor_id)
.trigger('change'); .trigger('change');
$row.find('select[name="rx_support[]"]') $row.find('.rx-support-select')
.val(submission.rx_support || ''); .val(submission.rx_support || '');
$row.find('select[name="other_molecule_use[]"]') $row.find('.other-molecule-select')
.val(submission.other_molecule_use || ''); .val(submission.other_molecule_use || '');
setSubmissionId($row, submission.submission_id); setSubmissionId($row, submission.submission_id);
}); });
} }
function updateDoctorDropdowns() { function prefillAllDoctorTables() {
$('.doctor-table-body').each(function() {
let selectedDoctors = []; prefillDoctorTableSection($(this), $(this).data('category'));
});
$('.doctor-select').each(function(){
let value = $(this).val();
if(value){
selectedDoctors.push(value);
} }
}); function updateDoctorDropdowns($tbody) {
let selectedDoctors = [];
$('.doctor-select').each(function(){ $tbody.find('.doctor-select').each(function() {
let value = $(this).val();
if (value) {
selectedDoctors.push(value);
}
});
let currentDropdown = $(this); $tbody.find('.doctor-select').each(function() {
let currentValue = currentDropdown.val(); let currentDropdown = $(this);
let currentValue = currentDropdown.val();
currentDropdown.find('option').each(function(){ currentDropdown.find('option').each(function() {
let option = $(this);
let originalText = option.data('original-text') || option.text();
let option = $(this); option.data('original-text', originalText);
option.text(originalText);
option.prop('disabled', false);
let originalText = let optionValue = option.val();
option.data('original-text') || option.text();
option.data('original-text', originalText); if (
optionValue &&
optionValue !== currentValue &&
selectedDoctors.includes(optionValue)
) {
option.prop('disabled', true);
option.text(originalText + ' (Already Added)');
}
});
});
}
option.text(originalText); function updateOtherMoleculeDropdowns($tbody) {
let sectionMolecule = $tbody.data('molecule-use');
option.prop('disabled', false); $tbody.find('.other-molecule-select').each(function() {
let ddl = $(this);
let optionValue = option.val(); ddl.find('option').each(function() {
let option = $(this);
let originalText = option.data('original-text') || option.text();
if( option.data('original-text', originalText);
optionValue && option.text(originalText);
optionValue !== currentValue && option.prop('disabled', false);
selectedDoctors.includes(optionValue)
){
option.prop('disabled', true);
option.text( if (sectionMolecule && option.val() === sectionMolecule) {
originalText + option.prop('disabled', true);
' (Already Added)' option.text(originalText + ' (Already Added)');
); }
} });
});
}
function buildSubmitFormData() {
let fd = new FormData();
let form = $('#report-form')[0];
let rowFieldClasses = ['doctor-select', 'rx-support-select', 'other-molecule-select'];
Array.from(form.elements).forEach(function(el) {
if (!el.name || el.disabled) {
return;
}
if (el.name.match(/^id(\[|$)/)) {
return;
}
if (rowFieldClasses.some(function(cls) { return el.classList.contains(cls); })) {
return;
}
if (el.type === 'file') {
if (el.files.length) {
fd.append(el.name, el.files[0]);
}
return;
}
if (el.type === 'checkbox') {
if (el.checked) {
fd.append(el.name, el.value);
}
return;
}
if (el.type === 'radio') {
if (el.checked) {
fd.append(el.name, el.value);
}
return;
}
if (el.tagName === 'SELECT' && el.multiple) {
Array.from(el.selectedOptions).forEach(function(option) {
fd.append(el.name, option.value);
});
return;
}
fd.append(el.name, el.value);
});
getDoctorRows().forEach(function(item) {
let $row = item.$row;
fd.append('contact_id[]', $row.find('.doctor-select').val());
fd.append('rx_support[]', $row.find('.rx-support-select').val());
fd.append('other_molecule_use[]', $row.find('.other-molecule-select').val());
fd.append('molecule_use[]', item.moleculeUse);
let submissionId = $row.attr('data-submission-id');
if (submissionId) {
fd.append('id[' + item.rowIndex + ']', submissionId);
}
});
return fd;
}
$(document).on('change', '.doctor-select', function() {
updateDoctorDropdowns($(this).closest('.doctor-table-body'));
}); });
});
}
$(document).on(
'change',
'.doctor-select',
updateDoctorDropdowns
);
updateDoctorDropdowns();
function updateOtherMoleculeDropdowns() {
let selectedMolecule = $('#field-molecule_use').val();
let categoryIndex = resolveCategoryIndex(selectedMolecule);
$('select[name="other_molecule_use[]"]').each(function(){
let ddl = $(this);
ddl.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);
if(
selectedMolecule &&
option.val() === selectedMolecule
){
option.prop('disabled', true);
option.text(
originalText + ' (Already Added)'
);
}
});
});
prefillDoctorTableFromCategory(categoryIndex);
updateDoctorDropdowns();
}
$('#field-molecule_use').on('change', updateOtherMoleculeDropdowns);
$('.doctor-select').select2({ $('.doctor-select').select2({
width: '100%', width: '100%',
placeholder: 'Search Doctor', placeholder: 'Search Doctor',
allowClear: true allowClear: true
}); });
if ($('#field-molecule_use').val()) { prefillAllDoctorTables();
updateOtherMoleculeDropdowns();
} else { $('.doctor-table-body').each(function() {
clearDoctorTable(); let $tbody = $(this);
} updateOtherMoleculeDropdowns($tbody);
$('#report-form').on('submit', function(event){ updateDoctorDropdowns($tbody);
});
$('#report-form').on('submit', function(event) {
event.preventDefault(); event.preventDefault();
let fd = new FormData($('#report-form')[0]);
for (let pair of fd.entries()) {
console.log(pair[0], pair[1]);
}
$("#pageloader").fadeIn(); $("#pageloader").fadeIn();
$.ajax({ $.ajax({
type: "POST", type: "POST",
url: '/form/ajaxsubmitmultiple', url: '/form/ajaxsubmitmultiple',
data: new FormData($('#report-form')[0]), data: buildSubmitFormData(),
processData: false, processData: false,
contentType: false, contentType: false,
success: function(data) { success: function(data) {
$("#pageloader").fadeOut(); $("#pageloader").fadeOut();
if(data.status == 'success') { if (data.status == 'success') {
Swal.fire({ Swal.fire({
title: 'Great!', title: 'Great!',
text: 'Your data is successfully submitted!', text: 'Your data is successfully submitted!',
@ -735,14 +717,6 @@ for (let pair of fd.entries()) {
} }
}); });
}); });
@if($id)
setTimeout(function () {
console.log("EDIT MODE TRIGGERED");
$('#field-select-category').trigger('change');
}, 300);
@endif
}); });
</script> </script>
</body> </body>