<?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 tb_tindakan INNER JOIN datapasien ON tb_tindakan.id_pasien = datapasien.id_pasien WHERE  timestamp BETWEEN '$awal' AND '$akhir' AND tindakan like '%$tindakan%' AND masalah='selesai ' ORDER BY masalah 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 keterangan like '%gelang_id%'"));
    if ($checkdata > 0) {
        $site = "<div class='btn btn-sm btn-success'><i class='fas fa-check'></i></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]'>
                Survei
                </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>Survei</th>
                            	<th>Ya</th>
                            	<th>Tidak</th>
                            </tr>
                            <tr class='table-stripped'>
                                <td>Apakah pasien sudah mendapat penjelasan saat akan dipasang gelang identitas?</td>
                                <td align='center'><input type='radio' required name='question1' value='1'></td>
                                <td align='center'><input type='radio' name='question1' value='0'></td>
                            </tr>
                            <tr class='table-stripped'>
                                <td>Apakah pasien sudah memahami tujuan dan manfaat pemasangan gelang identitas?</td>
                                <td align='center'><input type='radio' required name='question2' value='1'></td>
                                <td align='center'><input type='radio' name='question2' value='0'></td>
                            </tr>
                         </table>
                         <div class='modal-footer'>
                                <button type='submit' class='btn btn-primary btn-sm' id='simpan_survey' name='simpan_survey'>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);
