load->database(); } public function getSum($field, $table) { $this->db->select_sum($field); $query = $this->db->get($table); return $query->result(); } public function activity_log($data){ $this->db->insert('audit_log', $data); // die; } public function get_dashboard_menu() { $dashboardMenu=array(); $caregiversData=$this->getCaregiversData(); $patientsData=$this->getPatientsData(); $physiciansData=$this->getPhysiciansData(); $coordinatorsData=$this->getCoordinatorsData(); $dashboardMenu=array( 'caregivers'=>$caregiversData, 'patients'=>$patientsData, 'physicians'=>$physiciansData, 'coordinators'=>$coordinatorsData, ); return $dashboardMenu; } private function getCaregiversData() { $this->db->select('*'); $this->db->from('caregiver'); $this->db->where(array('verification_status' => "verified")); $query=$this->db->get(); $rows=$query->num_rows(); // return $query->result(); return $rows; } private function getPatientsData() { $this->db->select('*'); $this->db->from('patient_details'); $this->db->where(array('active_status' => 1)); $query = $this->db->get(); $rows=$query->num_rows(); // return $query->result(); return $rows; } private function getPhysiciansData() { $this->db->select('*'); $this->db->from('physician'); $this->db->where(array('verification_status' => "verified")); $query = $this->db->get(); $rows=$query->num_rows(); // return $query->result(); return $rows; } private function getCoordinatorsData() { $this->db->select('*'); $this->db->from('coordinator'); $this->db->where(array('status' => 1)); $query = $this->db->get(); $rows=$query->num_rows(); // return $query->result(); return $rows; } public function get_menu($user_id){ $this->db->select('a.name'); $this->db->from('groups a'); $this->db->join('users_groups b', 'b.group_id = a.id', 'left'); $this->db->where('b.user_id', $user_id); $data = $this->db->get()->row(); $group =$data->name; //print_r($group);die; if($group=='Caregiver') { $accessMatrix = $this->__caregiverAccessMatrix($group,$user_id); } else if($group=='Physician') { //echo "phy"; $accessMatrix = $this->__physicianAccessMatrix($group,$user_id); //echo '
'; print_r($accessMatrix); echo '';die; // die; } else if($group=='Patient') { $accessMatrix = $this->__patientAccessMatrix($group,$user_id); // die("1"); } else { $accessMatrix = $this->__codinatorAccessMatrix($group,$user_id); } return $accessMatrix; } private function __codinatorAccessMatrix($group,$user_id) { $accessableMenu = array(); $mainCounter = 0; $this->db->order_by('menu_order', 'asc'); $mainmenu = $this->db->get_where('permissions', array('parent_id' => 0,'status'=>'1'))->result(); foreach ($mainmenu as $menu) { $accessableChildren = array(); $childrenCount = 0; $this->db->order_by('menu_order', 'asc'); $children = $this->db->get_where('permissions', array('parent_id' => $menu->id,'status'=>'1'))->result(); foreach($children as $child) { $accessableChildren[$childrenCount]['ID'] = $child->id; $accessableChildren[$childrenCount]['TEXT'] = $child->name; $accessableChildren[$childrenCount]['URL'] = $child->url; $accessableChildren2 = array(); $childrenCount2 = 0; $this->db->order_by('menu_order', 'asc'); $child2=$this->db->get_where('permissions', array('parent_id' => $child->id,'status'=>'1'))->result(); foreach($child2 as $c2) { $accessableChildren2[$childrenCount2]['ID'] = $c2->id; $accessableChildren2[$childrenCount2]['TEXT'] = $c2->name; $accessableChildren2[$childrenCount2]['URL'] = $c2->url; $accessableChildren3 = array(); $childrenCount3 = 0; $this->db->order_by('menu_order', 'asc'); $child3=$this->db->get_where('permissions', array('parent_id' => $c2->id,'status'=>'1'))->result(); foreach($child3 as $c3) { $accessableChildren3[$childrenCount3]['ID'] = $c3->id; $accessableChildren3[$childrenCount3]['TEXT'] = $c3->name; $accessableChildren3[$childrenCount3]['URL'] = $c3->url; $childrenCount3++; } $accessableChildren2[$childrenCount2]['CHILDREN'] = $accessableChildren3; $childrenCount2++; } $accessableChildren[$childrenCount]['CHILDREN'] = $accessableChildren2; $childrenCount++; } $accessableMenu['MAIN'][$mainCounter]['ID'] = $menu->id; $accessableMenu['MAIN'][$mainCounter]['TEXT'] = $menu->name; $accessableMenu['MAIN'][$mainCounter]['URL'] = $menu->url; $accessableMenu['MAIN'][$mainCounter]['Menu_Icon'] = $menu->menu_icon; $accessableMenu['MAIN'][$mainCounter]['CHILDREN'] = $accessableChildren; $mainCounter++; } // _die($accessableMenu['MAIN']); $accessMenu = array(); foreach($accessableMenu['MAIN'] as $mainId=>$main) { $pass = true; $pass = (count($main['CHILDREN'])>0)?$this->ion_auth->coordinator_permission($main['URL']):true; $pass = $this->ion_auth->coordinator_permission($main['URL']); $pass = ($group ==='admin')?true:$pass; if($pass===true) { foreach($main['CHILDREN'] as $childId=>$child) { $pass = true; $pass = $this->ion_auth->coordinator_permission($child['URL']); $pass = ($group ==='admin')?true:$pass; if($pass) { foreach($child['CHILDREN'] as $grandChildId=>$grandChild) { $pass = true; $pass = $this->ion_auth->coordinator_permission($grandChild['URL']); $pass = ($group ==='admin')?true:$pass; if($pass) { foreach($grandChild['CHILDREN'] as $greatgrandChildId=>$greatgrandChild) { $pass = true; $pass = $this->ion_auth->coordinator_permission($grandChild['URL']); $pass = ($group ==='admin')?true:$pass; if($pass) { $accessMenu['MAIN'][$mainId]['CHILDREN'][$childId]['CHILDREN'][$grandChildId]['CHILDREN'][$greatgrandChildId]['NAME'] = $greatgrandChild['TEXT']; $accessMenu['MAIN'][$mainId]['CHILDREN'][$childId]['CHILDREN'][$grandChildId]['CHILDREN'][$greatgrandChildId]['URL'] = $greatgrandChild['URL']; } } $accessMenu['MAIN'][$mainId]['CHILDREN'][$childId]['CHILDREN'][$grandChildId]['NAME'] = $grandChild['TEXT']; $accessMenu['MAIN'][$mainId]['CHILDREN'][$childId]['CHILDREN'][$grandChildId]['URL'] = $grandChild['URL']; } } $accessMenu['MAIN'][$mainId]['CHILDREN'][$childId]['NAME'] = $child['TEXT']; $accessMenu['MAIN'][$mainId]['CHILDREN'][$childId]['URL'] = $child['URL']; } } $accessMenu['MAIN'][$mainId]['NAME'] = $main['TEXT']; $accessMenu['MAIN'][$mainId]['URL'] = $main['URL']; $accessMenu['MAIN'][$mainId]['Menu_Icon'] = $main['Menu_Icon']; } } return $accessMenu; } private function __caregiverAccessMatrix($group,$user_id) { //echo $user_id; $this->db->where('ion_user_id', $user_id); $caregiver_dtl = $this->db->get('caregiver')->row(); $caregiver_menu = $this->db->order_by("menu_order", "asc")->get_where('caregiver_menu',array('parent_id' => '0','status'=>'1'))->result(); //echo '
'; print_r($caregiver_menu); echo '';die; $accessMenu=array(); $i=0; foreach($caregiver_menu as $menu){ $caregiver_child_menu = $this->db->order_by("menu_order", "asc")->get_where('caregiver_menu',array('parent_id' => $menu->id,'status'=>'1'))->result(); $Children = array(); $childrenCount = 0; foreach($caregiver_child_menu as $child){ if($caregiver_dtl->verification_status=='unverified' && $child->menu_for=='unverified'){ $accessMenu['MAIN'][$i]['CHILDREN'][$childrenCount]['NAME'] = $child->name; $accessMenu['MAIN'][$i]['CHILDREN'][$childrenCount]['URL'] = $child->url; $accessMenu['MAIN'][$i]['CHILDREN'][$childrenCount]['Menu_Icon'] = $child->menu_icon; $childrenCount++; }else if($caregiver_dtl->verification_status=='verified' && $child->menu_for=='verified'){ $accessMenu['MAIN'][$i]['CHILDREN'][$childrenCount]['NAME'] = $child->name; $accessMenu['MAIN'][$i]['CHILDREN'][$childrenCount]['URL'] = $child->url; $accessMenu['MAIN'][$i]['CHILDREN'][$childrenCount]['Menu_Icon'] = $child->menu_icon; $childrenCount++; }else if($child->menu_for=='all'){ $accessMenu['MAIN'][$i]['CHILDREN'][$childrenCount]['NAME'] = $child->name; $accessMenu['MAIN'][$i]['CHILDREN'][$childrenCount]['URL'] = $child->url; $accessMenu['MAIN'][$i]['CHILDREN'][$childrenCount]['Menu_Icon'] = $child->menu_icon; $childrenCount++; } } if($caregiver_dtl->verification_status=='unverified' && $menu->menu_for=='unverified'&& $caregiver_dtl->submited_for_verification == 'no'){ $accessMenu['MAIN'][$i]['NAME'] = $menu->name; $accessMenu['MAIN'][$i]['URL'] = $menu->url; $accessMenu['MAIN'][$i]['Menu_Icon'] = $menu->menu_icon; $i++; }else if($caregiver_dtl->verification_status=='verified' && $menu->menu_for=='verified'){ $accessMenu['MAIN'][$i]['NAME'] = $menu->name; $accessMenu['MAIN'][$i]['URL'] = $menu->url; $accessMenu['MAIN'][$i]['Menu_Icon'] = $menu->menu_icon; $i++; }else if($menu->menu_for=='all'){ $accessMenu['MAIN'][$i]['NAME'] = $menu->name; $accessMenu['MAIN'][$i]['URL'] = $menu->url; $accessMenu['MAIN'][$i]['Menu_Icon'] = $menu->menu_icon; $i++; } } return $accessMenu; } private function __physicianAccessMatrix($group,$user_id) { //echo $user_id;die; $this->db->where('ion_user_id', $user_id); $physician_dtl = $this->db->get('physician')->row(); $physician_menu = $this->db->order_by("menu_order", "asc")->get_where('physician_menu',array('parent_id' => '0'))->result(); //echo '
'; print_r($physician_menu); echo '';die; $accessMenu=array(); $i=0; foreach($physician_menu as $menu){ $physician_child_menu = $this->db->order_by("menu_order", "asc")->get_where('physician_menu',array('parent_id' => $menu->id))->result(); //echo '
'; print_r($physician_dtl); echo '';die; $Children = array(); $childrenCount = 0; foreach($physician_child_menu as $child){ if($physician_dtl->verification_status=='unverified' && $child->menu_for=='unverified'){ $accessMenu['MAIN'][$i]['CHILDREN'][$childrenCount]['NAME'] = $child->name; $accessMenu['MAIN'][$i]['CHILDREN'][$childrenCount]['URL'] = $child->url; $accessMenu['MAIN'][$i]['CHILDREN'][$childrenCount]['Menu_Icon'] = $child->menu_icon; $childrenCount++; }else if($physician_dtl->verification_status=='verified' && $child->menu_for=='verified'){ $accessMenu['MAIN'][$i]['CHILDREN'][$childrenCount]['NAME'] = $child->name; $accessMenu['MAIN'][$i]['CHILDREN'][$childrenCount]['URL'] = $child->url; $accessMenu['MAIN'][$i]['CHILDREN'][$childrenCount]['Menu_Icon'] = $child->menu_icon; $childrenCount++; }else if($child->menu_for=='all'){ $accessMenu['MAIN'][$i]['CHILDREN'][$childrenCount]['NAME'] = $child->name; $accessMenu['MAIN'][$i]['CHILDREN'][$childrenCount]['URL'] = $child->url; $accessMenu['MAIN'][$i]['CHILDREN'][$childrenCount]['Menu_Icon'] = $child->menu_icon; $childrenCount++; } } if($physician_dtl->verification_status=='unverified' && $menu->menu_for=='unverified'){ $accessMenu['MAIN'][$i]['NAME'] = $menu->name; $accessMenu['MAIN'][$i]['URL'] = $menu->url; $accessMenu['MAIN'][$i]['Menu_Icon'] = $menu->menu_icon; $i++; }else if($physician_dtl->verification_status=='verified' && $menu->menu_for=='verified'){ $accessMenu['MAIN'][$i]['NAME'] = $menu->name; $accessMenu['MAIN'][$i]['URL'] = $menu->url; $accessMenu['MAIN'][$i]['Menu_Icon'] = $menu->menu_icon; $i++; }else if($menu->menu_for=='all'){ $accessMenu['MAIN'][$i]['NAME'] = $menu->name; $accessMenu['MAIN'][$i]['URL'] = $menu->url; $accessMenu['MAIN'][$i]['Menu_Icon'] = $menu->menu_icon; $i++; } } //echo '
'; print_r($accessMenu); echo '';die; return $accessMenu; } private function __patientAccessMatrix($group,$user_id) { //echo $user_id; $this->db->where('ion_user_id', $user_id); $patient_dtl = $this->db->get('patient_details')->row(); $patient_menu = $this->db->order_by("menu_order", "asc")->get_where('patient_menu',array('parent_id' => '0','status'=>'1'))->result(); //echo '
'; print_r($caregiver_menu); echo '';die; $accessMenu=array(); $i=0; foreach($patient_menu as $menu) { $patient_child_menu = $this->db->order_by("menu_order", "asc")->get_where('patient_menu',array('parent_id' => $menu->id,'status'=>'1'))->result(); $Children = array(); $childrenCount = 0; foreach($patient_child_menu as $child) { if($patient_dtl->active_status=='0' && $child->menu_for=='unverified') { $accessMenu['MAIN'][$i]['CHILDREN'][$childrenCount]['NAME'] = $child->name; $accessMenu['MAIN'][$i]['CHILDREN'][$childrenCount]['URL'] = $child->url; $accessMenu['MAIN'][$i]['CHILDREN'][$childrenCount]['Menu_Icon'] = $child->menu_icon; $childrenCount++; } else if($patient_dtl ->active_status=='1' && $child->menu_for=='verified') { $accessMenu['MAIN'][$i]['CHILDREN'][$childrenCount]['NAME'] = $child->name; $accessMenu['MAIN'][$i]['CHILDREN'][$childrenCount]['URL'] = $child->url; $accessMenu['MAIN'][$i]['CHILDREN'][$childrenCount]['Menu_Icon'] = $child->menu_icon; $childrenCount++; } else if($child->menu_for=='all') { $accessMenu['MAIN'][$i]['CHILDREN'][$childrenCount]['NAME'] = $child->name; $accessMenu['MAIN'][$i]['CHILDREN'][$childrenCount]['URL'] = $child->url; $accessMenu['MAIN'][$i]['CHILDREN'][$childrenCount]['Menu_Icon'] = $child->menu_icon; $childrenCount++; } } if($menu->menu_for=='unverified' && $patient_dtl->active_status=='0') { $accessMenu['MAIN'][$i]['NAME'] = $menu->name; $accessMenu['MAIN'][$i]['URL'] = $menu->url; $accessMenu['MAIN'][$i]['Menu_Icon'] = $menu->menu_icon; $i++; } else if($menu->menu_for=='verified' && $patient_dtl->active_status=='1') { $accessMenu['MAIN'][$i]['NAME'] = $menu->name; $accessMenu['MAIN'][$i]['URL'] = $menu->url; $accessMenu['MAIN'][$i]['Menu_Icon'] = $menu->menu_icon; $i++; } else if($menu->menu_for=='all') { $accessMenu['MAIN'][$i]['NAME'] = $menu->name; $accessMenu['MAIN'][$i]['URL'] = $menu->url; $accessMenu['MAIN'][$i]['Menu_Icon'] = $menu->menu_icon; $i++; } } return $accessMenu; // return $patient_dtl; } public function getCargiverInfo($id){ $this->db->where('id', $id); $query = $this->db->get('caregiver')->row(); $query->full_name=$query->fname.' '.$query->lname; //return json_encode($query); $this->db->where('id', $query->qualification_type); $this->db->where('status', '1'); $qualification = $this->db->get('master_cg_skills')->row(); $query->qualification_name=$qualification->name; return $query; } function getSchedule($patientId='',$caregiverId='',$start='',$end=''){ $this->db->where('status','1'); if($patientId!='') $this->db->where('patient_id',$patientId); if($caregiverId!='') $this->db->where('caregiver_id',$caregiverId); if($start!='' && $end!='') $this->db->where("start >= '".$start."' AND end <= '".$end."'"); $query = $this->db->get('caregiver_schedule')->result(); $i=0; foreach($query as $q){ //$id = $q->id; $sed[$i]['id']=$q->id; $sed[$i]['patientId']=$q->patient_id; $sed[$i]['caregiverId']=$q->caregiver_id; $sed[$i]['start']=$q->start; $sed[$i]['end']=$q->end; $sed[$i]['title']=$q->title." (".$q->acceptance_status.")"; $sed[$i]['color']='#e83e8c'; $i++; } $availability=$this->db->get_where('caregiver_availability',array('caregiver_id'=>$caregiverId,'status'=>1))->result(); foreach($availability as $avl){ $sed[$i]['id']=$avl->id; //$sed[$i]['patientId']=$q->patient_id; $sed[$i]['caregiverId']=$avl->caregiver_id; $sed[$i]['start']=$avl->start; $sed[$i]['end']=$avl->end; //$sed[$i]['title']=$q->title; $sed[$i]['rendering']='background'; $sed[$i]['color']='#a2f0ba'; $i++; } $ret = array(); foreach($sed as $q){ $ret[] = $q; } return $ret; } function insertDocExpireDate($data){ //pre($data);die; $date=date('Y-m-d'); $this->db->where('caregiver_id', $data['caregiver_id']); $this->db->where('doc_name', $data['doc_name']); $this->db->where('status', '1'); $this->db->update('caregiver_doc_expire_details', array('status'=>0,'updated_on'=>$date)); //echo $this->db->last_query();die; $this->db->insert('caregiver_doc_expire_details', $data); return $this->db->insert_id(); } function getExpireDateByCaregiverIdAndDocType($data){ $this->db->where('caregiver_id', $data['caregiver_id']); $this->db->where('doc_name', $data['doc_name']); $this->db->where('status', '1'); $this->db->order_by('id', 'desc'); $query = $this->db->get('caregiver_doc_expire_details')->row(); return $query; } function name_by_code($code){ $this->db->like('stateCode', $code); $query = $this->db->get('master_statelist'); return $query->row(); } function getting_name_from_short_code($type){ $this->db->select('constant_table.name'); $this->db->where('short_code', $type); $query = $this->db->get('constant_table')->row(); // _die($query); $name = $query->name; return $name; } function getCitizenList($data){ $list_type = array('A', 'B'); $condition_type = array((int)$data, 2); $this->db->select('*'); $this->db->where_in('list_type', $list_type); $this->db->where_in('condition_type', $condition_type); $this->db->order_by('name'); $query = $this->db->get('master_citizenship_doc'); // _die($this->db->last_query()); return $query->result(); } function getCitizenName($data){ $this->db->select('master_citizenship_doc.name'); $this->db->where('short_code', $data); $query = $this->db->get('master_citizenship_doc')->row(); // _die($query); $name = $query->name; return $name; } function getting_document_from_docId($doc_id){ $this->db->select('*'); $this->db->from('users_documents'); $this->db->where('id',$doc_id); $query=$this->db->get();; return $query->row(); } // adb dashboard function getAllCaregiversData($action){ $currentDate = time(); $start_date=''; $end_date=''; if ($action=='week') { $start_date = date('Y-m-d', strtotime('this week', $currentDate)); $end_date = date('Y-m-d', strtotime('this week +6 days', $currentDate)); } elseif ($action=='month') { $start_date = date('Y-m-01'); $end_date = date('Y-m-t'); } elseif ($action=='year') { $currentYear = date('Y'); $start_date = date('Y-01-01', strtotime($currentYear)); $end_date = date('Y-12-31', strtotime($currentYear)); } $this->db->select('*'); $this->db->from('caregiver'); $this->db->where(array('verification_status' => "verified")); if ($start_date!='' && $end_date!='') { $this->db->where('DATE(application_date) >=', $start_date); $this->db->where('DATE(application_date) <=', $end_date); } $query=$this->db->get(); $rows=$query->num_rows(); // return $query->result(); return $rows; } function getTotalSchedule($action=''){ $currentDate = time(); $start_date=''; $end_date=''; if ($action=='week') { $start_date = date('Y-m-d', strtotime('this week', $currentDate)); $end_date = date('Y-m-d', strtotime('this week +6 days', $currentDate)); } elseif ($action=='month') { $start_date = date('Y-m-01'); $end_date = date('Y-m-t'); } elseif ($action=='year') { $currentYear = date('Y'); $start_date = date('Y-01-01', strtotime($currentYear)); $end_date = date('Y-12-31', strtotime($currentYear)); } $this->db->select('*'); $this->db->from('caregiver_patient_clock_in_out'); $this->db->where(array('status' => 1)); if ($start_date!='' && $end_date!='') { $this->db->where('DATE(created_on) >=', $start_date); $this->db->where('DATE(created_on) <=', $end_date); } $query=$this->db->get(); $rows=$query->num_rows(); // return $query->result(); return $rows; } function getPreviousTotalSchedule($action=''){ $currentDate = time(); $start_date=''; $end_date=''; if ($action=='week') { $start_date = date('Y-m-d', strtotime('last week', $currentDate)); $end_date = date('Y-m-d', strtotime('last week +6 days', $currentDate)); } elseif ($action=='month') { $start_date = date('Y-m-01', strtotime('first day of previous month')); $end_date = date('Y-m-t', strtotime('last day of previous month')); } elseif ($action=='year') { $start_date = date('Y-01-01', strtotime('-1 year')); // Start of the previous year $end_date = date('Y-12-31', strtotime('-1 year')); // End of the previous year } $this->db->select('*'); $this->db->from('caregiver_patient_clock_in_out'); $this->db->where(array('status' => 1)); if ($start_date!='' && $end_date!='') { $this->db->where('DATE(created_on) >=', $start_date); $this->db->where('DATE(created_on) <=', $end_date); } $query=$this->db->get(); $rows=$query->num_rows(); // return $query->result(); return $rows; } function getTotalScheduleRequest(){ $currentDate = time(); $start_date = date('Y-m-01'); $end_date = date('Y-m-t'); $this->db->from('caregiver_schedule'); $this->db->where('DATE(start) >=', $start_date); $this->db->where('DATE(start) <', $end_date); $query = $this->db->get(); // return $query->result(); return $query->num_rows(); } function getDailyBasisSchedule($data=''){ try{ $from_api=isset($data['from_api'])&&$data['from_api']!=""?trim($data['from_api']):''; $start=isset($data['start'])?(0+(int)($data['start'])):0; $limit=isset($data['limit'])?(0+(int)($data['limit'])):10; $search=isset($data['search'])&&$data['search']!=""?trim($data['search']):''; $order_column=isset($data['order_column'])?(0+(int)($data['order_column'])):'default'; $order_type=isset($data['order_type'])&&$data['order_type']!=""?trim($data['order_type']):'DESC'; $filter=isset($data['filter'])&&$data['filter']!=""?trim($data['filter']):'week'; $startDate=isset($data['start_date'])&&$data['start_date']!=""?trim($data['start_date']):null; $endDate=isset($data['end_date'])&&$data['end_date']!=""?trim($data['end_date']):null; $this->db->distinct(); $this->db->select( 'SQL_CALC_FOUND_ROWS (CASE WHEN DATE(CURRENT_TIMESTAMP()) > cs.end THEN "past" WHEN DATE(CURRENT_TIMESTAMP()) < cs.end THEN "present" ELSE "" END) AS tense, (CASE WHEN (cio.clock_in_time IS NULL AND cio.clock_out_time IS NULL AND cs.acceptance_status="Unconfirmed" AND CURRENT_TIMESTAMP() < cs.end ) THEN "unconfirmed" WHEN (cio.clock_in_time IS NULL AND cio.clock_out_time IS NULL AND cs.acceptance_status="Accepted" AND CURRENT_TIMESTAMP() < cs.end ) THEN "upcoming" WHEN (cio.clock_in_time IS NOT NULL AND ( ((cio.clock_out_time IS NULL OR cio.clock_out_time IS NOT NULL) AND cs.acceptance_status="Accepted") OR (cio.clock_out_time IS NULL AND cs.acceptance_status="Reported") ) ) THEN "ongoing" WHEN (cio.clock_in_time IS NOT NULL AND cio.clock_out_time IS NOT NULL AND cs.acceptance_status="Reported" ) THEN "completed" WHEN (cio.clock_in_time IS NULL AND cio.clock_out_time IS NULL AND cs.acceptance_status IN("Unconfirmed","Accepted") AND CURRENT_TIMESTAMP() > cs.end ) THEN "missed" WHEN (cio.clock_in_time IS NULL AND cio.clock_out_time IS NULL AND cs.acceptance_status="Declined" ) THEN "declined" ELSE "undefined" END) AS live_status, cs.id AS schedule_id, p.id AS patient_id, CONCAT(p.first_name, " ", p.last_name) AS patient_name, CONCAT(c.fname, " ", c.lname) AS caregiver_name, v.vedor_name AS vendor_name, cs.acceptance_status, cs.start AS start_time, cs.end AS end_time, cio.clock_in_time, cio.clock_out_time',false ); $this->db->from('caregiver_schedule cs'); $this->db->join('caregiver c','cs.caregiver_id=c.id'); $this->db->join('patient_details p','cs.patient_id=p.id'); $this->db->join('master_vendor v','p.reference_id=v.id','left'); $this->db->join('caregiver_patient_clock_in_out cio','cs.id=cio.schedule_id','left'); $this->db->where('cs.status',1); $this->db->where('c.status',1); $this->db->where('c.verification_status', 'verified'); $this->db->where('p.active_status','1'); $this->db->where('DATE(cs.end) BETWEEN "'.$startDate.'" AND "'.$endDate.'"'); if($order_column=='default'){ $this->db->order_by('cs.start', 'ASC'); }else if($order_column==0){ $this->db->order_by('cs.id',$order_type); }elseif($order_column==1){ $this->db->order_by('p.first_name',$order_type); }elseif($order_column==2){ $this->db->order_by('v.vedor_name',$order_type); } if(isset($search) && $search!=''){ $this->db->group_start(); $this->db->like('cs.id', $search); $this->db->or_like("CONCAT(p.first_name,' ',p.last_name)",$search); $this->db->or_like("v.vedor_name",$search); $this->db->group_end(); } if($from_api==''){ $this->db->limit($limit,$start); } $query=$this->db->get(); $openCases=$query->result_array(); $openCasesCount=$query->num_rows(); $main_query=$this->db->last_query(); $total_count=($this->db->query("SELECT FOUND_ROWS() AS total_rows"))->row()->total_rows; $response=(object)[ 'status'=>200, 'msg'=>'fetched successfully', 'data'=>(object)[ 'total_count'=>$total_count, 'count'=>$openCasesCount, 'schedules'=>$openCases, 'query'=>$main_query ] ]; return $response; }catch(Exception $e){ $getMsg="Caregiver_model - getDailyBasisSchedule: ".$e->getMessage(); echo $getMsg; } } function hms_get_adb_vendors_overview($data){ try{ $from_api=isset($data['from_api'])&&$data['from_api']!=""?trim($data['from_api']):''; $start=isset($data['start'])?(0+(int)($data['start'])):0; $limit=isset($data['limit'])?(0+(int)($data['limit'])):10; $search=isset($data['search'])&&$data['search']!=""?trim($data['search']):''; $filter=isset($data['filter'])&&$data['filter']!=""?trim($data['filter']):'week'; $order_column=isset($data['order_column'])?(0+(int)($data['order_column'])):0; $order_type=isset($data['order_type'])&&$data['order_type']!=""?trim($data['order_type']):'DESC'; $require=isset($data['require'])&&$data['require']!=""?trim($data['require']):'data'; $currentDate = time(); $start_date=''; $end_date=''; if ($filter=='week') { $start_date = date('Y-m-d', strtotime('this week', $currentDate)); $end_date = date('Y-m-d', strtotime('this week +6 days', $currentDate)); } elseif ($filter=='month') { $start_date = date('Y-m-01'); $end_date = date('Y-m-t'); } elseif ($filter=='year') { $currentYear = date('Y'); $start_date = date('Y-01-01', strtotime($currentYear)); $end_date = date('Y-12-31', strtotime($currentYear)); } $this->db->select(' (CASE WHEN (f.acceptance_status IN("Declined","Reported") OR f.patient_id IS NULL) THEN "New" WHEN (f.acceptance_status IN("Unconfirmed","Accepted")) THEN "Open" ELSE "New" END) AS live_status, a.id, a.patient_id, a.first_name, a.last_name, a.referral_type, a.address, b.vedor_name, c.name as service_type' ); $this->db->from('patient_details a'); $this->db->join('master_vendor b', 'b.id = a.reference_id', 'left'); $this->db->join('master_cg_skills c', 'c.id = a.level_of_service', 'left'); $this->db->join('users e','e.id=a.ion_user_id', 'left'); $this->db->join('caregiver_schedule f', 'a.id=f.patient_id', 'left'); $this->db->where(array('e.active' => 1)); $this->db->where('a.reference_information', 'Reffered by Vendor'); if ($start_date!='' && $end_date!='') { $this->db->where('DATE(FROM_UNIXTIME(e.created_on)) >=', $start_date); $this->db->where('DATE(FROM_UNIXTIME(e.created_on)) <=', $end_date); } if($order_column==0){ $this->db->order_by('a.id',$order_type); }else if($order_column==1){ $this->db->order_by('b.vedor_name',$order_type); }else if($order_column==2){ $this->db->order_by('a.first_name',$order_type); }else if($order_column==3){ $this->db->order_by('c.name',$order_type); }else if($order_column==4){ $this->db->order_by('a.address',$order_type); }else if($order_column==5){ $this->db->order_by('a.referral_type',$order_type); } if(isset($search) && $search!=''){ $this->db->group_start(); $this->db->like('a.id', $search); $this->db->or_like("CONCAT(a.first_name, ' ', a.last_name)", $search); $this->db->or_like('a.address', $search); $this->db->or_like('a.referral_type', $search); $this->db->or_like('b.vedor_name', $search); $this->db->or_like('c.name', $search); $this->db->group_end(); } $this->db->where('a.active_status','1'); // $this->db->group_by('f.patient_id'); if($require=="data"){ if ($from_api == '') { $this->db->limit($limit,$start); } $this->db->order_by('a.id',"DESC"); $query=$this->db->get(); $result=$query->result_array(); }else if($require=="count"){ $this->db->order_by('a.id',"DESC"); $query=$this->db->get(); $result=$query->num_rows(); } return $result; }catch(Exception $e){ $getMsg="Vendors_overview - hms_get_adb_vendors_overview: ".$e->getMessage(); echo $getMsg; } } function hms_get_adb_financial_overview($data){ try{ $from_api=isset($data['from_api'])&&$data['from_api']!=""?trim($data['from_api']):''; $start=isset($data['start'])?(0+(int)($data['start'])):0; $limit=isset($data['limit'])?(0+(int)($data['limit'])):10; $search=isset($data['search'])&&$data['search']!=""?trim($data['search']):''; $filter=isset($data['filter'])&&$data['filter']!=""?trim($data['filter']):'month'; $order_column=isset($data['order_column'])?(0+(int)($data['order_column'])):0; $order_type=isset($data['order_type'])&&$data['order_type']!=""?trim($data['order_type']):'DESC'; $require=isset($data['require'])&&$data['require']!=""?trim($data['require']):'data'; $currentDate=time(); $start_date=''; $end_date=''; if ($filter=='week') { $start_date = date('Y-m-d', strtotime('this week', $currentDate)); $end_date = date('Y-m-d', strtotime('this week +6 days', $currentDate)); }else if($filter=='month') { $start_date = date('Y-m-01'); $end_date = date('Y-m-t'); }else if($filter=='year') { $currentYear = date('Y'); $start_date = date('Y-01-01', strtotime($currentYear)); $end_date = date('Y-12-31', strtotime($currentYear)); } $this->db->distinct(); $this->db->select( '(CASE WHEN (cs.acceptance_status="Reported" AND a.reporting_approval="1" ) THEN "completed" WHEN (cio.clock_in_time IS NULL AND cio.clock_out_time IS NULL AND cs.acceptance_status IN("Unconfirmed","Accepted") AND CURRENT_TIMESTAMP() > cs.end ) THEN "missed" ELSE "pending" END) AS live_status, cs.id, p.id AS patient_id, CONCAT(p.first_name, " ", p.last_name) AS patient_name, cs.acceptance_status, p.address, JSON_UNQUOTE(JSON_EXTRACT(p.address, "$.City")) AS main_city, JSON_UNQUOTE(JSON_EXTRACT(p.address, "$.Zipcode")) AS main_zipcode, v.vedor_name, mcs.name as service_type' ); $this->db->from('caregiver_schedule cs'); $this->db->join('patient_details p', 'cs.patient_id=p.id'); $this->db->join('master_vendor v', 'p.reference_id=v.id'); $this->db->join('master_cg_skills mcs', 'p.level_of_service=mcs.id'); $this->db->join('caregiver_patient_clock_in_out cio', 'cs.id=cio.schedule_id', 'left'); $this->db->join('assessment a', 'cs.id=a.schedule_id', 'left'); $this->db->where('cs.status', '1'); $this->db->where('p.reference_information', 'Reffered by Vendor'); $this->db->where('p.active_status', 1); if($start_date!='' && $end_date!=''){ $this->db->where('DATE(cs.end) BETWEEN "'.$start_date.'" AND "'.$end_date.'"'); } $this->db->group_start(); // Start of grouped conditions $this->db->or_group_start(); // Start of OR conditions within the group $this->db->where('cs.acceptance_status', 'Reported'); $this->db->where('a.reporting_approval', '1'); $this->db->group_end(); // End of OR conditions within the group $this->db->or_group_start(); // Start of another OR conditions within the group $this->db->where('cio.clock_in_time IS NULL'); $this->db->where('cio.clock_out_time IS NULL'); $this->db->where_in('cs.acceptance_status', ['Unconfirmed', 'Accepted']); $this->db->where('CURRENT_TIMESTAMP() > cs.end'); $this->db->group_end(); // End of another OR conditions within the group $this->db->group_end(); // End of grouped conditions if($order_column==0){ $this->db->order_by('cs.id',$order_type); }else if($order_column==1){ $this->db->order_by('cs.acceptance_status',$order_type); }else if($order_column==2){ $this->db->order_by('v.vedor_name',$order_type); }else if($order_column==3){ $this->db->order_by('p.first_name',$order_type); }else if($order_column==4){ $this->db->order_by('mcs.name',$order_type); }else if($order_column==5){ $this->db->order_by('p.address',$order_type); } if(isset($search) && $search!=''){ $this->db->group_start(); $this->db->like('cs.id', $search); if(strtolower($search)=='completed') { // $this->db->or_like('cs.acceptance_status', 'Accepted'); $this->db->or_like('cs.acceptance_status', 'Reported'); }else if (strtolower($search)=='missed') { $this->db->or_like('cs.acceptance_status', 'Unconfirmed'); $this->db->or_like('cs.acceptance_status', 'Accepted'); } $this->db->or_like('v.vedor_name', $search); $this->db->or_like("CONCAT(p.first_name, ' ', p.last_name)", $search); $this->db->or_like('mcs.name', $search); $this->db->or_like('p.address', $search); $this->db->group_end(); } if($require=="data"){ if ($from_api == '') { $this->db->limit($limit,$start); } $this->db->order_by('cs.id',"DESC"); $query=$this->db->get(); $result=$query->result_array(); }else if($require=="count"){ $this->db->order_by('cs.id',"DESC"); $query=$this->db->get(); $result=$query->num_rows(); } return $result; #old-query // $this->db->select('a.id, p.id as patient_id, CONCAT(p.first_name, " ", p.last_name) as patient_name, a.acceptance_status, p.address, b.vedor_name, c.name as service_type'); // $this->db->from('caregiver_schedule a'); // $this->db->join('patient_details p', 'a.patient_id = p.id', 'left'); // $this->db->join('master_vendor b', 'b.id = p.reference_id', 'left'); // $this->db->join('master_cg_skills c', 'c.id = p.level_of_service', 'left'); // $this->db->where('p.reference_information', 'Reffered by Vendor'); // if ($start_date!='' && $end_date!='') { // $this->db->where('DATE(a.start) >=', $start_date); // $this->db->where('DATE(a.start) <=', $end_date); // } // if($order_column==0){ // $this->db->order_by('a.id',$order_type); // }else if($order_column==1){ // $this->db->order_by('a.acceptance_status',$order_type); // }else if($order_column==2){ // $this->db->order_by('b.vedor_name',$order_type); // }else if($order_column==3){ // $this->db->order_by('p.first_name',$order_type); // }else if($order_column==4){ // $this->db->order_by('c.name',$order_type); // }else if($order_column==5){ // $this->db->order_by('a.address',$order_type); // } // if(isset($search) && $search!=''){ // $this->db->group_start(); // $this->db->like('a.id', $search); // if (strtolower($search) == 'completed') { // $this->db->or_like('a.acceptance_status', 'Accepted'); // $this->db->or_like('a.acceptance_status', 'Reported'); // }elseif (strtolower($search) == 'missed') { // $this->db->or_like('a.acceptance_status', 'Unconfirmed'); // $this->db->or_like('a.acceptance_status', 'Declined'); // } // $this->db->or_like("CONCAT(p.first_name, ' ', p.last_name)", $search); // $this->db->or_like('p.address', $search); // $this->db->or_like('b.vedor_name', $search); // $this->db->or_like('c.name', $search); // $this->db->group_end(); // } // if($require=="data"){ // if ($from_api == '') { // $this->db->limit($limit,$start); // } // $this->db->order_by('a.id',"DESC"); // $query=$this->db->get(); // $result=$query->result_array(); // }else if($require=="count"){ // $this->db->order_by('a.id',"DESC"); // $query=$this->db->get(); // $result=$query->num_rows(); // } // return $result; #old-query }catch(Exception $e){ $getMsg="Financial_overview - hms_get_adb_financial_overview: ".$e->getMessage(); echo $getMsg; } } function get_adb_quick_cards_chart_data($filter='', $data_for='', $num_of_row=5){ $num_of_row = $num_of_row-1; if ($filter == 'year') { $currentYear = date('Y'); $result = []; for ($i = $num_of_row; $i >= 0; $i--) { $firstDay = date('Y-m-d', strtotime("$currentYear -$i year January 1")); $lastDay = date('Y-m-d', strtotime("$currentYear -$i year December 31")); $count = 0; if($data_for=='scheduled_visits'){ $count = $this->getScheduledVisitsBarChatQuery($firstDay,$lastDay); } $result[] = $count; } return $result; }elseif($filter == 'month'){ $currentMonth = date('m'); $currentYear = date('Y'); $result = array(); for ($i = $num_of_row; $i >= 0; $i--) { $month = $currentMonth - $i; $year = $currentYear; if ($month < 1) { $month += 12; $year--; } $firstDay = date('Y-m-01', strtotime("$year-$month-01")); $lastDay = date('Y-m-t', strtotime("$year-$month-01")); $count = 0; if($data_for=='scheduled_visits'){ $count = $this->getScheduledVisitsBarChatQuery($firstDay,$lastDay); } $result[] = $count; } return $result; }elseif($filter == 'week'){ $currentDate = new DateTime(); $currentWeekNumber = $currentDate->format("W"); $result = array(); for ($i = $num_of_row; $i >= 0; $i--) { $startOfWeek = clone $currentDate; $startOfWeek->modify("-$i weeks"); $startOfWeek->modify('Monday this week'); $endOfWeek = clone $startOfWeek; $endOfWeek->modify('Sunday this week'); $firstDay = $startOfWeek->format('Y-m-d'); $lastDay = $endOfWeek->format('Y-m-d'); $count = 0; if($data_for=='scheduled_visits'){ $count = $this->getScheduledVisitsBarChatQuery($firstDay,$lastDay); } $result[] = $count; } return $result; } } private function getScheduledVisitsBarChatQuery($start='',$end=''){ $this->db->select('*'); $this->db->from('caregiver_patient_clock_in_out'); $this->db->where(array('status' => 1)); if ($start!='' && $end!='') { $this->db->where('DATE(created_on) >=', $start); $this->db->where('DATE(created_on) <=', $end); } $query = $this->db->get(); return $query->num_rows(); } // adb dashboard }