<?php

date_default_timezone_set('asia/jakarta');
include "model/koneksi.php";

$awal  = date('Y-m-d H:i:s', strtotime($_GET['awal']));
$akhir = date('Y-m-d H:i:s', strtotime($_GET['akhir']));
$tindakan =                             $_GET['tindakan'];

$query = mysqli_query($open, "SELECT * FROM datapasien WHERE  tanggal BETWEEN '$awal' AND '$akhir'  AND NOT status_keluar like '%delete%' ORDER BY tanggal ASC ");

$array = array();
$no = 0;
$statuscode = '200';

while ($data = mysqli_fetch_assoc($query)) {
    $no++;
    $checkdata = mysqli_num_rows(mysqli_query($openinmut, "SELECT*FROM tb_indikator_mutu WHERE id_pasien='$data[id_pasien]' AND insiden=1 AND insiden_ctrl=1"));
    if ($checkdata > 0) {
        $site = "<div class='btn btn-sm btn-success'><i class='fas fa-check'></i></div>";
    } else {
        $checkdata = mysqli_num_rows(mysqli_query($openinmut, "SELECT*FROM tb_indikator_mutu WHERE id_pasien='$data[id_pasien]' AND insiden_ctrl=1 AND keterangan like '%control%'"));
        if ($checkdata > 0) {
            $site = "<div class='btn btn-sm btn-warning' style='font-size:8px;'>menunggu</div>";
        } else {
            $site = "";
        }
    }

    $sub_array['no']        = " <div>$no</div>";
    $sub_array['ruang']     = " <div>$data[ruang]</div>";
    $sub_array['tanggal']   = " <div>$data[tanggal]</div>";
    $sub_array['register']  = " <div>$data[register]</div>";
    $sub_array['nama']      = " <div>$data[nama]</div>";
    $sub_array['tindakan']  =
        "<div class='accordion accordion-flush' id='TombolSurvey'>
        <div class='accordion-item'>
            <h6 class='accordion-header' id='IsiSurvey'>
            <button id='linkfilter' class='accordion-button collapsed' type='button' data-bs-toggle='collapse' data-bs-target='#KolomSurvey$data[id_pasien]' aria-expanded='false' aria-controls='KolomSurvey$data[id_pasien]'>
                pilih laporan..
                </button>
                </h6>
                <div id='KolomSurvey$data[id_pasien]' class='accordion-collapse collapse' aria-labelledby='IsiSurvey' data-bs-parent='#TombolSurvey'>
                <div class='modal-body'>
                <form id='simpan' method='POST'>
                        <input type='text' hidden name='id_pasien' value='$data[id_pasien]'>
                        <input type='text' hidden name='tanggal' value='$data[tanggal]'>
                        <input type='text' hidden name='register' value='$data[register]'>
                        <input type='text' hidden name='tindakan' value='$tindakan'>
                        <input type='text' hidden name='awal' value='$awal'>
                        <input type='text' hidden name='akhir' value='$akhir'>
                        <table class='table table-bordered table-stripped'>
                            <tr class='table-stripped' align='center'>
                                <th>Jenis Laporan Insiden</th>
                                <th>Kontrol</th>
                            </tr>
                            <tr class='table-stripped'>
                                <td>KTD</td>
                                <td align='center'><input type='radio' required name='insiden_ctrl' value='ktd'></td>
                                
                                </tr>
                                <tr class='table-stripped'>

                                <td>KNC</td>
                                <td align='center'><input type='radio' required name='insiden_ctrl' value='knc'></td>
                             
                                </tr>
                                </table>
                                <div class='modal-footer'>
                                <button type='submit' class='btn btn-primary btn-sm' id='tambahData_kontrol' name='tambahData_kontrol'>simpan</button>
                                <button type='reset' class='btn btn-warning btn-sm' name='batal' data-bs-dismiss='modal'>Batal</button>
                        </div>
                    </form>
                </div>
            </div>
        </div>
        </div>";
    $sub_array['status'] = "<div>$site</div>";

    $array[] = $sub_array;
}
$dataset = array(
    "echo" => 1,

    "totalrecords" => count($array),
    "totaldisplayrecords" => count($array),
    "data" => $array

);
echo json_encode($dataset);
