 <div class="breadcrumb">
    <h1>Merge Patient Data</h1>
    <ul>
        <li><a href="<?php echo SITE_URL.ADMIN_DIR ?>">Dashboard</a></li>
        <li>Merge Patient Data</li>
        <li><a href="<?php echo SITE_URL ?>x-admin/adminloglist.php?module_id=<?php echo $module_id ?>" target="_blank">Log</a></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>

<div class="row">
    <div class="col-md-12">
        <div class="card mb-4">
            <div class="card-body">
                <form action="" id='frm-user' method="post" enctype="multipart/form-data">
                    <div class="row">
                      
                        <!-- <div class="col-md-6 form-group mb-3" id="div_patient_name_left">
                            <label for="patient_name_left">Patient Name </label>
                            <input type="text" class="form-control" id="patient_name_left" name="patient_name_left"  placeholder="Enter name" >
                            <div class="invalid-tooltip" id="msg_patient_name_left"></div>
                        </div>
                        <div class="col-md-6 form-group mb-3" id="div_patient_name_right">
                            <label for="patient_name_right">Patient name </label>
                            <input type="text" class="form-control" id="patient_name_right" name="patient_name_right"  placeholder="Enter name" >
                            <div class="invalid-tooltip" id="msg_patient_name_right" ></div>
                        </div> -->
                        <div class="col-md-6 form-group mb-3" id="div_patient_name_left">
                            <label for="guarantor_search`">Search Guarantor </label>
                            <input type="text" class="form-control" id="guarantor_search" name="guarantor_search"  placeholder="Enter name" >
                            <div class="invalid-tooltip" id="msg_guarantor_id"></div>
                        </div>
                        <div class="col-md-6 form-group mb-3" id="div_guarantor_id">
                            <label for="guarantor_id">Select Guarantor </label>
                            <select class="form-control" id="guarantor_id" name="guarantor_id">
                            <option value="">Select Guarantor</option>
                            </select>
                            <div class="invalid-tooltip" id="msg_guarantor_id"></div>
                        </div>
                        <div class="col-md-6 form-group mb-3" id="div_patient_accepter">
                            <label for="patient_accepter">Select Accepter </label>
                            <select class="form-control" id="patient_accepter" name="patient_accepter">
                              <option value="">Select Accepter</option>
                            </select>
                            <div class="invalid-tooltip" id="msg_patient_accepter"></div>
                        </div>
                        <div class="col-md-6 form-group mb-3" id="div_patient_looser">
                            <label for="patient_looser">Select Looser </label>
                            <select class="form-control" id="patient_looser" name="patient_looser">
                              <option value="">Select Looser</option>
                            </select>
                            <div class="invalid-tooltip" id="msg_patient_looser"></div>
                        </div>
                        <div class="col-md-12">
                          <span id="loaderid"></span>
                        </div>
                        <div class="col-md-12" id="div_app_submit">
                            <input type="button" class="btn btn-primary" id="submit" name="submit" value="Submit">
                        </div>
                  </div>
                </form>
            </div>
        </div>
    </div>
</div>
 <div class='loader-bubble loader-bubble-secondary m-5' align="center" style="display: none;"></div>
<div id="btnid"></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: 400px !important;  
}

</style>
<script type="application/javascript">
   $(document).ready(function() {
    //event.preventDefault();

    // $("#patient_name_left").keypress(function(event)
    // {
      
    //   if(event.which == '13')
    //   {
    //     $( "#patient_name_left" ).blur();
    //   }
    // });
    $("#guarantor_search").keypress(function(event){
      if(event.which == '13'){
        $( "#guarantor_search" ).blur();
      }
    });
    

    $("#guarantor_search").blur(function(){
      var guarantor_search = $("#guarantor_search").val();
        $.ajax
        ({
            url: 'merge_patient.php', 
            type: "POST",
            cache: false,
            data: ({act:'getpatient',search_guarantor: guarantor_search}),
            success: function(data){
                $("#guarantor_id").html(data);
            }
        });

    });

    $("#guarantor_id").on('change',function(){
        var guarantor_id = $("#guarantor_id").val();
        if(guarantor_id != ''){
          $.ajax({
            url: "merge_patient.php", 
            type: "POST",
            cache: false,
            data: ({act:"getpatientOfguarantor",guarantor_id: guarantor_id}),
            success: function(res){
                $("#patient_accepter").html(res);
                $("#patient_looser").html(res);
            }
          });
        }
    });

    $('#submit').on('click', function(e) {
        var accepter =$("#patient_accepter").val();
        var looser =$("#patient_looser").val();
        if(accepter != '' && looser!=''){
          $("#loaderid").html("Process is going on, pleae wait for some time.");
          $.ajax({
            url: "merge_patient.php", 
            type: "POST",
            cache: false,
            data: ({act:"mergePatient",accepter: accepter,looser:looser}),
            success: function(res){
                $("#loaderid").html("Successfully merged patient. please refresh and check.");
            }
          });
        }
    });
});

</script>
<?php //} ?>