<?php   
// Include main file
include_once('../libs/main.php');
// Check admin Login
include_once('checkLogin.php');
// Logical section of page
$practiceObj =  new  practice();
$adminlogObj = new admin_log();

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

if($filename == 'practicelist.php')
{
    $module_id = $adminlogObj->getModuleId($filename);
    $page_id = $adminlogObj->getPageId($filename);
}

if(isset($_REQUEST['act']) && $_REQUEST['act']=="refresh"){
    $param = array(
        // "app_id"=>sikka::APPID,
        // "app_key"=>sikka::APPKEY,
        "offset"=>sikka_v4::OFFSET,
        "limit"=>50
    );

    $header = array(
        "App-Id: ".sikka_v4::APPID,
        "App-Key: ".sikka_v4::APPKEY
    );

    $curlParam =array(
        "endpoint" =>sikka_v4::ENDPOINT_AUTH,
        "event"=>"authorized_practices",
        "query_data"=>$param,
        "header"=>$header,
        "method"=>"GET",
        "type"=>"SIKKA"
    );

    $practiceObj = new practice();
    $status  = $practiceObj->pullPractices($curlParam);
    if($status){
        header("Location:practicelist.php");
        exit;
    }
}
if(isset($_REQUEST['act']) && $_REQUEST['act']=="refresh_etl"){
    $param = array(
        // "app_id"=>sikka::APPID,
        // "app_key"=>sikka::APPKEY,
        "offset"=>sikka_v4::OFFSET,
        "limit"=>50
    );

    $header = array(
        "App-Id: ".sikka_v4::APPID_ETL,
        "App-Key: ".sikka_v4::APPKEY_ETL
    );

    $curlParam =array(
        "endpoint" =>sikka_v4::ENDPOINT_AUTH_ETL,
        "event"=>"authorized_practices",
        "query_data"=>$param,
        "header"=>$header,
        "method"=>"GET",
        "type"=>"CLOUD"
    );

    $practiceObj = new practice();
    $status  = $practiceObj->pullPractices($curlParam);
    if($status){
        header("Location:practicelist.php");
        exit;
    }
}
if(isset($_REQUEST['act']) && $_REQUEST['act']=='pms_status' && isset($_REQUEST['pms_id']))
{ 
    if(isset($_REQUEST['status']) && $_REQUEST['pms_data'] == '1')
    {
        $practice_accessObj = new practice();
        $where = array("practice_id="=>$_REQUEST['pms_id']);
        $practiceArg = array('where'=>$where);
        $practicedata = $practice_accessObj->FromFields($practiceArg);
        //print_r($messagecenter_data);exit;
        if($practicedata->practice_writeback == 'on')
        {
            $writeback = 'off';
            $old_practice_writeback = 'Enable';
            $new_practice_writeback = 'Disable';
        }else{
            $writeback = 'on';
            $old_practice_writeback = 'Disable';
            $new_practice_writeback = 'Enable';
        }

        $clinic_detail = " <b>Practice Writeback old</b> ".$old_practice_writeback." <b>to</b> ".$new_practice_writeback;

        $data_writeback['practice_writeback'] = $writeback;
        $rs=$practice_accessObj->updateRecords($data_writeback,$_REQUEST['pms_id']);
        //echo RECORD_STATUS;
        $admin_log = $adminlogObj->addAdminLog($_SESSION['admin_id'],$module_id,$page_id,$clinic_detail);
        echo json_encode(array("msg" => RECORD_STATUS, "writeback" => $writeback));
        return true;
    }

    if(isset($_REQUEST['status']) && $_REQUEST['pms_data'] == '2')
    {
        $practice_accessObj = new practice();
        $where = array("practice_id="=>$_REQUEST['pms_id']);
        $practiceArg = array('where'=>$where);
        $practicedata = $practice_accessObj->FromFields($practiceArg);
        //print_r($messagecenter_data);exit;
        if($practicedata->practice_sync == 'on')
        {
            $sync = 'off';
            $old_sync = 'Enable';
            $new_sync = 'Disable';
        }else{
            $sync = 'on';
            $old_sync = 'Disable';
            $new_sync = 'Enable';
        }

        $clinic_detail = " <b>Practice sync old</b> ".$old_sync." <b>to</b> ".$new_sync;

        $data_sync['practice_sync'] = $sync;
        $rs=$practice_accessObj->updateRecords($data_sync,$_REQUEST['pms_id']);
        //echo RECORD_STATUS;
        $admin_log = $adminlogObj->addAdminLog($_SESSION['admin_id'],$module_id,$page_id,$clinic_detail);
        echo json_encode(array("msg" => RECORD_STATUS, "sync" => $sync));
        return true;
    }

    if(isset($_REQUEST['status']) && $_REQUEST['pms_data'] == '3')
    {

        $practice_accessObj = new practice();
        $where = array("practice_id="=>$_REQUEST['pms_id']);
        $practiceArg = array('where'=>$where);
        $practicedata = $practice_accessObj->FromFields($practiceArg);
        //print_r($messagecenter_data);exit;
        if($practicedata->practice_patientwriteback == 'on')
        {
            $practice_patientwriteback = 'off';
            $old_practice_patientwriteback = 'Enable';
            $new_practice_patientwriteback = 'Disable';  
        }else{
            $practice_patientwriteback = 'on';
            $old_practice_patientwriteback = 'Disable';
            $new_practice_patientwriteback = 'Enable';
        }

        $clinic_detail = " <b>Patient Writeback old</b> ".$old_practice_patientwriteback." <b>to</b> ".$new_practice_patientwriteback;

        $data_sync['practice_patientwriteback'] = $practice_patientwriteback;
        $rs=$practice_accessObj->updateRecords($data_sync,$_REQUEST['pms_id']);
        //echo RECORD_STATUS;

        $admin_log = $adminlogObj->addAdminLog($_SESSION['admin_id'],$module_id,$page_id,$clinic_detail);
        echo json_encode(array("msg" => RECORD_STATUS, "patientwriteback" => $patientwriteback));
        return true;
    }

    if(isset($_REQUEST['status']) && $_REQUEST['pms_data'] == '4')
    {

        $practice_accessObj = new practice();
        $where = array("practice_id="=>$_REQUEST['pms_id']);
        $practiceArg = array('where'=>$where);
        $practicedata = $practice_accessObj->FromFields($practiceArg);
        //print_r($messagecenter_data);exit;
        if($practicedata->practice_appointmentwriteback == 'on')
        {
            $practice_appointmentwriteback = 'off';
            $old_practice_appointmentwriteback = 'Enable';
            $new_practice_appointmentwriteback = 'Disable';   
        }else{
            $practice_appointmentwriteback = 'on';
            $old_practice_appointmentwriteback = 'Disable';
            $new_practice_appointmentwriteback = 'Enable';
        }
        
        $clinic_detail = " <b>Appointment writeback old</b> ".$old_practice_appointmentwriteback." <b>to</b> ".$new_practice_appointmentwriteback;

        $data_sync['practice_appointmentwriteback'] = $practice_appointmentwriteback;
        $rs=$practice_accessObj->updateRecords($data_sync,$_REQUEST['pms_id']);
        //echo RECORD_STATUS;
        $admin_log = $adminlogObj->addAdminLog($_SESSION['admin_id'],$module_id,$page_id,$clinic_detail);
        echo json_encode(array("msg" => RECORD_STATUS, "appointmentwriteback" => $practice_appointmentwriteback));
        return true;
    }

    if(isset($_REQUEST['status']) && $_REQUEST['pms_data'] == '5')
    {

        $practice_accessObj = new practice();
        $where = array("practice_id="=>$_REQUEST['pms_id']);
        $practiceArg = array('where'=>$where);
        $practicedata = $practice_accessObj->FromFields($practiceArg);
        //print_r($messagecenter_data);exit;
        if($practicedata->practice_statuswriteback == 'on')
        {
            $practice_statuswriteback = 'off';
            $old_practice_statuswriteback = 'Enable';
            $new_practice_statuswriteback = 'Disable';  
        }else{
            $practice_statuswriteback = 'on';
            $old_practice_statuswriteback = 'Disable';
            $new_practice_statuswriteback = 'Enable'; 
        }
        
        $clinic_detail = " <b>Status writeback old</b> ".$old_practice_statuswriteback." <b>to</b> ".$new_practice_statuswriteback;

        $data_sync['practice_statuswriteback'] = $practice_statuswriteback;
        $rs=$practice_accessObj->updateRecords($data_sync,$_REQUEST['pms_id']);
        //echo RECORD_STATUS;
        $admin_log = $adminlogObj->addAdminLog($_SESSION['admin_id'],$module_id,$page_id,$clinic_detail);
        echo json_encode(array("msg" => RECORD_STATUS, "statuswriteback" => $practice_statuswriteback));
        return true;
    }

    if(isset($_REQUEST['status']) && $_REQUEST['pms_data'] == '6')
    {

        $practice_accessObj = new practice();
        $where = array("practice_id="=>$_REQUEST['pms_id']);
        $practiceArg = array('where'=>$where);
        $practicedata = $practice_accessObj->FromFields($practiceArg);
        //print_r($messagecenter_data);exit;
        if($practicedata->practice_tempwriteback == 'on')
        {
            $practice_tempwriteback = 'off';
            $old_practice_tempwriteback = 'Enable';
            $new_practice_tempwriteback = 'Disable';
        }else{
            $practice_tempwriteback = 'on';
            $old_practice_tempwriteback = 'Disable';
            $new_practice_tempwriteback = 'Enable'; 
        }
        
        $clinic_detail = " <b>Temp writeback old</b> ".$old_practice_tempwriteback." <b>to</b> ".$new_practice_tempwriteback;

        $data_sync['practice_tempwriteback'] = $practice_tempwriteback;
        $rs=$practice_accessObj->updateRecords($data_sync,$_REQUEST['pms_id']);
        //echo RECORD_STATUS;
        $admin_log = $adminlogObj->addAdminLog($_SESSION['admin_id'],$module_id,$page_id,$clinic_detail);
        echo json_encode(array("msg" => RECORD_STATUS, "tempstatuswriteback" => $practice_tempwriteback));
        return true;
    }

}



if (isset($_REQUEST['act']) && $_REQUEST['act']=='load'){
    $records = $_REQUEST['length'];
    $start=0;
    if(isset($_GET['start']) && $_GET['start']!='0'){
        $page = $_GET['start'];
    }
    $start=($page-1)*$limit;
    $limit = array('start'=>$_GET['start'],'record'=>$records);
    
    $where = " 1=1 ";
    //serach parmeter

    if(isset($_REQUEST['office_id']) && $_REQUEST['office_id'] != "")
    {
        $where .= " AND  practice_office_id = '".$_REQUEST['office_id']."' ";
    }
    if (isset($_REQUEST['sikka_id']) && $_REQUEST['sikka_id']!=""){
        $where .= " AND  practice_sikka_id = '".$_REQUEST['sikka_id']."' ";
    }
    if (isset($_REQUEST['practice_name']) && $_REQUEST['practice_name']!=""){
        $where .= " AND  practice_name = '".$_REQUEST['practice_name']."' ";
    }
    if (isset($_REQUEST['clinic_id']) && $_REQUEST['clinic_id']!=""){
        $where .= " AND  practice_xcare_id = '".$_REQUEST['clinic_id']."' ";
    }
    if(isset($_REQUEST['practice_id']) && $_REQUEST['practice_id'] != '')
    {
        $where .= " AND practice_id = '".$_REQUEST['practice_id']."'";
    }
    if(isset($_REQUEST['practice_pms']) && $_REQUEST['practice_pms'] != '')
    {
        $where .= " AND practice_pms = '".$_REQUEST['practice_pms']."'";
    }
    if(isset($_REQUEST['etl_type']) && $_REQUEST['etl_type'] != '')
     {
         $where .= " AND practice_endpoint = '".$_REQUEST['etl_type']."'";
     }
     if(isset($_REQUEST['sync_status']) && $_REQUEST['sync_status'] != '')
     {
         $where .= " AND practice_sync = '".$_REQUEST['sync_status']."'";
     }


    if (isset($_REQUEST['search']['value']) && $_REQUEST['search']['value']!=""){
        $where = " practice_office_id LIKE '%".$_REQUEST['search']['value']."%' OR practice_name LIKE '%".$_REQUEST['search']['value']."%'  OR practice_pms LIKE '%".$_REQUEST['search']['value']."%' OR practice_secret_key LIKE '%".$_REQUEST['search']['value']."%' OR practice_request_key LIKE '%".$_REQUEST['search']['value']."%' OR c.clinic_name LIKE '%".$_REQUEST['search']['value']."%' OR practice_id LIKE '%".$_REQUEST['search']['value']."%' ";
    }    
    $orderFields = array('practice_id','practice_pms','practice_name','','','','');
    
    // Array of order by 
    $orderby=array();
    if (isset($_REQUEST['order']['0']['column']) && $_REQUEST['order']['0']['column']!=""){
        $orderby = array(" ".$orderFields[$_REQUEST['order']['0']['column']]." ".$_REQUEST['order']['0']['dir']);
    }else{
        $orderby = array(" practice_id desc ");
    }

    $tables = array('tbl_clinic c');
    $jfields = array('c.clinic_id = p.practice_xcare_id');
    $jtype   = array("LEFT"); 
    $data    = array('joinTables' =>$tables, 'joinFields' =>$jfields, 'joinTypes' => $jtype,'where' => $where,'limit' => $limit, 'orderBy'=>$orderby);

    $practiceDetails = $practiceObj->getAllRecords($data);
    $recordsTotal   =   $practiceObj->getAllCount($data);

        
    if ($practiceDetails && count($practiceDetails)>0){
        foreach ($practiceDetails as $key => $practice){
            $clinicname="";
            if(is_null($practice->practice_name)){
                if(!is_null($practice->practice_xcare_id)){
                    $clinicObj = new clinic();
                    $c = $clinicObj->fromId($practice->practice_xcare_id);
                    $clinicname = $c->clinic_name;
                    $updateData  = array(
                        "practice_name" =>$clinicname
                    );
                    $practiceObj->updateRecords($updateData,$practice->practice_id);
                }
            }else{
                $clinicname = $practice->practice_name;
            }
            // $pmsPatientObj = new pmsPatient();
            // $where =array('pmsPatient_practice_id='=>$practice->practice_office_id);
            // $data =array('where'=>$where);
            // $exist = $pmsPatientObj->FromFields($data);
            // $status="";
            // if(!$exist){
            //     $status = ' <a href="pmsPatientlist.php?office_id='.$practice->practice_office_id.'" title="Fetch PMS Patient"><span class="badge badge-success">Pull Patients</span></a>';
            // }else{
            //     $status = ' <a href="pmsPatientlist.php?office_id='.$practice->practice_office_id.'" title="Fetch PMS Patient"><span class="badge badge-success">Pull Patients again</span></a>';
            // }
            // $pmsProviderObj = new pmsProvider();
            // $where =array('pmsProvider_office_id='=>$practice->practice_office_id);
            // $data =array('where'=>$where);
            // $exist = $pmsProviderObj->FromFields($data);
            // if(!$exist){
            //     $status .= ' <a href="pmsProviderlist.php?office_id='.$practice->practice_office_id.'" title="Fetch PMS Providers"><span class="badge badge-success">Pull Providers</span></a>';
            // }else{
            //     //againain
            //     $status .= ' <a href="pmsProviderlist.php?office_id='.$practice->practice_office_id.'" title="Fetch PMS Providers again"><span class="badge badge-success">Pull Providers againain</span></a>';
            // }
            
            // $guarantorObj = new guarantor();
            // $where =array('guarantor_practice_id='=>$practice->practice_office_id);
            // $data =array('where'=>$where);
            // $exist = $guarantorObj->FromFields($data);
            // if(!$exist){
            //     $status .= ' <a href="guarantorlist.php?office_id='.$practice->practice_office_id.'" title="Fetch PMS Guarantors"><span class="badge badge-success">Pull Guarantors</span></a>';
            // }else{
            //     $status .= ' <a href="guarantorlist.php?office_id='.$practice->practice_office_id.'" title="Fetch PMS Guarantors"><span class="badge badge-success">Pull Guarantors again</span></a>';
            // }
            // $pmsAppointmentObj = new pmsAppointment();
            // $where =array('pmsAppointment_practice_id='=>$practice->practice_office_id);
            // $data =array('where'=>$where);
            // $exist = $pmsAppointmentObj->FromFields($data);
            // if(!$exist){
            //     $status .= ' <a href="pmsAppointmentlist.php?office_id='.$practice->practice_office_id.'" title="Fetch PMS Appointments"><span class="badge badge-success">Pull Appointments</span></a>';
            // }else{
            //     $status .= ' <a href="pmsAppointmentlist.php?office_id='.$practice->practice_office_id.'" title="Fetch PMS Appointments"><span class="badge badge-success">Refresh Pull Appointments</span></a>';
            // }
            // $pmsAppointmentStatusObj = new pmsAppointmentStatus();
            // $where =array('pmsAppointmentStatus_office_id='=>$practice->practice_office_id);
            // $data =array('where'=>$where);
            // $exist = $pmsAppointmentStatusObj->FromFields($data);
            // if(!$exist){
            //     $status .= ' <a href="pmsAppointmentStatuslist.php?office_id='.$practice->practice_office_id.'" title="Fetch PMS Appointment Status"><span class="badge badge-success">Pull Appointment Status</span></a>';
            // }else{
            //     $status .= ' <a href="pmsAppointmentStatuslist.php?office_id='.$practice->practice_office_id.'" title="Fetch PMS Appointments Status"><span class="badge badge-success">Pull Appointment status again</span></a>';
            // }
            
            // $procedurecodeObj = new procedure_code();
            // $where =array('procedure_code_office_id='=>$practice->practice_office_id);
            // $data =array('where'=>$where);
            // $exist = $procedurecodeObj->FromFields($data);
            // if(!$exist){
            //     $status .= ' <a href="pmsProcedureCodelist.php?office_id='.$practice->practice_office_id.'" title="Fetch PMS Procedure Code"><span class="badge badge-success">Pull Procedure Code</span></a>';
            // }else{
            //     $status .= ' <a href="pmsProcedureCodelist.php?office_id='.$practice->practice_office_id.'" title="Fetch PMS Procedure Code"><span class="badge badge-success">Pull Procedure Code again</span></a>';
            // }
            // $treatment_plan_statusesObj = new treatment_plan_statuses();
            // $where =array('office_id='=>$practice->practice_office_id);
            // $data =array('where'=>$where);
            // $exist = $treatment_plan_statusesObj->FromFields($data);
            // if(!$exist){
            //     $status .= ' <a href="treatmentStatuslist.php?office_id='.$practice->practice_office_id.'" title="Fetch Treatment Status"><span class="badge badge-success">Pull Treatment Status</span></a>';
            // }else{
            //     //againain
            //     $status .= ' <a href="treatmentStatuslist.php?office_id='.$practice->practice_office_id.'" title="Fetch Treatment Status again"><span class="badge badge-success">Pull Treatment Status again</span></a>';
            // }
            // $treatment_plansObj = new treatment_plans();
            // $where =array('office_id='=>$practice->practice_office_id);
            // $data =array('where'=>$where);
            // $exist = $treatment_plansObj->FromFields($data);
            // if(!$exist){
            //     $status .= ' <a href="treatmentPlanlist.php?office_id='.$practice->practice_office_id.'" title="Fetch Treatment Plan"><span class="badge badge-success">Pull Treatment Plan</span></a>';
            // }else{
            //     //againain
            //     $status .= ' <a href="treatmentPlanlist.php?office_id='.$practice->practice_office_id.'" title="Fetch Treatment Plan again"><span class="badge badge-success">Pull Treatment Plan again</span></a>';
            // } 

            // $reminderObj = new reminder();
            // $where =array('office_id='=>$practice->practice_office_id);
            // $data =array('where'=>$where);
            // $exist = $reminderObj->FromFields($data);
            // if(!$exist){
            //     $status .= ' <a href="reminderlist.php?office_id='.$practice->practice_office_id.'" title="Fetch PMS Reminder"><span class="badge badge-success">Pull PMS Reminder</span></a>';
            // }else{
            //     // //againain
            //     // $status .= ' <a href="reminderlist.php?office_id='.$practice->practice_office_id.'" title="Fetch PMS Reminder again"><span class="badge badge-success">Pull Reminder again</span></a>';
            // } 
            if($practice->practice_writeback == 'on')
            {
                $writeback_pms = ' onclick="pms_change_status('.$practice->practice_id.',0,1)"';
                $writeback_check ='checked';
            }else{
                $writeback_pms = ' onclick="pms_change_status('.$practice->practice_id.',1,1)"';
                $writeback_check = "";
            }

            if($practice->practice_sync == 'on')
            {
                $sync_pms = ' onclick="pms_change_status('.$practice->practice_id.',0,2)"';
                $sync_check ='checked';
            }else{
                $sync_pms = ' onclick="pms_change_status('.$practice->practice_id.',1,2)"';
                $sync_check = "";
            }

            if($practice->practice_patientwriteback == 'on')
            {
                $patientwriteback_pms = ' onclick="pms_change_status('.$practice->practice_id.',0,3)"';
                $patientwriteback_check ='checked';
            }else{
                $patientwriteback_pms = ' onclick="pms_change_status('.$practice->practice_id.',1,3)"';
                $patientwriteback_check = "";
            }

            if($practice->practice_appointmentwriteback == 'on')
            {
                $appointmentwriteback_pms = ' onclick="pms_change_status('.$practice->practice_id.',0,4)"';
                $appointmentwriteback_check ='checked';
            }else{
                $appointmentwriteback_pms = ' onclick="pms_change_status('.$practice->practice_id.',1,4)"';
                $appointmentwriteback_check = "";
            }

            if($practice->practice_statuswriteback == 'on')
            {
                $statuswriteback_pms = ' onclick="pms_change_status('.$practice->practice_id.',0,5)"';
                $statuswriteback_check ='checked';
            }else{
                $statuswriteback_pms = ' onclick="pms_change_status('.$practice->practice_id.',1,5)"';
                $statuswriteback_check = "";
            }

            if($practice->practice_tempwriteback == 'on')
            {
                $tempstatuswriteback_pms = ' onclick="pms_change_status('.$practice->practice_id.',0,6)"';
                $tempstatuswriteback_check ='checked';
            }else{
                $tempstatuswriteback_pms = ' onclick="pms_change_status('.$practice->practice_id.',1,6)"';
                $tempstatuswriteback_check = "";
            }
            
            
            
            $writeback = "Writeback : <br/><label class='switch switch-primary mr-3 writeback'>
                                <input type='checkbox' id='pms_writeback_$practice->practice_id' name='pms_writeback' writeback-data='$practice->practice_writeback' pmswriteback-data = 'writeback'
                                 $writeback_pms  $writeback_check >
                                <span class='slider'></span>
                            </label>";
            /*$writeback = "Writeback : <label class='switch switch-primary mr-3 writeback'>
                                <input type='checkbox' id='pms_writeback' name='pms_writeback' 
                                 $writeback_pms  $writeback_check >
                                <span class='slider'></span>
                            </label>";*/

            $sync = "Sync : <br/><label class='switch switch-primary mr-3'>
                                <input type='checkbox' id='pms_sync_$practice->practice_id' name='pms_sync' sync-data='$practice->practice_sync'
                                 $sync_pms  $sync_check pmssync-data = 'sync' >
                                <span class='slider'></span>
                            </label>";
            /*$sync = "Sync : <label class='switch switch-primary mr-3'>
                                <input type='checkbox' id='pms_sync' name='pms_sync' 
                                 $sync_pms  $sync_check >
                                <span class='slider'></span>
                            </label>";*/
            $patientwriteback = "Patient Writeback : <label class='switch switch-primary mr-3'>
                                <input type='checkbox' id='pms_patientwriteback_$practice->practice_id' name='pms_writeback' patientwriteback-data='$practice->practice_patientwriteback'
                                 $patientwriteback_pms  $patientwriteback_check >
                                <span class='slider'></span>
                            </label>";

            $appointmentwriteback = "Appointment Writeback : <label class='switch switch-primary mr-3'>
                                <input type='checkbox' id='pms_appointmentwriteback_$practice->practice_id' name='pms_appointmentwriteback' appointmentwriteback-data='$practice->practice_appointmentwriteback'
                                 $appointmentwriteback_pms  $appointmentwriteback_check >
                                <span class='slider'></span>
                            </label>";

            $statuswriteback = "Status Writeback : <label class='switch switch-primary mr-3'>
                                <input type='checkbox' id='pms_statuswriteback_$practice->practice_id' name='pms_statuswriteback' statuswriteback-data='$practice->practice_statuswriteback'
                                 $statuswriteback_pms  $statuswriteback_check >
                                <span class='slider'></span>
                            </label>";

            $tempstatuswriteback = "Temp Status Writeback : <label class='switch switch-primary mr-3'>
                                <input type='checkbox' id='pms_tempstatuswriteback_$practice->practice_id' name='pms_tempstatuswriteback' tempstatuswriteback-data='$practice->practice_tempwriteback'
                                 $tempstatuswriteback_pms  $tempstatuswriteback_check >
                                <span class='slider'></span>
                            </label>";


                            
            $health_check =  '<img src="'. SITE_URL.'x-admin/assets/images/health-graph.png" alt="Health care" style="width:30px;">';
            $fetchPracticeData = '<img src="'. SITE_URL.'x-admin/assets/images/fetchPracticeData.png" alt="Fetch Practice Data" style="width:30px;">';
            $reactive="";
            if($_SESSION['admin_access']=='Full'){
                $reactive= ' <a href="practice_reactive.php?id='.$practice->practice_id.'" class="btn btn-danger white-btn"><i class="nav-icon i-Close-Window "></i></a>';
            }    

            $response[] = array(
                    "<b>Practice Id : </b>".$practice->practice_id."<br/><b>Office Id : </b>".$practice->practice_office_id."<br/><b>Sikka Id :</b>".$practice->practice_sikka_id."<br/><b>Xcare Id :</b>".$practice->practice_xcare_id."<br/><b>Clinic Name : </b>".$practice->clinic_name."<br/><b>PmsOnboardDate: </b>".$practice->pmsOnboardDate,
                    //"<b>Xcare Id :</b>".$practice->practice_xcare_id,
                    $practice->practice_pms, 
                    $clinicname,
                    "<b>Secret key : </b>".$practice->practice_secret_key.'<br/><b>Request key : </b>'.$practice->practice_request_key, 
                     
                    "<b>Appointment : </b>".$practice->practice_refresh_date."<br/><b>Patient :</b>".$practice->practice_prefresh_date."<br/><b>Guarantor:</b>".$practice->practice_grefresh_date."<br><b>pullGuarantors : </b>".$practice->practice_pullGuarantors."<br><b>pullPatients : </b>".$practice->practice_pullPatients."<br><b>pullAppointments : </b>".$practice->practice_pullAppointments."<br/><b>Counter: </b>".$practice->practice_not_refreshed_counter,
                    $status."<br/><br/>".$writeback."<br/><br/>".$sync."<br/><br/>".$patientwriteback."<br/><br/>".$appointmentwriteback."<br/><br/>".$statuswriteback."<br/><br/>".$tempstatuswriteback,

                    '<a href="practice_edit.php?act=edit&practice_id='.$practice->practice_id.'" class="btn btn-success white-btn"><i class="nav-icon i-Pen-2 "></i></a>'.$reactive.'<br/><br/><a href="practice_healthcheck.php?act=healthdata&practice_office_id='.$practice->practice_office_id.'" >'.$health_check.'</a><br/><br/><a href="fetchPracticeData.php?office_id='.$practice->practice_office_id.'" >'.$fetchPracticeData.'</a>',

             );
        }
        $result=array('recordsFiltered'=>$recordsTotal,'recordsTotal'=>$recordsTotal,'data'=>$response);
    }else{
        $result=array('recordsFiltered'=>0,'recordsTotal'=>0,'data'=>array());
    }
    echo json_encode($result);
    exit;
}

// Include Template 
include_once('../libs/routs.php')
?>