<script src="//code.jquery.com/jquery-1.12.0.min.js"></script>
<script src="js/Chart.min.js"></script>

<?php
include('includes/config/config.php');
error_reporting(0);
// $id = ($_REQUEST['flex_opd_id'] != '') ? ($_REQUEST['flex_opd_id']) : ($_REQUEST['patient_id']);
// if (!isset($id)) {
//     $id = ($_REQUEST['flex_patient_id'] != '') ? ($_REQUEST['flex_patient_id']) : ($_REQUEST['patient_id']);
// }
$id =getTableFieldValue('tbl_users','emp_id','user_id',$_SESSION['user_id']);


$sql = "select * from patient_master where id = '$id' ";
error_log("USER DETAILS::" .$sql);
$result = @mysqli_query($conn, $sql);
if (mysqli_num_rows($result) > 0) {
    $row = @mysqli_fetch_array($result);
}

$sql2 = "select * from health_advice";
$result2 = @mysqli_query($conn, $sql2);
if (mysqli_num_rows($result2) > 0) {
    $row2 = @mysqli_fetch_array($result2);
}

$sql3 = "select * from health_risk";
$result3 = @mysqli_query($conn, $sql3);
if (mysqli_num_rows($result3) > 0) {
    $row3 = @mysqli_fetch_array($result3);
}

$sql4 = "select * from training"; // training table not present ==> training_master 
$result4 = mysqli_query($conn, $sql4);
$row4 = mysqli_fetch_array($result4);



$query5 = "SELECT height, date(appointment_date) as dat FROM employee_appointment 
where emp_id='$id'and height != ''
UNION
SELECT cf.checkup_form_value as weight ,date(c.checkup_date) as dat from 
checkup_form c left join checkup_form_key_value cf on 
c.checkup_id=cf.checkup_form_id left join checkup_parameter cp on 
cp.`column_name` = cf.checkup_form_key 
where c.emp_id='$id' and cp.key_health_map_name=(select key_param_id from key_health_reportable_parameter_master where key_param_name='height') order by dat desc limit 1";
error_log("height " . $query5);
$result5 = @mysqli_query($conn, $query5);
$row5 = mysqli_fetch_array($result5);


$query6 = "SELECT `weight`, date(appointment_date) as dat FROM employee_appointment 
where emp_id='$id' and `weight` != ''
UNION
SELECT cf.checkup_form_value as weight ,date(c.checkup_date) as dat from 
checkup_form c left join checkup_form_key_value cf on 
c.checkup_id=cf.checkup_form_id left join checkup_parameter cp on 
cp.`column_name` = cf.checkup_form_key 
where c.emp_id='$id' and cp.key_health_map_name=(select key_param_id from key_health_reportable_parameter_master where key_param_name='weight') order by dat desc limit 1";
error_log("weight " . $query6);
$result6 = @mysqli_query($conn, $query6);
$row6 = mysqli_fetch_array($result6);

$query7 = "SELECT heart_rate as pulse, date(appointment_date) as dat FROM employee_appointment 
where emp_id='$id' and heart_rate != ''
UNION
SELECT cf.checkup_form_value as weight ,date(c.checkup_date) as dat from 
checkup_form c left join checkup_form_key_value cf on 
c.checkup_id=cf.checkup_form_id left join checkup_parameter cp on 
cp.`column_name` = cf.checkup_form_key 
where c.emp_id='$id' and cp.key_health_map_name=(select key_param_id from key_health_reportable_parameter_master where key_param_name='pulse') order by dat desc limit 1";
error_log("pulse " . $query7);
$result7 = @mysqli_query($conn, $query7);
$row7 = mysqli_fetch_array($result7);




$query8 = "SELECT bmi, date(appointment_date) as dat FROM employee_appointment 
where emp_id='$id' and bmi != ''
UNION
SELECT cf.checkup_form_value as weight ,date(c.checkup_date) as dat from 
checkup_form c left join checkup_form_key_value cf on 
c.checkup_id=cf.checkup_form_id left join checkup_parameter cp on 
cp.`column_name` = cf.checkup_form_key 
where c.emp_id='$id' and cp.key_health_map_name=(select key_param_id from key_health_reportable_parameter_master where key_param_name='bmi') order by dat desc limit 1";
error_log("bmi " . $query8);
$result8 = @mysqli_query($conn, $query8);
$row8 = mysqli_fetch_array($result8);


$query9 = "SELECT bp_sbp as sbp, date(appointment_date) as dat FROM employee_appointment 
where emp_id='$id'and bp_sbp != ''
UNION
SELECT cf.checkup_form_value as sbp ,date(c.checkup_date) as dat from 
checkup_form c left join checkup_form_key_value cf on 
c.checkup_id=cf.checkup_form_id left join checkup_parameter cp on 
cp.`column_name` = cf.checkup_form_key 
where c.emp_id='$id' and  (cp.key_health_map_name=(select key_param_id from key_health_reportable_parameter_master where key_param_name='sbp') or 
cp.key_health_map_name=(select key_param_id from key_health_reportable_parameter_master where key_param_name='sbp/dbp')) order by dat desc limit 1";
error_log("systolic_blood_pressure " . $query9);
$result9 = @mysqli_query($conn, $query9);
$row9 = mysqli_fetch_array($result9);



$query11 = "SELECT bp_dbp as dbp, date(appointment_date) as dat FROM employee_appointment 
where emp_id='$id'and bp_sbp != ''
UNION
SELECT cf.checkup_form_value as dbp ,date(c.checkup_date) as dat from 
checkup_form c left join checkup_form_key_value cf on 
c.checkup_id=cf.checkup_form_id left join checkup_parameter cp on 
cp.`column_name` = cf.checkup_form_key 
where c.emp_id='$id' and  (cp.key_health_map_name=(select key_param_id from key_health_reportable_parameter_master where key_param_name='dbp') or 
cp.key_health_map_name=(select key_param_id from key_health_reportable_parameter_master where key_param_name='sbp/dbp')) order by dat desc limit 1";
error_log("systolic_blood_pressure " . $query11);
$result11 = @mysqli_query($conn, $query11);
$row11 = mysqli_fetch_array($result11);

$sbp = "";
$dbp = "";
$bp_arr = explode("/", $row9['sbp']);
error_log("size " . sizeof($bp_arr));

if (sizeof($bp_arr) > 1) {
    $sbp =  $bp_arr[0];
} else {
    $sbp =  $bp_arr[0];
}

$bp_arr = explode("/", $row11['dbp']);
error_log("size " . sizeof($bp_arr));

if (sizeof($bp_arr) > 1) {
    $dbp =  $bp_arr[1];
} else {
    $dbp =  $bp_arr[0];
}

$bp = $sbp . "/" . $dbp;





$query10 = "SELECT health_index from checkup_form where emp_id='$id' order by checkup_date desc limit 1";
error_log("health index query " . $query10);
$result10 = @mysqli_query($conn, $query10);
$row10 = mysqli_fetch_array($result10);


$query12 = "SELECT  blood_sugar_fbs as fbs, date(appointment_date) as dat FROM employee_appointment 
where emp_id='$id' and  blood_sugar_fbs != ''
UNION
SELECT cf.checkup_form_value as weight ,date(c.checkup_date) as dat from 
checkup_form c left join checkup_form_key_value cf on 
c.checkup_id=cf.checkup_form_id left join checkup_parameter cp on 
cp.`column_name` = cf.checkup_form_key 
where c.emp_id='$id' and cp.key_health_map_name=(select key_param_id from key_health_reportable_parameter_master where key_param_name='fbs') order by dat desc limit 1";
error_log("fbs " . $query12);
$result12 = @mysqli_query($conn, $query12);
$row12 = mysqli_fetch_array($result12);

$query13 = "SELECT  blood_sugar_rbs as rbs, date(appointment_date) as dat FROM employee_appointment 
where emp_id='$id' and  blood_sugar_rbs != ''
UNION
SELECT cf.checkup_form_value as weight ,date(c.checkup_date) as dat from 
checkup_form c left join checkup_form_key_value cf on 
c.checkup_id=cf.checkup_form_id left join checkup_parameter cp on 
cp.`column_name` = cf.checkup_form_key 
where c.emp_id='$id' and cp.key_health_map_name=(select key_param_id from key_health_reportable_parameter_master where key_param_name='rbs') order by dat desc limit 1";
error_log("fbs " . $query13);
$result13 = @mysqli_query($conn, $query13);
$row13 = mysqli_fetch_array($result13);

$query14 = "SELECT blood_sugar_ppbs as ppbs, date(appointment_date) as dat FROM employee_appointment 
where emp_id='$id' and blood_sugar_ppbs != ''
UNION
SELECT cf.checkup_form_value as weight ,date(c.checkup_date) as dat from 
checkup_form c left join checkup_form_key_value cf on 
c.checkup_id=cf.checkup_form_id left join checkup_parameter cp on 
cp.`column_name` = cf.checkup_form_key 
where c.emp_id='$id' and cp.key_health_map_name=(select key_param_id from key_health_reportable_parameter_master where key_param_name='ppbs') order by dat desc limit 1";
error_log("fbs " . $query14);
$result14 = @mysqli_query($conn, $query14);
$row14 = mysqli_fetch_array($result14);

function calcBMI($weight, $height)
{
    $bmi = ($weight / ($height * $height)) * 10000;
    return round($bmi, 1) . PHP_EOL;
}
function ppa($past_illness)
{  $params='';
    $param_present = explode(', ', $past_illness);
    foreach ($param_present as $x => $val) {
        $params .= getFieldFromTable('param_name', 'history_parameter', 'param_id', $val) . "<br>";
    }
    return $params;
}
function healthAdvices($past_advices)
{  $params='';
    $param_present = explode(', ', $past_advices);
    foreach ($param_present as $x => $val) {
        $params .= getFieldFromTable('health_advice_name', 'health_advice', 'health_advice_id', $val) . "<br>";
    }
    return $params;
}


?>

<style>
.box {
    position: relative;
    border-radius: 3px;
    background: #ffffff;
    border-top: 3px solid #d2d6de;
    margin-bottom: 20px;
    width: 100%;
    box-shadow: 0 1px 1px rgba(0, 0, 0, 0.1);
}

.box.box-info {
    border-top-color: #00c0ef;
}

.box.box-danger {
    border-top-color: #dd4b39;
}

.box.modal-greytop {
    border-top-color: #d2d6de;
}

.box.box-success {
    border-top-color: #00a65a;
}

.box.box-warning {
    border-top-color: #f39c12;
}

.box.box-primary {
    border-top-color: #3c8dbc;
}

.card {
    box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2);
    transition: 0.3s;
    /* width: 40%; */
    border-radius: 5px;
    margin-top: 10px;
    border-radius: 5px 5px 5px 5px !important;
    background-color: #EDF5E1;
    /* font-family: 'Roboto Serif', serif; */
}

.card:hover {
    box-shadow: 0 13px 16px 0 rgba(0, 0, 0, 0.5);
}

.card2 {
    box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2);
    transition: 0.3s;
    /* width: 40%; */
    border-radius: 5px;
    margin-top: 10px;
    border-radius: 5px 5px 5px 5px !important;
    font-family: 'Roboto Serif', serif;
}

.card2:hover {
    box-shadow: 0 50px 70px 0 rgba(0, 0, 0, 0.5);
}
</style>

<div class="row" style="background-color:#5CDB95;">
    <div class="col-xs-12">
        <div class="col-xs-12 col-sm-3 center">
            <div>
                <!-- Profile Photo and name starts here  -->
                <span class="profile-picture card">
                    <!-- Profile Photo starts here  -->
                    <?php
                    if (isset($row['photo']) && $row['photo'] != null) {
                    ?>
                    <img id="avatar" class="editable img-responsive" alt="<?php echo $row['patient_name'] ?>"
                        src="data:<?php echo $row['image_type'] ?>;base64,<?php echo base64_encode($row['photo']) ?>"
                        style="display: block; width: 150px; height: 150px;" />

                    <?php

                    } else {
                        if ($row['gender'] != 'F') {
                        ?>
                    <img id="avatar" class="editable img-responsive" alt="<?php echo $row['fname'] ?>'s Avatar"
                        src="images/male-profile.png" style="display: block; width: 150px; height: 150px;" />

                    <?php
                        } else {
                        ?>
                    <img id="avatar" class="editable img-responsive" alt="<?php echo $row['fname'] ?>'s Avatar"
                        src="images/female-profile.png" style="display: block; width: 150px; height: 150px;" />
                    <?php
                        }
                    }
                    ?>
                </span> <!-- Profile Photo ends here  -->

                <br>


                <div class="label label-warnining label-xlg">
                    <!-- Profile name starts here  -->
                    <div class="inline position-relative">
                        <a href="#" class="user-title-label dropdown-toggle" data-toggle="dropdown">
                            <i class="glyphicon glyphicon-tint red"></i>
                            <span class="red"><?php echo  $row['blood_group'] ?></span>&nbsp;
                            <span class="white"><?php echo $row['patient_name'] ?></span>
                        </a>
                    </div>
                </div> <!-- Profile name ends here  -->

            </div> <!-- Profile Photo and name ends here  -->

        </div>

        <div class="col-xs-12 col-sm-9 center">
            <div class="row">
                <p class="alert" style="border-radius: 2%;background-color:#379683; color:#fff">Employee Health
                    Dashboard</p>
            </div>
            <div class="space space-4"></div>
            <div class="row">

                <div class="center">
                    <!-- <span class="btn btn-app btn-sm btn-pink no-hover"> <span
						class="line-height-1 smaller-100">24.1 </span> <br /> <span
						class="line-height-1 smaller-60"> Trend </span>
					</span>  -->
                    <span class="btn btn-app btn-sm btn-purple no-hover" style="width:80px;">
                        <span class="line-height-1 smaller-100 card2"><?php echo $row5['height'] ?></span><br />
                        <span class="line-height-1 smaller-60"> Height </span>
                    </span>
                    <span class="btn btn-app btn-sm btn-light no-hover" style="width:80px;">
                        <span class="line-height-1 smaller-100 card2"><?php echo $row6['weight'] ?></span><br />
                        <span class="line-height-1 smaller-60"> Weight </span>
                    </span>
                    <span class="btn btn-app btn-sm btn-grey no-hover" style="width:80px;">
                        <span class="line-height-1 smaller-100 card2"><?php echo $row8['bmi'] ?></span><br />
                        <span class="line-height-1 smaller-60"> BMI </span>
                    </span>
                    <span class="btn btn-app btn-sm btn-inverse no-hover" style="width:80px;">
                        <span class="line-height-1 smaller-100 card2"><?php echo $bp ?></span><br />
                        <span class="line-height-1 smaller-60">BP</span>
                    </span>
                    <span class="btn btn-app btn-sm btn-success no-hover" style="width:80px;"> <span
                            class="line-height-1 smaller-100 card2"><?php echo $row7['pulse'] ?></span> <br /> <span
                            class="line-height-1 smaller-60">Pulse</span>
                    </span>
                    <span class="btn btn-app btn-sm btn-primary no-hover" style="width:80px;"> <span
                            class="line-height-1 smaller-100 card2"><?php echo $row10['health_index'] ?></span> <br />
                        <span class="line-height-1 smaller-60">Health Index</span>
                    </span>
                    <span class="btn btn-app btn-sm btn-success no-hover" style="width:80px;"> <span
                            class="line-height-1 smaller-100 card2"><?php echo $row12['fbs'] ?></span> <br /> <span
                            class="line-height-1 smaller-60">FBS</span>
                    </span>
                    <span class="btn btn-app btn-sm btn-secondary no-hover" style="width:80px;"> <span
                            class="line-height-1 smaller-100 card2"><?php echo $row13['rbs'] ?></span> <br /> <span
                            class="line-height-1 smaller-60">RBS</span>
                    </span>
                    <span class="btn btn-app btn-sm btn-warning no-hover" style="width:80px;"> <span
                            class="line-height-1 smaller-100 card2"><?php echo $row14['ppbs'] ?></span> <br /> <span
                            class="line-height-1 smaller-60">PPBS</span>
                    </span>
                </div>


            </div>
        </div>
    </div>
</div>

<div class="row" style="background-color:#8EE4AF;">
    <div class="col-xs-12" style="margin-top: 10px">
        <div class="col-xs-12 col-sm-6 center">
            <!-- col-md-5 -->

            <p class="alert center" style="border-radius: 2%;background-color:#379683; color:#fff"><i
                    class="ace-icon fa fa-star orange card"></i> &nbsp;PATIENT BASIC INFO</p>
            <div class="space space-4"></div>
            <div class="profile-user-info profile-user-info-striped card">
                <?php if (!empty($row['emp_code'])) {
                ?>
                <div class="profile-info-row">
                    <div class="profile-info-name">Code</div>
                    <div class="profile-info-value">
                        <span><?php echo $row['emp_code'] ?></span>
                    </div>
                </div>
                <?php } ?>
                <?php if (!empty($row['employment_type_id'])) {
                ?>
                <div class="profile-info-row">
                    <div class="profile-info-name">Employment Type</div>
                    <div class="profile-info-value">
                        <span><?php echo ($row['employment_type_id']) == 1 ? "Permanent Employee" : "Contract" ?></span>
                    </div>
                </div>
                <?php } ?>
                <?php if (!empty(getTableFieldValue('employer_contractor', 'employer_contractor_name', 'id', "'" . $row['employer_contractor_id'] . "'"))) {
                ?>
                <div class="profile-info-row">
                    <div class="profile-info-name">Employer/Contractor</div>
                    <div class="profile-info-value">
                        <span><?php echo getTableFieldValue('employer_contractor', 'employer_contractor_name', 'id', "'" . $row['employer_contractor_id'] . "'") ?></span>
                    </div>
                </div>
                <?php } ?>

                <?php if (!empty(getTableFieldValue('designation', 'designation_name', 'designation_id', "'" . $row['designation_id'] . "'"))) {
                ?>
                <div class="profile-info-row">
                    <div class="profile-info-name">Designation</div>
                    <div class="profile-info-value">
                        <span><?php echo getTableFieldValue('designation', 'designation_name', 'designation_id', "'" . $row['designation_id'] . "'") ?></span>
                    </div>
                </div>

                <?php } ?>

                <?php if (!empty(getTableFieldValue('department', 'dept_name', 'dept_id', "'" . $row['dept_id'] . "'"))) {
                ?>
                <div class="profile-info-row">
                    <div class="profile-info-name">Department</div>
                    <div class="profile-info-value">
                        <span><?php echo getTableFieldValue('department', 'dept_name', 'dept_id', "'" . $row['dept_id'] . "'") ?></span>
                    </div>
                </div>
                <?php } ?>

                <?php if (!empty(getTableFieldValue('employee', 'patient_name', 'id', $row['mgr_emp_id']))) {
                ?>
                <div class="profile-info-row">
                    <div class="profile-info-name">Manager Name</div>
                    <div class="profile-info-value">
                        <span><?php echo getTableFieldValue('employee', 'patient_name', 'id', $row['mgr_emp_id']) ?></span>
                    </div>
                </div>
                <?php } ?>

                <?php if (!empty($row['father_name'])) {
                ?>
                <div class="profile-info-row">
                    <div class="profile-info-name">Father Name</div>
                    <div class="profile-info-value">
                        <span><?php echo $row['father_name'] ?></span>
                    </div>
                </div>
                <?php } ?>

                <?php if (!empty($row['aadhar_no'])) {
                ?>
                <div class="profile-info-row">
                    <div class="profile-info-name">Aadhar Number</div>
                    <div class="profile-info-value">
                        <span><?php echo $row['aadhar_no'] ?></span>
                    </div>
                </div>
                <?php } ?>

                <?php if ($row['doj'] != '0000-00-00' && !empty($row['doj'])) {
                ?>
                <div class="profile-info-row">
                    <div class="profile-info-name">Date of Joining</div>
                    <div class="profile-info-value">
                        <span><?php echo date_format(date_create($row['doj']), "d-M-Y ") ?></span>
                    </div>
                </div>
                <?php } ?>

                <?php if (!empty(date_format(date_create($row['dob']), "d-M-Y "))) {
                ?>
                <div class="profile-info-row">
                    <div class="profile-info-name">Date of Birth</div>
                    <div class="profile-info-value">
                        <span><?php echo date_format(date_create($row['dob']), "d-M-Y ") ?></span>
                    </div>
                </div>
                <?php } ?>

                <?php if (!empty($row['dob'])) {
                ?>
                <div class="profile-info-row">
                    <div class="profile-info-name">Age</div>
                    <div class="profile-info-value">
                        <span><?php echo isset($row['dob']) ? date_diff(date_create($row['dob']), date_create('today'))->y : "Not Available"; ?></span>
                    </div>
                </div>
                <?php } ?>

                <?php if (!empty($row['primary_phone'])) {
                ?>
                <div class="profile-info-row">
                    <div class="profile-info-name">Primary Phone</div>
                    <div class="profile-info-value">
                        <span><?php echo $row['primary_phone'] ?></span>
                    </div>
                </div>
                <?php } ?>

                <?php if (!empty($row['email_id'])) {
                ?>
                <div class="profile-info-row">
                    <div class="profile-info-name">Email</div>
                    <div class="profile-info-value">
                        <span>
                            <?php echo $row['email_id'] ?>
                        </span>
                    </div>
                </div>
                <?php } ?>

                <?php if (!empty($row['village'] && $row['tehsil'] && $row['district'] && $row['state'])) {
                ?>
                <div class="profile-info-row">
                    <div class="profile-info-name">Address</div>
                    <div class="profile-info-value">
                        <span><?php echo $row['village'] . " " . $row['tehsil'] . " " . $row['district'] . " " . $row['state'] ?></span>
                    </div>
                </div>
                <?php } ?>

                <?php if (!empty(getFieldFromTable('ohc_type_name', 'ohc_type', 'ohc_type_id', $row['ohc_type_id']))) {
                ?>
                <div class="profile-info-row">
                    <div class="profile-info-name">OHC Type</div>
                    <?php $ohc_name = getFieldFromTable('ohc_type_name', 'ohc_type', 'ohc_type_id', $row['ohc_type_id']); ?>
                    <div class="profile-info-value">
                        <span><?php echo $ohc_name ?></span>
                    </div>
                </div>
                <?php } ?>

            </div>
        </div>


        <div class="col-xs-12 col-sm-6 center">

            <p class="alert center" style="border-radius: 2%;background-color:#379683; color:#fff"><i
                    class="ace-icon fa fa-star orange card"></i> &nbsp;PATIENT LATEST VISIT DATA</p>

            <div class="space space-4"></div>
            <div id="accordion" class="accordion-style1 panel-group card">
                <div class="panel panel-default" style="text-align: left">
                    <div class="panel-heading">
                        <h4 class="panel-title">
                            <a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion"
                                href="#collapseOne">
                                <i class="ace-icon fa fa-angle-down bigger-110"
                                    data-icon-hide="ace-icon fa fa-angle-down"
                                    data-icon-show="ace-icon fa fa-angle-right"></i>&nbsp;Dependent List
                            </a>
                        </h4>
                    </div>


                    <!-- Patient Detail Panel Starts here  -->
                    <!-- OPD START -->
                    <div class="panel-collapse collapse in" id="collapseOne">
                        <div class="panel-body">
                            <div class="profile-user-info profile-user-info-striped"
                                style="margin: 0px; padding: 0px; width: 100%">

                                <?php
                                $sql_opd = "select * from emp_family_members where emp_id = '" . $id . "'";
                                error_log("sql opd: 407: " . $sql_opd);
                                if (!$result_opd = @mysqli_query($conn, $sql_opd)) {
                                    exit(error_log(mysqli_error($conn)));
                                }

                                if (mysqli_num_rows($result_opd) > 0) {
                                    while ($row_opd = @mysqli_fetch_array($result_opd)) {
                                        $name = $row_opd['name'];
                                        $depd_id = getTableFieldValue('patient_master', 'id', 'patient_name', "'" . $row_opd['name'] . "'", 'primary_patient_id', $id);
                                        error_log("dependent id" . $depd_id);

                                ?>

                                <div class="profile-info-row">
                                    <div class="profile-info-name">Name</div>
                                    <div class="profile-info-value">
                                        <a href="#" class="blue" title="Go To DashBoard"
                                            onclick=open_dashboard(<?= $depd_id ?>);><i
                                                class="ace-icon fa fa-tachometer bigger-130\"></i><?= "  " . $name ?></a>
                                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                        <a href="#" title="add opd" class="green"
                                            onclick=add_opd(<?= $depd_id ?>,'opd');><i
                                                class="ace-icon fa fa-edit bigger-130\"></i>Add OPD</a>

                                    </div>

                                </div>
                                <?php
                                    }
                                } else {
                                    ?>

                                <div class="profile-info-value">No Record found</div>

                                <?php  } ?>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="panel panel-default" style="text-align: left">
                    <div class="panel-heading">
                        <h4 class="panel-title">
                            <a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion"
                                href="#collapseOne">
                                <i class="ace-icon fa fa-angle-down bigger-110"
                                    data-icon-hide="ace-icon fa fa-angle-down"
                                    data-icon-show="ace-icon fa fa-angle-right"></i>&nbsp;Previous OPD Visit
                            </a>
                        </h4>
                    </div>


                    <!-- Patient Detail Panel Starts here  -->
                    <!-- OPD START -->
                    <div class="panel-collapse collapse in" id="collapseOne">
                        <div class="panel-body">
                            <div class="profile-user-info profile-user-info-striped"
                                style="margin: 0px; padding: 0px; width: 100%">

                                <?php
                                $sql_opd = "select * from employee_appointment where emp_id = '" . $id . "' and appointment_type='O' order by appointment_date desc limit 1";
                                error_log("sql opd: 407: " . $sql_opd);
                                if (!$result_opd = @mysqli_query($conn, $sql_opd)) {
                                    exit(error_log(mysqli_error($conn)));
                                }

                                if (mysqli_num_rows($result_opd) > 0) {
                                    if ($row_opd = @mysqli_fetch_array($result_opd)) {
                                        $aiment_ids = $row_opd['ailment_ids'];
                                        error_log("explode" . $row_opd['ailment_ids']);

                                ?>

                                <div class="profile-info-row">
                                    <div class="profile-info-name">Date & Time:</div>
                                    <div class="profile-info-value">
                                        <?php echo date_format(date_create($row_opd['appointment_date']), "d-M-Y H:i A") ?>
                                    </div>
                                </div>

                                <div class="profile-info-row">
                                    <div class="profile-info-name">Diagnosis:</div>
                                    <div class="profile-info-value">
                                        <?php echo getCommaSeperatedValuesForInClause("select ailment_name from ailment ", "ailment_id", $row_opd['ailments_new']); ?>
                                    </div>
                                </div>

                                <div class="profile-info-row">
                                    <div class="profile-info-name">Treatment:</div>
                                    <div class="profile-info-value">
                                        <?php echo getTreatmentText($row_opd['appointment_id']) ?></div>
                                </div>

                                <?php  } else {
                                        echo "No Results found";
                                    }
                                } else {
                                    ?>

                                <div class="profile-info-value">No Record found</div>

                                <?php  } ?>
                            </div>
                        </div>
                    </div>
                </div>
                <!-- OPD ENDS -->


                <!-- INJURY STARTS -->
                <div class="panel panel-default">
                    <div class="panel-heading" style="text-align: left">
                        <h4 class="panel-title">
                            <a class="accordion-toggle collapsed" data-toggle="collapse" data-parent="#accordion"
                                href="#collapseTwo">
                                <i class="ace-icon fa fa-angle-right bigger-110"
                                    data-icon-hide="ace-icon fa fa-angle-down"
                                    data-icon-show="ace-icon fa fa-angle-right"></i> &nbsp;Previous Injury </a>
                        </h4>
                    </div>

                    <div class="panel-collapse collapse" id="collapseTwo">
                        <div class="panel-body">
                            <div class="profile-user-info profile-user-info-striped"
                                style="margin: 0px; padding: 0px; width: 100%">
                                <?php
                                $sql_injury = "select * from employee_appointment where emp_id = '" . $id . "' and appointment_type='I' order by appointment_date desc limit 1";
                                error_log("sql injury: 525: " . $sql_injury);
                                if (!$result_injury = @mysqli_query($conn, $sql_injury)) {
                                    exit(error_log(mysqli_error($conn)));
                                }
                                if (mysqli_num_rows($result_injury) > 0) {
                                    if ($row_injury = mysqli_fetch_assoc($result_injury)) {
                                ?>

                                <div class="profile-info-row">
                                    <div class="profile-info-name">Date & Time:</div>
                                    <div class="profile-info-value">
                                        <?php echo date_format(date_create($row_injury['appointment_date']), "d-M-Y H:i A") ?>
                                    </div>
                                </div>

                                <div class="profile-info-row">
                                    <div class="profile-info-name">Diagnosis:</div>
                                    <div class="profile-info-value">
                                        <?php echo getCommaSeperatedValuesForInClause("select ailment_name from ailment ", "ailment_id", $row_injury['ailments_new']); ?>
                                    </div>
                                </div>

                                <div class="profile-info-row">
                                    <div class="profile-info-name">Treatment:</div>
                                    <div class="profile-info-value">
                                        <?php echo getTreatmentText($row_injury['appointment_id']) ?></div>
                                </div>

                                <?php  } else {
                                        echo "No Results found";
                                    }
                                } else {
                                    ?>

                                <div class="profile-info-value">No Record found</div>

                                <?php  } ?>

                            </div>
                        </div>
                    </div>
                </div>
                <!-- INJURY ENDS -->


                <div class="panel panel-default">
                    <div class="panel-heading">
                        <h4 class="panel-title" style="text-align: left">
                            <a class="accordion-toggle collapsed" data-toggle="collapse" data-parent="#accordion"
                                href="#collapseThree"> <i class="ace-icon fa fa-angle-right bigger-110"
                                    data-icon-hide="ace-icon fa fa-angle-down"
                                    data-icon-show="ace-icon fa fa-angle-right"></i> &nbsp;Previous Emergency
                            </a>
                        </h4>
                    </div>

                    <div class="panel-collapse collapse" id="collapseThree">
                        <div class="panel-body">
                            <div class="profile-user-info profile-user-info-striped"
                                style="margin: 0px; padding: 0px; width: 100%">
                                <?php

                                $sql_emergency = "select * from employee_appointment where emp_id = '" . $id . "' and isEmergency='1' order by appointment_date desc limit 1";

                                error_log("sql emergency: 643: " . $sql_emergency);

                                if (!$result_emergency = @mysqli_query($conn, $sql_emergency)) {
                                    exit(error_log(mysqli_error($conn)));
                                }

                                if (mysqli_num_rows($result_emergency) > 0) {
                                    if ($row_emergency = mysqli_fetch_assoc($result_emergency)) {
                                ?>

                                <div class="profile-info-row">
                                    <div class="profile-info-name">Date & Time:</div>
                                    <div class="profile-info-value">
                                        <?php echo date_format(date_create($row_emergency['appointment_date']), "d-M-Y H:i A") ?>
                                    </div>
                                </div>



                                <?php

                                        $appointment_type = $row_emergency['appointment_type'];

                                        $diagnosis = getCommaSeperatedValuesForInClause("select ailment_name from ailment ", "ailment_id", $row_emergency['ailment_new']);

                                        ?>

                                <div class="profile-info-row">
                                    <div class="profile-info-name">Diagnosis:</div>
                                    <div class="profile-info-value"><?php echo $diagnosis ?></div>
                                </div>

                                <div class="profile-info-row">
                                    <div class="profile-info-name">Treatment:</div>
                                    <div class="profile-info-value">
                                        <?php echo getTreatmentText($row_emergency['appointment_id']) ?></div>
                                </div>

                                <?php  } else { ?> No Results found
                                <?php
                                    }
                                } else {
                                    ?>

                                <div class="profile-info-value">No Record found</div>
                                <?php  } ?>
                            </div>
                        </div>
                    </div>
                </div>

                <div class="panel panel-default">
                    <div class="panel-heading" style="text-align: left">
                        <h4 class="panel-title">
                            <a class="accordion-toggle collapsed" data-toggle="collapse" data-parent="#accordion"
                                href="#collapseFour"> <i class="ace-icon fa fa-angle-right bigger-110"
                                    data-icon-hide="ace-icon fa fa-angle-down"
                                    data-icon-show="ace-icon fa fa-angle-right"></i> &nbsp;Previous Sickness Absenteeism
                            </a>
                        </h4>
                    </div>

                    <div class="panel-collapse collapse" id="collapseFour">
                        <div class="panel-body">
                            <div class="profile-user-info profile-user-info-striped"
                                style="margin: 0px; padding: 0px; width: 100%">

                                <?php
                                $sql_sickness = "select * from sickness where emp_id = '" . $id . "' order by sickness_date desc limit 1";
                                error_log("sql sickness: 789: " . $sql_sickness);
                                if (!$result_sickness = @mysqli_query($conn, $sql_sickness)) {
                                    exit(error_log(mysqli_error($conn)));
                                }
                                if (mysqli_num_rows($result_sickness) > 0) {
                                    if ($row_sickness = mysqli_fetch_assoc($result_sickness)) {
                                ?>

                                <div class="profile-info-row">
                                    <div class="profile-info-name">Date & Time:</div>
                                    <div class="profile-info-value"><?php echo $row_sickness['sickness_date'] ?></div>
                                </div>

                                <div class="profile-info-row">
                                    <div class="profile-info-name">Diagnosis:</div>
                                    <div class="profile-info-value">
                                        <?= getFieldFromTable('ailment_name', 'ailment', 'ailment_id', $row_sickness['ailment_name']) ?>
                                    </div>
                                </div>

                                <!-- <div class="profile-info-row">
											<div class="profile-info-name">Treatment:</div>
											<div class="profile-info-value"><?php echo $row_sickness['des'] ?></div>
										</div> -->

                                <?php  } else { ?>
                                No Results found
                                <?php
                                    }
                                } else {
                                    ?>
                                <div class="profile-info-value">No Record found</div>
                                <?php  } ?>
                            </div>
                        </div>
                    </div>
                </div>



                <div class="panel panel-default">
                    <div class="panel-heading" style="text-align: left">
                        <h4 class="panel-title">
                            <a class="accordion-toggle collapsed" data-toggle="collapse" data-parent="#accordion"
                                href="#collapseFive">
                                <i class="ace-icon fa fa-angle-right bigger-110"
                                    data-icon-hide="ace-icon fa fa-angle-down"
                                    data-icon-show="ace-icon fa fa-angle-right"></i> &nbsp;Training
                            </a>
                        </h4>
                    </div>

                    <div class="panel-collapse collapse" id="collapseFive">
                        <div class="panel-body">
                            <div class="profile-user-info profile-user-info-striped"
                                style="margin: 0px; padding: 0px; width: 100%">
                                <?php

                                $sql_training_complete = "select * from employee_assign_training where emp_id='" . $_SESSION['logged_user_empid'] . "' and status='Y' limit 1";

                                // echo $sql_training_complete;
                                error_log("sql training complete: 909: " . $sql_training_complete);

                                if (!$result_training_complete = @mysqli_query($conn, $sql_training_complete)) {

                                    exit(error_log(mysqli_error($conn)));
                                }

                                if (mysqli_num_rows($result_training_complete) > 0) {

                                    if ($row_training_complete = mysqli_fetch_assoc($result_training_complete)) {



                                        $query_schedule = "select * from  training_schedule where schedule_id='" . $row_training_complete['training_schedule_id'] . "' limit 1";

                                        // echo $query_schedule;
                                        error_log("query_schedule: " . $query_schedule);

                                        $result_schedule = @mysqli_query($conn, $query_schedule);

                                        while ($rows_schedule = mysqli_fetch_assoc($result_schedule)) {

                                            $training_name = getTableFieldValue('training_master', 'training_name', 'training_master_id', $rows_schedule['training_id']);

                                            $from_date = date_format(date_create($row_training['from_date']), "d-M-Y");

                                            $to_date = date_format(date_create($row_training['to_date']), "d-M-Y");

                                            $trainer_name = $rows_schedule['trainer_name'];

                                            $training_location = $rows_schedule['location'];

                                            // $training_schedule= $training_name.'('.$rows_schedule['trainer_name'].','.date_format(date_create($row_training['from_date']),"d-M-Y").' '.date_format(date_create($row_training['to_date']),"d-M-Y").')';

                                        }



                                ?>

                                <div class="profile-info-row">
                                    <div class="profile-info-name">Training Name:</div>
                                    <div class="profile-info-value"><?php echo $training_name ?></div>
                                </div>

                                <div class="profile-info-row">
                                    <div class="profile-info-name">To Date:</div>
                                    <div class="profile-info-value"><?php echo $to_date ?></div>
                                </div>

                                <div class="profile-info-row">
                                    <div class="profile-info-name">From Date:</div>
                                    <div class="profile-info-value"><?php echo $from_date ?></div>
                                </div>

                                <div class="profile-info-row">
                                    <div class="profile-info-name">Trainer Name:</div>
                                    <div class="profile-info-value"><?php echo $trainer_name ?></div>
                                </div>

                                <div class="profile-info-row">
                                    <div class="profile-info-name">Completion Date:</div>
                                    <div class="profile-info-value">
                                        <?php echo $date_completion = date_format(date_create($row_training_complete['completion_date']), "d-M-Y") ?>
                                    </div>
                                </div>

                                <div class="profile-info-row">
                                    <div class="profile-info-name">Status Name:</div>
                                    <div class="profile-info-value"><?php echo 'complete' ?></div>
                                </div>

                                <?php

                                        $date_completion = "";

                                        // if($row_emp_assign_training['completion_date']!=null && $row_emp_assign_training['completion_date']!='0000-00-00' )

                                        // $date_completion= date_format(date_create($row_emp_assign_training['completion_date']),"d-M-Y");

                                    }
                                } else {
                                    ?> No Results found<?php
                                                    }

                                                        ?>





                            </div>
                        </div>
                    </div>
                </div>

                <!-- Previous Medical Examination start here  -->
                <div class="panel panel-default">
                    <div class="panel-heading" style="text-align: left">
                        <h4 class="panel-title">
                            <a class="accordion-toggle collapsed" data-toggle="collapse" data-parent="#accordion"
                                href="#collapseSix">
                                <i class="ace-icon fa fa-angle-right bigger-110"
                                    data-icon-hide="ace-icon fa fa-angle-down"
                                    data-icon-show="ace-icon fa fa-angle-right"></i> &nbsp;Previous Medical Examination
                            </a>
                        </h4>
                    </div>

                    <div class="panel-collapse collapse" id="collapseSix">
                        <div class="panel-body">
                            <div class="profile-user-info profile-user-info-striped"
                                style="margin: 0px; padding: 0px; width: 100%">
                                <?php
                                $sql_checkup = "select * from checkup_form where emp_id = '" . $id . "' order by checkup_date desc limit 1";

                                error_log("sql checkup: 1076: " . $sql_checkup);
                                if (!$result_checkup = @mysqli_query($conn, $sql_checkup)) {
                                    exit(error_log(mysqli_error($conn)));
                                }

                                if (mysqli_num_rows($result_checkup) > 0) {
                                    if ($row_checkup = mysqli_fetch_assoc($result_checkup)) {
                                ?>

                                <div class="profile-info-row">
                                    <div class="profile-info-name">Date & Time:</div>
                                    <div class="profile-info-value">
                                        <?php echo date_format(date_create($row_checkup['checkup_date']), "d-M-Y H:i A") ?>
                                    </div>
                                </div>

                                <div class="profile-info-row">
                                    <div class="profile-info-name">Medications:</div>
                                    <div class="profile-info-value">
                                        <?php echo (isset($row_checkup['reglar_medication'])) ? ($row_checkup['reglar_medication']) : ("NA") ?>
                                    </div>
                                </div>

                                <?php  } else {
                                        echo "No Results found";
                                    }
                                } else {
                                    ?>

                                <div class="profile-info-value">No Record found</div>
                                <?php  } ?>

                            </div>
                        </div>
                    </div>
                </div>
                <!-- Previous Medical Examination ends here  -->

                <!-- PAst Present Illness start here  -->
                <div class="panel panel-default">
                    <div class="panel-heading" style="text-align: left">
                        <h4 class="panel-title">
                            <a class="accordion-toggle collapsed" data-toggle="collapse" data-parent="#accordion"
                                href="#collapsePastIllness">
                                <i class="ace-icon fa fa-angle-right bigger-110"
                                    data-icon-hide="ace-icon fa fa-angle-down"
                                    data-icon-show="ace-icon fa fa-angle-right"></i> &nbsp;Past Present Illness
                            </a>
                        </h4>
                    </div>

                    <div class="panel-collapse collapse" id="collapsePastIllness">
                        <div class="panel-body">
                            <div class="profile-user-info profile-user-info-striped"
                                style="margin: 0px; padding: 0px; width: 100%">
                                <?php
                                $sql_checkup = "select past_present_illness,medical_entry_date from medical_examination where patient_id = '" . $id . "' order by medical_entry_date desc limit 1";
                                error_log("sql checkup: 1076: " . $sql_checkup);
                                if (!$result_checkup = @mysqli_query($conn, $sql_checkup)) {
                                    exit(error_log(mysqli_error($conn)));
                                }

                                if (mysqli_num_rows($result_checkup) > 0) {
                                    if ($row_checkup = mysqli_fetch_assoc($result_checkup)) {
                                ?>

                                <div class="profile-info-row">
                                    <div class="profile-info-name">Date & Time:</div>
                                    <div class="profile-info-value">
                                        <?php echo date_format(date_create($row_checkup['medical_entry_date']), "d-M-Y H:i A") ?>
                                    </div>
                                </div>

                                <div class="profile-info-row">
                                    <div class="profile-info-name">Medications:</div>
                                    <div class="profile-info-value">
                                        <?php echo ppa($row_checkup['past_present_illness']) ?></div>
                                </div>

                                <?php  } else {
                                        echo "No Results found";
                                    }
                                } else {
                                    ?>

                                <div class="profile-info-value">No Record found</div>
                                <?php  } ?>

                            </div>
                        </div>
                    </div>
                </div>
                <!-- PAst Present Illness ends here  -->

                <!-- Health Advice start here  -->
                <div class="panel panel-default">
                    <div class="panel-heading" style="text-align: left">
                        <h4 class="panel-title">
                            <a class="accordion-toggle collapsed" data-toggle="collapse" data-parent="#accordion"
                                href="#collapseHealthAdvices">
                                <i class="ace-icon fa fa-angle-right bigger-110"
                                    data-icon-hide="ace-icon fa fa-angle-down"
                                    data-icon-show="ace-icon fa fa-angle-right"></i> &nbsp;Health Advices
                            </a>
                        </h4>
                    </div>

                    <div class="panel-collapse collapse" id="collapseHealthAdvices">
                        <div class="panel-body">
                            <div class="profile-user-info profile-user-info-striped"
                                style="margin: 0px; padding: 0px; width: 100%">
                                <?php
                                $sql_checkup = "select health_advices_new,appointment_date from employee_appointment where emp_id = '" . $id . "' order by appointment_date desc limit 1";
                                error_log("sql checkup: 1076: " . $sql_checkup);
                                if (!$result_checkup = @mysqli_query($conn, $sql_checkup)) {
                                    exit(error_log(mysqli_error($conn)));
                                }

                                if (mysqli_num_rows($result_checkup) > 0) {
                                    if ($row_checkup = mysqli_fetch_assoc($result_checkup)) {
                                ?>

                                <div class="profile-info-row">
                                    <div class="profile-info-name">Date & Time:</div>
                                    <div class="profile-info-value"><?php echo $row_checkup['appointment_date'] ?></div>
                                </div>

                                <div class="profile-info-row">
                                    <div class="profile-info-name">Advices:</div>
                                    <div class="profile-info-value">
                                        <?php echo $row_checkup['health_advices_new'] ?></div>
                                </div>

                                <?php  } else {
                                        echo "No Results found";
                                    }
                                } else {
                                    ?>

                                <div class="profile-info-value">No Record found</div>
                                <?php  } ?>

                            </div>
                        </div>
                    </div>
                </div>
                <!-- Health Advice ends here  -->


                <!-- <div class="panel panel-default">

						<div class="panel-heading" style="text-align: left">

							<h4 class="panel-title">

								<a class="accordion-toggle collapsed" data-toggle="collapse"

									data-parent="#accordion"

									href="#collapseSeven"> <i

									class="ace-icon fa fa-angle-right bigger-110"

									data-icon-hide="ace-icon fa fa-angle-down"

									data-icon-show="ace-icon fa fa-angle-right"></i> &nbsp;Health

									Advice



								</a>

							</h4>

						</div>



						<div class="panel-collapse collapse" id="collapseSeven">

							<div class="panel-body">

													

										<?php



                                        $advices = explode(",", trim($row['known_health_advices'], ','));

                                        // echo $advices;

                                        $str_advices = '<ul>';

                                        for ($i = 0; $i < count($advices); $i++) {

                                            if ($i == 0) {

                                                $str_advices .= "<li style='text-align:left'>" . getTableFieldValue('health_advice', 'health_advice_name', 'health_advice_id', $advices[$i], '');

                                                $str_advices .= "</li>";
                                            } else {

                                                $str_advices .= '<li style="text-align:left">' . getTableFieldValue('health_advice', 'health_advice_name', 'health_advice_id', $advices[$i], '');

                                                $str_advices .= "</li>";
                                            }
                                        }

                                        $str_advices .= '</ul>';

                                        echo $str_advices;



                                        ?>

										

							</div>

						</div> -->

                <div class="panel panel-default">

                    <div class="panel-heading" style="text-align: left">

                        <h4 class="panel-title">

                            <a class="accordion-toggle collapsed" data-toggle="collapse" data-parent="#accordion"
                                href="#collapseEight"> <i class="ace-icon fa fa-angle-right bigger-110"
                                    data-icon-hide="ace-icon fa fa-angle-down"
                                    data-icon-show="ace-icon fa fa-angle-right"></i>

                                &nbsp;Significant Health Risks



                            </a>

                        </h4>

                    </div>



                    <div class="panel-collapse collapse" id="collapseEight">
                        <div class="panel-body">
                            <?php
                            $risks = explode(",", trim($row['known_health_risks'], ','));
                            // echo $advices;
                            $str_risks = '<ul>';
                            for ($i = 0; $i < count($risks); $i++) {
                                if ($i == 0) {
                                    $str_risks .= "<li style='text-align:left'>" .  getTableFieldValue('health_risk', 'health_risk_name', 'health_risk_id', $risks[$i], '');
                                    $str_risks .= "</li>";
                                } else {
                                    $str_risks .= '<li style="text-align:left">' . getTableFieldValue('health_risk', 'health_risk_name', 'health_risk_id', $risks[$i], '');
                                    $str_risks .= "</li>";
                                }
                            }
                            $str_risks .= '</ul>';
                            echo $str_risks;
                            ?>
                        </div>
                    </div>
                </div>

                <div class="panel panel-default">
                    <div class="panel-heading" style="text-align: left">
                        <h4 class="panel-title">
                            <a class="accordion-toggle collapsed" data-toggle="collapse" data-parent="#accordion"
                                href="#collapseNine"> <i class="ace-icon fa fa-angle-right bigger-110"
                                    data-icon-hide="ace-icon fa fa-angle-down"
                                    data-icon-show="ace-icon fa fa-angle-right"></i>
                                &nbsp;Additional Treatment Recommendations
                            </a>
                        </h4>
                    </div>

                    <div class="panel-collapse collapse" id="collapseNine">
                        <div class="panel-body">
                            <?php
                            $sql_checkup = "select * from employee_appointment where emp_id = '" . $id . "' order by appointment_date desc limit 1";

                            error_log("sql opd: 1076: " . $sql_checkup);
                            if (!$result_checkup = @mysqli_query($conn, $sql_checkup)) {
                                exit(error_log(mysqli_error($conn)));
                            }

                            if (mysqli_num_rows($result_checkup) > 0) {
                                if ($row_checkup = mysqli_fetch_assoc($result_checkup)) {
                            ?>

                            <div class="profile-info-row">
                                <div class="profile-info-name">Date & Time:</div>
                                <div class="profile-info-value">
                                    <?php echo date_format(date_create($row_checkup['appointment_date']), "d-M-Y H:i A") ?>
                                </div>
                            </div>

                            <div class="profile-info-row">
                                <div class="profile-info-name">Recommendations:</div>
                                <div class="profile-info-value">
                                    <?php echo (isset($row_checkup['external_treatments'])) ? ($row_checkup['external_treatments']) : ("NA") ?>
                                </div>
                            </div>

                            <?php  } else {
                                    echo "No Results found";
                                }
                            } else {
                                ?>

                            <div class="profile-info-value">No Record found</div>
                            <?php  } ?>

                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>





    <!-- Charts starts here  -->
    <br>
    <div class="container-fluid">

        <form id="filter_report" name="filter_report">
            <div class="row">
                <div class="col-sm-12 alert center" style="border-radius: 2%;background-color:#379683; color:#fff"><i
                        class="ace-icon fa fa-star orange card"></i> &nbsp;Choose date filter to see past data</div>
                <div class="col-sm-2">
                    <div class="panel panel-warning card">
                        <div class="panel-heading">
                            <h3 class="panel-title center">Start date</h3>
                        </div>
                        <div class="panel-body">
                            <div class="input-group">
                                <input class="form-control date-picker" style="width:auto" id="startDate"
                                    name="startDate" value="<?= date('01-01-Y') ?>" type=" text"
                                    data-date-format="dd-mm-yyyy" />
                            </div>
                        </div>
                    </div>
                </div>
                <div class="col-sm-2">
                    <div class="panel panel-warning card">
                        <div class="panel-heading">
                            <h3 class="panel-title center">End date</h3>
                        </div>
                        <div class="panel-body">
                            <div class="input-group">
                                <input class="form-control date-picker" style="width:auto" id="endDate" name="endDate"
                                    value="<?= date('d-m-Y') ?>" type=" text" data-date-format="dd-mm-yyyy" />
                            </div>


                        </div>
                    </div>

                </div>
                <div class="col-sm-2 wizard-card container-fluid " style="margin-top: 40px;">
                    <button type="button" class="card" id="mybtn" onclick="getShowingData();">GO</button>
                </div>

            </div>

        </form>
    </div>
    <?php

    ?>
    <div name="data_shower">

        <div class="container-fluid">
            <div class="row">
                <p class="alert center" style="border-radius: 2%;background-color:#379683; color:#fff"><i
                        class="ace-icon fa fa-star orange card"></i> &nbsp;BMI TRACKING</p>
                <div class="space space-4"></div>

                <div class="col-sm-6 wizard-card container-fluid card" style="
            padding-left: 20px;
           ">
                    <canvas id="patient_bmi"></canvas>
                    <?php include 'chart_employee_bmi_height_weight.php'; ?>
                </div>

                <div class="col-sm-6 container-fluid">

                    <table style="width: 100%" id="bmi_table" class="center card table">
                        <?php
                        $height = array();
                        $weight = array();
                        $bmi = array();
                        $medical_date = array();


                        $bmi_new = array();
                        $height_new = array();
                        $weight_new = array();

                        $startDate = date("d-m-Y", strtotime("-2 year"));

                        $endDate = date("d-m-Y");
                        // SQL query to select data from database

                        $sql_height = "SELECT height, date(appointment_date) as dat FROM employee_appointment 
                    where emp_id='$id'and height != '' and date(appointment_date) between STR_TO_DATE('" . $startDate . "', '%d-%m-%Y')  AND STR_TO_DATE('" . $endDate . "', '%d-%m-%Y')
                    UNION
                    SELECT cf.checkup_form_value as height ,date(c.checkup_date) as dat from 
                    checkup_form c left join checkup_form_key_value cf on 
                    c.checkup_id=cf.checkup_form_id left join checkup_parameter cp on 
                    cp.`column_name` = cf.checkup_form_key 
                    where c.emp_id='$id' and cp.key_health_map_name=(select key_param_id from key_health_reportable_parameter_master where key_param_name='height') and date(c.checkup_date) between STR_TO_DATE('" . $startDate . "', '%d-%m-%Y')  AND STR_TO_DATE('" . $endDate . "', '%d-%m-%Y') order by dat asc limit 10";
                        $result_height = mysqli_query($conn, $sql_height);

                        error_log(" height query for table" . $sql_height);
                        while ($row_height = mysqli_fetch_assoc($result_height)) {
                            array_push($medical_date, $row_height['dat']);
                            $height['height'][$row_height['dat']] = $row_height['height'];
                        }

                        $sql_weight = "SELECT `weight`, date(appointment_date) as dat FROM employee_appointment 
                    where emp_id='$id'and `weight` != '' and date(appointment_date) between STR_TO_DATE('" . $startDate . "', '%d-%m-%Y')  AND STR_TO_DATE('" . $endDate . "', '%d-%m-%Y')
                    UNION
                    SELECT cf.checkup_form_value as weight ,date(c.checkup_date) as dat from 
                    checkup_form c left join checkup_form_key_value cf on 
                    c.checkup_id=cf.checkup_form_id left join checkup_parameter cp on 
                    cp.`column_name` = cf.checkup_form_key 
                    where c.emp_id='$id' and cp.key_health_map_name=(select key_param_id from key_health_reportable_parameter_master where key_param_name='weight') and date(c.checkup_date) between STR_TO_DATE('" . $startDate . "', '%d-%m-%Y')  AND STR_TO_DATE('" . $endDate . "', '%d-%m-%Y') order by dat asc limit 10";
                        $result_weight = mysqli_query($conn, $sql_weight);
                        while ($row_weight = mysqli_fetch_assoc($result_weight)) {
                            array_push($medical_date, $row_weight['dat']);
                            $weight['weight'][$row_weight['dat']] = $row_weight['weight'];
                        }

                        // SQL query to select data from database
                        $sql_bmi = "SELECT `bmi`, date(appointment_date) as dat FROM employee_appointment where emp_id='$id'and `bmi` != '' and date(appointment_date) between STR_TO_DATE('" . $startDate . "', '%d-%m-%Y')  AND STR_TO_DATE('" . $endDate . "', '%d-%m-%Y')
                        UNION
                        SELECT cf.checkup_form_value as bmi ,date(c.checkup_date) as dat from checkup_form c left join checkup_form_key_value cf on c.checkup_id=cf.checkup_form_id left join checkup_parameter cp on cp.`column_name` = cf.checkup_form_key where c.emp_id='$id' and cp.key_health_map_name=(select key_param_id from key_health_reportable_parameter_master where key_param_name='bmi') and date(c.checkup_date) between STR_TO_DATE('" . $startDate . "', '%d-%m-%Y')  AND STR_TO_DATE('" . $endDate . "', '%d-%m-%Y') order by dat asc limit 10";
                        $result_bmi = mysqli_query($conn, $sql_bmi);
                        error_log("bmi for table query " . $sql_bmi);
                        if (mysqli_num_rows($result_bmi) > 0) {
                            while ($row_bmi = mysqli_fetch_assoc($result_bmi)) {
                                array_push($medical_date, $row_bmi['dat']);
                                $bmi['bmi'][$row_bmi['dat']] = $row_bmi['bmi'];
                            }
                        }
                        $medical_date = array_values(array_unique($medical_date));

                        for ($i = 0; $i < sizeof($medical_date); $i++) {

                            error_log("inside loop value" . $bmi['bmi'][$medical_date[$i]]);
                            error_log("inside loop value" . $height['height'][$medical_date[$i]]);
                            error_log("inside loop value" . $weight['weight'][$medical_date[$i]]);

                            if ($bmi['bmi'][$medical_date[$i]] == '') {
                                array_push($bmi_new, 0);
                            } else {
                                array_push($bmi_new, $bmi['bmi'][$medical_date[$i]]);
                            }
                            if ($height['height'][$medical_date[$i]] == '') {
                                array_push($height_new, 0);
                            } else {
                                array_push($height_new, $height['height'][$medical_date[$i]]);
                            }
                            if ($weight['weight'][$medical_date[$i]] == '') {
                                array_push($weight_new, 0);
                            } else {
                                array_push($weight_new, $weight['weight'][$medical_date[$i]]);
                            }
                        }
                        ?>

                        <thead>
                            <tr>
                                <td style="font-size: 10px" width="15%"><strong>Date</strong></td>
                                <td style="font-size: 10px" width="15%"><strong>height</strong></td>
                                <td style="font-size: 10px" width="15%"><strong>weight</strong></td>
                                <td style="font-size: 10px" width="15%"><strong>bmi</strong></td>
                            </tr>
                        </thead>
                        <tbody>
                            <?php
                            for ($i = 0; $i < sizeof($medical_date); $i++) {
                                $newDate = date("d-m-Y", strtotime($medical_date[$i]));
                            ?>
                            <tr>
                                <td><?php echo $newDate; ?></td>
                                <td><?php echo $height_new[$i] ?></td>
                                <td><?php echo $weight_new[$i]; ?></td>
                                <td><?php echo $bmi_new[$i] ?></td>
                            </tr>
                            <?php
                            }  ?>
                        </tbody>


                    </table>
                </div>
            </div>
        </div>
        <hr>
        <div class="container-fluid">
            <div class="row">
                <p class="alert center" style="border-radius: 2%;background-color:#379683; color:#fff"><i
                        class="ace-icon fa fa-star orange card"></i> &nbsp;OSI TRACKING</p>
                <div class="space space-4"></div>
                <div class="col-sm-6 wizard-card container-fluid card" style="
            padding-left: 20px;
           ">
                    <canvas id="patient_osi"></canvas>
                    <?php include 'chart_employee_OSI.php'; ?>
                </div>
                <div class="col-sm-6 wizard-card container-fluid">

                    <table style="width: 100%" id="osi_table" class="center card table">
                        <thead>
                            <tr>


                                <td style="font-size: 10px" width="15%"><strong>Months</strong></td>
                                <td style="font-size: 10px" width="15%"><strong>OPD Visits</strong></td>
                                <td style="font-size: 10px" width="15%"><strong>Injury Visits</strong></td>
                                <td style="font-size: 10px" width="15%"><strong>Sickness Visits</strong></td>




                            </tr>
                        </thead>
                        <tbody>

                            <?php

                            $startMonth = '1';

                            $endMonth = '12';

                            $year = date("Y");
                            // SQL query to select data from database

                            for ($i = $startMonth; $i <= $endMonth; $i++) {
                                $query1 = "SELECT COUNT(appointment_id) FROM employee_appointment WHERE MONTH(appointment_date) = $i and YEAR(appointment_date)='$year' AND appointment_type='O' AND emp_id='$id' ";

                                // $testMonth = $endMonth - $m;
                                // if ($testMonth <= 0) {
                                //     $testMonth += 12;
                                // }
                                error_log("count query for osi " . $query1);
                                $result1 = mysqli_query($conn, $query1);
                                while ($row1 = $result1->fetch_assoc()) {
                                    $month_name = date("F", mktime(0, 0, 0, $i, 10));
                            ?> <tr>
                                <td>
                                    <?php echo $month_name; ?>
                                </td>
                                <td>
                                    <?php echo $row1['COUNT(appointment_id)']; ?>
                                </td>
                                <?php
                                }
                                $m++;


                                $query2 = "SELECT COUNT(appointment_id) FROM employee_appointment WHERE MONTH(appointment_date) = $i and YEAR(appointment_date)='$year' AND appointment_type='I' AND emp_id='$id' ";
                                $result2 = mysqli_query($conn, $query2);
                                while ($row2 = $result2->fetch_assoc()) {

                                    ?>
                                <td>
                                    <?php echo $row2['COUNT(appointment_id)']; ?>
                                </td>
                                <?php
                                        $query3 = "SELECT COUNT(sickness_id) FROM sickness WHERE MONTH(sickness_date) = $i and YEAR(sickness_date)='$year' AND emp_id='$id' ";
                                        $result3 = mysqli_query($conn, $query3);
                                        while ($row3 = $result3->fetch_assoc()) {

                                        ?>
                                <td>
                                    <?php echo $row3['COUNT(sickness_id)']; ?>
                                </td>
                            </tr>
                            <?php
                                        }
                                    }
                                }


                        ?>




                        </tbody>

                    </table>

                </div>

            </div>
        </div>

        <hr>
        <div class="container-fluid">
            <div class="row">
                <p class="alert center" style="border-radius: 2%;background-color:#379683; color:#fff"><i
                        class="ace-icon fa fa-star orange card"></i> &nbsp;BP TRACKING</p>
                <div class="space space-4"></div>
                <div class="col-sm-6 wizard-card container-fluid card" style="
            padding-left: 20px;
           ">
                    <canvas id="patient_bp"></canvas>
                    <?php include 'chart_employee_blood_pressure.php'; ?>
                </div>
                <div class="col-sm-6 wizard-card container-fluid">

                    <table style="width: 100%" id="bp_table" class="center card table">
                        <?php
                        $bp_dbp = array();
                        $bp_sbp = array();
                        $medical_date = array();

                        $sbp_new = array();
                        $dbp_new = array();


                        $query = "SELECT bp_sbp as sbp, date(appointment_date) as dat FROM employee_appointment where emp_id='$id'and bp_sbp != '' and date(appointment_date) between STR_TO_DATE('" . $startDate . "', '%d-%m-%Y')  AND STR_TO_DATE('" . $endDate . "', '%d-%m-%Y')UNION 
                    SELECT cf.checkup_form_value as sbp ,date(c.checkup_date) as dat from checkup_form c left join checkup_form_key_value cf on c.checkup_id=cf.checkup_form_id left join checkup_parameter cp on cp.`column_name` = cf.checkup_form_key where c.emp_id='$id' and  (cp.key_health_map_name=(select key_param_id from key_health_reportable_parameter_master where key_param_name='sbp') or cp.key_health_map_name=(select key_param_id from key_health_reportable_parameter_master where key_param_name='sbp/dbp')) and date(c.checkup_date) between STR_TO_DATE('" . $startDate . "', '%d-%m-%Y')  AND STR_TO_DATE('" . $endDate . "', '%d-%m-%Y') order by dat desc limit 25";

                        error_log("sbp query " . $query);
                        $result = @mysqli_query($conn, $query);
                        if (mysqli_num_rows($result) > 0) {
                            while ($row = @mysqli_fetch_array($result)) {
                                array_push($medical_date, $row[1]);

                                $bp_arr = explode("/", $row[0]);
                                error_log("size " . sizeof($bp_arr));
                                if (sizeof($bp_arr) > 1) {
                                    $bp_sbp['sbp'][$row[1]] = $bp_arr[0];
                                } else {
                                    $bp_sbp['sbp'][$row[1]] = $bp_arr[0];
                                }
                            }
                        }

                        $query = "SELECT bp_dbp as dbp, date(appointment_date) as dat FROM employee_appointment where emp_id='$id'and bp_dbp != '' and date(appointment_date) between STR_TO_DATE('" . $startDate . "', '%d-%m-%Y')  AND STR_TO_DATE('" . $endDate . "', '%d-%m-%Y')UNION
                    SELECT cf.checkup_form_value as dbp ,date(c.checkup_date) as dat from checkup_form c left join checkup_form_key_value cf on c.checkup_id=cf.checkup_form_id left join checkup_parameter cp on cp.`column_name` = cf.checkup_form_key where c.emp_id='$id' and  (cp.key_health_map_name=(select key_param_id from key_health_reportable_parameter_master where key_param_name='dbp') or cp.key_health_map_name=(select key_param_id from key_health_reportable_parameter_master where key_param_name='sbp/dbp')) and date(c.checkup_date) between STR_TO_DATE('" . $startDate . "', '%d-%m-%Y')  AND STR_TO_DATE('" . $endDate . "', '%d-%m-%Y') order by dat desc limit 25";

                        error_log("dbp query " . $query);
                        $result = @mysqli_query($conn, $query);
                        if (mysqli_num_rows($result) > 0) {
                            while ($row = @mysqli_fetch_array($result)) {
                                array_push($medical_date, $row[1]);

                                $bp_arr = explode("/", $row[0]);
                                error_log("size " . sizeof($bp_arr));

                                if (sizeof($bp_arr) > 1) {
                                    $bp_dbp['dbp'][$row[1]] = $bp_arr[1];
                                } else {
                                    $bp_dbp['dbp'][$row[1]] = $bp_arr[0];
                                }
                            }
                        }
                        $medical_date = array_values(array_unique($medical_date));

                        for ($i = 0; $i < sizeof($medical_date); $i++) {

                            error_log("inside loop value" . $bp_sbp['sbp'][$medical_date[$i]]);
                            error_log("inside loop value" . $bp_dbp['dbp'][$medical_date[$i]]);

                            if ($bp_sbp['sbp'][$medical_date[$i]] == '') {
                                array_push($sbp_new, 0);
                            } else {
                                array_push($sbp_new, $bp_sbp['sbp'][$medical_date[$i]]);
                            }
                            if ($bp_dbp['dbp'][$medical_date[$i]] == '') {
                                array_push($dbp_new, 0);
                            } else {
                                array_push($dbp_new, $bp_dbp['dbp'][$medical_date[$i]]);
                            }
                        }


                        ?>
                        <thead>
                            <tr>
                                <td style="font-size: 10px" width="15%"><strong>Date</strong></td>
                                <td style="font-size: 10px" width="15%"><strong>Sbp</strong></td>
                                <td style="font-size: 10px" width="15%"><strong>Dbp</strong></td>
                            </tr>
                        </thead>
                        <tbody>
                            <?php
                            for ($i = 0; $i < sizeof($medical_date); $i++) {
                                $newDate = date("d-m-Y", strtotime($medical_date[$i]));
                            ?>
                            <tr>
                                <td><?php echo $newDate; ?></td>
                                <td><?php echo $sbp_new[$i] ?></td>
                                <td><?php echo $dbp_new[$i]; ?></td>
                            </tr>
                            <?php
                            }  ?>
                        </tbody>


                    </table>
                </div>

            </div>
        </div>
        <hr>
        <div class="container-fluid">
            <div class="row">
                <p class="alert center" style="border-radius: 2%;background-color:#379683; color:#fff"><i
                        class="ace-icon fa fa-star orange card"></i> &nbsp;BLOOD SUGAR TRACKING</p>
                <div class="space space-4"></div>
                <div class="col-sm-6 wizard-card container-fluid card" style="padding-left: 20px;">
                    <canvas id="patient_bs"></canvas>
                    <?php include 'chart_employee_blood_sugar.php'; ?>
                </div>
                <div class="col-sm-6 wizard-card container-fluid">

                    <table style="width: 100%" id="suger_table" class="center card table table-striped">
                        <?php

                        $blood_sugar_ppbs = array();
                        $blood_sugar_fbs = array();
                        $blood_sugar_rbs = array();
                        $medical_date = array();


                        $fbs_new = array();
                        $rbs_new = array();
                        $ppbs_new = array();

                        $query = "SELECT blood_sugar_rbs as rbs, date(appointment_date) as dat FROM employee_appointment where emp_id='$id'and blood_sugar_rbs != '' and date(appointment_date) between STR_TO_DATE('" . $startDate . "', '%d-%m-%Y')  AND STR_TO_DATE('" . $endDate . "', '%d-%m-%Y') UNION
                    SELECT cf.checkup_form_value as rbs ,date(c.checkup_date) as dat from checkup_form c left join checkup_form_key_value cf on c.checkup_id=cf.checkup_form_id left join checkup_parameter cp on cp.`column_name` = cf.checkup_form_key where c.emp_id='$id' and cp.key_health_map_name=(select key_param_id from key_health_reportable_parameter_master where key_param_name='rbs') and date(c.checkup_date) between STR_TO_DATE('" . $startDate . "', '%d-%m-%Y')  AND STR_TO_DATE('" . $endDate . "', '%d-%m-%Y')  order by dat desc limit 25";

                        error_log("rbs query " . $query);
                        $result = @mysqli_query($conn, $query);
                        if (mysqli_num_rows($result) > 0) {
                            while ($row = @mysqli_fetch_array($result)) {
                                array_push($medical_date, $row[1]);
                                $blood_sugar_rbs['rbs'][$row[1]] = $row[0];
                            }
                        }

                        $query = "SELECT blood_sugar_fbs as fbs, date(appointment_date) as dat FROM employee_appointment where emp_id='$id'and blood_sugar_fbs != '' and date(appointment_date) between STR_TO_DATE('" . $startDate . "', '%d-%m-%Y')  AND STR_TO_DATE('" . $endDate . "', '%d-%m-%Y') UNION
                    SELECT cf.checkup_form_value as fbs ,date(c.checkup_date) as dat from checkup_form c left join checkup_form_key_value cf on c.checkup_id=cf.checkup_form_id left join checkup_parameter cp on cp.`column_name` = cf.checkup_form_key where c.emp_id='$id' and cp.key_health_map_name=(select key_param_id from key_health_reportable_parameter_master where key_param_name='fbs') and date(c.checkup_date) between STR_TO_DATE('" . $startDate . "', '%d-%m-%Y')  AND STR_TO_DATE('" . $endDate . "', '%d-%m-%Y')  order by dat desc limit 25";

                        error_log("rbs query " . $query);
                        $result = @mysqli_query($conn, $query);
                        if (mysqli_num_rows($result) > 0) {
                            while ($row = @mysqli_fetch_array($result)) {
                                array_push($medical_date, $row[1]);
                                $blood_sugar_fbs['fbs'][$row[1]] = $row[0];
                            }
                        }


                        $query = "SELECT blood_sugar_ppbs as ppbs, date(appointment_date) as dat FROM employee_appointment where emp_id='$id'and blood_sugar_ppbs != '' and date(appointment_date) between STR_TO_DATE('" . $startDate . "', '%d-%m-%Y')  AND STR_TO_DATE('" . $endDate . "', '%d-%m-%Y') UNION
                    SELECT cf.checkup_form_value as ppbs ,date(c.checkup_date) as dat from checkup_form c left join checkup_form_key_value cf on c.checkup_id=cf.checkup_form_id left join checkup_parameter cp on cp.`column_name` = cf.checkup_form_key where c.emp_id='$id' and cp.key_health_map_name=(select key_param_id from key_health_reportable_parameter_master where key_param_name='ppbs') and date(c.checkup_date) between STR_TO_DATE('" . $startDate . "', '%d-%m-%Y')  AND STR_TO_DATE('" . $endDate . "', '%d-%m-%Y')  order by dat desc limit 25";

                        error_log("rbs query " . $query);
                        $result = @mysqli_query($conn, $query);
                        if (mysqli_num_rows($result) > 0) {
                            while ($row = @mysqli_fetch_array($result)) {
                                array_push($medical_date, $row[1]);
                                $blood_sugar_ppbs['ppbs'][$row[1]] = $row[0];
                            }
                        }
                        $medical_date = array_values(array_unique($medical_date));
                        error_log("sugar chart date array " . print_r($medical_date, true));
                        for ($i = 0; $i < sizeof($medical_date); $i++) {

                            error_log("inside loop value" . $blood_sugar_rbs['rbs'][$medical_date[$i]]);
                            error_log("inside loop value" . $blood_sugar_fbs['fbs'][$medical_date[$i]]);
                            error_log("inside loop value" . $blood_sugar_ppbs['ppbs'][$medical_date[$i]]);

                            if ($blood_sugar_rbs['rbs'][$medical_date[$i]] == '') {
                                array_push($rbs_new, 0);
                            } else {
                                array_push($rbs_new, $blood_sugar_rbs['rbs'][$medical_date[$i]]);
                            }
                            if ($blood_sugar_fbs['fbs'][$medical_date[$i]] == '') {
                                array_push($fbs_new, 0);
                            } else {
                                array_push($fbs_new, $blood_sugar_fbs['fbs'][$medical_date[$i]]);
                            }
                            if ($blood_sugar_ppbs['ppbs'][$medical_date[$i]] == '') {
                                array_push($ppbs_new, 0);
                            } else {
                                array_push($ppbs_new, $blood_sugar_ppbs['ppbs'][$medical_date[$i]]);
                            }
                        }
                        ?>

                        <thead>
                            <tr>
                                <td style="font-size: 10px" width="15%"><strong>Date</strong></td>
                                <td style="font-size: 10px" width="15%"><strong>FBS</strong></td>
                                <td style="font-size: 10px" width="15%"><strong>RBS</strong></td>
                                <td style="font-size: 10px" width="15%"><strong>PPBS</strong></td>
                            </tr>
                        </thead>
                        <tbody>
                            <?php
                            for ($i = 0; $i < sizeof($medical_date); $i++) {
                                $newDate = date("d-m-Y", strtotime($medical_date[$i]));
                            ?>
                            <tr>
                                <td><?php echo $newDate; ?></td>
                                <td><?php echo $fbs_new[$i] ?></td>
                                <td><?php echo $rbs_new[$i]; ?></td>
                                <td><?php echo $ppbs_new[$i] ?></td>
                            </tr>
                            <?php
                            }  ?>
                        </tbody>

                    </table>
                </div>

            </div>
        </div>
    </div>
    <!-- Charts ends here  -->








    <!-- <div class="row">

				<div class="col-sm-6" style="padding-top: 30px">

					<div class="widget-box transparent">



						<h4 class="widget-title lighter">

							<i class="ace-icon fa fa-star orange"></i> Blood Pressure Tracker



						</h4>









						<div class="widget-body">

							<div class="widget-main no-padding">

								<div id="canvas-holder1" style="width: 100%;">

									<div class="chartjs-size-monitor">

										<div class="chartjs-size-monitor-expand">

											<div class=""></div>

										</div>

										<div class="chartjs-size-monitor-shrink">

											<div class=""></div>

										</div>

									</div>

									<canvas id="chart"

										style="display: block; width: 1013px; height: 506px;"

										width="1013" height="506" class="chartjs-render-monitor"></canvas>

									<div id="chartjs-tooltip" class="center"

										style="opacity: 0; left: 527.674px; top: 88.722px; font-family: &amp; amp; quot; Helvetica Neue&amp;amp; quot; , Helvetica , Arial, sans-serif; font-size: 12px; font-style: normal; padding: 6px;">

										<table>

											<thead>

												<tr>

													<th>April</th>

												</tr>

											</thead>

											<tbody>

												<tr>

													<td><span class="chartjs-tooltip-key"

														style="background: rgb(255, 61, 103); border-color: rgb(255, 61, 103); border-width: 2px"></span>My

														First dataset: 93</td>

												</tr>

												<tr>

													<td><span class="chartjs-tooltip-key"

														style="background: rgb(5, 155, 255); border-color: rgb(5, 155, 255); border-width: 2px"></span>My

														Second dataset: 2</td>

												</tr>

											</tbody>

										</table>

									</div>

								</div> -->







    <!-- </div> -->
    <!-- /.widget-main -->
    <!-- </div> -->
    <!-- /.widget-body -->
    <!-- </div> -->
    <!-- /.widget-box -->
    <!-- </div> -->



    <!-- <div class="col-sm-6" style="padding-top: 30px">

					<div class="widget-box transparent">



						<h4 class="widget-title lighter">

							<i class="ace-icon fa fa-star orange"></i> Patient Weight

							Tracker



						</h4>









						<div class="widget-body">

							<div class="widget-main no-padding">

								<div id="canvas-holder2" style="width: 100%;">

									<div class="chartjs-size-monitor">

										<div class="chartjs-size-monitor-expand">

											<div class=""></div>

										</div>

										<div class="chartjs-size-monitor-shrink">

											<div class=""></div>

										</div>

									</div>

									<canvas id="chart1"

										style="display: block; width: 1013px; height: 506px;"

										width="1013" height="506" class="chartjs-render-monitor"></canvas>







								</div> -->

    <!-- /.widget-main -->

    <!-- </div> -->

    <!-- /.widget-body -->

    <!-- </div> -->

    <!-- /.widget-box -->

    <!-- </div> -->

    <!-- </div> -->







    <!-- PAGE CONTENT ENDS -->

    <!-- </div> -->

    <div class="row">

        <div class="col-sm-6" style="padding-top: 30px">

            <div class="widget-box transparent">



                <!-- <h4 class="widget-title lighter">

							<i class="ace-icon fa fa-star orange"></i> Health Index Tracker



						</h4> -->


                <div class="widget-body">

                    <div class="widget-main no-padding">

                        <div id="canvas-holder3" style="width: 100%;">

                            <div class="chartjs-size-monitor">

                                <div class="chartjs-size-monitor-expand">
                                    <div class=""></div>
                                </div>

                                <div class="chartjs-size-monitor-shrink">
                                    <div class=""></div>
                                </div>

                            </div>

                            <canvas id="chart3" style="display: block; width: 0px; height: 0px;" width="0" height="0"
                                class="chartjs-render-monitor"></canvas>
                            <!--width: 1013px; height: 506px -->
                        </div>

                        <!-- /.widget-main -->

                    </div>

                    <!-- /.widget-body -->

                </div>

                <!-- /.widget-box -->

            </div>









            <!-- PAGE CONTENT ENDS -->

        </div>

        <!-- /.col -->



        <!-- <div class="col-sm-6" style="padding-top: 30px">

					<div class="widget-box transparent">



						<h4 class="widget-title lighter">

							<i class="ace-icon fa fa-star orange"></i> Patient Hygiene Parameter

							Tracker



						</h4> -->









        <!-- <div class="widget-body">

							<div class="widget-main no-padding"> -->

        <!-- <div id="canvas-holder4" style="width: 100%;">

									<div class="chartjs-size-monitor">

										<div class="chartjs-size-monitor-expand">

											<div class=""></div>

										</div>

										<div class="chartjs-size-monitor-shrink">

											<div class=""></div>

										</div>

									</div>

									<canvas id="chart4"

										style="display: block; width: 1013px; height: 506px;"

										width="1013" height="506" class="chartjs-render-monitor"></canvas>







								</div> -->

        <!-- /.widget-main -->

        <!-- </div> -->

        <!-- /.widget-body -->

        <!-- </div> -->

        <!-- /.widget-box -->

        <!-- </div> -->









        <!-- PAGE CONTENT ENDS -->

        <!-- </div> -->

    </div>

</div>

</div>
<form name="f1" method="post" id="flex_opd_id_medical" action="">
    <div id="flex1" style="width: 100%"></div>
    <input type="hidden" name="flex_opd_id" id="flex_opd_id" />
</form>

<form name="f2" method="post" id="employee_form" action="">
    <div id="flex1" style="width: 100%"></div>
    <input type="hidden" name="flex_patient_id" id="flex_patient_id" />
</form>

<script async="" src="./js/analytics.js"></script>

<script src="./js/Chart.min.js"></script>

<script src="./js/utils.js"></script>

<script>
function open_dashboard(emp_id) {
    // alert(emp_id);
    if (emp_id != null && emp_id != '') {
        $("#flex_opd_id").val(emp_id);
        $("#flex_opd_id_medical").attr('target', '_blank');
        $("#flex_opd_id_medical").attr('method', 'POST');
        $("#flex_opd_id_medical").attr('action', 'emp_dashboard.php');
        $("#flex_opd_id_medical").submit();

    }
}

function add_opd(patientId, task) {
    // alert(patientId + "  "+ task);
    if (task != null && task != '') {
        if ((task == 'opd' || task == 'visitor_opd') && patientId != null && patientId != '') {
            $("#flex_patient_id").val(patientId);
            $("#employee_form").attr('method', 'POST');
            $("#employee_form").attr('action', 'opd_form.php');
            $("#employee_form").submit();
        }
    }
}

var emp_id = "<?php echo $id ?>"



//alert(emp_id);

var health_index_array = [];

var health_index_labels = [];

var hyg_param_values = [];

var hyg_param_labels = [];



var myData = [];

var mylabels = [];

var myDbp = [];

var heartRate = [];



$.ajax({

    type: 'get',

    url: 'select_employee_sbp.php',

    data: {
        'emp_id': emp_id
    },

    dataType: 'json',

    async: false,

    success: function(data) {

        for (var i = 0; i < data.length; i++) {

            myData.push(data[i].checkup_form_value);

            mylabels.push(data[i].checkup_date);

            //myDbp.push(data[i].dbp);

            //heartRate.push(data[i].heart_rate);

        }

    },

    error: function(data) {



    }

});

$.ajax({

    type: 'get',

    url: 'select_employee_dbp.php',

    data: {
        'emp_id': emp_id
    },

    dataType: 'json',

    async: false,

    success: function(data) {

        for (var i = 0; i < data.length; i++) {

            myDbp.push(data[i].checkup_form_value);



            //myDbp.push(data[i].dbp);

            //heartRate.push(data[i].heart_rate);

        }

    },

    error: function(data) {



    }

});

$.ajax({

    type: 'get',

    url: 'select_employee_pulse.php',

    data: {
        'emp_id': emp_id
    },

    dataType: 'json',

    async: false,

    success: function(data) {

        for (var i = 0; i < data.length; i++) {





            //myDbp.push(data[i].dbp);

            heartRate.push(data[i].checkup_form_value);

        }

    },

    error: function(data) {



    }

});





$(document).ready(function() {





    $.ajax({

        type: 'POST',

        url: 'select_employee_health_index.php',

        data: {
            'emp_id': emp_id
        },

        dataType: 'json',

        async: false,

        success: function(data) {

            if (data != null) {



                for (var i = 0; i < data.length; i++) {

                    health_index_array[i] = data[i].health_score;

                    health_index_labels[i] = data[i].checkup_date;

                }

            }

        },

        error: function(data) {



        }

    });

    var barChartData = {

        labels: health_index_labels,

        datasets: [{

            label: 'Health Index',

            backgroundColor: color(window.chartColors.red).alpha(0.5).rgbString(),

            borderColor: window.chartColors.red,

            borderWidth: 1,

            data: health_index_array

        }]



    };

    var ctx1 = document.getElementById('chart3');

    var chart = new Chart(ctx1, {

        type: 'bar',

        data: barChartData,

        options: {

            responsive: true,

            legend: {

                position: 'bottom',

            },

            title: {

                display: true,

                text: 'Health Index History'

            }

        }

    });





});



var color = Chart.helpers.color;

//var MONTHS = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];





















$.ajax({

    type: 'get',

    url: 'select_employee_hygiene_parameter.php',

    data: {
        'emp_id': emp_id
    },

    dataType: 'json',

    async: false,

    success: function(data) {

        for (var i = 0; i < data.length; i++) {





            //myDbp.push(data[i].dbp);

            hyg_param_values.push(data[i].hyg_parameter_val);

            hyg_param_labels.push(data[i].checkup_date);



        }

    },

    error: function(data) {



    }

});



var data = {

    labels: hyg_param_labels,

    datasets: [

        {

            label: "Indium",

            data: hyg_param_values,

            backgroundColor: "blue",

            borderColor: "lightblue",

            fill: false,

            lineTension: 0,

            radius: 5

        },



    ]

};

var ctx = $("#chart4");



var chart = new Chart(ctx, {

    type: "line",

    data: data,

    options: {

        title: {

            display: true,

            text: 'Indium (Hygiene Parameter) In Employee'

        },

        tooltips: {

            callbacks: {

                label: function(tooltipItems, data) {

                    return data.datasets[tooltipItems.datasetIndex].label + ':' + tooltipItems.yLabel +
                        ' mg/m3';

                }

            },

            enabled: true,

            mode: 'index',

            position: 'nearest',

            custom: customTooltips

        },

        legend: {

            display: true,

            position: 'bottom',

        },

        scales: {

            yAxes: [{

                ticks: {

                    // Include a dollar sign in the ticks

                    callback: function(value, index, values) {

                        return value + ' mg/m3';

                    }

                }

            }]

        }

    }

});







var emp_weight_array = [];

var emp_weight_labels = [];



$.ajax({

    type: 'POST',

    url: 'select_employee_weight.php',

    data: {
        'emp_id': emp_id
    },

    dataType: 'json',

    async: false,

    success: function(data) {

        for (var i = 0; i < data.length; i++) {

            emp_weight_array[i] = data[i].checkup_form_value;

            emp_weight_labels[i] = data[i].checkup_date;

        }

    },

    error: function(data) {



    }

});







var data = {

    labels: emp_weight_labels,

    datasets: [

        {

            label: "Weight",

            data: emp_weight_array,

            backgroundColor: "blue",

            borderColor: "lightblue",

            fill: false,

            lineTension: 0,

            radius: 5

        },



    ]

};

var ctx = $("#chart1");



var chart = new Chart(ctx, {

    type: "line",

    data: data,

    options: {

        title: {

            display: true,

            text: 'Weight History'

        },

        tooltips: {

            callbacks: {

                label: function(tooltipItems, data) {

                    return data.datasets[tooltipItems.datasetIndex].label + ':' + tooltipItems.yLabel +
                        ' Kgs';

                }

            },

            enabled: true,

            mode: 'index',

            position: 'nearest',

            custom: customTooltips

        },

        legend: {

            display: true,

            position: 'bottom',

        },

        scales: {

            yAxes: [{

                ticks: {

                    // Include a dollar sign in the ticks

                    callback: function(value, index, values) {

                        return value + ' Kgs';

                    }

                }

            }]

        }

    }

});



var ctx = $("#chartWeight");



var chart = new Chart(ctx, {

    type: "line",

    data: data,

    options: {

        title: {

            display: true,

            text: 'Weight History'

        },

        tooltips: {

            callbacks: {

                label: function(tooltipItems, data) {

                    return data.datasets[tooltipItems.datasetIndex].label + ':' + tooltipItems.yLabel +
                        ' Kgs';

                }

            },

            enabled: true,

            mode: 'index',

            position: 'nearest',

            custom: customTooltips

        },

        legend: {

            display: true,

            position: 'bottom',

        },

        scales: {

            yAxes: [{

                ticks: {

                    // Include a dollar sign in the ticks

                    callback: function(value, index, values) {

                        return value + ' Kgs';

                    }

                }

            }]

        }

    }

});



var rightVision = [];

var empRightVisionLabels = [];

$.ajax({

    type: 'POST',

    url: 'select_employee_vision.php',

    data: {
        'emp_id': emp_id
    },

    dataType: 'json',

    async: false,

    success: function(data) {

        for (var i = 0; i < data.length; i++) {

            rightVision[i] = data[i].checkup_form_value;

            empRightVisionLabels[i] = data[i].checkup_date;

        }

    },

    error: function(data) {



    }

});







var dataVision = {

    labels: empRightVisionLabels,

    datasets: [

        {

            label: "Right Vision",

            data: rightVision,

            backgroundColor: "blue",

            borderColor: "lightblue",

            fill: false,

            lineTension: 0,

            radius: 5

        },



    ]

};



var ctxVision = document.getElementById('chartVision');

var chart = new Chart(ctxVision, {

    type: 'line',

    data: dataVision,

    options: {

        responsive: true,

        legend: {

            position: 'bottom',

        },

        title: {

            display: true,

            text: 'Right Vision History'

        }

    }

});



Chart.defaults.global.pointHitDetectionRadius = 1;



var customTooltips = function(tooltip) {

    // Tooltip Element

    var tooltipEl = document.getElementById('chartjs-tooltip');



    if (!tooltipEl) {

        tooltipEl = document.createElement('div');

        tooltipEl.id = 'chartjs-tooltip';

        tooltipEl.innerHTML = '<table></table>';

        this._chart.canvas.parentNode.appendChild(tooltipEl);

    }



    // Hide if no tooltip

    if (tooltip.opacity === 0) {

        tooltipEl.style.opacity = 0;

        return;

    }



    // Set caret Position

    tooltipEl.classList.remove('above', 'below', 'no-transform');

    if (tooltip.yAlign) {

        tooltipEl.classList.add(tooltip.yAlign);

    } else {

        tooltipEl.classList.add('no-transform');

    }



    function getBody(bodyItem) {

        return bodyItem.lines;

    }



    // Set Text

    if (tooltip.body) {

        var titleLines = tooltip.title || [];

        var bodyLines = tooltip.body.map(getBody);



        var innerHtml = '<thead>';



        titleLines.forEach(function(title) {

            innerHtml += '<tr><th>' + title + '</th></tr>';

        });

        innerHtml += '</thead><tbody>';



        bodyLines.forEach(function(body, i) {

            var colors = tooltip.labelColors[i];

            var style = 'background:' + colors.backgroundColor;

            style += '; border-color:' + colors.borderColor;

            style += '; border-width: 2px';

            var span = '<span class="chartjs-tooltip-key" style="' + style + '"></span>';

            innerHtml += '<tr><td>' + span + body + '</td></tr>';

        });

        innerHtml += '</tbody>';



        var tableRoot = tooltipEl.querySelector('table');

        tableRoot.innerHTML = innerHtml;

    }



    var positionY = this._chart.canvas.offsetTop;

    var positionX = this._chart.canvas.offsetLeft;



    // Display, position, and set styles for font

    tooltipEl.style.opacity = 1;

    tooltipEl.style.left = positionX + tooltip.caretX + 'px';

    tooltipEl.style.top = positionY + tooltip.caretY + 'px';

    tooltipEl.style.fontFamily = tooltip._bodyFontFamily;

    tooltipEl.style.fontSize = tooltip.bodyFontSize + 'px';

    tooltipEl.style.fontStyle = tooltip._bodyFontStyle;

    tooltipEl.style.padding = tooltip.yPadding + 'px ' + tooltip.xPadding + 'px';

};











var lineChartData = {

    labels: mylabels,

    datasets: [{

            label: 'Blood Pressure(SBP)',

            data: myData,

            borderColor: window.chartColors.blue,

            pointBackgroundColor: window.chartColors.blue,

            fill: false,



        }, {

            label: 'Blood Pressure(DBP)',

            data: myDbp,

            borderColor: window.chartColors.green,

            pointBackgroundColor: window.chartColors.green,

            fill: false,



        }, {

            label: 'Heart Rate',

            data: heartRate,

            borderColor: window.chartColors.red,

            pointBackgroundColor: window.chartColors.red,

            fill: false,



        }



    ]

};



//window.onload = function() {

var chartEl = document.getElementById('chart');

window.myLine = new Chart(chartEl, {

    type: 'line',

    data: lineChartData,

    options: {

        title: {

            display: true,

            text: 'Blood Pressure History'

        },

        tooltips: {

            enabled: false,

            mode: 'index',

            position: 'nearest',

            custom: customTooltips

        },

        legend: {

            display: true,

            position: 'bottom',

        },



    }

});

var chartEl = document.getElementById('chartBP');

window.myLine = new Chart(chartEl, {

    type: 'line',

    data: lineChartData,

    options: {

        title: {

            display: true,

            text: 'Blood Pressure History'

        },

        tooltips: {

            enabled: false,

            mode: 'index',

            position: 'nearest',

            custom: customTooltips

        },

        legend: {

            display: true,

            position: 'bottom',

        },



    }

});


$(document).ready(function() {

    $("#opd_visit").click(function() {

        $("#opd_visit_list").toggle();

    });

});

$(document).ready(function() {

    $("#injury").click(function() {

        $("#injury_list").toggle();

    });

});

$(document).ready(function() {

    $("#emergency").click(function() {

        $("#emergency_list").toggle();

    });

});

$(document).ready(function() {

    $("#examination").click(function() {

        $("#examination_list").toggle();

    });

});

$(document).ready(function() {

    $("#health_risk").click(function() {

        $("#health_risk_list").toggle();

    });

});

$(document).ready(function() {

    $("#sickness").click(function() {

        $("#sickness_list").toggle();

    });

});

$(document).ready(function() {

    $("#health_advice").click(function() {

        $("#health_advice_list").toggle();

    });

});

$(document).ready(function() {

    $("#training").click(function() {

        $("#training_list").toggle();

    });

});

window.onload = getShowingDa();

function getShowingData() {
    var start = $("#startDate").val();
    var end = $("#endDate").val();
    var id = <?php echo $id ?>;
    var date = [];
    var BMI = [];
    var weight = [];
    var height = [];
    var sbp = [];
    var dbp = [];
    var ppbs = [];
    var fbs = [];
    var rbs = [];

    function formatDateBMI(input) {
        var datePart = input.match(/\d+/g),
            year = datePart[2],
            month = datePart[1],
            day = datePart[0];
        return month;
    }

    function toMonthName(monthNumber) {
        const date = new Date();
        date.setMonth(monthNumber - 1);

        return date.toLocaleString('en-US', {
            month: 'long',
        });
    }
    var start_Month = formatDateBMI(start);
    var end_Month = formatDateBMI(end);



    var months = [];
    var sickness = [];
    var opd = [];
    var injury = [];
    // var monthOSI = [];


    $.ajax({
        url: 'filter_report_deshboard.php',
        data: {
            startDate: start,
            endDate: end,
            id: id,
            start_Month: start_Month,
            end_Month: end_Month
        },
        type: 'POST',
        dataType: 'json',
        success: function(data) {
            // alert(data);

            date = data['date'][0];
            BMI = data['bmi'][0];
            weight = data['weight'][0];
            height = data['height'][0];
            sbp = data['bp_sbp'][0];
            dbp = data['bp_dbp'][0];
            ppbs = data['blood_sugar_ppbs'][0];
            fbs = data['blood_sugar_fbs'][0];
            rbs = data['blood_sugar_rbs'][0];
            months = data['months'][0];
            sickness = data['sickness'];
            opd = data['opd'][0];
            injury = data['injury'];
            //      monthOSI = data['monthOSI'][0];
            //console.log(data['injury']);

            // BMI table
            var content = "";
            content += "<thead><tr>" +
                "<td>DATE</strong></td><td>HEIGHT</strong></td><td>WEIGHT</strong></td><td>BMI</strong></td>"

            content += "</thead>";
            for (var l = 0; l < date.length; l++) {
                content += "<tr><td>" + date[l].split("-").reverse().join("-") + "</td><td>" + height[l] +
                    "</td><td>" + weight[l] +
                    "</td><td>" + BMI[l] + "</td>";
                content += "</tr>";
            }
            $("#bmi_table").html(content);

            // OSI table
            var content1 = "";
            content1 += "<thead><tr>" +
                "<td>Month</strong></td><td>OPD Visits</strong></td><td>Injure Visit</strong></td><td>Sickness Visits</strong></td>"

            content1 += "</thead>";
            for (var l = 0; l < months.length; l++) {
                // alert(toMonthName(months[l]));
                content1 += "<tr><td>" + toMonthName(months[l]) + "</td><td>" + opd[l] + "</td><td>" +
                    injury[l] +
                    "</td><td>" + sickness[l] + "</td>";
                content1 += "</tr>";
            }
            $("#osi_table").html(content1);

            // BP table
            var content2 = "";
            content2 += "<thead><tr>" +
                "<td>DATE</strong></td><td>SBP</strong></td><td>DBP</strong></td>"
            // consol.log(date);
            content2 += "</thead>";
            for (var l = 0; l < date.length; l++) {
                content2 += "<tr><td>" + date[l].split("-").reverse().join("-") + "</td><td>" + sbp[l] +
                    "</td><td>" + dbp[l] + "</td>";
                content2 += "</tr>";
            }
            $("#bp_table").html(content2);

            var content = "";
            content += "<thead><tr>" +
                "<td>DATE</strong></td><td>FBS</strong></td><td>RBS</strong></td><td>PPBS</strong></td>"
            // consol.log(date);
            content += "</thead>";
            for (var l = 0; l < date.length; l++) {
                content += "<tr><td>" + date[l].split("-").reverse().join("-") + "</td><td>" + fbs[l] +
                    "</td><td>" + rbs[l] +
                    "</td><td>" + ppbs[l] + "</td>";
                content += "</tr>";
            }
            $("#suger_table").html(content);



            var ctx_bmi = document.getElementById('patient_bmi').getContext('2d');
            var ctx_osi = document.getElementById('patient_osi').getContext('2d');
            var ctx_bp = document.getElementById('patient_bp').getContext('2d');
            var ctx_bs = document.getElementById('patient_bs').getContext('2d');

            //  BMI Graph
            function formatDateBMI(input) {
                var datePart = input.match(/\d+/g),
                    year = datePart[0],
                    month = datePart[1],
                    day = datePart[2];
                return day + '-' + month + '-' + year;
            }
            var xaxis = [];
            for (let i = 0; i < date.length; i++) {
                xaxis[i] = formatDateBMI(date[i]);
            }
            var myChart_bmi = new Chart(ctx_bmi, {
                type: 'line',
                options: {
                    title: {
                        display: true,
                        text: "BMI Graph"
                    },
                    legend: {
                        position: "bottom"
                    },
                    scales: {
                        yAxes: [{
                            ticks: {
                                precision: 0
                            }
                        }]
                    }
                },
                data: {
                    labels: xaxis,
                    datasets: [{
                        data: BMI,
                        label: "BMI",
                        borderColor: "#d45087",
                        backgroundColor: "#d45087",
                        fill: false,
                        pointBackgroundColor: function(context) {
                            var index = context.dataIndex;
                            var value = context.dataset.data[index];
                            return value < 85 ? 'red' : // draw negative values in red
                                index % 2 ? 'blue' :
                                // else, alternate values in blue and green
                                'green';
                        }

                    }, {
                        data: weight,
                        label: "weight",
                        borderColor: "#ff7c43",
                        backgroundColor: "#ffa500",
                        fill: false,
                        pointBackgroundColor: function(context) {
                            var index = context.dataIndex;
                            var value = context.dataset.data[index];
                            return value < 124 ? 'red' : // draw negative values in red
                                index % 2 ? 'blue' :
                                // else, alternate values in blue and green
                                'green';
                        }

                    }, {
                        data: height,
                        label: "height",
                        borderColor: "#3e95cd",
                        backgroundColor: "#7bb6dd",
                        fill: false,
                        pointBackgroundColor: function(context) {
                            var index = context.dataIndex;
                            var value = context.dataset.data[index];
                            return value < 124 ? 'red' : // draw negative values in red
                                index % 2 ? 'blue' :
                                // else, alternate values in blue and green
                                'green';
                        }

                    }]
                },
            });
            //  OSI Graph
            var axis = [];
            for (var i = 0; i < months.length; i++) {
                axis[i] = 'Month:' + months[i];
            }
            var myChart_osi = new Chart(ctx_osi, {
                type: 'line',
                options: {
                    title: {
                        display: true,
                        text: "OSI Graph"
                    },
                    legend: {
                        position: "bottom"
                    },
                    scales: {
                        yAxes: [{
                            ticks: {
                                precision: 0
                            }
                        }]
                    }
                },
                data: {
                    labels: axis,
                    datasets: [{
                        data: opd,
                        label: "OPD",
                        borderColor: "#d45087",
                        backgroundColor: "#d45087",
                        fill: false,
                        pointBackgroundColor: function(context) {
                            var index = context.dataIndex;
                            var value = context.dataset.data[index];
                            return value < 85 ? 'red' : // draw negative values in red
                                index % 2 ? 'blue' :
                                // else, alternate values in blue and green
                                'green';
                        }

                    }, {
                        data: injury,
                        label: "Injury",
                        borderColor: "#ff7c43",
                        backgroundColor: "#ffa500",
                        fill: false,
                        pointBackgroundColor: function(context) {
                            var index = context.dataIndex;
                            var value = context.dataset.data[index];
                            return value < 124 ? 'red' : // draw negative values in red
                                index % 2 ? 'blue' :
                                // else, alternate values in blue and green
                                'green';
                        }

                    }, {
                        data: sickness,
                        label: "Sickness",
                        borderColor: "#3e95cd",
                        backgroundColor: "#7bb6dd",
                        fill: false,
                        pointBackgroundColor: function(context) {
                            var index = context.dataIndex;
                            var value = context.dataset.data[index];
                            return value < 124 ? 'red' : // draw negative values in red
                                index % 2 ? 'blue' :
                                // else, alternate values in blue and green
                                'green';
                        }

                    }]
                },
            });
            //----------  bp chart--------------//

            var myChart_bp = new Chart(ctx_bp, {
                type: 'line',
                options: {
                    title: {
                        display: true,
                        text: "BP Graph"
                    },
                    legend: {
                        position: "bottom"
                    },
                    scales: {
                        yAxes: [{
                            ticks: {
                                precision: 0
                            }
                        }]
                    }
                },
                data: {
                    labels: xaxis,
                    datasets: [{
                        data: dbp,
                        label: "DBP",
                        borderColor: "#d45087",
                        backgroundColor: "#d45087",
                        fill: false,
                        pointBackgroundColor: function(context) {
                            var index = context.dataIndex;
                            var value = context.dataset.data[index];
                            return value < 85 ? 'red' : // draw negative values in red
                                index % 2 ? 'blue' :
                                // else, alternate values in blue and green
                                'green';
                        }

                    }, {
                        data: sbp,
                        label: "SBP",
                        borderColor: "#ff7c43",
                        backgroundColor: "#ffa500",
                        fill: false,
                        pointBackgroundColor: function(context) {
                            var index = context.dataIndex;
                            var value = context.dataset.data[index];
                            return value < 124 ? 'red' : // draw negative values in red
                                index % 2 ? 'blue' :
                                // else, alternate values in blue and green
                                'green';
                        }

                    }]
                },
            });
            //--------------- bs chart-------------//
            var myChart_bs = new Chart(ctx_bs, {
                type: 'line',
                options: {
                    title: {
                        display: true,
                        text: "BS Graph"
                    },
                    legend: {
                        position: "bottom"
                    },
                    scales: {
                        yAxes: [{
                            ticks: {
                                precision: 0
                            }
                        }]
                    }
                },
                data: {
                    labels: xaxis,
                    datasets: [{
                        data: ppbs,
                        label: "PPBS",
                        borderColor: "#3e95cd",
                        backgroundColor: "#7bb6dd",
                        fill: false,
                        pointBackgroundColor: function(context) {
                            var index = context.dataIndex;
                            var value = context.dataset.data[index];
                            return value < 140 ? 'red' : // draw negative values in red
                                index % 2 ? 'blue' :
                                // else, alternate values in blue and green
                                'green';
                        }

                    }, {
                        data: fbs,
                        label: "FBS",
                        borderColor: "#d45087",
                        backgroundColor: "#d45087",
                        fill: false,
                        pointBackgroundColor: function(context) {
                            var index = context.dataIndex;
                            var value = context.dataset.data[index];
                            return value < 124 ? 'red' : // draw negative values in red
                                index % 2 ? 'blue' :
                                // else, alternate values in blue and green
                                'green';
                        }

                    }, {
                        data: rbs,
                        label: "RBS",
                        borderColor: "#ff7c43",
                        backgroundColor: "#ffa500",
                        fill: false,
                        pointBackgroundColor: function(context) {
                            var index = context.dataIndex;
                            var value = context.dataset.data[index];
                            return value < 124 ? 'red' : // draw negative values in red
                                index % 2 ? 'blue' :
                                // else, alternate values in blue and green
                                'green';
                        }

                    }]
                },

            });

        },

        error: function(data) {
            BootstrapDialog.alert('Error Populating Reports Details');
            return;
        }
    });



}
</script>



<style>
.btn.btn-app.btn-sm {

    width: 110px
}



.btn-xl {

    width: 120px !important;

    height: 100px;

}



.btn-xxl {

    width: 170px !important;

    height: 100px;

}



.label-xs {

    font-size: 10px !important;

}



.label-xs-header {

    font-size: 10px !important;

    text-align: left;

    margin-left: 0px;

    padding-left: 0px;

    font-weight: bold;

}



.profile-info-name {

    font-size: 10px !important;

    text-align: left;

    width: 35%;

}



.profile-info-value {

    font-size: 10px !important;

    text-align: left;

    width: 65%;

}



.widget-title {

    font-size: 12px;

}
</style>