310 lines
14 KiB
PHP
Executable File
310 lines
14 KiB
PHP
Executable File
<?php
|
|
|
|
if (!defined('BASEPATH'))
|
|
exit('No direct script access allowed');
|
|
|
|
class Generate_bill_model extends CI_model {
|
|
|
|
function __construct() {
|
|
parent::__construct();
|
|
$this->load->database();
|
|
}
|
|
|
|
function name_list(){
|
|
//SELECT * FROM patient WHERE id in (SELECT DISTINCT patient_id FROM timesheet_approval)
|
|
$this->db->select("patient_details.*");
|
|
$this->db->from("patient_details");
|
|
$this->db->where('patient_details.id IN (SELECT DISTINCT patient_id FROM timesheet_approval)');
|
|
$this->db->where('patient_details.active_status',1);
|
|
//$this->db->join("patient_details", "patient_details.id = patient.id");
|
|
|
|
//echo $this->db->get_compiled_select(); die;
|
|
$patients = $this->db->get()->result_array();
|
|
//echo '<br>'.$this->db->last_query();die;
|
|
|
|
foreach($patients as $indx=>$patient)
|
|
{
|
|
$patientId = $patient['id'];
|
|
//echo '<br>'.$patientId;
|
|
$this->db->select('COUNT(*) as billedAmmount');
|
|
$this->db->where('billed',1);
|
|
$this->db->where('isApproved',1);
|
|
$this->db->where('patient_id',$patientId);
|
|
$billed = $this->db->get('timesheet_approval')->result_array();
|
|
//echo '<br>'.$this->db->last_query();
|
|
//echo '<pre>'; print_r($billed); echo '</pre>';
|
|
$patients[$indx]['billed_count'] = $billed[0]['billedAmmount'];
|
|
|
|
$this->db->select('COUNT(*) as unbilledAmmount');
|
|
$this->db->where('billed',0);
|
|
$this->db->where('isApproved','1');
|
|
$this->db->where('patient_id', $patientId);
|
|
$unbilled = $this->db->get('timesheet_approval')->result_array();
|
|
//echo '<br>'.$this->db->last_query();
|
|
//echo '<pre>'; print_r($unbilled); echo '</pre>';
|
|
$patients[$indx]['unBilled_count'] = $unbilled[0]['unbilledAmmount'];
|
|
}
|
|
|
|
//echo '<pre>'; print_r($patients); echo '</pre>'; exit;
|
|
return $patients;
|
|
}
|
|
function getNameBysearch($search,$orderColumn, $orderType) {
|
|
if($orderColumn==1)
|
|
$this->db->order_by('name', $orderType);
|
|
|
|
$this->db->select("patient_details.*");
|
|
$this->db->from("patient_details");
|
|
$this->db->where('patient_details.id IN (SELECT DISTINCT patient_id FROM timesheet_approval)');
|
|
$this->db->where('patient_details.active_status',1);
|
|
//$this->db->join("patient_details", "patient_details.id = patient.id");
|
|
$patients = $this->db->get()->result_array();
|
|
|
|
|
|
foreach($patients as $indx=>$patient)
|
|
{
|
|
$patientId = $patient['id'];
|
|
//echo $patientId;die;
|
|
$this->db->select('COUNT(*) as billedAmmount');
|
|
$this->db->where('billed',1);
|
|
$this->db->where('isApproved',1);
|
|
$this->db->where('patient_id',$patientId);
|
|
$billed = $this->db->get('timesheet_approval')->result_array();
|
|
//echo '<br>'.$this->db->last_query();
|
|
//echo '<pre>'; print_r($billed); echo '</pre>';
|
|
$patients[$indx]['billed_count'] = $billed[0]['billedAmmount'];
|
|
|
|
$this->db->select('COUNT(*) as unbilledAmmount');
|
|
$this->db->where('billed',0);
|
|
$this->db->where('isApproved',1);
|
|
$this->db->where('patient_id', $patientId);
|
|
$unbilled = $this->db->get('timesheet_approval')->result_array();
|
|
//echo '<br>'.$this->db->last_query();
|
|
//echo '<pre>'; print_r($unbilled); echo '</pre>';
|
|
$patients[$indx]['unBilled_count'] = $unbilled[0]['unbilledAmmount'];
|
|
}
|
|
|
|
|
|
$this->db->limit($limit, $start);
|
|
//$patients = $this->db->get();
|
|
return $patients;
|
|
}
|
|
|
|
function getNameByLimit($limit, $start, $orderColumn, $orderType) {
|
|
|
|
if($orderColumn==1){
|
|
$this->db->order_by('name', $orderType);
|
|
}
|
|
|
|
$this->db->select("patient_details.*,CONCAT_WS(' ', patient_details.first_name, patient_details.last_name) AS name");
|
|
$this->db->from("patient_details");
|
|
$this->db->where('patient_details.id IN (SELECT DISTINCT patient_id FROM timesheet_approval)');
|
|
$this->db->where('patient_details.active_status',1);
|
|
$this->db->limit($limit, $start);
|
|
$patients = $this->db->get()->result_array();
|
|
|
|
foreach($patients as $indx=>$patient)
|
|
{
|
|
$patientId = $patient['id'];
|
|
|
|
$this->db->select('COUNT(*) as billedAmmount');
|
|
$this->db->where('billed',1);
|
|
$this->db->where('isApproved',1);
|
|
$this->db->where('patient_id',$patientId);
|
|
$billed = $this->db->get('timesheet_approval')->result_array();
|
|
$patients[$indx]['billed_count'] = $billed[0]['billedAmmount'];
|
|
|
|
$this->db->select('COUNT(*) as unbilledAmmount');
|
|
$this->db->where('billed',0);
|
|
$this->db->where('isApproved',1);
|
|
$this->db->where('patient_id', $patientId);
|
|
$unbilled = $this->db->get('timesheet_approval')->result_array();
|
|
$patients[$indx]['unBilled_count'] = $unbilled[0]['unbilledAmmount'];
|
|
}
|
|
|
|
|
|
|
|
//$patients = $this->db->get();
|
|
return $patients;
|
|
}
|
|
|
|
function getNameByLimitBySearch($limit, $start, $search,$orderColumn,$orderType) {
|
|
|
|
if($orderColumn==1){
|
|
$this->db->order_by('name', $orderType);
|
|
}
|
|
$this->db->select("patient_details.*,CONCAT_WS(' ', patient_details.first_name, patient_details.last_name) AS name");
|
|
$this->db->from("patient_details");
|
|
$this->db->where('patient_details.id IN (SELECT DISTINCT patient_id FROM timesheet_approval)');
|
|
$this->db->where('patient_details.active_status',1);
|
|
|
|
$this->db->like('patient_details.first_name', $search);
|
|
$this->db->or_like('patient_details.last_name', $search);
|
|
$this->db->limit($limit, $start);
|
|
$patients = $this->db->get()->result_array();
|
|
//echo '<pre>'; print_r($patients); echo '</pre>'; die;
|
|
foreach($patients as $indx=>$patient)
|
|
{
|
|
$patientId = $patient['id'];
|
|
|
|
$this->db->select('COUNT(*) as billedAmmount');
|
|
$this->db->where('billed',1);
|
|
$this->db->where('isApproved',1);
|
|
$this->db->where('patient_id',$patientId);
|
|
$billed = $this->db->get('timesheet_approval')->result_array();
|
|
$patients[$indx]['billed_count'] = $billed[0]['billedAmmount'];
|
|
|
|
$this->db->select('COUNT(*) as unbilledAmmount');
|
|
$this->db->where('billed',0);
|
|
$this->db->where('isApproved',1);
|
|
$this->db->where('patient_id', $patientId);
|
|
$unbilled = $this->db->get('timesheet_approval')->result_array();
|
|
$patients[$indx]['unBilled_count'] = $unbilled[0]['unbilledAmmount'];
|
|
}
|
|
return $patients;
|
|
}
|
|
|
|
function caregiverInfo($id){
|
|
//print_r($id);exit;
|
|
$this->db->select("timesheet_approval.*");
|
|
$this->db->select("CONCAT_WS(' ', patient_details.first_name, patient_details.last_name) AS patient_name");
|
|
//$this->db->select("assessment.timeIn as timeIn,assessment.timeOut as timeOut");
|
|
$this->db->select("caregiver.fname as caregiver_fname,caregiver.lname as caregiver_lname");
|
|
$this->db->select("timesheet_approval.isApproved as isApproved");
|
|
$this->db->from("timesheet_approval");
|
|
$this->db->where('timesheet_approval.patient_id', $id);
|
|
$this->db->where('timesheet_approval.billed', 0);
|
|
$this->db->join("patient_details", "timesheet_approval.patient_id = patient_details.id","left");
|
|
$this->db->join("caregiver", "timesheet_approval.caregiver_id = caregiver.id","left");
|
|
//$this->db->join("assessment", "assessment.patient_id=timesheet_approval.patient_id","left");
|
|
|
|
|
|
//echo $this->db->get_compiled_select(); die;
|
|
$query = $this->db->get()->result();
|
|
// echo $this->db->last_query();die;
|
|
// echo '<pre>'; print_r($query); echo '</pre>'; die;
|
|
return $query;
|
|
}
|
|
function getPatientInformation($id){
|
|
//print_r($id);exit;
|
|
$this->db->select("timesheet_approval.*");
|
|
$this->db->or_where_in('id', $id);
|
|
$this->db->from("timesheet_approval");
|
|
$timesheet = $this->db->get()->result();
|
|
//echo '<pre>'; print_r($timesheet); echo '</pre>'; exit;
|
|
$this->db->select_max('date');
|
|
$this->db->from('timesheet_approval');
|
|
$this->db->where('patient_id', $timesheet[0]->patient_id);
|
|
$maxDate = $this->db->get()->row();
|
|
//echo '<pre>'; print_r($maxDate); echo '</pre>'; exit;
|
|
$this->db->select_min('date');
|
|
$this->db->from('timesheet_approval');
|
|
$this->db->where('patient_id', $timesheet[0]->patient_id);
|
|
$minDate = $this->db->get()->row();
|
|
//echo '<pre>'; print_r($minDate); echo '</pre>'; exit;
|
|
$this->db->select("patient_details.*");
|
|
$this->db->select("master_cg_skills.name as patient_level_service");
|
|
$this->db->select("patient_insurance_info.InsEin as ein,patient_insurance_info.InsContractStart as start_date,patient_insurance_info.InsContractEnd as end_date,patient_insurance_info.InsLocation as location");
|
|
//$this->db->select("patient_payment_info.payerType as payer_type");
|
|
$this->db->where('patient_details.id', $timesheet[0]->patient_id);
|
|
$this->db->from("patient_details");
|
|
$this->db->join("master_cg_skills", "patient_details.level_of_service = master_cg_skills.id");
|
|
//$this->db->join("patient_payment_info", "patient_details.id = patient_payment_info.patient_id");
|
|
$this->db->join("patient_insurance_info", "patient_details.id = patient_insurance_info.main_id");
|
|
|
|
$query = $this->db->get()->row();
|
|
$patient_payment_info = $this->db->get_where('patient_payment_info',array('patient_id'=>$query->id))->row();
|
|
$query->maxDate = $maxDate;
|
|
$query->minDate = $minDate;
|
|
$query->payer_type = $patient_payment_info;
|
|
// echo $this->db->get_compiled_select(); die;
|
|
|
|
//echo $this->db->last_query();die;
|
|
//echo '<pre>'; print_r($query); echo '</pre>'; exit;
|
|
return $query;
|
|
}
|
|
function getPayerType(){
|
|
$query=$this->db->get_where('master_payertype', array('status' => '1'));
|
|
return $query->result();
|
|
}
|
|
function getPatient($id){
|
|
|
|
$query=$this->db->get_where('patient_details', array('id' => $id))->row();
|
|
$patient_level_service = $this->db->get_where('master_cg_skills',array('id'=>$query->level_of_service))->row();
|
|
$query->patient_level_services = $patient_level_service;
|
|
return $query;
|
|
}
|
|
function saveBill($data) {
|
|
unset($data['submit']);
|
|
$folder_name='uploads/BillingDocuments/BILL_'.str_pad($data['patient_id'], 6, "0", STR_PAD_LEFT).'/';
|
|
$uploadData['folder_name']=$folder_name;
|
|
$uploadData['NAME']='uploads';
|
|
$uploadData['NEW_FILENAME_START']='DOC';
|
|
//$uploadData['CONFIG']['allowed_types']='gif|jpg|png|jpeg|pdf';
|
|
$uploadData['CONFIG']['allowed_types']=array('gif','jpg','png','jpeg','pdf');
|
|
$uploadData['CONFIG']['max_size']='20480000';
|
|
|
|
$output=fileStore($_FILES,$uploadData);
|
|
|
|
|
|
$data['uploads'] = $output['NEW_FILE_NAME'];
|
|
$data['upload_path'] = $output['PATH'];
|
|
|
|
$this->db->insert('bill', $data);
|
|
|
|
$insert_id = $this->db->insert_id();
|
|
|
|
$this->db->select("timesheet_approval.*");
|
|
$this->db->select("CONCAT_WS(' ', patient_details.first_name, patient_details.last_name) AS patient_name");
|
|
$this->db->select("caregiver.fname as caregiver_fname,caregiver.lname as caregiver_lname");
|
|
$this->db->select("timesheet_approval.isApproved as isApproved");
|
|
$this->db->from("timesheet_approval");
|
|
$this->db->where('timesheet_approval.patient_id', $data['patient_id']);
|
|
$this->db->join("patient_details", "timesheet_approval.patient_id = patient_details.id");
|
|
$this->db->join("caregiver", "timesheet_approval.caregiver_id = caregiver.id");
|
|
//$this->db->join("assessment", "patient.id = assessment.patient_id");
|
|
$query = $this->db->get()->result();
|
|
// echo $this->db->last_query();die;
|
|
// echo '<pre>'; print_r($query); echo '</pre>'; die;
|
|
foreach ($query as $key => $val) {
|
|
$inv_id = $insert_id;
|
|
$inv_id = "INV-HMS/".date("ymd") . sprintf('%03s', $inv_id);//concatenating incremented value
|
|
$value = $inv_id;
|
|
$billDetails = array(
|
|
'timesheeet_id' => $val->id,
|
|
'assessment_id' => $val->assessment_id,
|
|
'patient_id' => $val->patient_id,
|
|
'caregiver_id' => $val->caregiver_id,
|
|
'bill_id' => $insert_id,
|
|
'invoice_id' => $value,
|
|
'date' => $val->date,
|
|
'inTime' => $val->inTime,
|
|
'outTime' => $val->outTime,
|
|
'totalTime' => $val->totalTime,
|
|
'comment' => $val->comment,
|
|
'isApproved' => $val->isApproved
|
|
);
|
|
$this->db->select("bill.*");
|
|
$this->db->where('id', $insert_id);
|
|
$this->db->from("bill");
|
|
$bill_id['invoice_id'] = $inv_id;
|
|
$this->db->update('bill', $bill_id);
|
|
|
|
$this->db->insert('bill_details', $billDetails);
|
|
}
|
|
foreach ($query as $key => $val) {
|
|
$this->db->select("timesheet_approval.*");
|
|
$this->db->where('id', $val->id);
|
|
$this->db->from("timesheet_approval");
|
|
$timesheetUpdate = array(
|
|
'billed' => 1
|
|
);
|
|
$this->db->update('timesheet_approval', $timesheetUpdate);
|
|
}
|
|
|
|
//echo $this->db->last_query();die;
|
|
|
|
|
|
}
|
|
|
|
}
|