<?php 
include_once('../libs/main.php');
// Check admin Login
include_once('checkLogin.php');

$appointmentObj =  new  appointment();

if (isset($_REQUEST['act']) && $_REQUEST['act']=='load' && isset($_REQUEST['app_type']) && $_REQUEST['app_type']!='' )
{
	$app_type = $_REQUEST['app_type'];

    if($app_type == 'guestappointment')
    {
        //$guestappointmentObj =  new  guestappointment();
        $guestappointmentObj =  new  guestAppointment();

        $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";

        if(isset($_REQUEST['unique_id']) && $_REQUEST['unique_id'] != '')
        {
            $where .= " AND guestAppointment_unique_id = '".$_REQUEST['unique_id']."'";
        }
        if(isset($_REQUEST['clinic_id']) && $_REQUEST['clinic_id'] != '')
        {
            $where .= " AND  guestAppointment_clinic_id = '".$_REQUEST['clinic_id']."' ";
        }
        if(isset($_REQUEST['appointment_id']) && $_REQUEST['appointment_id'] != '')
        {
            $where .= " AND  guestAppointment_id = '".$_REQUEST['appointment_id']."' ";
        }

        if(isset($_REQUEST['all_email']) && $_REQUEST['all_email'] != '')
        {
            $where .= " AND (clinic_email = '".$_REQUEST['all_email']."' OR cdoctor_email = '".$_REQUEST['all_email']."' OR guestAppointment_pemail = '".$_REQUEST['all_email']."' )";
        }
        if(isset($_REQUEST['all_phone']) && $_REQUEST['all_phone'] != '')
        {
            $where .= " AND (clinic_phone = '".$_REQUEST['all_phone']."' OR cdoctor_phone = '".$_REQUEST['all_phone']."' OR guestAppointment_pphone = '".$_REQUEST['all_phone']."') ";
        }

        if(isset($_REQUEST['patient_name']) && $_REQUEST['patient_name'] != '')
        {
           $patientname = preg_replace('/\s\s+/', ' ', $_REQUEST['patient_name']);
           $fullname = explode(" ", $patientname);
            if($fullname && count($fullname)>0)
            {
                $where ="";
                foreach ($fullname as $key => $f) 
                {
                    $where .=" guestAppointment_pfname LIKE '%".($f)."%' OR guestAppointment_pfname LIKE '%".(ucfirst($f))."%'  OR guestAppointment_plname LIKE '%".($f)."%' OR guestAppointment_plname LIKE '%".(ucfirst($f))."%'";
                    if( ($key+1) != count($fullname) )
                    {
                            $where .=" OR ";
                    }
                }
            }
        }

        if (isset($_REQUEST['start_date']) && $_REQUEST['start_date']!="" && isset($_REQUEST['end_date']) && $_REQUEST['end_date']!="" ){
            $where .= " AND  guestAppointment_date BETWEEN '".$_REQUEST['start_date']."' AND '".$_REQUEST['end_date']."' ";
        }
        
        if (isset($_REQUEST['start_time']) && $_REQUEST['start_time']!="" && isset($_REQUEST['end_time']) && $_REQUEST['end_time']!="" )
        {
            
            $cstart_time = date("h:i A",strtotime($_REQUEST['start_time']));
            $cend_time = date("h:i A",strtotime($_REQUEST['end_time']));
            
            $where .= " AND  (STR_TO_DATE(guestAppointment_time, '%l:%i %p' ) >= STR_TO_DATE('".$cstart_time."', '%l:%i %p' ) AND STR_TO_DATE(appointment_etime, '%l:%i %p' ) <= STR_TO_DATE( '".$cend_time."', '%l:%i %p' ) ) ";
        }

        if (isset($_REQUEST['search']['value']) && $_REQUEST['search']['value']!="")
        {

            $where .= " AND (c.clinic_name LIKE '%".$_REQUEST['search']['value']."%' OR c.clinic_id LIKE '%".$_REQUEST['search']['value']."%' OR c.clinic_unique_id LIKE '%".$_REQUEST['search']['value']."%' OR c.clinic_phone LIKE '%".$_REQUEST['search']['value']."%' OR c.clinic_email LIKE '%".$_REQUEST['search']['value']."%' OR g.guestAppointment_id LIKE '%".$_REQUEST['search']['value']."%' OR g.guestAppointment_unique_id LIKE '%".$_REQUEST['search']['value']."%' OR g.guestAppointment_clinic_id LIKE '%".$_REQUEST['search']['value']."%' OR g.guestAppointment_doctor_id LIKE '%".$_REQUEST['search']['value']."%' OR g.guestAppointment_appointmenttype_id LIKE '%".$_REQUEST['search']['value']."%' OR g.guestAppointment_date LIKE '%".$_REQUEST['search']['value']."%' OR g.guestAppointment_time LIKE '%".$_REQUEST['search']['value']."%' )";

        }    
        $orderFields = array('guestAppointment_id','clinic_id');

        // 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(" guestAppointment_id DESC ");
        }

        $fields  = array('g.*','c.clinic_name','c.clinic_id','c.clinic_unique_id','c.clinic_phone','c.clinic_email','c.clinic_website',
            'cd.cdoctor_fullname','cd.cdoctor_doctor_id','cd.cdoctor_provider_id','cd.cdoctor_email','cd.cdoctor_phone');
        $tables = array('tbl_clinic c','tbl_doctor d','tbl_appointmenttype apt','tbl_cdoctor cd');
        $jfields = array(
            'g.guestAppointment_clinic_id = c.clinic_id',
            'g.guestAppointment_doctor_id = d.doctor_id',
            'g.guestAppointment_appointmenttype_id = apt.appointmenttype_id',
            'g.guestAppointment_doctor_id = cd.cdoctor_doctor_id'
        );
    
        $jtype   = array("INNER","INNER","LEFT","INNER"); 

        $groupBy = array("guestAppointment_id");
        $data    = array('fields' => $fields, 'where' => $where,  'joinTables' =>$tables, 'joinFields' =>$jfields, 'joinTypes' => $jtype, 'limit' => $limit,'groupBy'=>$groupBy,'orderBy'=>$orderby);

        $guestappointmentDetails = $guestappointmentObj->getAllRecords($data);

        //print_r($guestappointmentDetails);exit;
        $recordsTotal   =   $guestappointmentObj->getAllCount($data);

        if ($guestappointmentDetails && count($guestappointmentDetails)>0){
            foreach ($guestappointmentDetails as $key => $guestappdata)
            {
                
                 
                $response[] = array(
                    "<b>Appoitment Id: </b>".$guestappdata->guestAppointment_id."<br/><b>Unique Id: </b>".$guestappdata->guestAppointment_unique_id."<br/><b>Clinic Id: </b>".$guestappdata->guestAppointment_clinic_id."<br/><b>Doctor Id: </b>".$guestappdata->guestAppointment_doctor_id."<br/><b>AppoitmentType Id: </b>".$guestappdata->guestAppointment_appointmenttype_id,

                    "<b>Clinic Id:
                     </b>".$guestappdata->clinic_id."<br/><b>Unique Id:
                     </b>".$guestappdata->clinic_unique_id."<br/><b>Clinic
                     Name: </b>".$guestappdata->clinic_name."<br/><b>Clinic
                     Phone: </b>".$guestappdata->clinic_phone."<br/><b>Clinic
                     Email: </b>".$guestappdata->clinic_email."<br/><br/><b>Doctor Id:
                     </b>".$guestappdata->cdoctor_doctor_id."<br/><b>Doctor
                     Provider:
                     </b>".$guestappdata->cdoctor_provider_id."<br/><b>Doctor
                     Fullname:
                     </b>".$guestappdata->cdoctor_fullname."<br/><b>Doctor
                     Email:
                     </b>".$guestappdata->cdoctor_email."<br/><b>Doctor
                     Phone: </b>".$guestappdata->cdoctor_phone,

                     "<b>First Name: </b>".$guestappdata->guestAppointment_pfname."<br/><b>Last Name: </b>".$guestappdata->guestAppointment_plname."<br/><b>Email: </b>".$guestappdata->guestAppointment_pemail."<br/><b>Phone: </b>".$guestappdata->guestAppointment_pphone."<br/><b>Dob: </b>".$guestappdata->guestAppointment_pdob."<br/><b>Gender: </b>".$guestappdata->guestAppointment_pgender,


                     $guestappdata->guestAppointment_date." ".$guestappdata->guestAppointment_time,
                     /*$guestappdata->appointment_status*/
                     //$more_detail_url
                   
                );
                
            }

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

    }else
    {
        $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";
        if($app_type != 'all_data')
        {
            $where = " appointment_status='".$app_type."' ";
        }

        if(isset($_REQUEST['unique_id']) && $_REQUEST['unique_id'] != '')
        {
            $where .= " AND appointment_unique_id = '".$_REQUEST['unique_id']."'";
        }
        if(isset($_REQUEST['clinic_id']) && $_REQUEST['clinic_id'] != '')
        {
            $where .= " AND  appointment_clinic_id = '".$_REQUEST['clinic_id']."' ";
        }
        if(isset($_REQUEST['dependant_id']) && $_REQUEST['dependant_id'] != '')
        {
            $where .= " AND  appointment_dependant_id = '".$_REQUEST['dependant_id']."' ";
        }
        if (isset($_REQUEST['start_date']) && $_REQUEST['start_date']!="" && isset($_REQUEST['end_date']) && $_REQUEST['end_date']!="" ){
            $where .= " AND  appointment_date BETWEEN '".$_REQUEST['start_date']."' AND '".$_REQUEST['end_date']."' ";
        }
        
        if (isset($_REQUEST['start_time']) && $_REQUEST['start_time']!="" && isset($_REQUEST['end_time']) && $_REQUEST['end_time']!="" )
        {
            
            $cstart_time = date("h:i A",strtotime($_REQUEST['start_time']));
            $cend_time = date("h:i A",strtotime($_REQUEST['end_time']));
            
            $where .= " AND  (STR_TO_DATE(guestAppointment_time, '%l:%i %p' ) >= STR_TO_DATE('".$cstart_time."', '%l:%i %p' ) AND STR_TO_DATE(guestAppointment_time, '%l:%i %p' ) <= STR_TO_DATE( '".$cend_time."', '%l:%i %p' ) ) ";
        }
        if(isset($_REQUEST['appointment_status']) && $_REQUEST['appointment_status'] != '')
        {
            $where .= " AND  appointment_status = '".$_REQUEST['appointment_status']."' ";
        }
        if(isset($_REQUEST['all_email']) && $_REQUEST['all_email'] != '')
        {
            $where .= " AND (clinic_email = '".$_REQUEST['all_email']."' OR cdoctor_email = '".$_REQUEST['all_email']."' OR patient_email_address = '".w::e($_REQUEST['all_email'])."' )";
        }
        if(isset($_REQUEST['all_phone']) && $_REQUEST['all_phone'] != '')
        {
            $where .= " AND (clinic_phone = '".$_REQUEST['all_phone']."' OR cdoctor_phone = '".$_REQUEST['all_phone']."' OR patient_phone = '".w::e($_REQUEST['all_phone'])."' )";
        }
        if(isset($_REQUEST['all_website']) && $_REQUEST['all_website'] != '')
        {
            $where .= " AND  clinic_website = '".$_REQUEST['all_website']."'";
        }
        if(isset($_REQUEST['patient_name']) && $_REQUEST['patient_name'] != '')
        {
           $patientname = preg_replace('/\s\s+/', ' ', $_REQUEST['patient_name']);
           $fullname = explode(" ", $patientname);
            if($fullname && count($fullname)>0)
            {
                $where ="";
                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))."%'";
                    if( ($key+1) != count($fullname) )
                    {
                            $where .=" OR ";
                    }
                }
            }
        }
        if(isset($_REQUEST['appointment_id']) && $_REQUEST['appointment_id'] != '')
        {
            $where .= " AND appointment_id = '".$_REQUEST['appointment_id']."'";
        }
        /*if(isset($_REQUEST['dependant_name']) && $_REQUEST['dependant_name'] != '')
        {
            $depentfullname = str_replace(' ', '', $_REQUEST['dependant_name']);
            $fullname = $_REQUEST['dependant_name'];   
            $where .= " AND CONCAT(dependant_fname,'',dependant_lname) LIKE '%".($fullname)."%'"; 
            $where .= " AND ('%".$depentfullname."%' LIKE Concat(Concat('%',dependant_fname),'%') 
                        OR '%".$depentfullname."%' LIKE  Concat(Concat('%',dependant_lname),'%'))";  
        }*/

    
        if (isset($_REQUEST['search']['value']) && $_REQUEST['search']['value']!=""){

            //OR cd.cdoctor_fullname LIKE '%".$_REQUEST['search']['value']."%' OR cd.cdoctor_provider_id LIKE '%".$_REQUEST['search']['value']."%' OR cd.cdoctor_doctor_id LIKE '%".$_REQUEST['search']['value']."%' OR cd.cdoctor_email LIKE '%".$_REQUEST['search']['value']."%' OR cd.cdoctor_phone LIKE '%".$_REQUEST['search']['value']."%'

            $where .= " AND (c.clinic_name LIKE '%".$_REQUEST['search']['value']."%' OR c.clinic_id LIKE '%".$_REQUEST['search']['value']."%' OR c.clinic_unique_id LIKE '%".$_REQUEST['search']['value']."%' OR c.clinic_phone LIKE '%".$_REQUEST['search']['value']."%' OR c.clinic_email LIKE '%".$_REQUEST['search']['value']."%' OR c.clinic_website LIKE '%".$_REQUEST['search']['value']."%' OR appointment_id LIKE '%".$_REQUEST['search']['value']."%' OR dep.dependant_fname LIKE '%".w::e($_REQUEST['search']['value'])."%' OR dep.dependant_lname LIKE '%".w::e($_REQUEST['search']['value'])."%' OR a.appointment_unique_id LIKE '%".$_REQUEST['search']['value']."%' OR a.appointment_clinic_id LIKE '%".$_REQUEST['search']['value']."%' OR a.appointment_doctor_id LIKE '%".$_REQUEST['search']['value']."%' OR a.appointment_dependant_id LIKE '%".$_REQUEST['search']['value']."%' OR a.appointment_appointmenttype_id LIKE '%".$_REQUEST['search']['value']."%' OR a.appointment_patient_id LIKE '%".$_REQUEST['search']['value']."%' OR p.patient_fname LIKE '%".w::e($_REQUEST['search']['value'])."%' OR p.patient_lname LIKE '%".w::e($_REQUEST['search']['value'])."%' OR p.patient_email_address LIKE '%".w::e($_REQUEST['search']['value'])."%' OR p.patient_phone LIKE '%".w::e($_REQUEST['search']['value'])."%' OR p.patient_unique_id LIKE '%".$_REQUEST['search']['value']."%' OR p.patient_id LIKE '%".$_REQUEST['search']['value']."%' OR a.appointment_status LIKE '%".$_REQUEST['search']['value']."%' OR a.appointment_date LIKE '%".$_REQUEST['search']['value']."%' OR a.appointment_time LIKE '%".$_REQUEST['search']['value']."%' OR dep.dependant_fname LIKE '%".w::e(ucfirst($_REQUEST['search']['value']))."%' OR dep.dependant_lname LIKE '%".w::e(ucfirst($_REQUEST['search']['value']))."%' OR dep.dependant_fname LIKE '%".w::e(ucwords($_REQUEST['search']['value']))."%' OR dep.dependant_lname LIKE '%".w::e(ucwords($_REQUEST['search']['value']))."%' OR p.patient_fname LIKE '%".w::e(ucfirst($_REQUEST['search']['value']))."%' OR p.patient_lname LIKE '%".w::e(ucfirst($_REQUEST['search']['value']))."%' OR p.patient_fname LIKE '%".w::e(ucwords($_REQUEST['search']['value']))."%' OR p.patient_lname LIKE '%".w::e(ucwords($_REQUEST['search']['value']))."%' OR p.patient_email_address LIKE '%".w::e(ucfirst($_REQUEST['search']['value']))."%' OR p.patient_email_address LIKE '%".w::e(ucwords($_REQUEST['search']['value']))."%' )";

        }    
        $orderFields = array('appointment_id','clinic_id','dependant_fname','patient_id');

        // 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{
            if($app_type == 'requested')
            {
                $orderby = array(" appointment_created_at ASC ");
            }else if($app_type == 'scheduled')
            {
                $orderby = array(" appointment_date ASC ");         
            }else if($app_type == 'completed')
            {
                $orderby = array(" appointment_date DESC ");            
            }else if($app_type == 'cancelled')
            {
                $orderby = array(" appointment_id DESC ");          
            }else if($app_type == 'all_data')
            {
                $orderby = array(" appointment_id DESC ");          
            }
        }

        //'cd.cdoctor_fullname','cd.cdoctor_doctor_id','cd.cdoctor_provider_id','cd.cdoctor_email','cd.cdoctor_phone'
        $fields  = array('a.*','c.clinic_name','c.clinic_id','c.clinic_unique_id','c.clinic_phone','c.clinic_email','c.clinic_website','dep.dependant_fname','dep.dependant_lname','apt.appointmenttype_name','p.patient_id','p.patient_unique_id','p.patient_fname','p.patient_lname','p.patient_email_address','p.patient_phone',
            'cd.cdoctor_fullname','cd.cdoctor_doctor_id','cd.cdoctor_provider_id','cd.cdoctor_email','cd.cdoctor_phone');
        $tables = array('tbl_clinic c','tbl_doctor d','tbl_dependant dep','tbl_appointmenttype apt','tbl_patient p','tbl_cdoctor cd');
        $jfields = array(
            'a.appointment_clinic_id = c.clinic_id',
            'a.appointment_doctor_id = d.doctor_id',
            'a.appointment_dependant_id = dep.dependant_id',
            'a.appointment_appointmenttype_id = apt.appointmenttype_id',
            'a.appointment_patient_id = p.patient_id',
            'a.appointment_doctor_id = cd.cdoctor_doctor_id'
        );
    
        $jtype   = array("INNER","INNER","INNER","LEFT","LEFT","INNER","INNER"); 

        $groupBy = array("appointment_id");
        $data    = array('fields' => $fields, 'where' => $where,  'joinTables' =>$tables, 'joinFields' =>$jfields, 'joinTypes' => $jtype, 'limit' => $limit,'groupBy'=>$groupBy,'orderBy'=>$orderby);

        $appointmentDetails = $appointmentObj->getAllRecords($data);

        //print_r($appointmentDetails);exit;
        $recordsTotal   =   $appointmentObj->getAllCount($data);

        if ($appointmentDetails && count($appointmentDetails)>0){
            foreach ($appointmentDetails as $key => $appRequested){
                
                //echo $appRequested['appointment_assignTo'];exit;
                if(!is_null($appRequested->appointment_assignTo))
                {

                    $patientObj =  new patient();
                    $where = 'patient_id IN ('.$appRequested->appointment_assignTo.')';
                    $patientArg    = array('where' => $where);
                    $patientDetails = $patientObj->getAllRecords($patientArg);
                    $assign_detail = '';
                    foreach ($patientDetails as $key => $patientData) 
                    {
                        $assign_detail .= "<b> ID : </b>".$patientData->patient_id."<br/><b>Unique Id : </b>".$patientData->patient_unique_id."<br/><b>First Name :</b>".w::d($patientData->patient_fname)."<br/><b>Last Name : </b>".w::d($patientData->patient_lname)."<br/><b>Email : </b>".w::d($patientData->patient_email_address)."<br/><b>Phone : </b>".w::d($patientData->patient_phone)."<br/><br/>";
                    }
                }

               /* if(isset($appRequested->appointment_doctor_id) && $appRequested->appointment_doctor_id != '')
                {
                    //'cd.cdoctor_fullname','cd.cdoctor_doctor_id','cd.cdoctor_provider_id','cd.cdoctor_email','cd.cdoctor_phone'
                    $cdoctorObj =  new cdoctor();
                    $where = 'cdoctor_doctor_id IN ('.$appRequested->appointment_doctor_id.')';
                    $cdoctorArg    = array('where' => $where);
                    $cdoctorDetails = $cdoctorObj->getAllRecords($cdoctorArg);
                    $doctor_detail = '';
                    foreach ($cdoctorDetails as $cdkey => $cdoctorDetailsData) 
                    {

                        $doctor_detail ="<br/><b>Doctor Id : </b>".$cdoctorDetailsData->cdoctor_doctor_id."<br/><b>Doctor Provider : </b>".$cdoctorDetailsData->cdoctor_provider_id."<br/><b>Doctor Fullname : </b>".$cdoctorDetailsData->cdoctor_fullname."<br/><b>Doctor Email : </b>".$cdoctorDetailsData->cdoctor_email."<br/><b>Doctor Phone : </b>".$cdoctorDetailsData->cdoctor_phone;
                    }
                }*/


                if($app_type == 'all_data')
                {
                    $more_detail_url = "<b><a href='appointmentdetail.php?type=all_data&appoint_id=".$appRequested->appointment_id."'>View</a></b>";
                }else{
                    $more_detail_url = "<b><a href='appointmentdetail.php?appoint_id=".$appRequested->appointment_id."'>View</a></b>";
                }
                
                if($app_type != 'requested')
                {

                    $response[] = array(
                        "<b>Appoitment Id: </b>".$appRequested->appointment_id."<br/><b>Unique Id: </b>".$appRequested->appointment_unique_id."<br/><b>Clinic Id: </b>".$appRequested->appointment_clinic_id."<br/><b>Doctor Id: </b>".$appRequested->appointment_doctor_id."<br/><b>Patient Id: </b>".$appRequested->appointment_patient_id."<br/><b>Dependant Id: </b>".$appRequested->appointment_dependant_id."<br/><b>AppoitmentType Id: </b>".$appRequested->appointment_appointmenttype_id,

                        "<b>Clinic Id: </b>".$appRequested->clinic_id."<br/><b>Unique Id: </b>".$appRequested->clinic_unique_id."<br/><b>Clinic Name: </b>".$appRequested->clinic_name."<br/><b>Clinic Phone: </b>".$appRequested->clinic_phone."<br/><b>Clinic Email: </b>".$appRequested->clinic_email."<br/><b>Clinic Website: </b>".$appRequested->clinic_website."<br/><b>Doctor Id: </b>".$appRequested->cdoctor_doctor_id."<br/><b>Doctor Provider: </b>".$appRequested->cdoctor_provider_id."<br/><b>Doctor Fullname: </b>".$appRequested->cdoctor_fullname."<br/><b>Doctor Email: </b>".$appRequested->cdoctor_email."<br/><b>Doctor Phone: </b>".$appRequested->cdoctor_phone,
                            

                        //."<br/><b>Clinic Name : </b>".$appRequested->clinic_name."<br/><b>Doctor Name : </b>".$appRequested->cdoctor_fullname."<br/><b>AppoitmentType : </b>".$appRequested->appointmenttype_name."<br/><b>Referral : </b>".$appRequested->appointment_referral
                        //$appRequested->appointment_unique_id,
                        "<b>First Name: </b>".w::d($appRequested->dependant_fname)."<br/><b>Last Name: </b>".w::d($appRequested->dependant_lname),

                        "<b>Id: </b>".$appRequested->patient_id."<br/><b>Unique Id: </b>".$appRequested->patient_unique_id."<br/><b>First Name: </b>".w::d($appRequested->patient_fname)."<br/><b>Last Name: </b>".w::d($appRequested->patient_lname)."<br/><b>Email: </b>".w::d($appRequested->patient_email_address)."<br/><b>Phone: </b>".w::d($appRequested->patient_phone),
                        $assign_detail,
                        $appRequested->appointment_date.' '.$appRequested->appointment_time,
                       // $appRequested->appointmenttype_name,
                        $appRequested->appointment_status,
                        $more_detail_url
                        //"<b><a href='appointmentdetail.php?appoint_id=".$appRequested->appointment_id."'>View</a></b>"
                    );
                    //$response = array_merge($response_data, $assign_detail); 
                    //print_r($response);exit;

                }else{

                    $response[] = array(
                        "<b>Appoitment Id: </b>".$appRequested->appointment_id."<br/><b>Unique Id: </b>".$appRequested->appointment_unique_id."<br/><b>Clinic Id: </b>".$appRequested->appointment_clinic_id."<br/><b>Doctor Id: </b>".$appRequested->appointment_doctor_id."<br/><b>Patient Id: </b>".$appRequested->appointment_patient_id."<br/><b>Dependant Id: </b>".$appRequested->appointment_dependant_id."<br/><b>AppoitmentType Id: </b>".$appRequested->appointment_appointmenttype_id,

                        "<b>Clinic Id: </b>".$appRequested->clinic_id."<br/><b>Unique Id: </b>".$appRequested->clinic_unique_id."<br/><b>Clinic Name: </b>".$appRequested->clinic_name."<br/><b>Clinic Phone: </b>".$appRequested->clinic_phone."<br/><b>Clinic Email: </b>".$appRequested->clinic_email."<br/><b>Clinic Website: </b>".$appRequested->clinic_website."<br/><b>Doctor Id: </b>".$appRequested->cdoctor_doctor_id."<br/><b>Doctor Provider: </b>".$appRequested->cdoctor_provider_id."<br/><b>Doctor Fullname: </b>".$appRequested->cdoctor_fullname."<br/><b>Doctor Email: </b>".$appRequested->cdoctor_email."<br/><b>Doctor Phone: </b>".$appRequested->cdoctor_phone,

                        //$appRequested->appointment_unique_id,
                        //"<br/><b>Clinic Name : </b>".$appRequested->clinic_name."<br/><b>Doctor Name : </b>".$appRequested->cdoctor_fullname."<br/><b>AppoitmentType : </b>".$appRequested->appointmenttype_name."<br/><b>Referral : </b>".$appRequested->appointment_referral
                        "<b>First Name: </b>".w::d($appRequested->dependant_fname)."<br/><b>Last Name: </b>".w::d($appRequested->dependant_lname),

                        "<b>Id: </b>".$appRequested->patient_id."<br/><b>Unique Id: </b>".$appRequested->patient_unique_id."<br/><b>First Name: </b>".w::d($appRequested->patient_fname)."<br/><b>Last Name: </b>".w::d($appRequested->patient_lname)."<br/><b>Email: </b>".w::d($appRequested->patient_email_address)."<br/><b>Phone: </b>".w::d($appRequested->patient_phone),

                        $assign_detail,
                        //$appRequested->appointmenttype_name,
                        $appRequested->appointment_status,
                        $more_detail_url
                        //"<b><a href='appointmentdetail.php?appoint_id=".$appRequested->appointment_id."'>View</a></b>"
                    );
                }
            }

            $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');
?>