<?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%' ");
$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 los=1"));

    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'>$data[status_keluar]<br>lama tunggu : $data[waiting]</div>";
    $sub_array['add']       = "<div class='input-group'>
                                <form method='POST'>
                                <input hidden type='text' name='id_pasien' value='$data[id_pasien]'>
                                <input hidden type='text' name='tanggal' value='$data[tanggal]'>
                                <input hidden type='text' name='register' value='$data[register]'>
                                <input hidden type='text' name='tindakan' value='$tindakan'>
                                <input hidden type='text' name='awal' value='$awal'>
                                <input hidden type='text' name='akhir' value='$akhir'>
                                <input type='submit' class='btn-primary btn-sm' name='tambahData' value='Add' aria-valuemin='0' oninvalid='this.setCustomValidity('pilih check dulu')'>
                                </form>
                                </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);
