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

if (isset($_REQUEST['act']) && $_REQUEST['act']=='getdata' && isset($_REQUEST['select_data']) && $_REQUEST['select_data']!='' )
{
    if($_REQUEST['select_data'] == '1')
    {
        $json = json_decode(file_get_contents(SITE_URL.'api_v2/guarantorsdata.json'));
        /*echo "<pre>";
        print_r($json[0]->guarantors[0]->items);
        echo "</pre>";*/
        $guarantor_data = $json[0]->guarantors[0]->items;

        foreach ($guarantor_data as $all_gurantors) 
        {
            
            $loadeddate_t = date("Y-m-d H:i:s", (strtotime(date($all_gurantors->loadeddate)) + '1'));
            $guarantors =array(
                      "guarantor_id"=>$all_gurantors->guarantor_id,
                      "guarantor_firstname"=>$all_gurantors->firstname,
                      "guarantor_lastname"=>$all_gurantors->lastname,
                      "guarantor_birthdate"=>$all_gurantors->birthdate,
                      "guarantor_phone"=>$all_gurantors->phone,
                      "guarantor_workphone"=>$all_gurantors->workphone,
                      "guarantor_cell"=>$all_gurantors->cell,
                      "guarantor_email"=>$all_gurantors->email,
                      "guarantor_loadeddate"=>$loadeddate_t,
                      "guarantor_flag"=>$all_gurantors->flag,
                      "guarantor_gender"=>$all_gurantors->gender,
                      "guarantor_changes"=>$all_gurantors->changes
                    );
            echo json_encode($guarantors);
            exit;
               
        }
    }else if($_REQUEST['select_data'] == '2')
    {
        $json = json_decode(file_get_contents(SITE_URL.'api_v2/patientdata.json'));
        /*echo "<pre>";
        print_r($json[0]->guarantors[0]->items);
        echo "</pre>";*/
        $patient_data = $json[0]->patients[0]->items;

        foreach ($patient_data as $all_patient) 
        {
            
            $loadeddate_t = date("Y-m-d H:i:s", (strtotime(date($all_patient->loadeddate)) + '1'));
            $patients =array(
                      "patient_id" =>$all_patient->patient_id,
                      "guarantor_id"=>$all_patient->guarantor_id,
                      "guarantor_firstname"=>$all_patient->firstname,
                      "guarantor_lastname"=>$all_patient->lastname,
                      "guarantor_birthdate"=>$all_patient->birthdate,
                      "homephone"=>$all_patient->homephone,
                      "guarantor_workphone"=>$all_patient->workphone,
                      "guarantor_cell"=>$all_patient->cell,
                      "guarantor_email"=>$all_patient->email,
                      "guarantor_loadeddate"=>$loadeddate_t,
                      "guarantor_flag"=>$all_patient->flag,
                      "guarantor_gender"=>$all_patient->gender,
                      "guarantor_changes"=>$all_patient->changes
                    );
            echo json_encode($patients);
            exit;
               
        }
    }else if($_REQUEST['select_data'] == '3')
    {
        $json = json_decode(file_get_contents(SITE_URL.'api_v2/data.json'));
        /*echo "<pre>";
        print_r($json[0]->guarantors[0]->items);
        echo "</pre>";*/
        $appointment_data = $json[0]->appointments[0]->items;

        foreach ($appointment_data as $all_appointment) 
        {
            
            $loadeddate_t = date("Y-m-d H:i:s", (strtotime(date($all_appointment->loadeddate)) + '1'));
            $appointments =array(
                      "patient_id" =>$all_appointment->patient_id,
                      "guarantor_id"=>$all_appointment->guarantor_id,
                      "appointment_sr_no"=>$all_appointment->appointment_sr_no,
                      "provider_id"=>$all_appointment->provider_id,
                      "app_date"=>$all_appointment->date,
                      "app_time"=>$all_appointment->time,
                      "app_length"=>$all_appointment->length,
                      "app_amount"=>$all_appointment->amount,
                      "app_status"=>$all_appointment->status,
                      "guarantor_loadeddate"=>$loadeddate_t,
                      "guarantor_flag"=>$all_appointment->flag,
                      "guarantor_changes"=>$all_appointment->changes
                    );
            //print_r($appointments);exit;
            echo json_encode($appointments);
            exit;
               
        }
    }else{
        $all_data = array();
        echo json_encode($all_data);
            exit;
    }
    
}




if (isset($_REQUEST['act']) && $_REQUEST['act']=='load' && isset($_REQUEST['select_data']) && $_REQUEST['select_data'] != '')
{
        $search_data = $_REQUEST['select_data'];
        if($search_data == '1')
        {
            $json = json_decode(file_get_contents(SITE_URL.'api_v2/guarantorsdata.json'),1);
    
            $data = $json[0]['guarantors'];
            $guarantors = $data[0]['items'][0];
            $guarantors['changes'] = array();

            $guarantor_id = $_REQUEST['manual_guarantor_id'];
        }
        if($search_data == '2')
        {
            $json = json_decode(file_get_contents(SITE_URL.'api_v2/patientdata.json'),1);
    
            $data = $json[0]['patients'];
            $patients = $data[0]['items'][0];
            $patients['changes'] = array();

            $patient_id = $_REQUEST['manual_patient_id'];
            $homephone = $_REQUEST['homephone'];
            $guarantor_id = $_REQUEST['manual_patientguarantor_id'];
        }
        if($search_data == '3')
        {
            $json = json_decode(file_get_contents(SITE_URL.'api_v2/data.json'),1);
    
            $data = $json[0]['appointments'];
            $appointments = $data[0]['items'][0];
            $appointments['changes'] = array();

            $patient_id = $_REQUEST['manual_apppatient_id'];
            $appointment_sr_no = $_REQUEST['appointment_sr_no'];
            $provider_id = $_REQUEST['provider_id'];
            $app_date = $_REQUEST['app_date'];
            $app_time = $_REQUEST['app_time'];
            $app_length = $_REQUEST['app_length'];
            $app_amount = $_REQUEST['app_amount'];
            $app_status = $_REQUEST['app_status'];
        }

        
        $firstname = $_REQUEST['manual_guarantor_fname'];
        $lastname = $_REQUEST['manual_guarantor_lname'];
        $birthdate = $_REQUEST['manual_birthdate'];
        $phone = $_REQUEST['manual_phone'];
        $workphone = $_REQUEST['manual_workphone'];
        $cell = $_REQUEST['manual_cell'];
        $email_address = $_REQUEST['manual_email_address'];
        $loadeddate = $_REQUEST['manual_loadedate'];
        $flag = $_REQUEST['manual_flag'];
        $gender = $_REQUEST['manual_gender'];


        if($flag == 'updated')
        {

            if(isset($_REQUEST['othermanual_guarantor_id']) && $_REQUEST['othermanual_guarantor_id'] != '')
            {
                

                $changes_gurantor[] = array("field"=>"guarantorid",
                                        "oldvalue"=>$_REQUEST['othermanual_guarantor_id'],
                                        "newvalue"=>$_REQUEST['othermanual_guarantor_id']);
                
            }
            if(isset($_REQUEST['othermanual_guarantor_fname']) && $_REQUEST['othermanual_guarantor_fname'] != '')
            {
      
                $changes_gurantor[] = array("field"=>"firstname",
                                        "oldvalue"=>$_REQUEST['othermanual_guarantor_fname'],
                                        "newvalue"=>$_REQUEST['othermanual_guarantor_fname']);
                
            }
            if(isset($_REQUEST['othermanual_guarantor_lname']) && $_REQUEST['othermanual_guarantor_lname'] != '')
            {
                
                $changes_gurantor[] = array("field"=>"lastname",
                                        "oldvalue"=>$_REQUEST['othermanual_guarantor_lname'],
                                        "newvalue"=>$_REQUEST['othermanual_guarantor_lname']);
                
            }
            if(isset($_REQUEST['othermanual_birthdate']) && $_REQUEST['othermanual_birthdate'] != '')
            {
      
                $changes_gurantor[] = array("field"=>"birthdate",
                                        "oldvalue"=>$_REQUEST['othermanual_birthdate'],
                                        "newvalue"=>$_REQUEST['othermanual_birthdate']);
                
            }
            if(isset($_REQUEST['othermanual_phone']) && $_REQUEST['othermanual_phone'] != '')
            {
      
                $changes_gurantor[] = array("field"=>"phone",
                                        "oldvalue"=>$_REQUEST['othermanual_phone'],
                                        "newvalue"=>$_REQUEST['othermanual_phone']);
                
            }
            if(isset($_REQUEST['othermanual_workphone']) && $_REQUEST['othermanual_workphone'] != '')
            {
      
                $changes_gurantor[] = array("field"=>"workphone",
                                        "oldvalue"=>$_REQUEST['othermanual_workphone'],
                                        "newvalue"=>$_REQUEST['othermanual_workphone']);
                
            }
            if(isset($_REQUEST['otehrmanual_cell']) && $_REQUEST['otehrmanual_cell'] != '')
            {
      
                $changes_gurantor[] = array("field"=>"cell",
                                        "oldvalue"=>$_REQUEST['otehrmanual_cell'],
                                        "newvalue"=>$_REQUEST['otehrmanual_cell']);
                
            }
            if(isset($_REQUEST['othermanual_email_address']) && $_REQUEST['othermanual_email_address'] != '')
            {
      
                $changes_gurantor[] = array("field"=>"email",
                                        "oldvalue"=>$_REQUEST['othermanual_email_address'],
                                        "newvalue"=>$_REQUEST['othermanual_email_address']);
                
            }
            if(isset($_REQUEST['othermanual_homephone']) && $_REQUEST['othermanual_homephone'] != '')
            {
      
                $changes_gurantor[] = array("field"=>"homephone",
                                        "oldvalue"=>$_REQUEST['othermanual_homephone'],
                                        "newvalue"=>$_REQUEST['othermanual_homephone']);
                
            }

            if(isset($_REQUEST['othermanual_provider_id']) && $_REQUEST['othermanual_provider_id'] != '')
            {
      
                $changes_gurantor[] = array("field"=>"provider_id",
                                        "oldvalue"=>$_REQUEST['othermanual_provider_id'],
                                        "newvalue"=>$_REQUEST['othermanual_provider_id']);
                
            }
            if(isset($_REQUEST['othermanual_appstatus']) && $_REQUEST['othermanual_appstatus'] != '')
            {
      
                $changes_gurantor[] = array("field"=>"status",
                                        "oldvalue"=>$_REQUEST['othermanual_appstatus'],
                                        "newvalue"=>$_REQUEST['othermanual_appstatus']);
                
            }
            if(isset($_REQUEST['othermanual_appdate']) && $_REQUEST['othermanual_appdate'] != '')
            {
      
                $changes_gurantor[] = array("field"=>"date",
                                        "oldvalue"=>$_REQUEST['othermanual_appdate'],
                                        "newvalue"=>$_REQUEST['othermanual_appdate']);
                
            }
            if(isset($_REQUEST['othermanual_apptime']) && $_REQUEST['othermanual_apptime'] != '')
            {
      
                $changes_gurantor[] = array("field"=>"time",
                                        "oldvalue"=>$_REQUEST['othermanual_apptime'],
                                        "newvalue"=>$_REQUEST['othermanual_apptime']);
                
            }
            if(isset($_REQUEST['othermanual_amount']) && $_REQUEST['othermanual_amount'] != '')
            {
      
                $changes_gurantor[] = array("field"=>"amount",
                                        "oldvalue"=>$_REQUEST['othermanual_amount'],
                                        "newvalue"=>$_REQUEST['othermanual_amount']);
                
            }
            if(isset($_REQUEST['othermanual_patientguarantor']) && $_REQUEST['othermanual_patientguarantor'] != '')
            {
              $changes_gurantor[] = array("field"=>"guarantorid",
                                        "oldvalue"=>$_REQUEST['othermanual_patientguarantor'],
                                        "newvalue"=>$_REQUEST['othermanual_patientguarantor']);
              
            }
        }else
        {
            $changes_gurantor = array();
        }
        //print_r($changes_gurantor);exit;
        if($search_data == '1')
        {
            if($flag == 'Added')
            {
                $guarantorsrnoData = array(
                "manual_entry_sr_no" =>$guarantor_id,
                "manual_entry_type" =>"guranoters"
                );
                $rs = $manualentry_appoinmentObj->addRecords($guarantorsrnoData);
            }

            $replacementData = array('guarantor_id' => $guarantor_id,'firstname' => $firstname,'lastname' => $lastname,'birthdate' => $birthdate,'phone' => $phone,'workphone' => $workphone,'cell' => $cell,'email' => $email_address,'loadeddate' => $loadeddate,'flag' => $flag,'gender' => $gender,"changes"=>$changes_gurantor);
            $newArrayData = array_replace_recursive($guarantors, $replacementData);
            //print_r($newArrayData);exit;
            $json[0]['guarantors'][0]['items'][0] = $newArrayData;
            file_put_contents('../api_v2/guarantorsdata.json', json_encode($json));
        }

        if($search_data == '2')
        {

            if($flag == 'Added')
            {
                $patientsrnoData = array(
                "manual_entry_sr_no" =>$patient_id,
                "manual_entry_type" =>"patient"
                );
                $rs = $manualentry_appoinmentObj->addRecords($patientsrnoData);
            }

            $replacementData = array('patient_id' => $patient_id,'guarantor_id' => $guarantor_id,'firstname' => $firstname,'lastname' => $lastname,'birthdate' => $birthdate,'workphone' => $workphone,'homephone'=> $homephone,'cell' => $cell,'email' => $email_address,'loadeddate' => $loadeddate,'flag' => $flag,'gender' => $gender,"changes"=>$changes_gurantor);
            $newArrayData = array_replace_recursive($patients, $replacementData);
            //print_r($newArrayData);exit;
            $json[0]['patients'][0]['items'][0] = $newArrayData;
            file_put_contents('../api_v2/patientdata.json', json_encode($json));
        }

        if($search_data == '3')
        {
            if($flag == 'Added')
            {
                $appoinmnetsrnoData = array(
                "manual_entry_sr_no" =>$appointment_sr_no,
                "manual_entry_type" =>"appointments"
                );
                $rs = $manualentry_appoinmentObj->addRecords($appoinmnetsrnoData);
            }
            
            $replacementData = array('patient_id' => $patient_id,'guarantor_id' => $guarantor_id,'appointment_sr_no' => $appointment_sr_no,'provider_id' => $provider_id,'date' => $app_date,'time' => $app_time,'length'=> $app_length,'amount'=> $app_amount,'status'=> $app_status,'loadeddate' => $loadeddate,'flag' => $flag,"changes"=>$changes_gurantor,'description' => '');
            //print_r($replacementData);exit;
            $newArrayData = array_replace_recursive($appointments, $replacementData);
            $json[0]['appointments'][0]['items'][0] = $newArrayData;
            //print_r($json);exit;
            file_put_contents('../api_v2/data.json', json_encode($json));
        }
        

        //print_r($replacementData);exit;
        
        /*print(json_encode($newArrayData, JSON_PRETTY_PRINT));
        exit;*/
        //print_r($json);exit;
        //exit;
        if(isset($_REQUEST['clinic_id']) && $_REQUEST['clinic_id'] != '')
        {
             if($search_data == '1')
             {
                 $endpoint = SITE_URL.'cron/fetchNewGuarantors.php?id='.$_REQUEST['clinic_id'];
             }else if($search_data == '2')
             {
                 $endpoint = SITE_URL.'cron/fetchNewPatients.php?id='.$_REQUEST['clinic_id'];
             }
             else if($search_data == '3')
             {
                 $endpoint = SITE_URL.'cron/fetchNewAppointments.php?id='.$_REQUEST['clinic_id'];
             } 
        }
        

        /*if(isset($_REQUEST['clinic_id']) && $_REQUEST['clinic_id'] != '')
        {
             $clinic_id = $_REQUEST['clinic_id'];
             if($search_data == '1')
             {
                 $endpoint = SITE_URL.'cron/fetchNewGuarantors.php';
             }else if($search_data == '2')
             {
                 $endpoint = SITE_URL.'cron/fetchNewPatients.php';
             }

             $data = array(
                        "id" => $clinic_id 
                    );
                $url = $endpoint . '?' . http_build_query($data);
                $curl = curl_init();
                curl_setopt_array($curl, array(
                  CURLOPT_URL => $url,
                  CURLOPT_RETURNTRANSFER => true,
                  CURLOPT_ENCODING => "",
                  CURLOPT_MAXREDIRS => 10,
                  CURLOPT_TIMEOUT => 0,
                  CURLOPT_FOLLOWLOCATION => true,
                  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
                  CURLOPT_CUSTOMREQUEST => "GET",
                ));
                $response = curl_exec($curl);
                curl_close($curl);
                return $response;
        }*/

        echo json_encode(array("msg" => "successd","clinic_id"=>$_REQUEST['clinic_id'],"SITE_URL"=>$endpoint));
        exit;
}

if(isset($_REQUEST['act']) && $_REQUEST['act'] == 'getdependant' && isset($_REQUEST['search_patient']) && $_REQUEST['search_patient'] != '')
{
    $dependantObj = new dependant();
    $fields = array('dependant_id','dependant_fname','dependant_lname','dependant_email_address','dependant_phone','dependant_guarantor_id');
    $fullname = explode(" ", trim($_REQUEST['search_patient']));
    $tables = array('tbl_clinic_patient c');
    $jfields = array('c.clinic_patient_depid=d.dependant_id');
    $jtype   = array("INNER"); 
    if($fullname && count($fullname)>0){
        $where ="clinic_patient_cid='".$_REQUEST['clinic_id']."' AND ( ";
        foreach ($fullname as $key => $f) {
            /*$where .=" dependant_fname LIKE '%".($f)."%' OR dependant_fname LIKE '%".(ucfirst($f))."%'  OR dependant_lname LIKE '%".($f)."%' OR dependant_lname LIKE '%".(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,  'joinTables' =>$tables, 'joinFields' =>$jfields, 'joinTypes' => $jtype);
    $alldependant = $dependantObj->getAllRecords($dependantArg);
    //print_r($alldependant);exit;
    if(isset($alldependant) && count($alldependant) > 0)
    {
        foreach ($alldependant as $dkey => $dependantvalue) 
        {

            //$dependantfullname = ($dependantvalue->dependant_fname)." ".($dependantvalue->dependant_lname);

            $patientObj = new patient();
            $fields = array('patient_id','patient_fname','patient_lname');
            $where = "patient_id='".$dependantvalue->dependant_guarantor_id."'";
            $patientArg    = array('fields'=>$fields,'where' => $where);
            $allpatient = $patientObj->fromFields($patientArg);
            if($allpatient)
            {
                $guranoter = w::d($allpatient->patient_fname)." ".w::d($allpatient->patient_lname);
            }

            $dependantfullname = w::d($dependantvalue->dependant_fname)." ".w::d($dependantvalue->dependant_lname);
            $all_data = '<div class="col-md-3"><input type="radio"  name="dependant_name" id="dependant_name" onclick="getdependant_data('.$dependantvalue->dependant_id.')" /> &nbsp;&nbsp;<span> '.$dependantfullname.' </span><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span>'.w::d($dependantvalue->dependant_email_address).'</span><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span>'.w::d($dependantvalue->dependant_phone).'</span><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span>'.$guranoter.'</span></div>' ;
            
            $response[] =(
                      $all_data
                    );
            
        }
        
        $result=array('dependant'=>$response);
    }else{
        $result=array('dependant'=>array());
    }
    echo json_encode($result);
    exit;
    
}

if(isset($_REQUEST['act']) && $_REQUEST['act'] == 'searchdependantId' && isset($_REQUEST['depId']) && $_REQUEST['depId'])
{
    $dependantObj = new dependant();
    $fields = array('dependant_id','dependant_fname','dependant_lname','dependant_phone','dependant_gender','dependant_dob','dependant_email_address');
    $where = "dependant_id='".$_REQUEST['depId']."'";
    $dependantArg    = array('fields'=>$fields,'where' => $where);
    $alldependant = $dependantObj->fromFields($dependantArg);
    //print_r($alldependant);exit;
    if(isset($alldependant))
    {
        $dep_gender = "";
        if($alldependant->dependant_gender == 'Male')
        {
            $dep_gender = 'M';
        }else if($alldependant->dependant_gender == 'Female')
        {
            $dep_gender = 'F';
        }
        
        $response =array(
                  "dependant_id"=>$alldependant->dependant_id,
                  "dependant_fname"=>w::d($alldependant->dependant_fname),
                  "dependant_lname"=>w::d($alldependant->dependant_lname),
                  "dependant_email_address"=>w::d($alldependant->dependant_email_address),
                  "dependant_phone"=>w::d($alldependant->dependant_phone),
                  "dependant_gender"=>$dep_gender,
                  "dependant_dob"=>w::d($alldependant->dependant_dob),

                );
        $result=array('dependant'=>$response);
    }else{
        $result=array('dependant'=>array());
    }
    echo json_encode($result);
    exit;
}

if(isset($_REQUEST['act']) && $_REQUEST['act'] == 'getappoinmnet' && isset($_REQUEST['clinic_id']) && $_REQUEST['clinic_id'])
{
    $pmsappointmentObj = new pmsAppointment();
    //$pmsappointmentObj = new pmsappointment();

    $fields = array('p.pmsAppointment_id','p.pmsAppointment_sr_no','pmsp.pmsPatient_patient_id','pmsp.pmsPatient_fname','pmsp.pmsPatient_lname','pmsp.pmsPatient_email','pmsp.pmsPatient_cell','pmsp.pmsAppointment_date','pmsp.pmsAppointment_time');
    $tables = array('tbl_pmsPatient pmsp');
    $jfields = array('pmsp.pmsPatient_patient_id = p.pmsAppointment_patient_id');
    $jtype   = array("INNER");
    $where = "pmsp.pmsPatient_clinic_id='".$_REQUEST['clinic_id']."' AND pmsp.pmsPatient_patient_id='".$_REQUEST['apppatientid']."'  AND p.pmsAppointment_sr_no LIKE '%XRA%' ";
    $orderby = array(" pmsAppointment_sr_no ASC ");
    $pmsappointmentArg   = array('where' => $where,  'joinTables' =>$tables, 'joinFields' =>$jfields, 'joinTypes' => $jtype,'orderBy'=>$orderby);
    //$pmsappointmentArg    = array('fields'=>$fields,'where' => $where, 'orderBy'=>$orderby);
    $pmsappointment = $pmsappointmentObj->getAllRecords($pmsappointmentArg);
    //print_r($pmsappointment);exit;
    if(isset($pmsappointment) && count($pmsappointment) > 0)
    {
        $all_data = "";
        foreach ($pmsappointment as $dkey => $pmsappointmentvalue) 
        {

            $fullname = $pmsappointmentvalue->pmsPatient_fname.' '.$pmsappointmentvalue->pmsPatient_lname.' '.$pmsappointmentvalue->pmsPatient_patient_id;

            $all_data = '<div class="col-md-3"><input type="radio"  name="appoinmnet_name" id="appoinmnet_name" onclick="getappoinment_data('.$pmsappointmentvalue->pmsAppointment_id.')" /> &nbsp;&nbsp;<span> '.$pmsappointmentvalue->pmsAppointment_sr_no.' </span><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span>'.$fullname.'</span><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span>'.$pmsappointmentvalue->pmsPatient_email.'</span><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span>'.$pmsappointmentvalue->pmsPatient_cell.'</span><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span>'.date('Y-m-d',strtotime($pmsappointmentvalue->pmsAppointment_date)).' - '.date('g:i A', strtotime($pmsappointmentvalue->pmsAppointment_time)).'</span></div>' ;
            
            
            $response[] =(
                      $all_data
                    );
            
        }
        
        $result=array('appointments'=>$response);
    }else{
        $result=array('appointments'=>array());
    }
    echo json_encode($result);
    exit;
}

if(isset($_REQUEST['act']) && $_REQUEST['act'] == 'getappoinmnetId' && isset($_REQUEST['pmsAppoinmnetId']) && $_REQUEST['pmsAppoinmnetId'])
{
    $pmsappointmentObj = new pmsAppointment();
    //$pmsappointmentObj = new pmsappointment();
    $fields = array('pmsAppointment_id','pmsAppointment_sr_no','pmsAppointment_patient_id','pmsAppointment_provider_id','pmsAppointment_date','pmsAppointment_time','pmsAppointment_length','pmsAppointment_amount','pmsAppointment_status');
    $where = "pmsAppointment_id='".$_REQUEST['pmsAppoinmnetId']."'";
    
    $pmsappointmentArg    = array('fields'=>$fields,'where' => $where);
    $pmsappointment = $pmsappointmentObj->fromFields($pmsappointmentArg);
    //print_r($pmsappointment);exit;
    if(isset($pmsappointment))
    {
        
        $response =array(
                  "pmsAppointment_sr_no"=>$pmsappointment->pmsAppointment_sr_no,
                  "pmsAppointment_patient_id"=>$pmsappointment->pmsAppointment_patient_id,
                  "pmsAppointment_provider_id"=>$pmsappointment->pmsAppointment_provider_id,
                  "pmsAppointment_date"=>$pmsappointment->pmsAppointment_date,
                  "pmsAppointment_time"=>$pmsappointment->pmsAppointment_time,
                  "pmsAppointment_length"=>$pmsappointment->pmsAppointment_length,
                  "pmsAppointment_amount"=>$pmsappointment->pmsAppointment_amount,
                  "pmsAppointment_status"=>$pmsappointment->pmsAppointment_status,

                );
        $result=array('appointmentdata'=>$response);
    }else{
        $result=array('appointmentdata'=>array());
    }
    echo json_encode($result);
    exit;
}
    
$fields = array('p.*','c.clinic_name','c.clinic_id');
$tables = array('tbl_clinic c');
$jfields = array('c.clinic_id = p.practice_xcare_id');
$jtype   = array("INNER"); 
$where = array();
$practicArg    = array('fields'=>$fields,'where' => $where,  'joinTables' =>$tables, 'joinFields' =>$jfields, 'joinTypes' => $jtype);
$allClinic = $practiceObj->getAllRecords($practicArg);


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