<?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>Inj</th>
        <th>Doc</th>
        <th>Complants.</th>
        <th>Exam.Find.</th>
        <th>Diagnosis</th>
        <th>Trtmnt.</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 = getTreatmentText($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:" . $rowOfEmployeeAppointment['bp_sbp'] . ", DBP:" . $rowOfEmployeeAppointment['bp_dbp'] . ", FBS:" . $rowOfEmployeeAppointment['blood_sugar_fbs'] . ", RBS:" . $rowOfEmployeeAppointment['blood_sugar_rbs'] . ", Temp:" . $rowOfEmployeeAppointment['temperature'] . ", SPOC2%:" . $rowOfEmployeeAppointment['spo2_percent'];
            ?><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  getCommaSeperatedValuesForInClause("select examination_finding from examination_findings ", "id", $rowOfEmployeeAppointment['examination_remarks']) ?>
        </td>
        <td><?php echo  $diagnosis ?></td>
        <td><?php echo  getTreatmentText($rowOfEmployeeAppointment['appointment_id']) ?></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');
?>