<table class="table table-striped table-bordered table-hover" style="width: 100%; border: 1px;">
    <tr bgcolor="#eeeeee">
        <td width="4%"><b>Sr</b></td>
        <td width="20%"><b>Medicine</b></td>
        <td width="10%"><b>Frequency</b></td>
        <td width="10%"><b>Timing</b></td>
        <td width="10%"><b>Admin. Route</b></td>
        <td width="10%"><b>Duration</b></td>
        <td width="10%"><b>Dose Qty</b></td>
        <td width="16%">Batch</td>
        <td width="10%"><b>Qty Issued</b></td>
    </tr>

    <?php
    // $treatment_apps="(".$appointment_id;
    // $followups="select followup_id from followup_details where  appointment_id='$appointment_id' ";

    // $res_followups = mysqli_query($conn, $followups);
    // while ($rows_followups = mysqli_fetch_array($res_followups)) {

    //     $treatment_apps.=','.$rows_followups["followup_id"];
    // }
    // $treatment_apps.=")";
    if ($appointment_id == null || $appointment_id == '') {
        $appointment_id = $row['appointment_id'];
        $followup_id = $row['followup_id'];
    }


    $sql_treatment = "select * from  treatment where  appointment_id='$appointment_id' and followup_id='$followup_id' and is_display!='N'";
    error_log('tata' . $sql_treatment);
    $res_treatment = mysqli_query($conn, $sql_treatment);
    $count = 0;
    $total_pay_cost = 0;

    while ($rows_treatement = mysqli_fetch_array($res_treatment)) {
        $item_id = $rows_treatement['item_id'];
        $visit_date = getFieldFromTable('appointment_date', 'employee_appointment', 'appointment_id', $appointment_id);

        error_log("date getting :" . $visit_date);

        $date_new = date_create($visit_date);
        $visit_date =  date_format($date_new, "Y-m-d");

        error_log("date getting after formatting :" . $visit_date);

        $form_name_query = "select mf.* from tbl_items tb left join medicine_form mf on tb.item_form_id = mf.form_id where tb.item_id='" . $item_id . "'";

        error_log("checking if its qty is fixed or not " . $form_name_query);

        $form_name_result = mysqli_query($conn, $form_name_query);
        $form_name_qty = mysqli_fetch_assoc($form_name_result);
        $form_name = $form_name_qty['form_code'];

        $srno = $count + 1;
        $unit_id = getFieldFromTable("unit_id", "tbl_items", "item_id", $item_id);
        error_log("bcnxvchdvnhm" . $rows_treatement['timing_id']);

    ?>
        <tr>
            <td style="font-size: 10px"><?php echo $srno; ?></td>
            <td style="font-size: 10px"><?php echo getItemWithFormNamePdf($item_id) ?></td>
            <td style="font-size: 10px">
                <?php echo strtoupper(getTableFieldValue('medicine_frequency', 'medicine_frequency', 'frequency_id', $rows_treatement['frequency_id'], '')); ?>
            </td>

            <td style="font-size: 10px">
                <?php echo strtoupper(getTableFieldValue('medicine_timings', 'timing_description', 'timing_id', $rows_treatement['timing_id'])); ?>
            </td>
            <td style="font-size: 10px">
                <?php echo strtoupper(getTableFieldValue('dosage_category', 'dosage_category', 'dosage_category_id', $rows_treatement['dosage_category_id'])) ?>
            </td>


            <td style="font-size: 10px"><?php echo $rows_treatement['for_days'] ?> &nbsp;&nbsp;Day(s)</td>

            <td style="font-size: 10px;">

                <?php if ($form_name == "SYRUP") {
                    echo $rows_treatement['item_qty'] . " ML";
                } else if ($form_name == "DROP" || $form_name == "EYE DROP" || $form_name == "EAR DROP") {
                    echo $rows_treatement['item_qty'] . " DROP";
                } else {
                    echo $rows_treatement['item_qty'];
                }
                ?>
            </td>

            <td style="font-size: 10px;">
                <?php echo $rows_treatement['item_batch_no']; ?>
            </td>

            <td style="font-size: 10px"><?php echo $rows_treatement['issued_qty'] ?> &nbsp;<?php echo $unitMap[$unit_id] ?>
            </td>
        </tr>
    <?php

        $count++;
    }

    $sql_treatment = "select * from  treatment_external where appointment_id='" . $appointment_id . "'";

    $result_for_treatment_external = mysqli_query($conn, $sql_treatment);
    $num_rows_treatment_external = @mysqli_num_rows($result_for_treatment_external);
    if ($num_rows_treatment_external) {
    ?>
        <!--  <tr>

		<td align="center" colspan="7"><b>Additional Treatments Recommended</b></td>
	</tr> -->
    <?php
    }

    while ($rows_treatement_external = mysqli_fetch_array($result_for_treatment_external)) {
        $srno = $count + 1;
    ?>

        <tr>
            <td style="font-size: 10px"><?php echo $srno ?></td>
            <td style="font-size: 10px"><?php echo  strtoupper($rows_treatement_external['item_name']) ?></td>
            <td style="font-size: 10px"><?php echo strtoupper($rows_treatement_external['dosage']) ?></td>
            <td style="font-size: 10px">
                <?php echo strtoupper(getTableFieldValue('medicine_timings', 'timing_description', 'timing_id', $rows_treatement_external['timing'], '')); ?>
            </td>
            <td style="font-size: 10px">
                <?php echo strtoupper(getTableFieldValue('dosage_category', 'dosage_category', 'dosage_category_id', $rows_treatement_external['dosage_category_id'])) ?>
            </td>
            <td style="font-size: 10px"><?php echo $rows_treatement_external['for_days'] ?>  &nbsp;&nbsp;Day(s)</td>

            <td style="font-size: 10px">
                <?php echo $rows_treatement_external['item_qty'] ?></td>
            <td></td>
            <td style="font-size: 10px"></td>
        </tr>

    <?php
        $count++;
    }

    ?>

</table>