<?php

defined('BASEPATH') OR exit('No direct script access allowed');

class Labtest_Model extends CI_Model {

    public function insertlab() {
        $data = array("Patient_Id" => $_POST['patientid'],
            "Sample_Collection_Flag" => 1,
            "Date_Collection" => $_POST['collected_date'],
            "Lab_Type" => $_POST['lab_type'],
            
            "Lab_Id" => $_POST['lab_id'],
            "Inserted_SI" => $this->session->userdata('id'),
            "Inserted_BY" => $this->session->userdata('name'),
            "Inserted_DT" => date('Y-m-d H:i:s')
        );
        $this->db->insert('lab_tests', $data);
    }

    public function fetch_data() {

        $this->db->select('*');
        $this->db->from('lab_tests');
        $this->db->where('Deleted_DT', NULL);
        $this->db->order_by('LTtest_Id', 'DESC');
        $query = $this->db->get();
        return $query->result();
    }

    public function fetch_patients() {
        return $this->db->where('deleted_DT',NULL)->or_where('(deleted_DT IS NOT NULL AND deactive_cronjob_flag = 0)')->order_by('id', 'desc')->get('mst_guard')->result();
    }
    
    public function fetch_labs() {
        
        return $this->db->where('deleted_DT',NULL)->get('mst_labs')->result();
    }

   
    public function update($id) {

        $data = array("name" => $_POST['name'],
            "address" => $_POST['address'],
            "email" => $_POST['emailid'],
            "contact" => $_POST['contact'],
            "city" => $_POST['city'],
            "Longitude" => $_POST['longitude'],
            "Latitude" => $_POST['latitude'],
            "Modify_SI" => $this->session->userdata('id'),
            "Modify_BY" => $this->session->userdata('username'),
            "Modify_DT" => date('Y-m-d H:i:s'));
        $c = $this->db->where('id', $id)->update('mst_office', $data);
    }
    
    
       
    public function summary_delete($id) {

        $data = array(
            "Deleted_SI" => $this->session->userdata('id'),
            "Deleted_BY" => $this->session->userdata('username'),
            "Deleted_DT" => date('Y-m-d H:i:s'));
        $c = $this->db->where('LSumm_Id', $id)->update('tbl_lab_summaries', $data);
    }

    
    
    public function insert_lab_sumary() {
        $data = array(
            "Lab_Id" => $_POST['lab_id'],
            "Lab_Type" => $_POST['lab_type'],
            "total_samples_daily" => $_POST['total_samples_daily'],
            "total_samples_progressive" => $_POST['total_samples_progressive'],
            "total_positive_daily" => $_POST['total_positive_daily'],
            "total_positive_progressive" => $_POST['total_positive_progressive'],
            "total_negative_daily" => $_POST['total_negative_daily'],
            "total_negative_progressive" => $_POST['total_negative_progressive'],
            
            "Inserted_SI" => $this->session->userdata('id'),
            "Inserted_BY" => $this->session->userdata('name'),
            "Inserted_DT" => date('Y-m-d H:i:s')
        );
        $this->db->insert('tbl_lab_summaries', $data);
    }

    public function lab_summary_data() {

        $this->db->select('*');
        $this->db->from('tbl_lab_summaries');
        $this->db->where('Deleted_DT', NULL);
        $this->db->order_by('LSumm_Id', 'DESC');
        $query = $this->db->get();
        return $query->result();
    }
    

}
