<?php

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

class M_drts_lp_ppi extends CI_Model {
    function ruang(){
        $query = $this->load->database('saturssa', TRUE);
        $query->where('Pelayanan', "Ya");
        $query->order_by('Nama', 'ASC');
        return $query->get('daftar_lokasi_ruang')->result();
    }

//================================================================PLEBITIS
    function plebitis() {
        if(isset($_POST['tanggalmonitoring'])) {
            $dateall    = $this->input->post('tanggalmonitoring');
            $pisah      = explode ("-", $dateall);
            $awal       = date("Y-m-d", strtotime($pisah[0]));
            $akhir      = date("Y-m-d", strtotime($pisah[1]));
        }else{
            $awal       = date("Y-m-d");
            $akhir      = date("Y-m-d");
        }

        $query = $this->load->database('saturssa', TRUE);
        $query->join('directus_users',      'directus_users.id = data_medis_plebitis.user_created', 'left');
        $query->join('data_mrs',            'data_mrs.id = data_medis_plebitis.FK_datamrs_datamedisplebitis_ID', 'left');
        $query->join('data_ppi',            'data_ppi.id = data_mrs.FK_ppi_datamrs_ID', 'left');
        $query->join('daftar_lokasi_ruang', 'daftar_lokasi_ruang.id = data_mrs.Ruang', 'left');
        $query->where('Tanggal_monitoring >=', $awal);
        $query->where('Tanggal_monitoring <=', $akhir);
        $query->order_by('Nama_pasien', 'ASC');
        $query->order_by('No_rekam_medis', 'ASC');
        $query->order_by('Tanggal_mrs', 'ASC');
        $query->order_by('Monitoring_ke', 'ASC');
        return $query->get('data_medis_plebitis')->result();
    }

    function medisplebitis(){
        if(isset($_POST['tanggalmonitoring'])) {
            $dateall    = $this->input->post('tanggalmonitoring');
            $pisah      = explode ("-", $dateall);
            $awal       = date("Y-m-d", strtotime($pisah[0]));
            $akhir      = date("Y-m-d", strtotime($pisah[1]));
        }else{
            $awal       = date("Y-m-d");
            $akhir      = date("Y-m-d");
        }

        $query = $this->load->database('saturssa', TRUE);
        $query->select('Monitoring_ke,Lama_pemakaian_infus,Diagnosa_nilai_plebitis_ppi,Tanggal_pemasangan_infus,FK_datamrs_datamedisplebitis_ID');
        $query->where('Tanggal_monitoring >=', $awal);
        $query->where('Tanggal_monitoring <=', $akhir);
        $query->order_by('Tanggal_pemasangan_infus','DESC');
        $query->order_by('Monitoring_ke','DESC');
        return $query->get('data_medis_plebitis')->result();
    }

//================================================================VAP

    function vap() {
        if(isset($_POST['tanggalmonitoring'])) {
            $dateall    = $this->input->post('tanggalmonitoring');
            $pisah      = explode ("-", $dateall);
            $awal       = date("Y-m-d", strtotime($pisah[0]));
            $akhir      = date("Y-m-d", strtotime($pisah[1]));
        }else{
            $awal       = date("Y-m-d");
            $akhir      = date("Y-m-d");
        }
        $query = $this->load->database('saturssa', TRUE);
        $query->join('directus_users',      'directus_users.id = data_medis_svap.user_created', 'left');
        $query->join('data_mrs',            'data_mrs.id = data_medis_svap.FK_datamrs_datamedissvap_ID', 'left');
        $query->join('data_ppi',            'data_ppi.id = data_mrs.FK_ppi_datamrs_ID', 'left');
        $query->join('daftar_lokasi_ruang', 'daftar_lokasi_ruang.id = data_mrs.Ruang', 'left');
        $query->where('Tanggal_monitoring >=', $awal);
        $query->where('Tanggal_monitoring <=', $akhir);
        $query->order_by('Nama_pasien', 'ASC');
        $query->order_by('No_rekam_medis', 'ASC');
        $query->order_by('Tanggal_mrs', 'ASC');
        $query->order_by('Monitoring_ke', 'ASC');
        return $query->get('data_medis_svap')->result();
    }

    function medisvap(){
        if(isset($_POST['tanggalmonitoring'])) {
            $dateall    = $this->input->post('tanggalmonitoring');
            $pisah      = explode ("-", $dateall);
            $awal       = date("Y-m-d", strtotime($pisah[0]));
            $akhir      = date("Y-m-d", strtotime($pisah[1]));
        }else{
            $awal       = date("Y-m-d");
            $akhir      = date("Y-m-d");
        }

        $query = $this->load->database('saturssa', TRUE);
        $query->select('Monitoring_ke,Lama_pemakaian_ventilator,Tanggal_pemasangan_ventilator,Diagnosa_ppi_dpjp,FK_datamrs_datamedissvap_ID');
        $query->where('Tanggal_monitoring >=', $awal);
        $query->where('Tanggal_monitoring <=', $akhir);
        $query->order_by('Tanggal_pemasangan_ventilator','DESC');
        $query->order_by('Monitoring_ke','DESC');
        return $query->get('data_medis_svap')->result();
    }

//================================================================HAP
    
    function hap() {
        if(isset($_POST['tanggalmonitoring'])) {
            $dateall    = $this->input->post('tanggalmonitoring');
            $pisah      = explode ("-", $dateall);
            $awal       = date("Y-m-d", strtotime($pisah[0]));
            $akhir      = date("Y-m-d", strtotime($pisah[1]));
        }else{
            $awal       = date("Y-m-d");
            $akhir      = date("Y-m-d");
        }
        $query = $this->load->database('saturssa', TRUE);
        $query->join('directus_users',      'directus_users.id = data_medis_hap.user_created', 'left');
        $query->join('data_mrs',            'data_mrs.id = data_medis_hap.FK_datamrs_datamedishap_ID', 'left');
        $query->join('data_ppi',            'data_ppi.id = data_mrs.FK_ppi_datamrs_ID', 'left');
        $query->join('daftar_lokasi_ruang', 'daftar_lokasi_ruang.id = data_mrs.Ruang', 'left');
        $query->where('Tanggal_monitoring >=', $awal);
        $query->where('Tanggal_monitoring <=', $akhir);
        $query->order_by('Nama_pasien', 'ASC');
        $query->order_by('No_rekam_medis', 'ASC');
        $query->order_by('Tanggal_mrs', 'ASC');
        $query->order_by('Monitoring_ke', 'ASC');
        return $query->get('data_medis_hap')->result();
    }

    function medishap(){
        if(isset($_POST['tanggalmonitoring'])) {
            $dateall    = $this->input->post('tanggalmonitoring');
            $pisah      = explode ("-", $dateall);
            $awal       = date("Y-m-d", strtotime($pisah[0]));
            $akhir      = date("Y-m-d", strtotime($pisah[1]));
        }else{
            $awal       = date("Y-m-d");
            $akhir      = date("Y-m-d");
        }

        $query = $this->load->database('saturssa', TRUE);
        $query->select('Monitoring_ke,Lama_tirah_baring,Tanggal_mulai_tirah_baring,Diagnosa_ppi_dpjp,FK_datamrs_datamedishap_ID');
        $query->where('Tanggal_monitoring >=', $awal);
        $query->where('Tanggal_monitoring <=', $akhir);
        $query->order_by('Tanggal_mulai_tirah_baring','DESC');
        $query->order_by('Monitoring_ke','DESC');
        return $query->get('data_medis_hap')->result();
    }

//================================================================IAD ANAK
    
    function iadanak() {
        if(isset($_POST['tanggalmonitoring'])) {
            $dateall    = $this->input->post('tanggalmonitoring');
            $pisah      = explode ("-", $dateall);
            $awal       = date("Y-m-d", strtotime($pisah[0]));
            $akhir      = date("Y-m-d", strtotime($pisah[1]));
        }else{
            $awal       = date("Y-m-d");
            $akhir      = date("Y-m-d");
        }
        $query = $this->load->database('saturssa', TRUE);
        $query->join('directus_users',      'directus_users.id = data_medis_siad_anak.user_created', 'left');
        $query->join('data_mrs',            'data_mrs.id = data_medis_siad_anak.FK_datamrs_datamedissiadanak_ID', 'left');
        $query->join('data_ppi',            'data_ppi.id = data_mrs.FK_ppi_datamrs_ID', 'left');
        $query->join('daftar_lokasi_ruang', 'daftar_lokasi_ruang.id = data_mrs.Ruang', 'left');
        $query->where('Tanggal_monitoring >=', $awal);
        $query->where('Tanggal_monitoring <=', $akhir);
        $query->order_by('Nama_pasien', 'ASC');
        $query->order_by('No_rekam_medis', 'ASC');
        $query->order_by('Tanggal_mrs', 'ASC');
        $query->order_by('Monitoring_ke', 'ASC');
        return $query->get('data_medis_siad_anak')->result();
    }

    function medisiadanak(){
        if(isset($_POST['tanggalmonitoring'])) {
            $dateall    = $this->input->post('tanggalmonitoring');
            $pisah      = explode ("-", $dateall);
            $awal       = date("Y-m-d", strtotime($pisah[0]));
            $akhir      = date("Y-m-d", strtotime($pisah[1]));
        }else{
            $awal       = date("Y-m-d");
            $akhir      = date("Y-m-d");
        }

        $query = $this->load->database('saturssa', TRUE);
        $query->select('Monitoring_ke,Lama_pemakaian_cvc,Tanggal_pemasangan_cvc,Diagnosa_ppi_dpjp,FK_datamrs_datamedissiadanak_ID');
        $query->where('Tanggal_monitoring >=', $awal);
        $query->where('Tanggal_monitoring <=', $akhir);
        $query->order_by('Tanggal_pemasangan_cvc','DESC');
        $query->order_by('Monitoring_ke','DESC');
        return $query->get('data_medis_siad_anak')->result();
    }

//================================================================IAD DEWASA
    
    function iaddewasa() {
        if(isset($_POST['tanggalmonitoring'])) {
            $dateall    = $this->input->post('tanggalmonitoring');
            $pisah      = explode ("-", $dateall);
            $awal       = date("Y-m-d", strtotime($pisah[0]));
            $akhir      = date("Y-m-d", strtotime($pisah[1]));
        }else{
            $awal       = date("Y-m-d");
            $akhir      = date("Y-m-d");
        }
        $query = $this->load->database('saturssa', TRUE);
        $query->join('directus_users',      'directus_users.id = data_medis_siad_dewasa.user_created', 'left');
        $query->join('data_mrs',            'data_mrs.id = data_medis_siad_dewasa.FK_datamrs_datamedissiaddewasa_ID', 'left');
        $query->join('data_ppi',            'data_ppi.id = data_mrs.FK_ppi_datamrs_ID', 'left');
        $query->join('daftar_lokasi_ruang', 'daftar_lokasi_ruang.id = data_mrs.Ruang', 'left');
        $query->where('Tanggal_monitoring >=', $awal);
        $query->where('Tanggal_monitoring <=', $akhir);
        $query->order_by('Nama_pasien', 'ASC');
        $query->order_by('No_rekam_medis', 'ASC');
        $query->order_by('Tanggal_mrs', 'ASC');
        $query->order_by('Monitoring_ke', 'ASC');
        return $query->get('data_medis_siad_dewasa')->result();
    }

    function medisiaddewasa(){
        if(isset($_POST['tanggalmonitoring'])) {
            $dateall    = $this->input->post('tanggalmonitoring');
            $pisah      = explode ("-", $dateall);
            $awal       = date("Y-m-d", strtotime($pisah[0]));
            $akhir      = date("Y-m-d", strtotime($pisah[1]));
        }else{
            $awal       = date("Y-m-d");
            $akhir      = date("Y-m-d");
        }

        $query = $this->load->database('saturssa', TRUE);
        $query->select('Monitoring_ke,Lama_pemakaian_cvc,Tanggal_pemasangan_cvc,Diagnosa_ppi_dpjp,FK_datamrs_datamedissiaddewasa_ID');
        $query->where('Tanggal_monitoring >=', $awal);
        $query->where('Tanggal_monitoring <=', $akhir);
        $query->order_by('Tanggal_pemasangan_cvc','DESC');
        $query->order_by('Monitoring_ke','DESC');
        return $query->get('data_medis_siad_dewasa')->result();
    }

//================================================================ISK ANAK

    function iskanak() {
        if(isset($_POST['tanggalmonitoring'])) {
            $dateall    = $this->input->post('tanggalmonitoring');
            $pisah      = explode ("-", $dateall);
            $awal       = date("Y-m-d", strtotime($pisah[0]));
            $akhir      = date("Y-m-d", strtotime($pisah[1]));
        }else{
            $awal       = date("Y-m-d");
            $akhir      = date("Y-m-d");
        }
        $query = $this->load->database('saturssa', TRUE);
        $query->join('directus_users',      'directus_users.id = data_medis_sisk_anak.user_created', 'left');
        $query->join('data_mrs',            'data_mrs.id = data_medis_sisk_anak.FK_datamrs_datamedissiskanak_ID', 'left');
        $query->join('data_ppi',            'data_ppi.id = data_mrs.FK_ppi_datamrs_ID', 'left');
        $query->join('daftar_lokasi_ruang', 'daftar_lokasi_ruang.id = data_mrs.Ruang', 'left');
        $query->where('Tanggal_monitoring >=', $awal);
        $query->where('Tanggal_monitoring <=', $akhir);
        $query->order_by('Nama_pasien', 'ASC');
        $query->order_by('No_rekam_medis', 'ASC');
        $query->order_by('Tanggal_mrs', 'ASC');
        $query->order_by('Monitoring_ke', 'ASC');
        return $query->get('data_medis_sisk_anak')->result();
    }

    function medisiskanak(){
        if(isset($_POST['tanggalmonitoring'])) {
            $dateall    = $this->input->post('tanggalmonitoring');
            $pisah      = explode ("-", $dateall);
            $awal       = date("Y-m-d", strtotime($pisah[0]));
            $akhir      = date("Y-m-d", strtotime($pisah[1]));
        }else{
            $awal       = date("Y-m-d");
            $akhir      = date("Y-m-d");
        }

        $query = $this->load->database('saturssa', TRUE);
        $query->select('Monitoring_ke,Lama_pemakaian_catheter_urine,Tanggal_pemasangan_catheter_urine,Diagnosa_ppi_dpjp,FK_datamrs_datamedissiskanak_ID');
        $query->where('Tanggal_monitoring >=', $awal);
        $query->where('Tanggal_monitoring <=', $akhir);
        $query->order_by('Tanggal_pemasangan_catheter_urine','DESC');
        $query->order_by('Monitoring_ke','DESC');
        return $query->get('data_medis_sisk_anak')->result();
    }

//================================================================ISK DEWASA

    function iskdewasa() {
        if(isset($_POST['tanggalmonitoring'])) {
            $dateall    = $this->input->post('tanggalmonitoring');
            $pisah      = explode ("-", $dateall);
            $awal       = date("Y-m-d", strtotime($pisah[0]));
            $akhir      = date("Y-m-d", strtotime($pisah[1]));
        }else{
            $awal       = date("Y-m-d");
            $akhir      = date("Y-m-d");
        }
        $query = $this->load->database('saturssa', TRUE);
        $query->join('directus_users',      'directus_users.id = data_medis_sisk_dewasa.user_created', 'left');
        $query->join('data_mrs',            'data_mrs.id = data_medis_sisk_dewasa.FK_datamrs_datamedissiskdewasa_ID', 'left');
        $query->join('data_ppi',            'data_ppi.id = data_mrs.FK_ppi_datamrs_ID', 'left');
        $query->join('daftar_lokasi_ruang', 'daftar_lokasi_ruang.id = data_mrs.Ruang', 'left');
        $query->where('Tanggal_monitoring >=', $awal);
        $query->where('Tanggal_monitoring <=', $akhir);
        $query->order_by('Nama_pasien', 'ASC');
        $query->order_by('No_rekam_medis', 'ASC');
        $query->order_by('Tanggal_mrs', 'ASC');
        $query->order_by('Monitoring_ke', 'ASC');
        return $query->get('data_medis_sisk_dewasa')->result();
    }

    function medisiskdewasa(){
        if(isset($_POST['tanggalmonitoring'])) {
            $dateall    = $this->input->post('tanggalmonitoring');
            $pisah      = explode ("-", $dateall);
            $awal       = date("Y-m-d", strtotime($pisah[0]));
            $akhir      = date("Y-m-d", strtotime($pisah[1]));
        }else{
            $awal       = date("Y-m-d");
            $akhir      = date("Y-m-d");
        }

        $query = $this->load->database('saturssa', TRUE);
        $query->select('Monitoring_ke,Lama_pemakaian_catheter_urine,Tanggal_pemasangan_catheter_urine,Diagnosa_ppi_dpjp,FK_datamrs_datamedissiskdewasa_ID');
        $query->where('Tanggal_monitoring >=', $awal);
        $query->where('Tanggal_monitoring <=', $akhir);
        $query->order_by('Tanggal_pemasangan_catheter_urine','DESC');
        $query->order_by('Monitoring_ke','DESC');
        return $query->get('data_medis_sisk_dewasa')->result();
    }

//================================================================SIOB

    function idobersih() {
        if(isset($_POST['tanggalmonitoring'])) {
            $dateall    = $this->input->post('tanggalmonitoring');
            $pisah      = explode ("-", $dateall);
            $awal       = date("Y-m-d", strtotime($pisah[0]));
            $akhir      = date("Y-m-d", strtotime($pisah[1]));
        }else{
            $awal       = date("Y-m-d");
            $akhir      = date("Y-m-d");
        }
        $query = $this->load->database('saturssa', TRUE);
        $query->join('directus_users',      'directus_users.id = data_medis_siob.user_created', 'left');
        $query->join('data_mrs',            'data_mrs.id = data_medis_siob.FK_datamrs_datamedissiob_ID', 'left');
        $query->join('data_ppi',            'data_ppi.id = data_mrs.FK_ppi_datamrs_ID', 'left');
        $query->join('daftar_lokasi_ruang', 'daftar_lokasi_ruang.id = data_mrs.Ruang', 'left');
        $query->where('Tanggal_monitoring >=', $awal);
        $query->where('Tanggal_monitoring <=', $akhir);
        $query->order_by('Nama_pasien', 'ASC');
        $query->order_by('No_rekam_medis', 'ASC');
        $query->order_by('Tanggal_mrs', 'ASC');
        $query->order_by('Monitoring_ke', 'ASC');
        return $query->get('data_medis_siob')->result();
    }

    function medisidobersih(){
        if(isset($_POST['tanggalmonitoring'])) {
            $dateall    = $this->input->post('tanggalmonitoring');
            $pisah      = explode ("-", $dateall);
            $awal       = date("Y-m-d", strtotime($pisah[0]));
            $akhir      = date("Y-m-d", strtotime($pisah[1]));
        }else{
            $awal       = date("Y-m-d");
            $akhir      = date("Y-m-d");
        }

        $query = $this->load->database('saturssa', TRUE);
        $query->select('Monitoring_ke,Lama_hari_perawatan,Tanggal_operasi,Diagnosa_ppi_dpjp,FK_datamrs_datamedissiob_ID');
        $query->where('Tanggal_monitoring >=', $awal);
        $query->where('Tanggal_monitoring <=', $akhir);
        $query->order_by('Tanggal_operasi','DESC');
        $query->order_by('Monitoring_ke','DESC');
        return $query->get('data_medis_siob')->result();
    }

//================================================================SIOBT

    function idoterkontaminasi() {
        if(isset($_POST['tanggalmonitoring'])) {
            $dateall    = $this->input->post('tanggalmonitoring');
            $pisah      = explode ("-", $dateall);
            $awal       = date("Y-m-d", strtotime($pisah[0]));
            $akhir      = date("Y-m-d", strtotime($pisah[1]));
        }else{
            $awal       = date("Y-m-d");
            $akhir      = date("Y-m-d");
        }
        $query = $this->load->database('saturssa', TRUE);
        $query->join('directus_users',      'directus_users.id = data_medis_siobt.user_created', 'left');
        $query->join('data_mrs',            'data_mrs.id = data_medis_siobt.FK_datamrs_datamedissiobt_ID', 'left');
        $query->join('data_ppi',            'data_ppi.id = data_mrs.FK_ppi_datamrs_ID', 'left');
        $query->join('daftar_lokasi_ruang', 'daftar_lokasi_ruang.id = data_mrs.Ruang', 'left');
        $query->where('Tanggal_monitoring >=', $awal);
        $query->where('Tanggal_monitoring <=', $akhir);
        $query->order_by('Nama_pasien', 'ASC');
        $query->order_by('No_rekam_medis', 'ASC');
        $query->order_by('Tanggal_mrs', 'ASC');
        $query->order_by('Monitoring_ke', 'ASC');
        return $query->get('data_medis_siobt')->result();
    }

    function medisidoterkontaminasi(){
        if(isset($_POST['tanggalmonitoring'])) {
            $dateall    = $this->input->post('tanggalmonitoring');
            $pisah      = explode ("-", $dateall);
            $awal       = date("Y-m-d", strtotime($pisah[0]));
            $akhir      = date("Y-m-d", strtotime($pisah[1]));
        }else{
            $awal       = date("Y-m-d");
            $akhir      = date("Y-m-d");
        }

        $query = $this->load->database('saturssa', TRUE);
        $query->select('Monitoring_ke,Lama_hari_perawatan,Tanggal_operasi,Diagnosa_ppi_dpjp,FK_datamrs_datamedissiobt_ID');
        $query->where('Tanggal_monitoring >=', $awal);
        $query->where('Tanggal_monitoring <=', $akhir);
        $query->order_by('Tanggal_operasi','DESC');
        $query->order_by('Monitoring_ke','DESC');
        return $query->get('data_medis_siobt')->result();
    }

    function datamrs(){
        $query = $this->load->database('saturssa', TRUE);
        $query->select('mrs.id, mrs.Tanggal_mrs, mrs.Tanggal_krs, ruang.Kode, ruang.Nama, ruang.Kelas');
        $query->join('daftar_lokasi_ruang ruang',       'ruang.id   = mrs.Ruang', 'left');
        return $query->get('data_mrs as mrs')->result();
    }

    function cucitangan(){
        if(isset($_POST['tanggalmonitoring'])) {
            $dateall    = $this->input->post('tanggalmonitoring');
            $pisah      = explode ("-", $dateall);
            $awal       = date("Y-m-d", strtotime($pisah[0]));
            $akhir      = date("Y-m-d", strtotime($pisah[1]));
        }else{
            $awal       = date("Y-m-d");
            $akhir      = date("Y-m-d");
        }

        $query = $this->load->database('saturssa', TRUE);
        $query->select('daftar_lokasi_ruang.Nama as namaruang,daftar_lokasi_ruang.Kode as koderuang, daftar_lokasi_ruang.Kelas as kelasruang, daftar_lokasi_ruang.id as idruang,
                        directus_users.first_name as first_name, 
                        data_cuci_tangan.date_created  as date_created, 
                        data_cuci_tangan_petugas.Petugas_cuci_tangan as petugas_cuci_tangan, 
                        data_cuci_tangan.Nilai_kepatuhan as nilai_kepatuhan, 
                        ');
        $query->join('data_tahun_bulan_cuci_tangan',        'data_ruang_cuci_tangan.id          = data_tahun_bulan_cuci_tangan.FK_ruang_tahun_bulan_ID', 'left');
        $query->join('data_cuci_tangan_petugas',            'data_tahun_bulan_cuci_tangan.id    = data_cuci_tangan_petugas.FK_tahun_bulan_petugas_ID', 'left');
        $query->join('data_cuci_tangan',                    'data_cuci_tangan_petugas.id        = data_cuci_tangan.FK_cuci_tangan_petugas_cuci_tangan_ID', 'left');
        $query->join('directus_users',                      'directus_users.id                  = data_cuci_tangan.user_created', 'left');
        $query->join('daftar_lokasi_ruang',                 'daftar_lokasi_ruang.id             = data_ruang_cuci_tangan.Ruangan', 'left');
        $query->where('Tanggal_cuci_tangan >=', $awal);
        $query->where('Tanggal_cuci_tangan <=', $akhir);
        $query->order_by('daftar_lokasi_ruang.Nama','ASC');
        $query->order_by('data_cuci_tangan_petugas.Petugas_cuci_tangan','ASC');
        return $query->get('data_ruang_cuci_tangan')->result();
    }

    function apd(){
        if(isset($_POST['tanggalmonitoring'])) {
            $dateall    = $this->input->post('tanggalmonitoring');
            $pisah      = explode ("-", $dateall);
            $awal       = date("Y-m-d", strtotime($pisah[0]));
            $akhir      = date("Y-m-d", strtotime($pisah[1]));
        }else{
            $awal       = date("Y-m-d");
            $akhir      = date("Y-m-d");
        }

        $query = $this->load->database('saturssa', TRUE);
        $query->select('daftar_lokasi_ruang.Nama as namaruang,daftar_lokasi_ruang.Kode as koderuang, daftar_lokasi_ruang.Kelas as kelasruang, daftar_lokasi_ruang.id as idruang,
                        directus_users.first_name as first_name, 
                        data_kepatuhan.date_created  as date_created, 
                        daftar_jenis_tindakan.Jenis_tindakan as jenis_tindakan, daftar_jenis_tindakan.Keterangan as keterangan,
                        data_kepatuhan.A_patuh as apatuh, data_kepatuhan.A_tidak_patuh as atidak_patuh, 
                        data_kepatuhan.B_patuh as bpatuh, data_kepatuhan.B_tidak_patuh as btidak_patuh, 
                        data_kepatuhan.C_patuh as cpatuh, data_kepatuhan.C_tidak_patuh as ctidak_patuh, 
                        data_kepatuhan.D_patuh as dpatuh, data_kepatuhan.D_tidak_patuh as dtidak_patuh, 
                        data_kepatuhan.E_patuh as epatuh, data_kepatuhan.E_tidak_patuh as etidak_patuh, 
                        data_kepatuhan.F_patuh as fpatuh, data_kepatuhan.F_tidak_patuh as ftidak_patuh, 
                        ');
        $query->join('data_apd',                            'data_ruang_apd.id          = data_apd.FK_ruang_apd_data_apd_ID', 'left');
        $query->join('data_kepatuhan',                      'data_apd.id                = data_kepatuhan.FK_data_apd_kepatuhan_ID', 'left');
        $query->join('directus_users',                      'directus_users.id          = data_kepatuhan.user_created', 'left');
        $query->join('daftar_lokasi_ruang',                 'daftar_lokasi_ruang.id     = data_ruang_apd.Ruangan', 'left');
        $query->join('daftar_jenis_tindakan',               'daftar_jenis_tindakan.id   = data_kepatuhan.Jenis_tindakan', 'left');

        $query->where('Tanggal_apd >=', $awal);
        $query->where('Tanggal_apd <=', $akhir);
        $query->order_by('daftar_lokasi_ruang.Nama','ASC');
        $query->order_by('daftar_lokasi_ruang.Kelas','ASC');
        $query->order_by('data_kepatuhan.Jenis_tindakan','ASC');
        return $query->get('data_ruang_apd')->result();
    }

}
?>