<?php
include('pdf_header.php');
include('pdf_ohc_header.php');
?>

<table border="1">
    <?php
    $sql = base64_decode($filterkey);
    $result = mysqli_query($conn, $sql);
    ?><tr>
        <th>Sr</th>
        <th>Date</th>
        <th>Ticket No</th>
        <th>ECode / G.Pass</th>
        <th>Patient Name</th>
        <th>Emg?</th>
        <th>Injury?</th>
        <th>Doc Consulted?</th>
        <th>Complaints.</th>
        <th>Diagnosis</th>
        <th>Treatment.</th>
        <th>Treatment given by</th>
        <th>Referral</th>
        <th>Follow up</th>
        <th>Vitals</th>
    </tr><?php
            $count = 0;
            while ($rowOfEmployeeAppointment = mysqli_fetch_assoc($result)) {
                $count = $count + 1;
                $diagnosis = getCommaSeperatedValuesForInClause("select ailment_name from ailment ", "ailment_id", $rowOfEmployeeAppointment['ailments_new']);

                $treatment_text = getTreatmentTextPdf($rowOfEmployeeAppointment['appointment_id']);
                $isEmergency = "";
                $isInjury = "";
                if ($appointment_type == 'I') {
                    $isInjury = "Yes";
                } else {
                    $isInjury = "No";
                }
                if ($rowOfEmployeeAppointment['IsEmergency'] == 1) {
                    $isEmergency = "Yes";
                } else {
                    $isEmergency = "No";
                }
                $doctor_attended_flag = "No";
                if ($rowOfEmployeeAppointment['doctor_attended_flag'] == 'Y') {
                    $doctor_attended_flag = "Yes";
                } else {
                    $doctor_attended_flag = "No";
                }

                $check_results = "SBP:" . $row_employee_appointment['bp_sbp'] . ", DBP:" . $row_employee_appointment['bp_dbp'] . ", TEMP:" . $row_employee_appointment['temperature'] . ", SpO2:" . $row_employee_appointment['spo2_percent'] . ",WEIGHT:" . $row_employee_appointment['weight'] . ",HEIGHT:" . $row_employee_appointment['height'] . ",BMI:" . $row_employee_appointment['bmi'] . ",RESPIRATORY RATE:" . $row_employee_appointment['respiratory_rate'] . ",HEART RATE:" . $row_employee_appointment['heart_rate'] . ",PULSE OUTPUT:" . $row_employee_appointment['pulse_output'] . ", GLASGOW COMA SCALE:" . $row_employee_appointment['glasgow_coma_scale'];
            ?><tr>
            <td><?php echo  $count ?></td>
            <td><?php echo  $rowOfEmployeeAppointment['appointment_date'] ?></td>
            <td><?php echo  $rowOfEmployeeAppointment['ticket_no'] ?></td>
            <td><?php echo  $rowOfEmployeeAppointment['emp_code'] ?></td>
            <td><?php echo  $rowOfEmployeeAppointment['patient_name'] ?></td>
            <td><?php echo  $isEmergency ?></td>
            <td><?php echo  $isInjury ?></td>
            <td><?php echo  $doctor_attended_flag ?></td>
            <td><?php echo  getCommaSeperatedValuesForInClause("select complaint from complaints ", "complaint_id", $rowOfEmployeeAppointment['complaints']); ?></td>
            <td><?php echo  $diagnosis ?></td>
            <td><?php echo  $treatment_text ?></td>
            <td><?php echo  getTableFieldValue('patient_master', 'patient_name', 'id', $rowOfEmployeeAppointment['doctor_last_attended']); ?></td>
            <td><?php echo  getCommaSeperatedValuesForInClause("select referral_point_name from referral_point ", "referral_point_id ", $rowOfEmployeeAppointment['referral']) ?></td>
            <td><?php echo  $rowOfEmployeeAppointment['followup'] ?></td>
            <td><?php echo  $check_results ?></td>
        </tr>
    <?php
            }
    ?>
</table>
<?php
include('pdf_footer.php');
?>