<?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 INNER JOIN tb_maternal ON datapasien.id_pasien=tb_maternal.id_pasien WHERE tanggal BETWEEN '$awal' AND '$akhir' AND jenis_persalinan like '%sc%' 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 timeinterval=1 OR id_pasien='$data[id_pasien]' AND keterangan like '%sc%'"));
    if ($checkdata > 0) {
        $site = "<div class='btn btn-sm btn-success'><i class='fas fa-check'></i></div>";
    } else {
        $site = "";
    }

    $start = date_create($data['pre_sc']);
    $end = date_create($data['post_sc']);
    $diff = date_diff($start, $end);
    $minute = $diff->i;
    $hour = $diff->h;
    $day = $diff->d;



    $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'>
                <p 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]'>
                        lihat tanggal dan jam..
                    </button>
                </p>
                <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-stripped'>
                                <tr class='table-stripped'>
                                    <td>Jam ACC DPJP</td>
                                    <td align='center'> <input required style='font-size:10px' type='text' readonly name='sc_pre' class='form-control' value='$data[pre_sc]'></a></td>
                                </tr>
                                <tr class='table-stripped'>
                                    <td>Jam Mulai Induksi Bius</td>
                                    <td align='center'><input required style='font-size:10px' type='text' readonly name='sc_post' class='form-control' value='$data[post_sc]'></a></td>
                                </tr>
                                <tr class='table-stripped'>
                                <td>Jeda waktu</td>
                                <td align='center'><input style='font-size:10px' type='text' readonly name='diff' class='form-control' value='$day hari- $hour jam- $minute menit'></a></td>
                                </tr>
                                </table>
                                <div class='table-footer'>
                                <button type='submit' class='btn btn-primary btn-sm' id='tambahData' name='tambahData'>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);
