563 lines
17 KiB
PHP
Executable File

<?php
if (!defined('BASEPATH'))
exit('No direct script access allowed');
class Referral_model extends CI_model {
function __construct()
{
parent::__construct();
$this->load->database();
}
function checkMail($email)
{
$result=$this->db->get_where('patient_details', array('patient_email' => $email))->num_rows();
return $result;
}
function insertPatient($data) {
$this->db->insert('patient_details', $data);
$insert_id = $this->db->insert_id();
// $this->db->insert('patient_details', array(''=>$insert_id));
return $insert_id;
}
function updatePatient($data,$pid){
$this->db->where('id', $pid);
$this->db->update('patient_details', $data);
return 'phs2';
}
function getPatientById($id)
{
$this->db->select('*');
$this->db->from('patient_details');
$this->db->where('id', $id);
$query = $this->db->get();
return $query->row();
}
function getPatientByIonId($id)
{
$this->db->select('*');
$this->db->from('patient_details');
$this->db->where('ion_user_id', $id);
$query = $this->db->get();
return $query->row();
}
function update_email_check($email,$ionid) {
//echo $email;die;
$this->db->where('email', $email)->where('id!=',$ionid);
$query = $this->db->get('users')->row();
//echo $this->db->last_query();
// print_r($query);
//die;
if($query)
return 1;
else
return 0;
}
function updateIonUser($email,$password,$id,$ionid){
$update_ion_user = array(
// 'email' => $email,
'password' => $password
);
$this->db->where('id', $ionid);
$query=$this->db->update('users', $update_ion_user);
// $update_caregiver = array(
// 'email' => $email
// );
// $this->db->where('id', $id);
// $this->db->update('caregiver', $update_caregiver);
if($query){
return true;
}else{
return false;
}
}
function approvePatient($pid){
$data = array('approve_status' => 1);
$this->db->where('id', $pid);
$this->db->update('patient_details', $data);
return 'approved';
}
function activateReferral($pid){
$data = array('active_status' => 1);
$this->db->where('id', $pid);
$this->db->update('patient_details', $data);
return 'approved';
}
function addPatientDocuments($data){
$this->db->insert('patient_documents', $data);
return $this->db->insert_id();
}
function mdOrdersInsert($data){
$this->db->insert('md_orders', $data);
return $this->db->insert_id();
}
function mdOrdersUpdate($data,$pid){
$this->db->where('patient_id', $pid);
$this->db->update('md_orders', $data);
return $pid;
}
function getMdOrdersByPatientId($pid)
{
$this->db->where('patient_id', $pid);
$query = $this->db->get('patient_md_order');
return $query->result();
}
function insertPatientInsurance($data,$pid) {
$this->db->where('patient_id',$pid);
$query = $this->db->get('patient_insurance_info');
if ($query->num_rows() > 0){
$this->db->where('patient_id', $pid);
$this->db->update('patient_insurance_info', $data);
return $this->db->insert_id();
}
else{
$this->db->insert('patient_insurance_info', $data);
return $this->db->insert_id();
}
}
function insuranceInfoCheck($pid){
$this->db->where('patient_id',$pid);
$query = $this->db->get('patient_insurance_info');
return $query->num_rows();
}
/*get necessesary dropdown details*/
function getPatientDoc($id,$type){
$this->db->where('patient_id', $id);
$this->db->where('documents_type', $type);
$query = $this->db->get('patient_documents');
return $query->result();
}
function getDocDetails($id){
$this->db->where('id', $id);
$query = $this->db->get('patient_documents');
return $query->result();
}
function getLanguages() {
$this->db->where('status', 1);
$query = $this->db->get('master_language');
return $query->result();
}
function getReferalSource() {
$this->db->where('status', 1);
$query = $this->db->get('master_patient_ref');
return $query->result();
}
function getEleDep(){
$this->db->where('status', 1);
$query = $this->db->get('master_ele_dependency');
return $query->result();
}
function getallergy(){
$this->db->where('status', 1);
$query = $this->db->get('master_allergy');
return $query->result();
}
function getICD(){
$this->db->where('status', 1);
$query = $this->db->get('master_icd');
return $query->result();
}
function getSkillNursingCareList(){
$this->db->where('status', 1);
$query = $this->db->get('master_skilled_nursing_care');
return $query->result();
}
function getHCPCScodes(){
$this->db->where('status', 1);
$query = $this->db->get('master_hpcs_cpt_codes');
return $query->result();
}
function getLevelService() {
$this->db->where('status', 1);
$query = $this->db->get('master_cg_skills');
return $query->result();
}
function getServiceActivity() {
$this->db->where('status', 1);
$query = $this->db->get('master_service_activity');
return $query->result();
}
function getTherapyType() {
$this->db->where('status', 1);
$query = $this->db->get('master_therapytype');
return $query->result();
}
function getAccessType() {
$query = $this->db->get('master_access_type');
return $query->result();
}
function getTubeType() {
$this->db->where('status', 1);
$query = $this->db->get('master_tubetype');
return $query->result();
}
function getPayertype() {
$this->db->where('status', 1);
$query = $this->db->get('master_payertype');
return $query->result();
}
function getvendorLists() {
$query = $this->db->get('master_vendor');
return $query->result();
}
function insuranceCompanyList() {
$this->db->where('status', 1);
$this->db->where('vendor_type', 1);
$query = $this->db->get('master_vendor');
return $query->result();
}
function insCompanyDetails($id)
{
$this->db->where('id', $id);
$query = $this->db->get('master_vendor');
return $query->row();
}
function relationLists() {
$query = $this->db->get('master_relations');
return $query->result();
}
/*get value by id*/
function getServiceNameByID($id)
{
$this->db->where('id', $id);
$query = $this->db->get('master_service_activity');
return $query->row();
}
function getTherapyNameByID($id)
{
$this->db->where('id', $id);
$query = $this->db->get('master_therapytype');
return $query->row();
}
function getAccessNameByID($id)
{
$this->db->where('id', $id);
$query = $this->db->get('master_access_type');
return $query->row();
}
/*get value by id*/
/*get necessesary dropdown details end*/
function getValueFrom($tableName,$fieldName,$fieldValue) {
$this->db->where($fieldName, $fieldValue);
$query = $this->db->get($tableName);
return $query->result();
}
/* for data table */
function status_change($post){
$id = $post['id'];
$stat = $post['val'];
$this->db->set('status', $stat);
$this->db->where('id', $id);
$this->db->update('patient_details');
if($stat == '1')
{
return 'Status set active';
}
else{
return 'Status set deactive';
}
}
function getWherevalueInsInfo($id){
// $this->db->where('main_id', $id);
// $query = $this->db->get('patient_insurance_info');
// return $query->result();
$this->db->select('*');
$this->db->from('patient_payment_info p1');
$this->db->join('patient_insurance_info p2', 'p1.main_id = p2.main_id', 'left');
$this->db->where('p1.main_id', $id);
$query = $this->db->get();
return $query->result();
}
public function getWherevalue($id){
$this->db->select('*');
$this->db->from('patient_details p1');
$this->db->join('patient_details_step2 p2', 'p1.id = p2.main_id', 'left');
$this->db->where('p1.id', $id);
$query = $this->db->get();
return $query->result();
}
function getWhereMdOrders($id){
$this->db->select('*');
$this->db->from('patient_md_order_step1 md1');
$this->db->join('patient_md_order_step2 md2', 'md1.id = md2.md_order_id', 'left');
$this->db->join('patient_md_order_step3 md3', 'md1.id = md3.md_order_id', 'left');
$this->db->where('md1.patient_id', $id);
$query = $this->db->get();
return $query->result();
}
function name_list(){
$this->db->where(array('active_status' => 1));
$query = $this->db->get('patient_details');
$this->db->order_by('id', 'DESC');
return $query->result();
}
function patientLists(){
$this->db->where(array('active_status' => 1));
$query = $this->db->get('patient_details');
$this->db->order_by('id', 'DESC');
return $query->result();
}
function getNameBysearch($search) {
$this->db->order_by('id', 'desc');
$this->db->group_start();
$this->db->like('id', $search);
$this->db->or_like('first_name', $search);
$this->db->or_like('last_name', $search);
$this->db->or_like('gender', $search);
$this->db->group_end();
$this->db->where(array('active_status' => 1));
$query = $this->db->get('patient_details');
return $query->result();
}
function getNameByLimit($limit, $start) {
$this->db->order_by('id', 'desc');
// $this->db->limit($limit, $start);
$this->db->where(array('active_status' => 1));
$query = $this->db->get('patient_details');
return $query->result();
}
function getNameByLimitBySearch($limit, $start, $search) {
$this->db->order_by('id', 'desc');
$this->db->group_start();
$this->db->like('id', $search);
$this->db->or_like('first_name', $search);
$this->db->or_like('last_name', $search);
$this->db->or_like('gender', $search);
$this->db->group_end();
$this->db->where(array('active_status' => 1));
// $this->db->limit($limit, $start);
$query = $this->db->get('patient_details');
return $query->result();
}
function name_listPending(){
$query = $this->db->get('patient_details');
$this->db->order_by('id', 'DESC');
return $query->result();
}
function getNameBysearchPending($search) {
$this->db->order_by('id', 'desc');
$this->db->group_start();
$this->db->like('id', $search);
$this->db->or_like('first_name', $search);
$this->db->or_like('last_name', $search);
$this->db->or_like('gender', $search);
$this->db->or_like('telephone', $search);
$this->db->group_end();
$query = $this->db->get('patient_details');
return $query->result();
}
function getNameByLimitPending($limit, $start) {
$this->db->order_by('id', 'desc');
$this->db->limit($limit, $start);
$query = $this->db->get('patient_details');
return $query->result();
}
function getNameByLimitBySearchPending($limit, $start, $search) {
$this->db->order_by('id', 'desc');
$this->db->group_start();
$this->db->like('id', $search);
$this->db->or_like('first_name', $search);
$this->db->or_like('last_name', $search);
$this->db->or_like('gender', $search);
$this->db->or_like('telephone', $search);
$this->db->group_end();
$this->db->limit($limit, $start);
$query = $this->db->get('patient_details');
return $query->result();
}
function delete_patient($id)
{
$this->db->where('id', $id);
$this->db->delete('patient_details');
}
function getWhereAssessment($id){
$this->db->select('*');
$this->db->from('assessment a1');
// $this->db->join('assessment_step2 a2', 'a1.id = a2.main_id', 'left');
// $this->db->join('assessment_step3 a3', 'a1.id = a3.main_id', 'left');
// $this->db->join('assessment_step4 a4', 'a1.id = a4.main_id', 'left');
// $this->db->join('assessment_step5 a5', 'a1.id = a5.main_id', 'left');
// $this->db->join('assessment_step6 a6', 'a1.id = a6.main_id', 'left');
$this->db->where('a1.patient_id',$id);
$query = $this->db->get();
return $query->result();
}
function getInitialAssessmentStatus($id)
{
$this->db->where('patient_id', $id);
$query = $this->db->get('assessment');
return $query->num_rows();
}
function getProgress($id){
$query=$this->db->get_where('patient_details', array('id' => $id))->row();
return $query->progress;
}
function insertNewReferral($data)
{
$this->db->insert('patient_details', $data);
$insert_id = $this->db->insert_id();
//updating main id to patient table
$this->db->where('id', $insert_id);
$this->db->update('patient_details', array('main_id' => $insert_id));
//patient_details_2_initialization
$this->db->insert('patient_details_step2', array('main_id' => $insert_id));
$this->db->insert('patient_insurance_info', array('main_id' => $insert_id));
$this->db->insert('patient_md_order_step3', array('main_id' => $insert_id));
$this->db->insert('patient_payment_info', array('main_id' => $insert_id));
return $insert_id;
}
function updateReferralTable($data, $table, $pid){
$this->db->where('main_id', $pid);
$this->db->update($table, $data);
$effected_row=$this->db->affected_rows();
if($effected_row>0){ return true; }else{ return false; }
}
function getGeninfoPctg($pid)
{
$this->db->select('*');
$this->db->from('patient_details');
$this->db->where('id', $pid);
$query = $this->db->get();
return $query->row();
}
function getPhysician($id){
$query=$this->db->get_where('physician', array('npi' => $id));
return $query->row();
}
function delete_patient_doc($id)
{
$this->db->where('id', $id);
$this->db->delete('patient_documents');
if ($this->db->affected_rows() == 0)
{
return FALSE;
}else{
return TRUE;
}
}
function getServiceHeads($id,$cg_type)
{
$this->db->select("a.*,IFNULL(a.priority,9999) as priority");
$this->db->where('skill_id',$cg_type);
$this->db->where('status','1');
$this->db->order_by('priority','asc');
$this->db->from('master_service_head a');
$query=$this->db->get();
$result=$query->result();
foreach($result as $res){
$this->db->where('service_head_id',$res->id);
$this->db->where('status','1');
$this->db->order_by('priority','asc');
$this->db->from('master_cg_service b');
$query2=$this->db->get();
$result2=$query2->result();
$res->data=$result2;
}
return $result;
}
function getServiceName($id)
{
$this->db->select("a.service_name");
$this->db->from("master_cg_service a");
$this->db->where('id',$id);
$query=$this->db->get();
return $query->row()->service_name;
}
function getTypeOfAccesses($ids)
{
foreach($ids as $id){
$this->db->select("a.name");
$this->db->where('id',$id);
$this->db->from('master_access_type a');
$query=$this->db->get();
$result[]=$query->row()->name;
}
return $result;
}
function getFileBypatientIdFileType($docType,$userId)
{
$this->db->select('path,file_name');
$this->db->where('patient_id', $userId);
$this->db->where('documents_type', $docType);
$this->db->order_by('id', 'desc');
$this->db->where('status', 1);
$query = $this->db->get('patient_documents');
// print_r($query);die;
// echo $this->db->last_query();die;
return $query->row();
}
public function getAnnualhomevalue($id){
$this->db->select('annual_in_home_performance');
$this->db->from('patient_details p1');
$this->db->join('patient_details_step2 p2', 'p1.id = p2.main_id', 'left');
$this->db->where('p1.id', $id);
$query = $this->db->get();
return $query->result();
}
}
/* for data table end */