ESH/review_excel_data_medical.php
2024-10-23 18:28:06 +05:30

529 lines
19 KiB
PHP

<?php include('techsyn_header.php');
error_reporting(E_ERROR | E_WARNING | E_PARSE);
?>
<link rel="stylesheet" href="assets/css/jquery.dataTables.css" />
<script src="assets/js/jquery.dataTables.js"></script>
<!-- Main Content Container for sid bar and body-->
<div class="main-container ace-save-state" id="main-container">
<script type="text/javascript">
try {
ace.settings.loadState('main-container')
} catch (e) {}
</script>
<?php include('techsyn_sidebar.php'); ?>
<!--breadcrumb-->
<?php
// $data = [];
// foreach ($_POST as $key => $value) {
// // Store each field and its value in an associative array
// $data[$key] = $value;
// }
// print_r($data);
// $checkup_type_id = $_POST['checkup_type_id'];
?>
<div class="main-content">
<div class="main-content-inner">
<div class="breadcrumbs ace-save-state" id="breadcrumbs">
<ul class="breadcrumb">
<li class="active">Medical List</li>
<li class="active">Review Uploaded Excel Data</li>
</ul>
<!-- End of breadcrumb -->
</div>
<div id="loader" class="loader hidden"></div>
<!-- TABLE FOR REVIEW -->
<div class="container">
<div class="text-center panel-heading" id="review_header" style="display:none;">
<h2><b>PREVIEW DATA</b></h2>
</div>
<div id="tableContainer" style="padding:10px">
</div>
<div class="container" id="box-footer" style="text-align: center;display: none;">
<button class="btn btn-primary" type="button" id="save_button" onclick="validate_review()">
<i class="ace-icon fa fa-save"></i> Confirm
</button>
<button class="btn btn-danger" type="button" id="update_button" onclick="validate_review('discard')">
<i class="ace-icon fa fa-floppy"></i> Discard
</button>
</div>
</div>
</div>
<?php include('techsyn_footer.php'); ?>
<style>
body {
font-family: Arial;
width: 100%;
}
.outer-container {
background: #F0F0F0;
border: #e0dfdf 1px solid;
padding: 40px 20px;
border-radius: 2px;
}
.btn-submit {
background: #333;
border: #1d1d1d 1px solid;
border-radius: 2px;
color: #f0f0f0;
cursor: pointer;
padding: 5px 20px;
font-size: 0.9em;
}
.tutorial-table {
margin-top: 40px;
font-size: 0.8em;
border-collapse: collapse;
width: 100%;
}
.tutorial-table th {
background: #f0f0f0;
border-bottom: 1px solid #dddddd;
padding: 8px;
text-align: left;
}
.tutorial-table td {
background: #FFF;
border-bottom: 1px solid #dddddd;
padding: 8px;
text-align: left;
}
#response {
padding: 10px;
margin-top: 10px;
border-radius: 2px;
display: none;
}
.success {
background: #c7efd9;
border: #bbe2cd 1px solid;
}
.error {
background: #fbcfcf;
border: #f3c6c7 1px solid;
}
div#response.display-block {
display: block;
}
/*table{
background-color: white;
}*/
#tableContainer {
margin-bottom: 10px;
overflow: auto;
/* max-height: 500px; Set a maximum height for the div */
}
#box-footer {
margin-bottom: 20px;
}
.loader {
border: 10px solid #3498db;
border-top: 10px solid #f3f3f3;
border-radius: 50%;
width: 60px;
height: 60px;
animation: spin 2s linear infinite;
position: fixed;
top: 12%;
left: 10%;
transform: translate(-50%, -50%);
z-index: 9999;
}
@keyframes spin {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(360deg);
}
}
.hidden {
display: none;
}
/*#no_review_patient{
border: 2px solid grey;
border-radius: 7px;
}*/
#table_review {
background-color: white;
}
#table_review td {
padding: 5px 0px;
transition: all 0.3s;
}
#table_review td:hover {
background-color: #E7F4FF;
}
</style>
<script>
var formId = "";
$(document).ready(function() {
// GET ID GTOM URL
const params = new URLSearchParams(window.location.search);
var checkupTypeId = params.get('checkup_type');
checkupTypeId = checkupTypeId.replace(/'/g, '');
formId = checkupTypeId;
// alert("FROM URL " + checkupTypeId);
if (checkupTypeId == "" || checkupTypeId == null || checkupTypeId == undefined) {
BootstrapDialog.alert("Checkup Type Not Found");
return false;
}
$.ajax({
url: "excel_header_medical_examination.php",
method: "POST",
data: {
checkupId: checkupTypeId
},
dataType: 'json',
beforeSend: function() {
// Show the loader before sending the AJAX request
showLoader();
},
success: function(data) {
console.log(data);
// BootstrapDialog.alert("SECCESS");
// BootstrapDialog.alert('Successfully uploaded' + data.responseText);
// console.log("FINAL KEYS ONLY " + Object.keys((data.final_result)));
// console.log("FINAL VALUES ONLY " + Object.values(data.final_result));
const final_res_keys = Object.keys(data.final_result);
const final_res_value = Object.values(data.final_result);
if ((final_res_value).length > 0) { // IF DATA RECIEVED
// Create the table element
var table = $('<table>').addClass('table table-bordered shadow');
table.attr('id', 'table_review');
var header = $('<thead></thead>');
// Create the table header row
var headerRow = $('<tr>');
var blankHeaderCell = $("<th>"); // Create a blank header cell
var textElement = $("<span>").text("Select all");
blankHeaderCell.append(textElement);
var checkboxElement = $("<input>").attr({
"type": "checkbox",
"id": "sel_all_checkbox",
"class": "sel_all_checkbox"
});
blankHeaderCell.append(checkboxElement);
var ischecked = 0;
checkboxElement.on('click', function() {
// alert("IN");
var checkboxes_to_sel = document.querySelectorAll('.checkbox-class');
if (ischecked === 0) {
// alert("CHECKING");
for (var i = 0; i < checkboxes_to_sel.length; i++) {
var cb = checkboxes_to_sel[i];
// Do something with each checkbox
cb.checked = true;
}
ischecked = 1;
// break;
} else if (ischecked === 1) {
// alert("UNCHECKING");
for (var i = 0; i < checkboxes_to_sel.length; i++) {
var cb = checkboxes_to_sel[i];
// Do something with each checkbox
cb.checked = false;
}
ischecked = 0;
// break;
}
});
headerRow.append(blankHeaderCell); // Append the blank header cell
// Iterate over the table header array and create header cells
$.each(data.excel_column_name, function(index, value) {
// Check if the index is even (to skip the keys)
// if (index % 2 === 1) {
var headerCell = $("<th>").text(value);
headerRow.append(headerCell);
// }
});
header.append(headerRow);
table.append(header);
var body = $('<tbody></tbody>');
// Create the table data rows
// Iterate over the patient_data array and create table rows
$.each(final_res_value, function(index, array) {
// Create a new table row
var row = $("<tr>");
var checkboxCell = $("<td>");
var checkbox = $('<input>').attr({
type: 'checkbox',
class: 'checkbox-class',
value: final_res_keys[index],
id: 'checkbox-' + index
});
checkbox.on('click', function() {
show_details(checkbox.val());
});
checkboxCell.append(checkbox);
row.append(checkboxCell);
// Iterate over the elements in the array and create table cells
$.each(array, function(index, value) {
var cell = $("<td>").text(value);
row.append(cell);
});
// Append the row to the table body
body.append(row);
});
table.append(body);
// Append the table to the container element
$('#tableContainer').append(table);
$('#tableContainer td').css('padding', '5px 10px');
// var h2Text = dataarray.length + " medical records inserted, Review Data";
// var h2Element = $("<h2>").text(h2Text);
// $("#insert_checkup").append(h2Element);
$('#review_header').css('display', 'block');
$('#box-footer').css('display', 'block');
// END LINE
}
},
complete: function() {
// Hide the loader when the AJAX request is complete
let data_table = new DataTable('#table_review', {
responsive: true
});
hideLoader();
},
error: function(data) {
BootstrapDialog.alert('Failed To Upload Data' + data.responseText);
}
});
});
var selectedValues = [];
function show_details(id_val) {
// alert(id_val);
var checked_value = id_val;
// DOES THE WORK AS CHECKED AND UNCHECKED
if (selectedValues.includes(checked_value)) {
// Element exists in the array, so remove it
var index = selectedValues.indexOf(checked_value);
selectedValues.splice(index, 1);
} else {
// Element does not exist in the array, so insert it
selectedValues.push(checked_value);
}
console.log(selectedValues);
}
// var final_submit = false;
function showLoader() {
const overlay = document.createElement('div');
overlay.classList.add('overlay');
document.body.appendChild(overlay);
// Disable pointer events for other elements
const elements = document.querySelectorAll('body > *:not(.overlay)');
elements.forEach(element => {
element.style.pointerEvents = 'none';
});
$('#loader').removeClass('hidden');
}
// Hide the loader
function hideLoader() {
const overlay = document.querySelector('.overlay');
if (overlay) {
overlay.remove();
}
// Restore pointer events for other elements
const elements = document.querySelectorAll('body > *:not(.overlay)');
elements.forEach(element => {
element.style.pointerEvents = 'auto';
});
$('#loader').addClass('hidden');
}
function validate() {
var checkup_type_id = $('#checkup_type_id').val();
if (checkup_type_id == '') {
BootstrapDialog.alert('Please Enter checkup type.!!!');
return false;
}
var file_id = $('#id-input-file-2').val();
if (file_id == '') {
BootstrapDialog.alert('Please select the file.!!!');
return false;
}
// final_submit = false;
$("#frmExcelImports").submit();
}
function validate_review(arg) {
if (arg === '' || arg === null || arg === undefined) {
if (selectedValues.length == 0) {
BootstrapDialog.alert("No Checkbox Selected");
return false;
}
$.ajax({
url: "move_upload_table_data_new.php",
method: "POST",
data: {
selectedID: selectedValues
},
dataType: 'json',
beforeSend: function() {
// Show the loader before sending the AJAX request
showLoader();
},
success: function(data) {
console.log(data);
// const responseData = JSON.parse(data);
const resp = 'New patient inserted: ' + data.patient_counter + '\n' + 'New Medical Record inserted: ' + data.form_insert + '\n' + 'Medical updated: ' + data.form_update + '\n' + 'New Key Value inserted: ' + data.form_key_insert + '\n' + 'Key value Updated: ' + data.form_key_update;
// BootstrapDialog.alert(resp);
BootstrapDialog.show({
title: 'Information',
message: resp,
buttons: [{
label: 'Okay',
action: function() {
location.replace("upload_excel_medical.php");
}
}]
});
// BootstrapDialog.alert("SUCCESS");
// location.reload();
},
complete: function() {
// Hide the loader when the AJAX request is complete
hideLoader();
},
error: function(data) {
BootstrapDialog.alert('Failed To Upload Data' + data.responseText);
}
});
} else {
BootstrapDialog.show({
title: 'ALERT',
message: 'Are You Sure You want to discard the process?',
buttons: [{
label: 'Confirm',
action: function() {
discard_data();
// location.replace("upload_excel_medical.php");
}
}]
});
return false;
}
}
function discard_data() {
if (formId === '' || formId === null || formId === undefined) {
BootstrapDialog.alert("ID not found");
return false;
}
$.ajax({
url: "delete_upload_table_data.php",
method: "POST",
data: {
id: formId
},
dataType: 'json',
beforeSend: function() {
// Show the loader before sending the AJAX request
showLoader();
},
success: function(data) {
console.log(data);
location.replace("upload_excel_medical.php");
// BootstrapDialog.alert("SUCCESS");
// location.reload();
},
complete: function() {
// Hide the loader when the AJAX request is complete
hideLoader();
},
error: function(data) {
BootstrapDialog.alert('Failed To Upload Data' + data.responseText);
}
});
}
</script>