<?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_tranfusi WHERE id_pasien='$data[id_pasien]'"));
    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'>
                <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'>
                <div class='input-group'>
                <input readonly style='font-size:9px;'type='text' class='form-control py-2' name='keterangan' value='$data[tindakan]'>
            
                <a class='btn btn-secondary' href='entry_tranfusi.php?idx=$data[id_pasien]' >entry dokumen</a>
               
                </div>
                </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);
