<?php
date_default_timezone_set('asia/jakarta');

if (isset($_GET['printf'])) {
    include "function_tanggal.php";
    $printf = tanggal(date('Y-m-d', strtotime($_GET['awal']))) . ' -  s/d  - ' . tanggal(date('Y-m-d', strtotime($_GET['akhir'])));
    echo "<div id='filter' hidden>" . $printf . "</div>";
    echo "<table class='table table-striped table-bordered table-hover datatable' width='100%' cellspacing='0' style='font-size: 12px;'>
    <thead>
    <tr>
    <th style='width:1%'>No</th>
    <th>Indikator Mutu</th>
    <th style='width:1%'>Num</th>
    <th style='width:1%'>Denum</th>
    <th style='width:7%'>Percentage</th>
    <th style='width:7%'>Target</th>
    <th style='width:1%'>Download</th>
    </tr>
            </thead>
            <tbody>";
    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']));

        $query = "SELECT * FROM tb_indikator_mutu WHERE tanggal BETWEEN '$awal' AND '$akhir'";

        $d_gelang = mysqli_num_rows(mysqli_query($open, "SELECT * FROM datapasien WHERE tanggal BETWEEN '$awal' AND '$akhir' AND NOT status_keluar like '%delete%'"));
        $hitung_gelang =  mysqli_num_rows(mysqli_query($openinmut, "SELECT keterangan FROM tb_indikator_mutu WHERE tanggal BETWEEN '$awal' AND '$akhir' AND keterangan ='gelang_id'"));
        $num_gelang = mysqli_num_rows(mysqli_query($openinmut, "$query AND question1=1 AND question2=1"));
        echo "<tr class='table table-striped table-bordered' style='font-size:10pt; font-weight:bold;'>";
        echo " <td>1</td>";
        echo " <td>Audit pemahaman terhadap pemakaian gelang identitas pasien ( n= $hitung_gelang responden)</td>";
        echo " <td>$num_gelang</td>";
        if ($d_gelang > 0) {
            $d_gelang_result = number_format($d_gelang / 10);
            $per_gelang = number_format((($num_gelang / $d_gelang_result) * 100), 2);
            echo " <td>$d_gelang_result</td>";
            echo " <td>$per_gelang %</td>";
        } else {
            echo " <td>-</td>";
            echo " <td>-</td>";
        }
        echo " <td>90 %</td>";
        echo "<td><a href='report/rpt_gelang.php?awal=$awal&akhir=$akhir'><img src='vendor/icons8-microsoft-excel-2019-48.png' alt=''></a></td>";
        echo " </tr>";

        $num_paps = mysqli_num_rows(mysqli_query($openinmut, "$query AND paps=1"));
        $num_los = mysqli_num_rows(mysqli_query($openinmut, "$query AND los=1"));
        $num_ktd = mysqli_num_rows(mysqli_query($openinmut, "$query AND insiden=1 AND keterangan='ktd'"));
        $num_knc = mysqli_num_rows(mysqli_query($openinmut, "$query AND insiden=1 AND keterangan='knc'"));
        $num_inf_con = mysqli_num_rows(mysqli_query($openinmut, "$query AND inf_con=1"));
        $num_site_mark = mysqli_num_rows(mysqli_query($openinmut, "$query AND site_mark=1"));
        $num_tranfusi = mysqli_num_rows(mysqli_query($openinmut, "SELECT * FROM tb_tranfusi WHERE tanggal BETWEEN '$awal' AND '$akhir' AND reaksi=1"));
        $num_sc = mysqli_num_rows(mysqli_query($openinmut, "$query AND timeinterval=1"));
        $num_identifikasi = mysqli_num_rows(mysqli_query($openinmut, "$query AND identifikasi=1 "));

        $denum_identifikasi = mysqli_num_rows(mysqli_query($open, "SELECT * FROM datapasien WHERE tanggal BETWEEN '$awal' AND '$akhir' AND NOT status_keluar like '%delete%'"));
        echo "<tr class='table table-striped table-bordered' style='font-size:10pt; font-weight:bold;'>";
        echo " <td>2</td>";
        echo " <td>Identifikasi pasien ( n= $num_identifikasi responden)</td>";
        echo " <td>$num_identifikasi</td>";
        if ($denum_identifikasi > 0) {
            $denum_identifikasi_result = number_format($denum_identifikasi / 10);
            $per_identifikasi = number_format((($num_identifikasi / $denum_identifikasi_result) * 100), 2);
            echo " <td>$denum_identifikasi_result</td>";
            echo " <td>$per_identifikasi %</td>";
        } else {
            echo " <td>-</td>";
            echo " <td>-</td>";
        }
        echo "<td>100 %</td>";
        echo "<td><a href='report/rpt_identifikasi.php?awal=$awal&akhir=$akhir'><img src='vendor/icons8-microsoft-excel-2019-48.png' alt=''></a></td>";
        echo " </tr>";


        $denum_sc = mysqli_num_rows(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%'"));
        echo "<tr class='table table-striped table-bordered' style='font-size:10pt; font-weight:bold;'>";
        echo "<td>3</td>";
        echo " <td>Respon-Time SC Emergency</td>";
        echo " <td>$num_sc</td>";
        echo " <td>$denum_sc</td>";
        if ($denum_sc > 0) {
            $per_sc = number_format((($num_sc / $denum_sc) * 100), 2);
            echo " <td>$per_sc %</td>";
        } else {
            echo " <td>-</td>";
        }
        echo "<td>80 %</td>";
        echo "<td><a href='report/rpt_rt_sc.php?awal=$awal&akhir=$akhir'><img src='vendor/icons8-microsoft-excel-2019-48.png' alt=''></a></td>";

        echo " </tr>";

        $denum_tranfusi = mysqli_num_rows(mysqli_query($openinmut, "SELECT * FROM tb_tranfusi WHERE tanggal BETWEEN '$awal' AND '$akhir'"));
        echo "<tr class='table table-striped table-bordered' style='font-size:10pt; font-weight:bold;'>";
        echo "<td>4</td>";
        echo " <td>Angka Kejadian reaksi tranfusi</td>";
        echo " <td>$num_tranfusi</td>";
        echo " <td>$denum_tranfusi</td>";
        if ($denum_tranfusi > 0) {
            $per_tranfusi = number_format((($num_tranfusi / $denum_tranfusi) * 100), 2);
            echo " <td>$per_tranfusi %</td>";
        } else {
            echo " <td>-</td>";
        }
        echo "<td>0 %</td>";
        echo "<td><a href='report/rpt_tranfusi.php?awal=$awal&akhir=$akhir'><img src='vendor/icons8-microsoft-excel-2019-48.png' alt=''></a></td>";
        echo " </tr>";

        $denum_paps = mysqli_num_rows(mysqli_query($open, "SELECT * FROM datapasien WHERE  tanggal BETWEEN '$awal' AND '$akhir' AND NOT status_keluar like '%delete%' "));
        echo "<tr class='table table-striped table-bordered' style='font-size:10pt; font-weight:bold;'>";
        echo "<td>5</td>";
        echo " <td>Pulang Atas Permintaan Sendiri</td>";
        echo " <td>$num_paps</td>";
        echo " <td>$denum_paps</td>";
        if ($denum_paps > 0) {
            $per_paps = number_format((($num_paps / $denum_paps) * 100), 2);
            echo " <td>$per_paps %</td>";
        } else {
            echo " <td>-</td>";
        }
        echo "<td>< 5 %</td>";
        echo "<td><a href='report/rpt_paps.php?awal=$awal&akhir=$akhir'><img src='vendor/icons8-microsoft-excel-2019-48.png' alt=''></a></td>";
        echo " </tr>";

        $denum_los = mysqli_num_rows(mysqli_query($open, "SELECT * FROM datapasien WHERE tanggal BETWEEN '$awal' AND '$akhir'  AND NOT status_keluar like '%delete%'"));
        echo "<tr class='table table-striped table-bordered' style='font-size:10pt; font-weight:bold;'>";
        echo "<td>6</td>";
        echo " <td>Ketepatan Waktu Pelayanan IGD 《 6 jam</td>";
        echo " <td>$num_los</td>";
        echo " <td>$denum_los</td>";
        if ($denum_los > 0) {
            $per_los = number_format((($num_los / $denum_los) * 100), 2);
            echo " <td>$per_los %</td>";
        } else {
            echo " <td>-</td>";
        }
        echo "<td>60 %</td>";
        echo "<td><a href='report/rpt_los.php?awal=$awal&akhir=$akhir'><img src='vendor/icons8-microsoft-excel-2019-48.png' alt=''></a></td>";
        echo " </tr>";


        $denum_ktd = mysqli_num_rows(mysqli_query($openinmut, "SELECT * FROM tb_indikator_mutu WHERE tanggal BETWEEN '$awal' AND '$akhir' AND insiden_ctrl=1 AND keterangan='ktd'"));
        echo "<tr class='table table-striped table-bordered' style='font-size:10pt; font-weight:bold;'>";
        echo "<td>7</td>";
        echo " <td>Kepatuhan pelaporan kejadian tidak diharapkan ( KTD )</td>";
        echo " <td>$num_ktd</td>";
        echo " <td>$denum_ktd</td>";
        if ($denum_ktd > 0) {
            $per_ktd = number_format((($num_ktd / $denum_ktd) * 100), 2);
            echo " <td>$per_ktd %</td>";
        } else {
            echo " <td>-</td>";
        }
        echo "<td>100 %</td>";
        echo "<td><a href='report/rpt_ktd.php?awal=$awal&akhir=$akhir'><img src='vendor/icons8-microsoft-excel-2019-48.png' alt=''></a></td>";
        echo " </tr>";


        $denum_knc = mysqli_num_rows(mysqli_query($openinmut, "SELECT * FROM tb_indikator_mutu WHERE tanggal BETWEEN '$awal' AND '$akhir' AND insiden_ctrl=1 AND keterangan='knc'"));
        echo "<tr class='table table-striped table-bordered' style='font-size:10pt; font-weight:bold;'>";
        echo "<td>8</td>";
        echo " <td>Kepatuhan pelaporan kejadian nyaris cedera ( KNC )</td>";
        echo " <td>$num_knc</td>";
        echo " <td>$denum_knc</td>";
        if ($denum_knc > 0) {
            $per_knc = number_format((($num_knc / $denum_knc) * 100), 2);
            echo " <td>$per_knc %</td>";
        } else {
            echo " <td>-</td>";
        }
        echo " <td>100 %</td>";
        echo "<td><a href='report/rpt_knc.php?awal=$awal&akhir=$akhir'><img src='vendor/icons8-microsoft-excel-2019-48.png' alt=''></a></td>";
        echo " </tr>";

        $denum_inf_con = mysqli_num_rows(mysqli_query($open, "SELECT * FROM datapasien INNER JOIN tb_tindakan ON datapasien.id_pasien=tb_tindakan.id_pasien WHERE tanggal BETWEEN '$awal' AND '$akhir' AND tindakan like '%IMTIGD_08%' AND NOT status_keluar like '%delete%'"));
        echo "<tr class='table table-striped table-bordered' style='font-size:10pt; font-weight:bold;'>";
        echo "<td>9</td>";
        echo " <td>Kelengkapan Informed Consent</td>";
        echo " <td>$num_inf_con</td>";
        echo " <td>$denum_inf_con</td>";
        if ($denum_inf_con > 0) {
            $per_inf_con = number_format((($num_inf_con / $denum_inf_con) * 100), 2);
            echo " <td>$per_inf_con %</td>";
        } else {
            echo " <td>-</td>";
        }
        echo " <td>100 %</td>";
        echo "<td><a href='report/rpt_inf_con.php?awal=$awal&akhir=$akhir'><img src='vendor/icons8-microsoft-excel-2019-48.png' alt=''></a></td>";
        echo " </tr>";

        $denum_site_mark = mysqli_num_rows(mysqli_query($open, "SELECT * FROM datapasien WHERE tanggal BETWEEN '$awal' AND '$akhir' AND status_keluar like '%OK%' AND NOT status_keluar like '%delete%'"));
        echo "<tr class='table table-striped table-bordered' style='font-size:10pt; font-weight:bold;'>";
        echo "<td>10</td>";
        echo " <td>Site Mark ( penandaan area yang akan dioperasi )</td>";
        echo " <td>$num_site_mark</td>";
        echo " <td>$denum_site_mark</td>";
        if ($denum_site_mark > 0) {
            $per_site_mark = number_format((($num_site_mark / $denum_site_mark) * 100), 2);
            echo " <td>$per_site_mark %</td>";
        } else {
            echo " <td>-</td>";
        }
        echo " <td>100 %</td>";
        echo "<td><a href='report/rpt_site_mark.php?awal=$awal&akhir=$akhir'><img src='vendor/icons8-microsoft-excel-2019-48.png' alt=''></a></td>";
        echo " </tr>";
    }
    echo "</tbody>";
    echo "</table>";
} else {
    echo "<div id='filter'>.$printf = ''.</div>";
}
?>

<script>
    $(document).ready(function() {
        var filter = document.getElementById('filter').innerHTML;
        document.getElementById('linkfilter').innerHTML = document.getElementById('linkfilter').innerHTML + " : " + filter;
    })
</script>