<html>



<head>

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
    <div id="opd_form_div">
        <form id="opd_form" name="opd_form">

            <?php 

// include autoloader;
include ('includes/config/config.php');

include_once ("includes/functions.php");
error_reporting(E_ERROR | E_PARSE);

$unitMap = getKeyValueMap('unit_master', 'unit_id', 'unit_name');

$query = "select * from company_profile ";

// echo $query;

$result = mysqli_query($conn,$query);

$row_company = mysqli_fetch_array($result);

@extract($row_company); 

$sql_employee_appointment = "select a.*, p.patient_name, p.dept_id, p.emp_code, p.father_name, p.designation_id,employer_contractor_id,
patient_cat_id, gender,blood_group,emp_cadre,dob from employee_appointment a, patient_master p where a.emp_id=p.id
 and appointment_id='" . $_REQUEST['appointment_id_pdf'] . "'";

// echo $sql_employee_appointment;

$res_emp_appoint = mysqli_query($conn,$sql_employee_appointment);

$rows_emp_appoint = mysqli_fetch_array($res_emp_appoint);

@extract($rows_emp_appoint);

$patient_name = $rows_emp_appoint['patient_name'];

// echo $query;



$employee_code = $rows_emp_appoint['emp_code'];

$father_name = $rows_emp_appoint['father_name'];

 $sql_detention="select det_id, reporting_time,disposal_time from detention_master where opd_id='" . $_REQUEST['appointment_id_pdf'] . "'";
	 //echo "query:".$sql;
	$result_detention = mysqli_query($conn,$sql_detention);	
	$num_rows=@mysqli_num_rows($result_detention);
	$row_detention =null;
	if($num_rows>0)
	{
		$row_detention=@mysqli_fetch_array($result_detention);
	}

if ($rows_emp_appoint['IsEmergency'] == 1) {

    $ans = "Yes";
} else {

    $ans = "No";
}

date_default_timezone_set('Asia/Kolkata');
$date = date('Y-m-d H:i:s');
$currentDate = date_format(date_create($date), "d-M-Y h:i:sa  ");
$ailment_names = $rows_emp_appoint['ailments_new'];


?>



            <style>
            table,
            tr,
            td {
                border: 1px solid black !important;

            }

            th {

                font-size: 12px;
                font-style: bold;
                vertical-align: top;
            }

            td {
                text-align: left;
                font-size: 13px;
                vertical-align: top;
            }

            @page {
                margin: 15px;
            }

            .btn {
                background-color: #4CAF50;
                border-radius: 5%;
                /* Green */
                border: none;
                color: white;
                padding: 5px 8px;
                text-align: center;
                text-decoration: none;
                display: inline-block;
                font-size: 12px;
                margin: 4px 2px;
                cursor: pointer;
            }

            @media print {
                #printPageButton {
                    display: none;
                }
            }
            </style>

</head>

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



<table style="border: none !important;" width="100%">

    <tr>
        <td align="right" style="font-size: 15px;border: none !important;"><button align="right" id="printPageButton"
                class="btn btn-success" onClick="window.print();">Print</button></td>
    </tr>

</table>







<!--  -->

<br>


<table cellspacing="0" width="100%">





    <tr>

        <td><b>TICKET NO.:</b> <?php  echo  $rows_emp_appoint['ticket_no']?></td>

        <td><b>REPORTING TIME:</b> <?php  echo date('d-m-Y H:i:s', strtotime($appointment_date))?> </td>

        <td><b>DISPOSAL TIME:</b> <?php  echo $row_detention['disposal_time']?> </td>



    </tr>







    <tr>

        <td width="33%"><b>PATIENT NAME:</b> <?php  echo $patient_name?></td>

        <td width="33%"><b>AGE:</b> <?php  echo ageCalculator($rows_emp_appoint['dob'])?></td>

        <td width="33%"><b>GENDER:</b> <?php  echo $rows_emp_appoint['gender']=='M'?"Male":"Female"?></td>


    </tr>










    <?php 
$ailment_names_ids = $rows_emp_appoint['ailments_new'];
$ailment_names_ids_array = array();
$ailment_names_ids_array = explode(",", $ailment_names_ids);
$ailment_names = "";
for ($i = 0; $i < count($ailment_names_ids_array); $i ++) {
    if ($i == 0) {
        $ailment_names = getTableFieldValue('ailment', 'ailment_name', 'ailment_id', $ailment_names_ids_array[$i]);
    } else {
        $ailment_names = $ailment_names . "," . getTableFieldValue('ailment', 'ailment_name', 'ailment_id', $ailment_names_ids_array[$i]);
    }
}
?>

    <tr>


        <td><b>DIAGNOSIS:</b> <?php  echo strtoupper($ailment_names)?></td>
        <td></td>
        <td></td>


    </tr>

</table>


<table cellspacing="0" width="100%">



    <tr align="center">
        <td colspan="6" width="30%"><b>OBSERVATION</b></center>
        </td>
        <td colspan="4" width="40%" align="center"><b>INTAKE</b></center>
        </td>
        <td colspan="3" width="30%" align="center"><b>OUTPUT</b></center>
        </td>
    </tr>

    <tr>
        <td width="5%"><b>TIME</b></td>
        <td width="5%"><b>BP</b></td>
        <td width="5%"><b>PULSE</b></td>
        <td width="5%"><b>SPO2</b></td>
        <td width="5%"><b>ECG</b></td>
        <td width="5%"><b>TEMP</b></td>
        <td width="10%"><b>TIME</b></td>
        <td width="10%"><b>MEDICINE</b></td>
        <td width="10%"><b>ADMINISTRATION ROUTE</b></td>
        <td width="10%"><b>ISSUED QTY</b></td>
        <td width="10%"><b>TIME</b></td>
        <td width="10%"><b>OUTPUT ROUTE</b></td>
        <td width="10%"><b>OUTPUT QTY</b></td>


    </tr>

    <?php $sql_observation = "select * from detention_observation where det_id = '" . $_REQUEST['appointment_id_pdf'] . "'";
       $result_observation = mysqli_query($conn,$sql_observation);
       $num_observation = mysqli_num_rows($result_observation);
       


       $sql_intake = "select * from detention_intake where det_id = '" . $_REQUEST['appointment_id_pdf'] . "'";
       $result_intake = mysqli_query($conn,$sql_intake);
       $num_intake = mysqli_num_rows($result_intake);
       

       $sql_output = "select * from detention_output where det_id = '" . $_REQUEST['appointment_id_pdf'] . "'";
       $result_output = mysqli_query($conn,$sql_output);
       $num_output = mysqli_num_rows($result_output);
       

       $row_num = ($num_observation > $num_intake)? (($num_observation > $num_output)? $num_observation : $num_output) : (( $num_intake > $num_output)?  $num_intake : $num_output);

       error_log("number of rows".$row_num);
    ?>

    <?php for($i=0;$i<$row_num;$i++){?>
    <tr>

        <?php if($row_observation = mysqli_fetch_assoc($result_observation)){
                @extract($row_observation);?>

        <td><?php  echo date('d-m-Y H:i:s', strtotime($row_observation['observation_time']))?></td>
        <td><?php  echo $row_observation['bp']?></td>
        <td><?php  echo $row_observation['pulse']?></td>
        <td><?php  echo $row_observation['spo2']?></td>
        <td><?php  echo $row_observation['ecg']?></td>
        <td><?php  echo $row_observation['temp']?></td>
        <?php } else {?>
        <td></td>
        <td></td>
        <td></td>
        <td></td>
        <td></td>
        <td></td>
        <?php }?>


        <?php if($row_intake = mysqli_fetch_assoc($result_intake)){
                @extract($row_intake);?>

        <td><?php  echo date('d-m-Y H:i:s', strtotime($row_intake['intake_time']))?></td>
        <td><?php  echo getItemWithFormName($row_intake['medicine'])?></td>
        <td><?php  echo strtoupper(getTableFieldValue('dosage_category','dosage_category','dosage_category_id',$row_intake['administration_route']))?>
        </td>
        <td><?php  echo $row_intake['issued_qty']?></td>
        <?php } else {?>
        <td></td>
        <td></td>
        <td></td>
        <td></td>
        <?php }?>

        <?php if($row_output = mysqli_fetch_assoc($result_output)){
                @extract($row_output);?>

        <td><?php  echo date('d-m-Y H:i:s', strtotime($row_output['output_time']))?></td>
        <td><?php  echo strtoupper($row_output['output_route'])?></td>
        <td><?php  echo strtoupper($row_output['output_qty'])?></td>
        <?php } else {?>
        <td></td>
        <td></td>
        <td></td>
        <?php }?>


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






</form>

<form id="employeeDetailsFormPdf" action="" method="POST">

    <input type="hidden" name="htmlText" id="htmlText" />

</form>
</div>
<script>
$(document).ready(function() {
    window.print();

});
</script>