<?php
header("Content-type:application/octet-stream");

header("Content-type: application/x-msdownload");
header("Content-Disposition: attachment; filename=excel_pending_medical_disbursment_list.xls");
header("Pragma: no-cache");
header("Expires: 0");
error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED);
?>
<?php
include('includes/config/config.php');
include('includes/functions.php')
//include('pop_up_top.php');
?>
<link href="includes/css-js/admin.css" rel="stylesheet" type="text/css" />

<body>
    <?php include('excel_ohc_header.php') ?>
    <table width="100%">
        <tr>
            <div style="font-size:12px">
                <td width="25%" align="left"> Run Date : <?php echo date("d-M-Y"); ?></td>
                <td width="50%" align="center" style="font-size:20px"><strong>PENDING MEDICINE</strong></td>
                <td width="25%" align="left"> User : <?php echo $username ?></td>
        </tr>
    </table>
    <table border="1" width="100%">
        <?php
        $sql = base64_decode($filterkey);
        // echo $sql;
        $results_employee_appointment = mysqli_query($conn, $sql);




        //echo $result;
        ?><tr><strong>
                <td width="10%">Date</td>
                <td width="5%">Ticket No</td>
                <!-- <td width="5%">Token No</td> -->
                <td width="8%">ECode / G.Pass</td>
                <td width="12%">Patient Name</td>
                <td width="5%">Emg</td>
                <td width="5%">Injury</td>
                <td width="5%">Doc. Con.</td>
                <td width="10%">Complants.</td>
                <td width="10%">Exam.Find.</td>
                <td width="10%">Vitals</td>
                <td width="10%">Remarks</td>
            </strong></tr><?php
                            while ($row_employee_appointment = mysqli_fetch_assoc($results_employee_appointment)) {

                                extract($row_employee_appointment);

                                $appointment_type = $row_employee_appointment['appointment_type'];

                                $emp_id = $row_employee_appointment['id'];
                                if ($appointment_type == 'O') {
                                    $diagnosis = getCommaSeperatedValuesForInClause("select ailment_name from ailment ", "ailment_id", $row_employee_appointment['ailment_ids']);
                                } else if ($appointment_type == 'I') {
                                    $diagnosis = getCommaSeperatedValuesForInClause("select injury_type_name from injury_type", "injury_type_id", $row_employee_appointment['injury_types']);
                                }

                                $appointment_type = $row_employee_appointment['appointment_type'];

                                $employee_appointment = $row_employee_appointment['appointment_id'];
                                $emp_id = $row_employee_appointment['emp_id'];
                                $isEmergency = "";
                                $isInjury = "";
                                if ($appointment_type == 'I') {
                                    $isInjury = "<span class='red'>Yes</i></span>";
                                } else {
                                    $isInjury = "<span class='green'>No</i></span>";
                                }
                                if ($row_employee_appointment['IsEmergency'] == 1) {
                                    $isEmergency = "<span class=' lighter red'>Yes</i></span>";
                                } else {
                                    $isEmergency = "<span class='green'>No</i></span>";
                                }

                                $doctor_attended_flag = "";
                                if ($row_employee_appointment['doctor_attended_flag'] == 'Y') {
                                    $doctor_attended_flag = "<span class=' lighter red'>Yes</i></span>";
                                } else {
                                    $doctor_attended_flag = "<span class='green'>No</i></span>";
                                }
                                $check_results = "SBP:" . $row_employee_appointment['bp_sbp'] . ", DBP:" . $row_employee_appointment['bp_dbp'] . ", FBS:" . $row_employee_appointment['blood_sugar_fbs'] . ", RBS:" . $row_employee_appointment['blood_sugar_rbs'];

                                $complaints = getCommaSeperatedValuesForInClause("select complaint from complaints ", "complaint_id", $row_employee_appointment['complaints']);
                                $referral = getCommaSeperatedValuesForInClause("select referral_point_name from referral_point ", "referral_point_id ", $row_employee_appointment['referral']);
                                
                                $findings = getCommaSeperatedValuesForInClause("select examination_finding from examination_findings ", "id", $row_employee_appointment['examination_remarks']);

                            ?><tr>
            <td><?php echo date_format(date_create($row_employee_appointment['appointment_date']), "d-M-Y H:i ") ?>
            </td>
            <td><?php echo $row_employee_appointment['ticket_no'] ?></td>
            <!-- <td><?php echo $row_employee_appointment['token_no'] ?></td> -->
            <td><?php echo $row_employee_appointment['emp_code'] ?></td>
            <td><?php echo $row_employee_appointment['patient_name'] ?></td>
            <td><?php echo $isEmergency ?></td>
            <td><?php echo $isInjury ?></td>
            <td><?php echo $doctor_attended_flag ?></td>
            <td><?php echo $complaints ?></td>
            <td><?php echo $findings ?></td>
            <td><?php echo $check_results ?></td>
            <td><?php echo $row_employee_appointment['remarks_rece'] ?></td>


        </tr>
        <?php
                            }
        ?>
    </table>
</body>