<div class="breadcrumb">
    <h1>Search Data</h1>
    <ul>
        <li><a href="<?php echo SITE_URL.ADMIN_DIR ?>">Dashboard</a></li>
        <li>Search Data</li>
    </ul>
</div>
<div class="separator-breadcrumb border-top"></div>
<div class="widget-body">
    <div class="portlet-body">
                        
    <?php echo (isset($successMsg) && $successMsg!='') ? "<div class='alert alert-success'><button data-dismiss='alert' class='close' type='button'>×</button>".base64_decode($successMsg)."</div>" : '' ; ?>
    <?php echo (isset($failedMsg) && $failedMsg!='') ? "<div class='alert alert-danger'><button data-dismiss='alert' class='close' type='button'>×</button>".base64_decode($failedMsg)."</div>" : '' ?>
   
    <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">
                        <label for="search_api">Select Api</label>
                        <select class="form-control" id="search_api" name="search_api" required="true">
                            <option value="">Select Api</option>
                            <option value="1">Appointments</option>
                            <option value="2">Practice Events</option>
                            <option value="3">Appointment Status</option>
                            <option value="4">Guarantor</option>
                            <option value="5">Patient</option>
                            <option value="6">Provider</option>
                            <option value="7">Procedure Code</option>
                            <option value="8">Practice Variables</option>
                        </select>
                    </div>

                    <div class="col-md-2" id="div_search_event" style="display: none;">
                        <label for="search_event">Select Event</label>
                        <select class="form-control" id="search_event" name="search_event">
                            <option value="">Select Event</option>
                            <option value="patients">Patients</option>
                            <option value="appointments">Appointments</option>
                            <option value="guarantors">Guarantors</option>
                        </select>
                    </div>

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

                        <label for="clinic_id">Select clinic</label>
                        <select class="form-control" id="clinic_id" name="clinic_id" required="true">
                            <option value="">Select Client</option>
                            <?php if($allClinic && count($allClinic) > 0){ foreach($allClinic as $clinic){ ?>
                            <option value="<?php echo $clinic->clinic_id; ?>" ><?php echo $clinic->clinic_name; ?></option>
                            <?php } } ?>
                        </select>
                    </div>

                    <div class="col-md-2" id="div_serial_no" >
                      <label for="serial_no">Serial No</label>
                      <input type="text" class="form-control" id="serial_no" name="serial_no" >

                    </div>

                    <div class="col-md-2" id="div_provider">

                        <label for="Provider_id">Select Provider</label>
                        <select class="form-control" id="provider_id" name="provider_id">
                            <option value="">Select Provider</option>
                            
                        </select>
                    </div>

                    <div class="col-md-2" id="div_st_date">
                      <label for="start_date">Start Date</label>
                      <input type="date" class="form-control" id="start_date" name="start_date" >

                    </div>

                    <div class="col-md-2" id="div_end_date">
                      <label for="end_date" id="end_br_date">End Date</label>
                      <input type="date" class="form-control" id="end_date" name="end_date" >
                    </div>

                    <div class="col-md-2" id="div_interval_search" style="display: none;">
                      <br/>
                      <label for="interval_search">Interval</label>
                      <input type="text" class="form-control" id="interval_search" name="interval_search" >
                    </div>

                    <div class="col-md-2" id="div_firstname_search" style="display: none;">
                      <label for="firstname_search">Firsr Name</label>
                      <input type="text" class="form-control" id="firstname_search" name="firstname_search" >
                    </div>

                    <div class="col-md-2" id="div_lastname_search" style="display: none;">
                      <label for="lastname_search">Last Name</label>
                      <input type="text" class="form-control" id="lastname_search" name="lastname_search" >
                    </div>

                    <div class="col-md-2" id="div_email_search" style="display: none;">
                      <label for="email_search" id="email_br_search">Email</label>
                      <input type="text" class="form-control" id="email_search" name="email_search" >
                    </div>

                    <div class="col-md-2" id="div_cell_search" style="display: none;">
                      <br/>
                      <label for="cell_search">Cell</label>
                      <input type="text" class="form-control" id="cell_search" name="cell_search" >
                    </div>

                    <div class="col-md-2" id="div_guarantor_id" style="display: none;">
                      <br/>
                      <label for="guarantor_id">GuarantorId</label>
                      <input type="text" class="form-control" id="guarantor_id" name="guarantor_id" >
                    </div>

                    <div class="col-md-2 mt-3 mt-md-0" id="searchdata_id">
                        <label for="" id="serach_br">&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" id="resetdata_id">
                        <label for="" id="reset_br">&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='loader-bubble loader-bubble-secondary m-5' align="center" style="display: none;"></div>
<div id="btnid"></div>
<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="" >       
                    <input type="hidden" id="action" name="action" value="">
                    <!-- <table id="list" class="display table table-striped table-bordered" style="width:100%">
                        <thead>
                            <tr>
                                <th>Sr.No</th>
                                <th>Data</th>
                                
                            </tr>
                        </thead>
                    </table> -->
                   
                    <div id="list_data" >
                    </div>
                  </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>

<?php  //if(isset($_REQUEST['client_id']) && $_REQUEST['client_id']!=""){ ?>
<script type="application/javascript">
   $(document).ready(function() {
    //event.preventDefault();
     
     $("#clinic_id").select2({
        tags: true
     });

     $("#search_api").on('change',function(){

       var search_api = $("#search_api").val();
       $('#div_patient_id').show();  
       if(search_api == '1')
       {
         //$("#div_st_date").hide();
         //$("#div_end_date").hide();
         $("#div_search_event").hide();
         $("#div_interval_search").hide();
         $("#div_st_date").show();
          $("#div_end_date").show();
         $("#start_date").val('');
         $("#end_date").val('');
         $("#search_event").val('');
         $("#interval_search").val('');
         $("#div_provider").show();
         $("#div_serial_no").show();
         $("#patient_id").val('');
         $("#clinic_id").val('');
         $("#div_firstname_search").hide();
         $("#div_lastname_search").hide();
         $("#div_email_search").hide();
         $("#div_cell_search").hide();
         $("#div_guarantor_id").hide();
         $('#end_br_date').before('<br/>');
         $('#searchdata_id').find('br').remove();
         $('#resetdata_id').find('br').remove(); 
         $('#serach_br').before('<br/>');
         $('#reset_br').before('<br/>');
         
       }else if(search_api == '2')
       {
          $("#div_st_date").show();
          $("#div_end_date").show();
          $("#div_search_event").show();
          $("#div_interval_search").show();
          $("#div_provider").hide();
          $("#provider_id").val('');
          $("#div_serial_no").hide();
          $("#serial_no").val('');
          $("#patient_id").val('');
          $("#clinic_id").val('');
          $("#div_firstname_search").hide();
          $("#div_lastname_search").hide();
          $("#div_email_search").hide();
          $("#div_cell_search").hide();
          $("#div_end_date").find('br').remove();
        }else if(search_api == '3')
        {
          $("#div_st_date").hide();
          $("#div_end_date").hide();
          $("#div_search_event").hide();
          $("#div_interval_search").hide();
          $("#div_provider").hide();
          $("#provider_id").val('');
          $("#div_serial_no").hide();
          $("#serial_no").val('');
          $("#patient_id").val('');
          $("#clinic_id").val('');
          $("#div_firstname_search").hide();
          $("#div_lastname_search").hide();
          $("#div_email_search").hide();
          $("#div_cell_search").hide();
          $("#div_guarantor_id").hide();
          $('#div_end_date').find('br').remove();
          $('#searchdata_id').find('br').remove();
          $('#resetdata_id').find('br').remove(); 
          
        }else if(search_api == '5')
        {
          $("#div_st_date").hide();
          $("#div_end_date").hide();
          $("#div_search_event").hide();
          $("#div_interval_search").hide();
          $("#div_provider").show();
          $("#provider_id").val('');
          $("#div_serial_no").hide();
          $("#serial_no").val('');
          $("#patient_id").val('');
          $("#clinic_id").val('');
          $("#div_firstname_search").show();
          $("#div_lastname_search").show();
          $("#div_email_search").show();
          $("#div_cell_search").show();
          $("#div_guarantor_id").show();
          $('#email_br_search').before('<br/>');
          $('#searchdata_id').find('br').remove();
          $('#resetdata_id').find('br').remove(); 
          $('#serach_br').before('<br/>');
          $('#reset_br').before('<br/>');
        }else if(search_api == '6')
        {
          $("#div_st_date").hide();
          $("#div_end_date").hide();
          $("#div_search_event").hide();
          $("#div_interval_search").hide();
          $("#div_provider").hide();
          $("#provider_id").val('');
          $("#div_serial_no").hide();
          $("#serial_no").val('');
          $("#patient_id").val('');
          $("#clinic_id").val('');
          $("#div_firstname_search").hide();
          $("#div_lastname_search").hide();
          $("#div_email_search").hide();
          $("#div_cell_search").hide();
          $("#div_guarantor_id").hide();
          $('#div_end_date').find('br').remove();
          $('#searchdata_id').find('br').remove();
          $('#resetdata_id').find('br').remove(); 
          $('#div_patient_id').hide();
        }else if(search_api == '7')
        {
          $("#div_st_date").hide();
          $("#div_end_date").hide();
          $("#div_search_event").hide();
          $("#div_interval_search").hide();
          $("#div_provider").hide();
          $("#provider_id").val('');
          $("#div_serial_no").hide();
          $("#serial_no").val('');
          $("#patient_id").val('');
          $("#clinic_id").val('');
          $("#div_firstname_search").hide();
          $("#div_lastname_search").hide();
          $("#div_email_search").hide();
          $("#div_cell_search").hide();
          $("#div_guarantor_id").hide();
          $('#div_end_date').find('br').remove();
          $('#searchdata_id').find('br').remove();
          $('#resetdata_id').find('br').remove(); 
          $('#div_patient_id').hide();
        }else if(search_api == '8')
        {
          $("#div_st_date").hide();
          $("#div_end_date").hide();
          $("#div_search_event").hide();
          $("#div_interval_search").hide();
          $("#div_provider").hide();
          $("#provider_id").val('');
          $("#div_serial_no").hide();
          $("#serial_no").val('');
          $("#patient_id").val('');
          $("#clinic_id").val('');
          $("#div_firstname_search").hide();
          $("#div_lastname_search").hide();
          $("#div_email_search").hide();
          $("#div_cell_search").hide();
          $("#div_guarantor_id").hide();
          $('#div_end_date').find('br').remove();
          $('#searchdata_id').find('br').remove();
          $('#resetdata_id').find('br').remove(); 
          $('#div_patient_id').hide();
        }else
        {
          $("#div_st_date").hide();
          $("#div_end_date").hide();
          $("#div_search_event").hide();
          $("#div_interval_search").hide();
          $("#div_provider").hide();
          $("#provider_id").val('');
          $("#div_serial_no").hide();
          $("#serial_no").val('');
          $("#patient_id").val('');
          $("#clinic_id").val('');
          $("#div_firstname_search").show();
          $("#div_lastname_search").show();
          $("#div_email_search").show();
          $("#div_cell_search").show();
          $('#div_email_search').find('br').remove();
          $('#searchdata_id').find('br').remove();
          $('#resetdata_id').find('br').remove(); 
          $('#serach_br').before('<br/>');
          $('#reset_br').before('<br/>');
        }
      });

      $("#clinic_id").on('change',function(){

       var ClinicId = $("#clinic_id").val();

       $.ajax({
                url: 'getprovider.php', 
                type: "POST",
                data: ({clinic_id: ClinicId}),
                success: function(data){
                    $("#provider_id").html(data);

                }
            });
      });

    $( "form" ).on( "submit", function(e) {
      e.preventDefault();
      var practice_xcare_id = $("#clinic_id").val();
      var patient_id = $("#patient_id").val();
      var search_api = $("#search_api").val();
      var start_date = $("#start_date").val();
      var end_date = $("#end_date").val();
      var provider_id = $("#provider_id").val();
      var serial_no = $("#serial_no").val();
      var search_event = $("#search_event").val();
      var interval_search = $("#interval_search").val();
      var firstname_search = $("#firstname_search").val();
      var lastname_search = $("#lastname_search").val();
      var email_search = $("#email_search").val();
      var cell_search = $("#cell_search").val();
      var guarantor_id = $("#guarantor_id").val();
      
      if(start_date === '' && search_api === '2' && interval_search === '')
      {
        $("#alert_msg").show();
        $("#alert_msg").html("<div class='alert alert-danger'><button data-dismiss='alert' class='close' type='button'>×</button>Please select Start Date.</div>");
         return false;
        
      }else if(end_date ==='' && search_api === '2'  && interval_search === '')
      {
        $("#alert_msg").show();
        $("#alert_msg").html("<div class='alert alert-danger'><button data-dismiss='alert' class='close' type='button'>×</button>Please select End Date.</div>");
         return false;
      }else if( start_date > end_date && search_api === '2'  && interval_search === '')
      {
        $("#alert_msg").show();
        $("#alert_msg").html("<div class='alert alert-danger'><button data-dismiss='alert' class='close' type='button'>×</button>End date should be greater than Start date.</div>");
         return false;
      }
     // return false;
     $(".loader-bubble").show();
     /*$("#btnid").html('<div class="loader-bubble loader-bubble-secondary m-5"></div><br/>');*/ 
     $.ajax({
        url: "search_data_pms.php?act=load&practice_xcare_id="+practice_xcare_id+"&patient_id="+patient_id+"&search_api="+search_api+"&start_date="+start_date+"&end_date="+end_date+"&provider_id="+provider_id+"&serial_no="+serial_no+"&search_event="+search_event+"&interval_search="+interval_search+"&firstname_search="+firstname_search+"&lastname_search="+lastname_search+"&email_search="+email_search+"&cell_search="+cell_search+"&guarantor_id="+guarantor_id,
        type:'POST',
        //data: postData,
        //dataType: 'json',
        success: function(output_string){
         $(".loader-bubble").hide();
         $("#list_data").html('');
         $("#list_data").append(output_string);
          
        }
    });
     

     
      /*$("#list").DataTable().destroy();

      $('#list').DataTable( {  
          "ajax": "search_data_pms.php?act=load&practice_xcare_id="+practice_xcare_id+"&patient_id="+patient_id+"&search_api="+search_api+"&start_date="+start_date+"&end_date="+end_date,
          "processing": true,
          "serverSide": true,
          "pageLength": 25,
                "aaSorting": [],
               "aoColumnDefs": [
                    { 'bSortable': false, 'aTargets': [0] }
                ],
          language: {
              "processing" : "<div class='loader-bubble loader-bubble-primary m-5'></div>",
              "sEmptyTable" :  "No records found."
          }
          
      } );*/
    });
     /*$('#list').DataTable( {  
          "ajax": "search_data_pms.php?act=load&client_id="+office_id+"&patient_id="+patient_id,
          "processing": true,
          "serverSide": true,
          "pageLength": 25,
                "aaSorting": [],
                "aoColumnDefs": [
                    { 'bSortable': false, 'aTargets': [0,2] }
                ],
          language: {
              "processing" : "<div class='loader-bubble loader-bubble-primary m-5'></div>",
              "sEmptyTable" :  "No records found."
          }
          
      } );*/
    });
</script>
<?php //} ?>