Team4 - Molecule Identification Form - New Changes (15 submission at a time)
Specific Folder FTP Upload / ftp-deploy (push) Successful in 1m38s
Details
Specific Folder FTP Upload / ftp-deploy (push) Successful in 1m38s
Details
This commit is contained in:
parent
aa64f54f0e
commit
66e0038543
|
|
@ -33,6 +33,12 @@
|
|||
'nac + acebrophylline' => 'nac_acebrophylline',
|
||||
];
|
||||
|
||||
$categoryMoleculeUse = [
|
||||
'erdosteine' => 'Erdosteine Prescriber',
|
||||
'erdosteine + acebrophylline' => 'Erdosteine + Acebrophylline',
|
||||
'nac + acebrophylline' => 'NAC + Acebrophylline',
|
||||
];
|
||||
|
||||
$moleculeUseToCategory = [
|
||||
'erdosteine prescriber' => 'erdosteine',
|
||||
'erdosteine' => 'erdosteine',
|
||||
|
|
@ -183,10 +189,10 @@
|
|||
@php
|
||||
|
||||
$hideFields = [
|
||||
|
||||
'contact_id',
|
||||
'rx_support',
|
||||
'other_molecule_use'
|
||||
'other_molecule_use',
|
||||
'molecule_use',
|
||||
];
|
||||
|
||||
@endphp
|
||||
|
|
@ -328,117 +334,72 @@
|
|||
@endforeach
|
||||
@if(!isset($form->is_approval) || (isset($form->is_approval) && $form->is_approval != 'yes' ) )
|
||||
<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="card">
|
||||
{{-- <div class="card-header">
|
||||
<h5 class="mb-0">Tagged Doctors</h5>
|
||||
</div> --}}
|
||||
<div class="card-body p-0">
|
||||
<div class="table-responsive">
|
||||
@php
|
||||
$doctors = [];
|
||||
|
||||
foreach($questions as $question){
|
||||
if($question->code == 'contact_id'){
|
||||
$doctors = $question->options ?? [];
|
||||
break;
|
||||
}
|
||||
}
|
||||
@endphp
|
||||
<table class="table table-bordered mb-0">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Doctor Name</th>
|
||||
|
||||
<th>Rxn/Week Support</th>
|
||||
|
||||
<th>Other Molecule Use</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="doctor-table-body">
|
||||
|
||||
@for($i=1; $i<=5; $i++)
|
||||
|
||||
<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>
|
||||
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
<h5 class="mb-0">{{ ucwords($categoryLabel) }}</h5>
|
||||
</div>
|
||||
<div class="card-body p-0">
|
||||
<div class="table-responsive">
|
||||
<table class="table table-bordered mb-0">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Doctor Name</th>
|
||||
<th>Rxn/Week Support</th>
|
||||
<th>Other Molecule Use</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody
|
||||
class="doctor-table-body"
|
||||
data-category="{{ $categoryPrefix }}"
|
||||
data-molecule-use="{{ $categoryMoleculeUse[$categoryLabel] }}"
|
||||
>
|
||||
@for($i = 1; $i <= 5; $i++)
|
||||
<tr class="doctor-row" data-row-index="{{ $globalRowIndex }}">
|
||||
<td>
|
||||
<select
|
||||
class="form-control doctor-select"
|
||||
required
|
||||
>
|
||||
<option value="">-- Select Doctor --</option>
|
||||
@foreach($doctors as $doctor)
|
||||
<option value="{{ $doctor->value }}">{{ $doctor->display }}</option>
|
||||
@endforeach
|
||||
|
||||
@endif
|
||||
|
||||
@endforeach
|
||||
|
||||
</select>
|
||||
</td>
|
||||
|
||||
<td>
|
||||
|
||||
<select
|
||||
name="rx_support[]"
|
||||
class="form-control"
|
||||
required
|
||||
>
|
||||
<option value="">-- Select --</option>
|
||||
<option value="1-3 Rxn/Week">1-3 Rxn/Week</option>
|
||||
<option value="4-7 Rxn/Week">4-7 Rxn/Week</option>
|
||||
<option value="8-11 Rxn/Week">8-11 Rxn/Week</option>
|
||||
<option value=">11 Rxn/Week">>11 Rxn/Week</option>
|
||||
</select>
|
||||
</td>
|
||||
|
||||
<td>
|
||||
|
||||
<select
|
||||
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>
|
||||
</select>
|
||||
</td>
|
||||
<td>
|
||||
<select class="form-control rx-support-select" required>
|
||||
<option value="">-- Select --</option>
|
||||
<option value="1-3 Rxn/Week">1-3 Rxn/Week</option>
|
||||
<option value="4-7 Rxn/Week">4-7 Rxn/Week</option>
|
||||
<option value="8-11 Rxn/Week">8-11 Rxn/Week</option>
|
||||
<option value=">11 Rxn/Week">>11 Rxn/Week</option>
|
||||
</select>
|
||||
</td>
|
||||
<td>
|
||||
<select class="form-control other-molecule-select" required>
|
||||
<option value="">-- Select --</option>
|
||||
<option value="Erdosteine Prescriber">Erdosteine Prescriber</option>
|
||||
<option value="Erdosteine + Acebrophylline">Erdosteine + Acebrophylline</option>
|
||||
<option value="NAC + Acebrophylline">NAC + Acebrophylline</option>
|
||||
<option value="No">No</option>
|
||||
</select>
|
||||
</td>
|
||||
</tr>
|
||||
@php $globalRowIndex++; @endphp
|
||||
@endfor
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@endforeach
|
||||
|
||||
<button class="btn btn-primary" type="submit" id="submit-btn"> Submit </button>
|
||||
</div>
|
||||
</div>
|
||||
@endif
|
||||
</form>
|
||||
<!-- 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="{{asset('assets/libs/sweetalert2/sweetalert2.min.js')}}"></script>
|
||||
<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) !!};
|
||||
|
||||
jQuery(document).ready(function($){
|
||||
function resolveCategoryIndex(moleculeUse) {
|
||||
if (!moleculeUse) {
|
||||
return null;
|
||||
}
|
||||
function getDoctorRows() {
|
||||
let rows = [];
|
||||
|
||||
let normalized = moleculeUse.toLowerCase().trim();
|
||||
let categoryKey = moleculeUseToCategory[normalized] || normalized;
|
||||
$('.doctor-table-body').each(function() {
|
||||
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) {
|
||||
$row.removeAttr('data-submission-id');
|
||||
$row.find('.submission-id').remove();
|
||||
}
|
||||
|
||||
function setSubmissionId($row, submissionId) {
|
||||
let $input = $row.find('.submission-id');
|
||||
|
||||
if (!$input.length) {
|
||||
$input = $('<input>', {
|
||||
type: 'hidden',
|
||||
class: 'submission-id',
|
||||
name: 'id[]'
|
||||
});
|
||||
$row.find('td').first().prepend($input);
|
||||
if (submissionId) {
|
||||
$row.attr('data-submission-id', submissionId);
|
||||
} else {
|
||||
$input.attr('name', 'id[]');
|
||||
removeSubmissionId($row);
|
||||
}
|
||||
|
||||
$input.val(submissionId || '');
|
||||
}
|
||||
|
||||
function clearDoctorTableRow($row) {
|
||||
removeSubmissionId($row);
|
||||
$row.find('.doctor-select').val('').trigger('change');
|
||||
$row.find('select[name="rx_support[]"]').val('');
|
||||
$row.find('select[name="other_molecule_use[]"]').val('');
|
||||
$row.find('.rx-support-select').val('');
|
||||
$row.find('.other-molecule-select').val('');
|
||||
}
|
||||
|
||||
function clearDoctorTable() {
|
||||
$('#doctor-table-body tr').each(function() {
|
||||
clearDoctorTableRow($(this));
|
||||
});
|
||||
$('#field-record_date').val('');
|
||||
}
|
||||
|
||||
function prefillDoctorTableFromCategory(categoryIndex) {
|
||||
clearDoctorTable();
|
||||
|
||||
if (!categoryIndex) {
|
||||
return;
|
||||
}
|
||||
|
||||
let categoryDoctors = categoryDoctorSubmissions[categoryIndex] || {};
|
||||
function prefillDoctorTableSection($tbody, categoryPrefix) {
|
||||
let categoryDoctors = categoryDoctorSubmissions[categoryPrefix] || {};
|
||||
let submissions = Object.values(categoryDoctors);
|
||||
|
||||
if (!submissions.length) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (submissions[0].record_date) {
|
||||
if (submissions[0].record_date && !$('#field-record_date').val()) {
|
||||
$('#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];
|
||||
if (!submission) {
|
||||
return false;
|
||||
|
|
@ -581,137 +525,175 @@ select option:disabled {
|
|||
$row.find('.doctor-select')
|
||||
.val(submission.doctor_id)
|
||||
.trigger('change');
|
||||
$row.find('select[name="rx_support[]"]')
|
||||
$row.find('.rx-support-select')
|
||||
.val(submission.rx_support || '');
|
||||
$row.find('select[name="other_molecule_use[]"]')
|
||||
$row.find('.other-molecule-select')
|
||||
.val(submission.other_molecule_use || '');
|
||||
setSubmissionId($row, submission.submission_id);
|
||||
});
|
||||
}
|
||||
|
||||
function updateDoctorDropdowns() {
|
||||
|
||||
let selectedDoctors = [];
|
||||
|
||||
$('.doctor-select').each(function(){
|
||||
|
||||
let value = $(this).val();
|
||||
|
||||
if(value){
|
||||
selectedDoctors.push(value);
|
||||
function prefillAllDoctorTables() {
|
||||
$('.doctor-table-body').each(function() {
|
||||
prefillDoctorTableSection($(this), $(this).data('category'));
|
||||
});
|
||||
}
|
||||
|
||||
});
|
||||
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);
|
||||
let currentValue = currentDropdown.val();
|
||||
$tbody.find('.doctor-select').each(function() {
|
||||
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 =
|
||||
option.data('original-text') || option.text();
|
||||
let optionValue = option.val();
|
||||
|
||||
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(
|
||||
optionValue &&
|
||||
optionValue !== currentValue &&
|
||||
selectedDoctors.includes(optionValue)
|
||||
){
|
||||
option.prop('disabled', true);
|
||||
option.data('original-text', originalText);
|
||||
option.text(originalText);
|
||||
option.prop('disabled', false);
|
||||
|
||||
option.text(
|
||||
originalText +
|
||||
' (Already Added)'
|
||||
);
|
||||
}
|
||||
if (sectionMolecule && option.val() === sectionMolecule) {
|
||||
option.prop('disabled', true);
|
||||
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({
|
||||
width: '100%',
|
||||
placeholder: 'Search Doctor',
|
||||
allowClear: true
|
||||
});
|
||||
width: '100%',
|
||||
placeholder: 'Search Doctor',
|
||||
allowClear: true
|
||||
});
|
||||
|
||||
if ($('#field-molecule_use').val()) {
|
||||
updateOtherMoleculeDropdowns();
|
||||
} else {
|
||||
clearDoctorTable();
|
||||
}
|
||||
$('#report-form').on('submit', function(event){
|
||||
|
||||
prefillAllDoctorTables();
|
||||
|
||||
$('.doctor-table-body').each(function() {
|
||||
let $tbody = $(this);
|
||||
updateOtherMoleculeDropdowns($tbody);
|
||||
updateDoctorDropdowns($tbody);
|
||||
});
|
||||
|
||||
$('#report-form').on('submit', function(event) {
|
||||
event.preventDefault();
|
||||
let fd = new FormData($('#report-form')[0]);
|
||||
|
||||
for (let pair of fd.entries()) {
|
||||
console.log(pair[0], pair[1]);
|
||||
}
|
||||
$("#pageloader").fadeIn();
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: '/form/ajaxsubmitmultiple',
|
||||
data: new FormData($('#report-form')[0]),
|
||||
data: buildSubmitFormData(),
|
||||
processData: false,
|
||||
contentType: false,
|
||||
success: function(data) {
|
||||
$("#pageloader").fadeOut();
|
||||
if(data.status == 'success') {
|
||||
if (data.status == 'success') {
|
||||
Swal.fire({
|
||||
title: 'Great!',
|
||||
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>
|
||||
</body>
|
||||
|
|
|
|||
Loading…
Reference in New Issue