<script type="text/javascript">
  
function pms_change_status1(pms_id,status,pms_data)
{
  $(".loading_image").show();
  $.ajax({
    url: "practicelist.php",
    data: 'act=pms_status&pms_id='+pms_id+'&status='+status+'&pms_data='+pms_data,
    /*dataType: 'json',
    cache: false,*/
    success: function(msg){
                $("#status_msg").show();
                $("#status_msg").html("<div class='alert alert-success'><button data-dismiss='alert' class='close' type='button'>×</button>Status updated successfully...</div>");
                $("#status_msg_td").html(msg);
                hideMessage();
    }
  });
}

function pms_change_status(pms_id,status,pms_data)
{

  swal({
        title: 'Are you sure ?',
        text: "change status!",
        type: 'warning',
        showCancelButton: true,
        confirmButtonColor: '#0CC27E',
        cancelButtonColor: '#FF586B',
        confirmButtonText: 'Yes, change status!',
        cancelButtonText: 'No, cancel!',
        confirmButtonClass: 'btn btn-success mr-5',
        cancelButtonClass: 'btn btn-danger',
        buttonsStyling: false
    }).then(function () {
        //location.href = 'practicelist.php?act=pms_status&pms_id='+pms_id+'&status='+status+'&pms_data='+pms_data;
        $.ajax({
          url: "practicelist.php",
          data: 'act=pms_status&pms_id='+pms_id+'&status='+status+'&pms_data='+pms_data,
          dataType: 'json',
          cache: false,
          success: function(data){
                      $("#status_msg").show();
                      $("#status_msg").html("<div class='alert alert-success'><button data-dismiss='alert' class='close' type='button'>×</button>Status updated successfully...</div>");
                      $("#status_msg_td").html(data.msg);
                      hideMessage();
                      $("#pms_writeback_"+pms_id).attr("writeback-data", data.writeback);
                      $("#pms_sync_"+pms_id).attr("sync-data", data.sync);
                      $("#pms_patientwriteback_"+pms_id).attr("patientwriteback-data", data.patientwriteback);
                      $("#pms_appointmentwriteback_"+pms_id).attr("appointmentwriteback-data", data.appointmentwriteback);
                      $("#pms_statuswriteback_"+pms_id).attr("statuswriteback-data", data.statuswriteback);
                      $("#pms_tempstatuswriteback_"+pms_id).attr("tempstatuswriteback-data", data.tempstatuswriteback);
          }
        });
    }, function (dismiss) {
      var chk_writeback = $("#pms_writeback_"+pms_id).attr('writeback-data');
      var chk_sync = $("#pms_sync_"+pms_id).attr('sync-data');
      var chk_patientwriteback = $("#pms_patientwriteback_"+pms_id).attr('patientwriteback-data');
      var chk_appointmentwriteback = $("#pms_appointmentwriteback_"+pms_id).attr('appointmentwriteback-data');
      var chk_statuswriteback = $("#pms_statuswriteback_"+pms_id).attr('statuswriteback-data');
      var chk_tempstatuswriteback = $("#pms_tempstatuswriteback_"+pms_id).attr('tempstatuswriteback-data');

      if(chk_writeback == 'on')
      {
        $("#pms_writeback_"+pms_id).prop('checked', true);
      }else{
        $("#pms_writeback_"+pms_id).prop('checked', false);
      }

      if(chk_sync == 'on')
      {
        $("#pms_sync_"+pms_id).prop('checked', true);
      }else{
        $("#pms_sync_"+pms_id).prop('checked', false);
      }

      if(chk_patientwriteback == 'on')
      {
        $("#pms_patientwriteback_"+pms_id).prop('checked', true);
      }else{
        $("#pms_patientwriteback_"+pms_id).prop('checked', false);
      }

      if(chk_appointmentwriteback == 'on')
      {
        $("#pms_appointmentwriteback_"+pms_id).prop('checked', true);
      }else{
        $("#pms_appointmentwriteback_"+pms_id).prop('checked', false);
      }

      if(chk_statuswriteback == 'on')
      {
        $("#pms_statuswriteback_"+pms_id).prop('checked', true);
      }else{
        $("#pms_statuswriteback_"+pms_id).prop('checked', false);
      }
      

      if(chk_tempstatuswriteback == 'on')
      {
        $("#pms_tempstatuswriteback_"+pms_id).prop('checked', true);
      }else
      {
        $("#pms_tempstatuswriteback_"+pms_id).prop('checked', false);
      }
      return false; 
    });
}

/*function prac_health_check(office_id)
{

  swal({
        title: 'Are you sure ?',
        text: "change status!",
        type: 'warning',
        showCancelButton: true,
        confirmButtonColor: '#0CC27E',
        cancelButtonColor: '#FF586B',
        confirmButtonText: 'Yes, change status!',
        cancelButtonText: 'No, cancel!',
        confirmButtonClass: 'btn btn-success mr-5',
        cancelButtonClass: 'btn btn-danger',
        buttonsStyling: false
    }).then(function () {
        //location.href = 'practicelist.php?act=pms_status&pms_id='+pms_id+'&status='+status+'&pms_data='+pms_data;
        console.log(office_id);
        return false;
        $.ajax({
          url: "practicelist.php",
          data: 'act=pms_status&pms_id='+pms_id+'&status='+status+'&pms_data='+pms_data,
          dataType: 'json',
          cache: false,
          success: function(data){
                      $("#status_msg").show();
                      $("#status_msg").html("<div class='alert alert-success'><button data-dismiss='alert' class='close' type='button'>×</button>Status updated successfully...</div>");
                      $("#status_msg_td").html(data.msg);
                      hideMessage();
                      $("#pms_writeback_"+pms_id).attr("writeback-data", data.writeback);
                      $("#pms_sync_"+pms_id).attr("sync-data", data.sync);
                      $("#pms_patientwriteback_"+pms_id).attr("patientwriteback-data", data.patientwriteback);
                      $("#pms_appointmentwriteback_"+pms_id).attr("appointmentwriteback-data", data.appointmentwriteback);
                      $("#pms_statuswriteback_"+pms_id).attr("statuswriteback-data", data.statuswriteback);
          }
        });
    }, function (dismiss) 
    {
      return false; 
    });
}*/
</script>


<div class="breadcrumb">
    <h1>Practices</h1>
    <ul>
        <li><a href="<?php echo SITE_URL.ADMIN_DIR ?>">Dashboard</a></li>
        <li>Practice list</li>
    </ul>
</div>
<div class="separator-breadcrumb border-top"></div>

<div class="row mb-4">
  <div class="col-md-6">
        &nbsp;
  </div>
  <div class="col-md-6 pull-right">
      <div class="button-group">
         <a href="practicelist.php?act=refresh_etl" class="btn btn-dark m-1">Refresh ETL</a>
         <a href="practicelist.php?act=refresh" class="btn btn-dark m-1">Refresh</a>
      </div>    
  </div>  
</div>
<div class="widget-body">
    <div class="portlet-body">
   
    <div id="status_msg" style="display: none;"><div class="alert alert-success"><button data-dismiss='alert' class='close' type='button'>×</button>&nbsp;</div></div>
    <div id="alert_msg" style="display: none;"><div class="alert alert-danger"><button data-dismiss='alert' class='close' type='button'>×</button>&nbsp;</div></div>

    </div>
</div>

<form action="" method="post">
<div class="row">
    <div class="col-lg-12 col-md-12">
        <div class="card mb-5">
            <div class="card-body">
                <div class="row row-xs">
                    
		    <div class="col-md-2  mt-3 mt-md-0">
                        <label for="practice_id">Practice Id</label>
                        <input type="text" class="form-control" name="practice_id" id="practice_id" />
                    </div>

                    <div class="col-md-2  mt-3 mt-md-0">
                        <label for="practice_pms">Practice PMS</label>
                        <select class="form-control" name="practice_pms" id="practice_pms">
                            <option value="">Select PracticePMS</option>
                            <?php
                                $practicepmsObj = new practice();
                                $fields  = array('practice_id','practice_pms');
                                $groupBy = array('practice_pms');
                                $data    = array('fields' => $fields,'groupBy'=>$groupBy);
                                $practicepmsDetails = $practicepmsObj->getAllRecords($data);

                                if($practicepmsDetails && count($practicepmsDetails) > 0 )
                                {
                                    foreach ($practicepmsDetails as $pkey => $practicepmsdata) 
                                    { 
                                        if(isset($practicepmsdata->practice_pms) && $practicepmsdata->practice_pms != '')
                                        {
                                        ?>

                                            <option value="<?php echo $practicepmsdata->practice_pms; ?>"><?php echo $practicepmsdata->practice_pms; ?></option>
                                        <?php } ?>    
                                        
                                   <?php }
                                }
                            ?>
                        </select> 
                    </div>

                    <div class="col-md-2  mt-3 mt-md-0">
                        <label for="etl_type">ETL Type</label>
                        <select class="form-control" name="etl_type" id="etl_type">
                            <option value="">Select ETL Type</option>
                            <option value="SIKKA">SIKKA</option>
                            <option value="CLOUD">CLOUD</option>
                        </select> 
                    </div>

                    <div class="col-md-2  mt-3 mt-md-0">
                        <label for="sync_status">Sync Status</label>
                        <select class="form-control" name="sync_status" id="sync_status">
                            <option value="">Select Sync Status</option>
                            <option value="on">On</option>
                            <option value="off">Off</option>
                        </select> 
                    </div>

                    <div class="col-md-2  mt-3 mt-md-0">
                        <label for="office_id">Office Id</label>
                        <input type="text" class="form-control" name="office_id" id="office_id" />
                    </div>

                    <div class="col-md-2 mt-3 mt-md-0"  id="div_practice_name">
                        <label for="practice_name">Practice Name</label>
                        <select class="form-control" name="practice_name" id="practice_name">
                            <option value="">Select Practice</option>
                            <?php
                                $practiceObj = new practice();
                                $fields  = array('practice_id','practice_name');
                                $data    = array('fields' => $fields);
                                $practiceDetails = $practiceObj->getAllRecords($data);

                                if($practiceDetails && count($practiceDetails) > 0 )
                                {
                                    foreach ($practiceDetails as $pkey => $practicedata) 
                                    { 
                                        if(isset($practicedata->practice_name) && $practicedata->practice_name != '')
                                        {
                                        ?>

                                            <option value="<?php echo $practicedata->practice_name; ?>"><?php echo $practicedata->practice_name; ?></option>
                                        <?php } ?>    
                                        
                                   <?php }
                                }
                            ?>
                        </select> 
                       <!-- <input type="text" class="form-control" name="practice_name" id="practice_name"  /> -->
                    </div>

                    <div class="col-md-2 mt-3 mt-md-0" id="div_sikka_id" >
                      <label for="sikka_id">PatientSikka Id</label>
                      <input type="text" class="form-control" name="sikka_id" id="sikka_id" />
                    </div>

                    <div class="col-md-2  mt-3 mt-md-0">
                        <label for="clinic_id">Clinic</label>
                        <select class="form-control" id="clinic_id" name="clinic_id">
                          <option value="">Select Clinic</option>
                          <?php
                                $clinicObj =  new  clinic();
                                $fields  = array('c.clinic_id','c.clinic_name');
                                $data    = array('fields' => $fields);
                                $clinicDetails = $clinicObj->getAllRecords($data);
                            ?>
                            
                            <?php if($clinicDetails && count($clinicDetails) > 0){ 
                                  foreach($clinicDetails as $clinicdata){ ?>
                                <option value="<?php echo $clinicdata->clinic_id; ?>"><?php echo $clinicdata->clinic_name; ?></option>
                                <?php } } ?>
                        </select>
                    </div>

                    <!-- <div class="col-md-2  mt-3 mt-md-0">
                        <label for="email">Email</label>
                        <input type="text" class="form-control" name="email" id="email" />
                    </div>

                    <div class="col-md-2  mt-3 mt-md-0">
                        <label for="guarantor_id">GuarantorId</label>
                        <input type="text" class="form-control" name="guarantor_id" id="guarantor_id" />
                    </div> -->

                    <div class="col-md-2 mt-3 mt-md-0">
                        <label for="">&nbsp;</label>
                        <button type="submit" name="submit" class="btn btn-primary btn-block">Search</button>
                    </div>
                    <div class="col-md-2 mt-3 mt-md-0">
                        <label for="">&nbsp;</label>
                        <button type="reset" name="reset" class="btn btn-primary btn-block" onClick="window.location.reload()">Reset</button>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
</form>

<div class="row mb-4">
    <div class="col-md-12 mb-4">
        <div class="card text-left">

            <div class="card-body">
                <div class="table-responsive">
                  <form id="listFrm" name="listFrm" action="" method="post">       
                    <input type="hidden" id="action" name="action" value="">
                    <table id="list" class="display table table-striped table-bordered" style="width:100%">
                        <thead>
                            <tr>
                                <th>Sikka Details</th>
                                <!-- <th>Xcare Details</th> -->
                                <th>PMS</th>
                                <th>Practice Name</th>
                                <!-- <th>Secret Key</th>
                                <th>RequestKey</th> -->
                                <th>Key</th>
                                <th>Refresh Date</th>
                                <th>Fetch Patients</th>
                                <th>Action</th>
                                <!-- <th>Health check</th> -->
                            </tr>
                        </thead>
                    </table>
                  </form>
                </div>
            </div>
        </div>
    </div>
</div>

<link href="./assets/styles/css/select2.min.css" rel="stylesheet" />
<script src="./assets/js/select2.min.js"></script>

<style type="text/css">
.select2 {
  width: 160px !important;
}
</style>
 
<script type="application/javascript">
   $(document).ready(function() {

    $("#clinic_id").select2({
        tags: true
     });
    
     $('#list').DataTable( { 
          "ajax": "practicelist.php?act=load",
          "processing": true,
          "serverSide": true,
          "pageLength": 25,
                "aaSorting": [],
                "aoColumnDefs": [
                    { 'bSortable': true, 'aTargets': [0] },
                    { 'bSortable': true, 'aTargets': [1] },
                    { 'bSortable': true, 'aTargets': [2] },
                    { 'bSortable': false, 'aTargets': [3] },
                    { 'bSortable': false, 'aTargets': [4] },
                    { 'bSortable': false, 'aTargets': [5] },
                    { 'bSortable': false, 'aTargets': [6] },
                ],
          language: {
              "processing" : "<div class='loader-bubble loader-bubble-primary m-5'></div>",
              "sEmptyTable" :  "No records found."
          }
          
      } );

     $( "form" ).on( "submit", function(e) {
        e.preventDefault();
        
        var practice_name = $("#practice_name").val();
        var sikka_id = $("#sikka_id").val();
        var office_id = $("#office_id").val();
        var clinic_id = $("#clinic_id").val();
	      var practice_id = $("#practice_id").val();
        var practice_pms = $("#practice_pms").val();
        var etl_type = $("#etl_type").val();
        var sync_status = $("#sync_status").val();

        //practice_search
        $('#list').DataTable().destroy();
          $('#list').DataTable( { 
            "ajax": "practicelist.php?act=load&practice_name="+practice_name+"&sikka_id="+sikka_id+"&office_id="+office_id+"&clinic_id="+clinic_id+"&practice_id="+practice_id+"&practice_pms="+practice_pms+"&etl_type="+etl_type+"&sync_status="+sync_status,
            "processing": true,
            "serverSide": true,
            "pageLength": 25,
                  "aaSorting": [],
                  "aoColumnDefs": [
                      { 'bSortable': false, 'aTargets': [0] },
                      { 'bSortable': false, 'aTargets': [1] },
                      { 'bSortable': false, 'aTargets': [2] },
                      { 'bSortable': false, 'aTargets': [3] },
                      { 'bSortable': false, 'aTargets': [4] },
                      { 'bSortable': false, 'aTargets': [5] },
                      { 'bSortable': false, 'aTargets': [6] },
                  ],
            language: {
                "processing" : "<div class='loader-bubble loader-bubble-primary m-5'></div>",
                "sEmptyTable" :  "No records found."
            }
            
        } );

      });
    });
</script>