<?php 
// Include main file
include_once('../libs/main.php');
// Check admin Login
include_once('checkLogin.php');
// Logical section of page

$adminlogObj = new admin_log();
$modulepagesObj = new module_pages();

$filename=basename($_SERVER['SCRIPT_FILENAME']);

if($filename == 'merge_patient.php'){
    $module_id = $adminlogObj->getModuleId($filename);
    $page_id = $adminlogObj->getPageId($filename);
    $allpages = $modulepagesObj->fromId($page_id);
    $pagename = $allpages->page;

}

if(isset($_REQUEST['act']) && $_REQUEST['act'] == 'getgurantor_left' && isset($_REQUEST['dependant_id']) && $_REQUEST['dependant_id'] != ''){
    $dependantObj = new dependant();
    $fields = array('dependant_id','dependant_fname','dependant_lname','dependant_email_address','dependant_phone','dependant_guarantor_id','dependant_login_id');
    $where ="dependant_id='".$_REQUEST['dependant_id']."'";
    $dependantArg    = array('fields'=>$fields,'where' => $where);
    $alldependant = $dependantObj->fromFields($dependantArg);
    if(isset($alldependant) && count($alldependant) > 0){
        foreach ($alldependant as $key => $dependantvalue) {
            $patientObj = new patient();
            $fields = array('patient_id','patient_fname','patient_lname','patient_phone','patient_email_address');
            $where = "patient_guarantor_id='".$dependantvalue->dependant_guarantor_id."'";
            $patientArg    = array('fields'=>$fields,'where' => $where);
            $allpatient = $patientObj->fromFields($patientArg);
            if($allpatient){
                $guranoter_name = '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b>Guarantor Detail</b><br/><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'.(w::d($allpatient->patient_fname))." ".(w::d($allpatient->patient_lname)).'</span><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
                    if($allpatient->patient_phone != ''){
                        $gurantor_phone_no = '<span>'.w::d($allpatient->patient_phone).'</span><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
                    }else{
                        $gurantor_phone_no = '';
                    }

                    if($allpatient->patient_email_address != ''){
                        $gurantor_email = '<span>'.w::d($allpatient->patient_email_address).'</span><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
                    }else{
                        $gurantor_email = '';
                    }

                    $gurantor_detail = $guranoter_name."".$gurantor_email.$gurantor_phone_no;
                

                if($dependantvalue->dependant_email_address != ''){
                    $email_add = '<span>'.w::d($dependantvalue->dependant_email_address).'</span><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
                }else{
                    $email_add = '';
                }

                if($dependantvalue->dependant_phone != ''){
                    $phone_no = '<span>'.w::d($dependantvalue->dependant_phone).'</span><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
                }else{
                    $phone_no = '';
                }

                if(!is_null($dependantvalue->dependant_login_id) && $dependantvalue->dependant_login_id != ''){
                    $patientObj = new patient();
                    $fields = array('patient_id','patient_fname','patient_lname','patient_phone','patient_email_address');
                    $where = "patient_id='".$dependantvalue->dependant_login_id."'";
                    $patientArg    = array('fields'=>$fields,'where' => $where);
                    $allpatientlogin = $patientObj->fromFields($patientArg);
                    if($allpatientlogin){
                        $patientloginfullname = '<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b>Login Detail</b><br/><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'.(w::d($allpatientlogin->patient_fname))." ".(w::d($allpatientlogin->patient_lname)).'</span><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
                        if($allpatientlogin->patient_phone != ''){
                            $allpatientlogin_phone_no = '<span>'.w::d($allpatientlogin->patient_phone).'</span><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
                        }else{
                            $allpatientlogin_phone_no = '';
                        }

                        if($allpatientlogin->patient_email_address != ''){
                            $allpatientlogin_email = '<span>'.w::d($allpatientlogin->patient_email_address).'</span><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
                        }else{
                            $allpatientlogin_email = '';
                        }
                        $allpatientlogin_detail = $patientloginfullname."".$allpatientlogin_email.$allpatientlogin_phone_no;
                        
                    }else{
                        $allpatientlogin_detail = '';
                    }
                }else{
                    $allpatientlogin_detail = '';
                }

                //onclick="getdependant_data('.$dependantvalue->dependant_id.')"
                $dependantfullname = ''.(w::d($dependantvalue->dependant_fname))." ".(w::d($dependantvalue->dependant_lname));

                $patient_detail = '<b>Patient Detail</b> <br/><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'.$dependantfullname.' </span><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'.($email_add).($phone_no).'<br/></span>';



                $all_data = '<div class="col-md-6">
                <input type="radio"  name="dependant_name_left" id="dependant_name_left" value="'.$dependantvalue->dependant_id.'"  /> &nbsp;&nbsp;'.$patient_detail.$gurantor_detail.'&nbsp;&nbsp;'.$allpatientlogin_detail.'</div>' ;
                
                $response[] =(
                          $all_data
                        );
                
            } 
        }
        $result=array('dependant'=>$response);
    }else{
        $result=array('dependant'=>array());
    }
    echo json_encode($result);
    exit;
    
}

if(isset($_REQUEST['act']) && $_REQUEST['act'] == 'getpatient' && isset($_REQUEST['search_patient']) && $_REQUEST['search_patient'] != ''){
    $dependantObj = new dependant();
    $fields = array('dependant_id','dependant_unique_id','dependant_fname','dependant_lname','cl.clinic_name as clinicname');
    $fullname = explode(" ", trim($_REQUEST['search_patient']));
    if($fullname && count($fullname)>0){
        if(count($fullname)==2){
                $where .=" (dependant_fname='".(w::e($fullname['0']))."' AND  dependant_lname='".(w::e($fullname['1']))."' ) OR (dependant_lname='".(w::e($fullname['0']))."' AND  dependant_fname='".(w::e($fullname['1']))."' ) OR (dependant_fname='".(w::e(ucfirst($fullname['0'])))."' AND  dependant_lname='".(w::e(ucfirst($fullname['1'])))."' ) OR (dependant_lname='".(w::e(ucfirst($fullname['0'])))."' AND  dependant_fname='".(w::e(ucfirst($fullname['1'])))."' ) ";    
        }else{
            $where ="( ";
            foreach ($fullname as $key => $f) {
                $where .=" dependant_fname LIKE '%".(w::e($f))."%' OR dependant_fname LIKE '%".(w::e(ucfirst($f)))."%'  OR dependant_lname LIKE '%".(w::e($f))."%' OR dependant_lname LIKE '%".(w::e(ucfirst($f)))."%' ";
                /*$where .=" dependant_fname LIKE '%".w::e($f)."%' OR dependant_fname LIKE '%".w::e(ucfirst($f))."%'  OR dependant_lname LIKE '%".w::e($f)."%' OR dependant_lname LIKE '%".w::e(ucfirst($f))."%' ";*/
                if( ($key+1) != count($fullname) ){
                        $where .=" OR ";
                }
            }
            $where .=" ) ";
        }
        
    }
    $tables = array('tbl_clinic_patient c','tbl_clinic cl');
    $jfields = array('c.clinic_patient_depid=d.dependant_id','cl.clinic_id=c.clinic_patient_cid');
    $jtype   = array("INNER","INNER"); 
    $dependantArg    = array('fields'=>$fields,'where' => $where,'joinTables' =>$tables, 'joinFields' =>$jfields, 'joinTypes' => $jtype);
    $alldependant = $dependantObj->getAllRecords($dependantArg);
   // print_r($alldependant);exit;
    ?>
    <option value="">Select Patient</option>
    <?php
    foreach ($alldependant as $key => $dependantvalue) 
    { ?>
       <option value="<?php echo $dependantvalue->dependant_id; ?>" ><?php echo w::d($dependantvalue->dependant_fname)." ".w::d($dependantvalue->dependant_lname)." - ".$dependantvalue->dependant_unique_id." - ".$dependantvalue->clinicname; ?></option>
                             
    <?php }
    exit;
}
if(isset($_REQUEST['act']) && $_REQUEST['act'] == 'getpatientOfguarantor' && isset($_REQUEST['guarantor_id']) && $_REQUEST['guarantor_id'] != ''){
    $guarantor_id =$_REQUEST['guarantor_id'];
    $dependantObj = new dependant();
    $fields = array('dependant_id','dependant_unique_id','dependant_fname','dependant_lname','cl.clinic_name as clinicname');
    $where =array('dependant_guarantor_id='=>$guarantor_id);
    $tables = array('tbl_clinic_patient c','tbl_clinic cl');
    $jfields = array('c.clinic_patient_depid=d.dependant_id','cl.clinic_id=c.clinic_patient_cid');
    $jtype   = array("INNER","INNER"); 
    $groupBy =array('dependant_id');
    $dependantArg    = array('fields'=>$fields,'where' => $where,'joinTables' =>$tables, 'joinFields' =>$jfields, 'joinTypes' => $jtype,'groupBy'=>$groupBy);
    $alldependant = $dependantObj->getAllRecords($dependantArg);
    ?>
    <option value="">Select Patient</option>
    <?php
        foreach ($alldependant as $key => $dependantvalue){ ?>
           <option value="<?php echo $dependantvalue->dependant_id; ?>"><?php echo w::d($dependantvalue->dependant_fname)." ".w::d($dependantvalue->dependant_lname)." - ".$dependantvalue->dependant_unique_id." - ".$dependantvalue->clinicname; ?></option>
    <?php }
    exit;
}

if(isset($_REQUEST['act']) && $_REQUEST['act'] == 'getpatient' && isset($_REQUEST['search_guarantor']) && $_REQUEST['search_guarantor'] != ''){
    $patientObj = new patient();
    $fields = array('patient_id','patient_unique_id','patient_fname','patient_lname');
    $fullname = explode(" ", trim($_REQUEST['search_guarantor']));
    $where ="patient_id=patient_guarantor_id";
    if($fullname && count($fullname)>0){
        if(count($fullname)==2){
            $where .=" AND  (patient_fname='".(w::e($fullname['0']))."' AND  patient_lname='".(w::e($fullname['1']))."' ) OR (patient_lname='".(w::e($fullname['0']))."' AND  patient_fname='".(w::e($fullname['1']))."' ) OR (patient_fname='".(w::e(ucfirst($fullname['0'])))."' AND  patient_lname='".(w::e(ucfirst($fullname['1'])))."' ) OR (patient_lname='".(w::e(ucfirst($fullname['0'])))."' AND  patient_fname='".(w::e(ucfirst($fullname['1'])))."' ) ";    
        }else{
            $where .=" AND ( ";
            foreach ($fullname as $key => $f) {
                $where .=" (patient_fname LIKE '%".(w::e($f))."%' OR patient_fname LIKE '%".(w::e(ucfirst($f)))."%'  OR patient_lname LIKE '%".(w::e($f))."%' OR patient_lname LIKE '%".(w::e(ucfirst($f)))."%' )";
                /*$where .=" dependant_fname LIKE '%".w::e($f)."%' OR dependant_fname LIKE '%".w::e(ucfirst($f))."%'  OR dependant_lname LIKE '%".w::e($f)."%' OR dependant_lname LIKE '%".w::e(ucfirst($f))."%' ";*/
                if( ($key+1) != count($fullname) ){
                        $where .=" OR ";
                }
            }
            $where .=" ) ";
        }
        
    }

    $dependantArg    = array('fields'=>$fields,'where' => $where);

    $allguarantor = $patientObj->getAllRecords($dependantArg);
   // print_r($alldependant);exit;
    ?>
    <option value="">Select Guarantor</option>
    <?php
    foreach ($allguarantor as $key => $guarantorvalue) 
    { ?>
       <option value="<?php echo $guarantorvalue->patient_id; ?>" ><?php echo w::d($guarantorvalue->patient_fname)." ".w::d($guarantorvalue->patient_lname)." - ".$guarantorvalue->patient_unique_id; ?></option>
                             
    <?php }
    exit;
}
if(isset($_REQUEST['act']) && $_REQUEST['act'] == 'getgurantor_right' && isset($_REQUEST['dependant_id']) && $_REQUEST['dependant_id'] != ''){
    $dependantObj = new dependant();
    $fields = array('dependant_id','dependant_fname','dependant_lname','dependant_email_address','dependant_phone','dependant_guarantor_id','dependant_login_id');
    $where ="dependant_id='".$_REQUEST['dependant_id']."'";
    $dependantArg    = array('fields'=>$fields,'where' => $where);
    $alldependant = $dependantObj->getAllRecords($dependantArg);
    //print_r($alldependant);exit;
    if(isset($alldependant) && count($alldependant) > 0)
    {
        foreach ($alldependant as $dkey => $dependantvalue) 
        {

            $patientObj = new patient();
            $fields = array('patient_id','patient_fname','patient_lname','patient_phone','patient_email_address');
            $where = "patient_guarantor_id='".$dependantvalue->dependant_guarantor_id."'";
            $patientArg    = array('fields'=>$fields,'where' => $where);
            $allpatient = $patientObj->fromFields($patientArg);
            if($allpatient)
            {
                $guranoter_name = '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b>Guarantor Detail</b><br/><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'.(w::d($allpatient->patient_fname))." ".(w::d($allpatient->patient_lname)).'</span><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';

                if($allpatient->patient_phone != '')
                {
                    $gurantor_phone_no = '<span>'.w::d($allpatient->patient_phone).'</span><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
                }else{
                    $gurantor_phone_no = '';
                }

                if($allpatient->patient_email_address != '')
                {
                    $gurantor_email = '<span>'.w::d($allpatient->patient_email_address).'</span><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
                }else{
                    $gurantor_email = '';
                }

                $gurantor_detail = $guranoter_name."".$gurantor_email.$gurantor_phone_no;
            }

            if($dependantvalue->dependant_email_address != '')
            {
                $email_add = '<span>'.w::d($dependantvalue->dependant_email_address).'</span><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
            }else{
                $email_add = '';
            }

            if($dependantvalue->dependant_phone != '')
            {
                $phone_no = '<span>'.w::d($dependantvalue->dependant_phone).'</span><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
            }else{
                $phone_no = '';
            }

            if(!is_null($dependantvalue->dependant_login_id) && $dependantvalue->dependant_login_id != '')
            {
                $patientObj = new patient();
                $fields = array('patient_id','patient_fname','patient_lname','patient_phone','patient_email_address');
                $where = "patient_id='".$dependantvalue->dependant_login_id."'";
                $patientArg    = array('fields'=>$fields,'where' => $where);
                $allpatientlogin = $patientObj->fromFields($patientArg);
                
                if($allpatientlogin)
                {
                    $patientloginfullname = '<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b>Login Detail</b><br/><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'.(w::d($allpatientlogin->patient_fname))." ".(w::d($allpatientlogin->patient_lname)).'</span><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';


                    if($allpatientlogin->patient_phone != '')
                    {
                        $allpatientlogin_phone_no = '<span>'.w::d($allpatientlogin->patient_phone).'</span><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
                    }else{
                        $allpatientlogin_phone_no = '';
                    }

                    if($allpatientlogin->patient_email_address != '')
                    {
                        $allpatientlogin_email = '<span>'.w::d($allpatientlogin->patient_email_address).'</span><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
                    }else{
                        $allpatientlogin_email = '';
                    }

                    $allpatientlogin_detail = $patientloginfullname."".$allpatientlogin_email.$allpatientlogin_phone_no;
                    
                }else{
                    $allpatientlogin_detail = '';
                }
            }else{
                $allpatientlogin_detail = '';
            }

            //onclick="getdependant_data('.$dependantvalue->dependant_id.')"
            $dependantfullname = ''.(w::d($dependantvalue->dependant_fname))." ".(w::d($dependantvalue->dependant_lname));

            $patient_detail = '<b>Patient Detail</b> <br/><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'.$dependantfullname.' </span><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'.($email_add).($phone_no).'<br/></span>';



            $all_data = '<div class="col-md-6">
            <input type="radio"  name="dependant_name_right" id="dependant_name_right" value="'.$dependantvalue->dependant_id.'"  /> &nbsp;&nbsp;'.$patient_detail.$gurantor_detail.'&nbsp;&nbsp;'.$allpatientlogin_detail.'</div>' ;
            
            $response[] =(
                      $all_data
                    );
            
        }
        
        $result=array('dependant'=>$response);
    }else{
        $result=array('dependant'=>array());
    }
    echo json_encode($result);
    exit;
    
}
if(isset($_REQUEST['act']) && $_REQUEST['act'] == 'mergePatient' && isset($_REQUEST['accepter']) &&  isset($_REQUEST['looser']) && $_REQUEST['looser'] != '' && $_REQUEST['accepter'] != ''){
    $dependantObj = new dependant();
    $looserId = $_REQUEST['looser'];
    $accepterId = $_REQUEST['accepter'];
    $accepter =$dependantObj->fromId($accepterId);
    $looser =$dependantObj->fromId($looserId);
    if($looser->dependant_guarantor_id==$accepter->dependant_guarantor_id){
        if(!is_null($accepter->dependant_login_id)){
            $appPatientId = $accepter->dependant_login_id;
            $assignId = $accepter->dependant_guarantor_id;
        }else{
            $appPatientId = $accepter->dependant_guarantor_id;
            $assignId = $accepter->dependant_guarantor_id;
        }

        $clinic_patientObj = new clinic_patient();
        $where =array('clinic_patient_depid='=>$looserId);
        $looserClinics = $clinic_patientObj->getAllRecords(array('where'=>$where));

        // update all appointment accordingly
        $appointmentData =array(
            "appointment_dependant_id"=>$accepterId,
            "appointment_patient_id"=>$appPatientId,
            "appointment_assignTo"=>$assignId,
        );
        $query ="UPDATE `tbl_appointment` SET `appointment_dependant_id`=".$accepterId.",`appointment_patient_id`=".$appPatientId.",`appointment_assignTo`=".$assignId." where appointment_dependant_id=".$looserId;
        $appointmentObj = new appointment();
        $appointmentObj->query($query);
        $rs =$appointmentObj->execute_query();
        if($rs){
            $appointmentLogData = "<b>All appointments transfer from looserId : ".$looserId." to accepterId : ".$accepterId."</b><p>".json_encode($appointmentData)."</p>";
        }else{
            $appointmentLogData="Error while transer appointments from looser to accepter. Or there is no records in appointments with looserId";
        }
        $admin_log = $adminlogObj->addAdminLog($_SESSION['admin_id'],$module_id,$page_id,$pagename,$appointmentLogData);

        $coverageObj = new coverage();
        $coverageData = array(
            "coverage_for"=>$accepterId
        );
        $coverageWhere =array('coverage_for='=>$looserId);
        $rs =$coverageObj->updateFromFields($coverageData,$coverageWhere);
        if($rs){
            $coverageLogData = "<b>All coverages transfer from looserId : ".$looserId." to accepterId : ".$accepterId."</b><p>".json_encode($coverageData)."</p>";
        }else{
            $coverageLogData="Error while transer coverages from looser to accepter. Or there is no records in coverages with looserId";
        }
        $admin_log = $adminlogObj->addAdminLog($_SESSION['admin_id'],$module_id,$page_id,$pagename,$coverageLogData);

        $coverage_expObj = new coverage_exp();
        $coverage_expData =array(
            "coverage_exp_for"=>$accepterId
        );
        $coverage_expWhere =array("coverage_exp_for="=>$looserId);
        $rs =$coverage_expObj->updateFromFields($coverage_expData,$coverage_expWhere);
        if($rs){
            $coverageExpenseLogData = "<b>All coverageExpenses transfer from looserId : ".$looserId." to accepterId : ".$accepterId."</b><p>".json_encode($coverage_expData)."</p>";
        }else{
            $coverageExpenseLogData="Error while transer coverageExpenses from looser to accepter. Or there is no records in coverageExpenses with looserId";
        }
        $admin_log = $adminlogObj->addAdminLog($_SESSION['admin_id'],$module_id,$page_id,$pagename,$coverageExpenseLogData);

        if(isset($looserClinics) && count($looserClinics)>0){
            foreach ($looserClinics as $key => $lclinic) {
                // update clinic wise pms patient xcare id-> assign accepter id to existing
                 $lc = $lclinic->clinic_patient_cid;
                 $clinicObj  = new clinic();
                 $clinicDetails =$clinicObj->fromId($lc);
                 $pmsPatientObj = new pmsPatient();
                 $where =array('pmsPatient_clinic_id='=>$lc,'pmsPatient_xcare_id='=>$looserId);
                 $arg = array('where'=>$where);
                 $pmsPatientDetails =$pmsPatientObj->fromFields($arg);
                 if($pmsPatientDetails){
                    // if exist assign new id
                    $pmsPatientData =array(
                        "pmsPatient_xcare_id"=>$accepterId
                    );
                    $rs =$pmsPatientObj->updateRecords($pmsPatientData,$pmsPatientDetails->pmsPatient_id);
                    if($rs){
                        $pmsPatientLogData = "<b>pmsPatients transfer from looserId : ".$looserId." to accepterId : ".$accepterId." for ".$clinicDetails->clinic_name."</b><p>".json_encode($pmsPatientData)."</p>";
                    }else{
                        $pmsPatientLogData="Error while transer pmsPatient from looser to accepter. Or there is no records in pmsPatient with looserId";
                    }
                    $admin_log = $adminlogObj->addAdminLog($_SESSION['admin_id'],$module_id,$page_id,$pagename,$pmsPatientLogData);
                 }
                 // remove looser from clinic
                $rs =$clinic_patientObj->deleteFromId($lclinic->clinic_patient_id);
                if($rs){
                    $pmsPatientLogData = "<b>Patient delete from ".$clinicDetails->clinic_name;
                }else{
                    $pmsPatientLogData="Error while delete the patient from clinic ".$clinicDetails->clinic_name;
                }
                $admin_log = $adminlogObj->addAdminLog($_SESSION['admin_id'],$module_id,$page_id,$pagename,$pmsPatientLogData);

                /// add new id to clinic
                $cpatientWhere =array('clinic_patient_cid='=>$lc,'clinic_patient_depid='=>$accepterId);
                $cpatientArg =array('where'=>$cpatientWhere);
                $existCpatient = $clinic_patientObj->fromFields($cpatientArg);
                if(!$existCpatient){
                    $clinic_patientData =array(
                        "clinic_patient_cid"=>$lc,
                        "clinic_patient_depid"=>$accepterId
                    );
                    $rs =$clinic_patientObj->addRecords($clinic_patientData);    
                    if($rs){
                        $pmsPatientLogData = "<b>Patient map with new patient id with ".$clinicDetails->clinic_name;
                    }else{
                        $pmsPatientLogData="Error while map the patient to clinic ".$clinicDetails->clinic_name;
                    }
                    $admin_log = $adminlogObj->addAdminLog($_SESSION['admin_id'],$module_id,$page_id,$pagename,$pmsPatientLogData);
                    }
            }           
        }
        // finally delete looser id and if delete if he/she has login
        if(!is_null($looser->dependant_login_id)){
            $patientObj = new patient();
            $patientObj->deleteFromId($looser->dependant_login_id);
        }
        $dependantObj->deleteFromId($looserId);
    }
    echo "success";
    exit;
}
// Include Template 
include_once('../libs/routs.php')
?>