<div class="breadcrumb">
    <h1>Patient Log</h1>
    <ul>
        <li><a href="<?php echo SITE_URL.ADMIN_DIR ?>">Dashboard</a></li>
        <li>Patient Log list</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 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 mt-3 mt-md-0"  id="div_patient_fullname">
                        <label for="patient_fullname">Patient Name</label>
                        <input type="text" class="form-control" name="patient_fullname" id="patient_fullname"  />
                    </div>

                    <div class="col-md-2 mt-3 mt-md-0" id="div_patient_log_clinic">
                        <label for="patient_log_clinic">Clinic</label>
                        <select class="form-control" id="patient_log_clinic" name="patient_log_clinic">
                            <option value="">Select clinic</option>
                            <?php
                                $clinicObj = new clinic();
                                $fields = array('clinic_id','clinic_name');
                                $where = array('clinic_status='=>'1');
                                $clinicArg = array('fields'=>$fields,'where'=>$where);
                                $allclinicdata = $clinicObj->getAllRecords($clinicArg);
                                foreach($allclinicdata as $clinic_value)
                                { ?>
                                    <option value="<?php echo $clinic_value->clinic_id; ?>"><?php echo $clinic_value->clinic_name; ?></option>
                                <?php }
                            ?>

                        </select>
                    </div>

                    <div class="col-md-2 mt-3 mt-md-0" id="div_patient_log_type">
                        <label for="patient_log_type">Type</label>
                        <select class="form-control" id="patient_log_type" name="patient_log_type">
                            <option value="">Select Type</option>
                            <?php
                                $patientdetailchangeObj = new patient_detail_change();
                                $fields = array('patient_detail_change_id','patient_detail_change_type');
                                $groupBy = array('patient_detail_change_type');
                                $patientArg = array('fields'=>$fields,'groupBy'=>$groupBy);
                                $patienttypedetail = $patientdetailchangeObj->getAllRecords($patientArg);
                                foreach($patienttypedetail as $value_type)
                                { ?>
                                    <option value="<?php echo $value_type->patient_detail_change_type; ?>"><?php echo $value_type->patient_detail_change_type; ?></option>
                                <?php }


                            ?>
                        </select>
                    </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>Log Id</th>
                                <th>Patient Detail</th>
                                <th>Clinic Detail</th>
                                <th>Change Parameter</th>
                                <th>Value</th>
                                <th>Timestamp</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() {

    $("#patient_log_clinic").select2({
        tags: true
     });
    
     $('#list').DataTable( { 
          "ajax": "patientloglistdata.php?act=load",
          "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."
          }
          
      });

     $( "form" ).on( "submit", function(e) {
        e.preventDefault();
        
        var patient_fullname = $("#patient_fullname").val();
        var patient_id = $("#patient_id").val();
        var patient_log_clinic = $("#patient_log_clinic").val();
        var patient_log_type = $("#patient_log_type").val();
        
        $('#list').DataTable().destroy();
          $('#list').DataTable( { 
            "ajax": "patientloglistdata.php?act=load&patient_fullname="+patient_fullname+"&patient_id="+patient_id+"&patient_clinicId="+patient_log_clinic+"&patient_log_type="+patient_log_type,
            "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."
            }
            
        } );

      });
    });
</script>