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

if(isset($_REQUEST['act']) && $_REQUEST['act']=='fetchPracticeData' && isset($_REQUEST['practice_office_id']))
{
    $practice_office_id = $_REQUEST['practice_office_id'];
    
    $pmsPatientObj = new pmsPatient();
    $where =array('pmsPatient_practice_id='=>$practice_office_id);
    $data =array('where'=>$where);
    $exist = $pmsPatientObj->FromFields($data);
    $status="";
    if(!$exist){
        $status = ' <a href="pmsPatientlist.php?office_id='.$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_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_office_id);
    $data =array('where'=>$where);
    $exist = $pmsProviderObj->FromFields($data);
    if(!$exist){
        $status .= ' <a href="pmsProviderlist.php?office_id='.$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_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_office_id);
    $data =array('where'=>$where);
    $exist = $guarantorObj->FromFields($data);
    if(!$exist){
        $status .= ' <a href="guarantorlist.php?office_id='.$practice_office_id.'" title="Fetch PMS Guarantors"><span class="badge badge-success">Pull Guarantors</span></a><br/><br/>';
    }else{
        $status .= ' <a href="guarantorlist.php?office_id='.$practice_office_id.'" title="Fetch PMS Guarantors"><span class="badge badge-success">Pull Guarantors again</span></a><br/><br/><br/>';
    }
    $pmsAppointmentObj = new pmsAppointment();
    $where =array('pmsAppointment_practice_id='=>$practice_office_id);
    $data =array('where'=>$where);
    $exist = $pmsAppointmentObj->FromFields($data);
    if(!$exist){
        $status .= ' <a href="pmsAppointmentlist.php?office_id='.$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_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_office_id);
    $data =array('where'=>$where);
    $exist = $pmsAppointmentStatusObj->FromFields($data);
    if(!$exist){
        $status .= ' <a href="pmsAppointmentStatuslist.php?office_id='.$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_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_office_id);
    $data =array('where'=>$where);
    $exist = $procedurecodeObj->FromFields($data);
    if(!$exist){
        $status .= ' <a href="pmsProcedureCodelist.php?office_id='.$practice_office_id.'" title="Fetch PMS Procedure Code"><span class="badge badge-success">Pull Procedure Code</span></a><br/><br/>';
    }else{
        $status .= ' <a href="pmsProcedureCodelist.php?office_id='.$practice_office_id.'" title="Fetch PMS Procedure Code"><span class="badge badge-success">Pull Procedure Code again</span></a><br/><br/><br/>';
    }
    $treatment_plan_statusesObj = new treatment_plan_statuses();
    $where =array('office_id='=>$practice_office_id);
    $data =array('where'=>$where);
    $exist = $treatment_plan_statusesObj->FromFields($data);
    if(!$exist){
        $status .= ' <a href="treatmentStatuslist.php?office_id='.$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_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_office_id);
    $data =array('where'=>$where);
    $exist = $treatment_plansObj->FromFields($data);
    if(!$exist){
        $status .= ' <a href="treatmentPlanlist.php?office_id='.$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_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_office_id);
    $data =array('where'=>$where);
    $exist = $reminderObj->FromFields($data);
    if(!$exist){
        $status .= ' <a href="reminderlist.php?office_id='.$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_office_id.'" title="Fetch PMS Reminder again"><span class="badge badge-success">Pull Reminder again</span></a>';
    } 

    if(!empty($status))
    {
        echo "<div class='mb-3'>$status</div>";
    }
    exit;
}

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