ESH/chronic_medication_medicine_report_excel.php
2024-10-23 18:28:06 +05:30

350 lines
16 KiB
PHP

<?php //include('pdf_header_reverse.php');
include('includes/config/config.php');
include('includes/functions.php');
//include('pop_up_top.php');
header("Content-type:application/octet-stream");
header("Content-type: application/x-msdownload");
header("Content-Disposition: attachment; filename=chronic_medication_medicine_report.xls");
header("Pragma: no-cache");
header("Expires: 0");
$detention_cat = $_REQUEST['detention_cat'];
$detention_sub_cat = $_REQUEST['detention_sub_cat'];
$only_referral = $_REQUEST['only_referral'];
$chronic_illness = $_REQUEST['chronic_illness'];
$is_depend = '';
$cat = '';
$referral = '';
if ($only_referral == 'Y') {
$referral = " and referral!='' ";
}
if ($detention_sub_cat == 'dep') {
$is_depend = "and primary_patient_id!=0";
}
$case_type = $_REQUEST['case_type'];
if ($case_type != 'ALL') {
$is_case = " and case_type='" . $case_type . "'";
}
error_log("detention_cat" . $detention_cat);
if ($detention_cat == '' || $detention_cat == null || $detention_cat == '7') {
$cat = "";
} else {
$cat = " and patient_cat_id='$detention_cat'";
}
$from_date1 = date('Y-m-d', strtotime($_POST['opdDate1']));
$from_date = date('d-m-Y', strtotime($from_date1));
$from_date2 = date('Y-m-d', strtotime($_POST['opdDate2']));
$to_date = date('d-m-Y', strtotime($from_date2));
?>
<link href="includes/css-js/admin.css" rel="stylesheet" type="text/css" />
<style>
@page {
margin: 15px;
}
.btn {
background-color: #4CAF50;
border-radius: 5%;
/* Green */
border: none;
color: white;
padding: 5px 8px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 12px;
margin: 4px 2px;
cursor: pointer;
}
@media print {
#printPageButton {
display: none;
}
}
</style>
<body>
<?php include('excel_ohc_header.php'); ?>
<table width="100%">
<tr>
<td style="font-size: 15px;"><strong style="margin-left: 400px">Chronic Medication Medicine Report
<?php if ($only_referral == 'Y') {
echo "(Referral)";
} ?> </strong></td>
</tr>
<tr>
<td align="left" style="font-size: 12px"><strong>From Date:
<? echo date("d-M-Y", strtotime($from_date)); ?>&nbsp;&nbsp;&nbsp;To Date:
<? echo date("d-M-Y", strtotime($to_date)); ?>
</strong></td>
<td align="right" style="font-size: 15px"><button align="center" id="printPageButton" class="btn btn-success" onClick="window.print();">Print</button></td>
</tr>
</table>
<br>
<table border="1" width="100%" cellspacing="0">
<?php
if ($chronic_illness == 'ALL') {
$sqll = "SELECT count(*) as total FROM employee_appointment a JOIN patient_master b on a.emp_id=b.id WHERE a.ohc_type_id='" . $_SESSION['current_ohcttype'] . "' and a.abnormalitys!='' and date_format(date(a.appointment_date),'%d-%m-%y') BETWEEN '$from_date1' and '$from_date2'" . $cat . $is_depend . $referral . $is_case . " ";
} else {
$sqll = "SELECT count(*) as total FROM employee_appointment a JOIN patient_master b on a.emp_id=b.id WHERE a.ohc_type_id='" . $_SESSION['current_ohcttype'] . "' and a.abnormalitys!='' and a.abnormalitys='$chronic_illness' and date_format(date(a.appointment_date),'%d-%m-%y') BETWEEN '$from_date1' and '$from_date2'" . $cat . $is_depend . $referral . $is_case . " ";
}
$result_sqll = mysqli_query($conn, $sqll);
$num_rows = mysqli_num_rows($result_sqll);
$row0 = mysqli_fetch_assoc($result_sqll);
error_log("total:" . $sqll);
if ($chronic_illness == 'ALL') {
$sql = "SELECT DATE_FORMAT(a.appointment_date, '%d-%m-%y') as date,a.*,b.* FROM employee_appointment a JOIN patient_master b on a.emp_id=b.id WHERE a.abnormalitys!='' and a.ohc_type_id='" . $_SESSION['current_ohcttype'] . "'" . $cat . $is_depend . $referral . $is_case . " order by a.appointment_date ASC";
} else {
$sql = "SELECT DATE_FORMAT(a.appointment_date, '%d-%m-%y') as date,a.*,b.* FROM employee_appointment a JOIN patient_master b on a.emp_id=b.id WHERE a.abnormalitys!='' and a.abnormalitys LIKE '%,$chronic_illness,%' or a.abnormalitys LIKE '%$chronic_illness,%' or a.abnormalitys LIKE '%,$chronic_illness%' or a.abnormalitys LIKE '%$chronic_illness%' and a.ohc_type_id='" . $_SESSION['current_ohcttype'] . "'" . $cat . $is_depend . $referral . $is_case . " order by a.appointment_date ASC";
}
error_log($sql . "get sql");
$result = mysqli_query($conn, $sql);
?>
<strong>
<tr bgcolor="#eeeeee">
<td>Sr.</td>
<td align="left" width="3%">Date</td>
<td align="left" width="3%">Time In</td>
<td align="left" width="3%">Time Out</td>
<td align="left" width="2%">Duration</td>
<td valign="top" align="left" width="3%">Emp. No.</td>
<td valign="top" align="left" width="8%">Name</td>
<td valign="top" align="left" width="2%">Age</td>
<td valign="top" align="left" width="2%">Sex</td>
<td valign="top" align="left" width="5%">Mobile No.</td>
<td valign="top" align="left" width="3%">Employer</td>
<td valign="top" align="left" width="5%">Designation</td>
<td valign="top" align="left" width="3%">Division</td>
<td valign="top" align="left" width="3%">Department</td>
<td valign="top" align="left" width="3%">Section</td>
<!-- <td valign="top" align="left" width="3%">Complaint</td> -->
<td valign="top" align="left" width="3%">Chronic Illness</td>
<td valign="top" align="left" width="3%">Diagnosis</td>
<td valign="top" align="left" width="5%">Treatment</td>
<?php if ($only_referral == 'Y') { ?>
<td valign="top" align="left" width="3%">Referred By</td>
<?php } ?>
<?php if ($only_referral == 'Y') { ?>
<td class="referral" valign="top" align="left" width="5%">Referral</td>
<?php } ?>
</tr>
<?php
$count = 1;
while ($row1 = mysqli_fetch_assoc($result)) {
extract($row1);
if (date("Y-m-d", strtotime($row1['appointment_date'])) >= $from_date1 && date("Y-m-d", strtotime($row1['appointment_date'])) <= $from_date2 && $row1['chronic_day']!='' && $row1['chronic_day']!='0') {
} else {
continue;
}
// error_log($row1['employer_contractor_id']);
?>
<tr>
<td><?php echo $count ?></td>
<td><?php echo $row1['date'] ?></td>
<td><?php echo date("d/M/Y H:i ", strtotime($row1['appointment_date'])) ?></td>
<td><?php if ($row1['clearance_time'] != null && $row1['clearance_time'] != '' && $row1['clearance_time'] != "00-00-00 00:00:00")
echo date("d/M/Y H:i ", strtotime($row1['clearance_time'])) ?></td>
<td><?php
if ($row1['clearance_time'] != null && $row1['clearance_time'] != '' && $row1['clearance_time'] != "00-00-00 00:00:00") {
$from = strtotime($row1['appointment_date']);
$to = strtotime($row1['clearance_time']);
$diff = abs($to - $from);
// To get the year divide the resultant date into
// total seconds in a year (365*60*60*24)
$years = floor($diff / (365 * 60 * 60 * 24));
// To get the month, subtract it with years and
// divide the resultant date into
// total seconds in a month (30*60*60*24)
$months = floor(($diff - $years * 365 * 60 * 60 * 24)
/ (30 * 60 * 60 * 24));
// To get the day, subtract it with years and
// months and divide the resultant date into
// total seconds in a days (60*60*24)
$days = floor(($diff - $years * 365 * 60 * 60 * 24 -
$months * 30 * 60 * 60 * 24) / (60 * 60 * 24));
// To get the hour, subtract it with years,
// months & seconds and divide the resultant
// date into total seconds in a hours (60*60)
$hours = floor(($diff - $years * 365 * 60 * 60 * 24
- $months * 30 * 60 * 60 * 24 - $days * 60 * 60 * 24)
/ (60 * 60));
// To get the minutes, subtract it with years,
// months, seconds and hours and divide the
// resultant date into total seconds i.e. 60
$minutes = floor(($diff - $years * 365 * 60 * 60 * 24
- $months * 30 * 60 * 60 * 24 - $days * 60 * 60 * 24
- $hours * 60 * 60) / 60);
// To get the minutes, subtract it with years,
// months, seconds, hours and minutes
$seconds = floor(($diff - $years * 365 * 60 * 60 * 24
- $months * 30 * 60 * 60 * 24 - $days * 60 * 60 * 24
- $hours * 60 * 60 - $minutes * 60));
error_log('year' . $months);
// Print the result
if ($years != 0 || $years != '0') printf($years . " year,",);
if ($months != 0 || $months != '0') echo ($months . " month,");
if ($days != 0 || $days != '0') echo ($days . " day,");
if ($hours != 0 || $hours != '0') echo ($hours . " hours,");
if ($minutes != 0 || $minutes != '0') echo ($minutes . " minutes,");
if ($seconds != 0 || $seconds != '0') echo ($seconds . " seconds,");
} ?>
</td>
<td><?php echo $row1['emp_code'] ?></td>
<td><?php echo $row1['patient_name'] ?></td>
<td><?php
$from = new DateTime($row1['dob']);
$to = new DateTime('today');
echo $from->diff($to)->y;
?></td>
<td><?php if ($row1['gender'] == 'M') {
echo 'Male';
} else {
echo 'Female';
} ?></td>
<td><?php echo $row1['primary_phone'] ?></td>
<td><?php echo getFieldFromTable('employer_contractor_name', 'employer_contractor', 'id', $row1['employer_contractor_id']) ?>
</td>
<td><?php echo getTableFieldValue('designation', 'designation_name', $row1['designation_id'], 'designation_id',) ?>
</td>
<td><?php echo getTableFieldValue('bussiness_unit', 'bu_name', $row1['bu_id'], 'bu_id') ?></td>
<td><?php echo getTableFieldValue('department', 'dept_name', $row1['dept_id'], 'dept_id') ?></td>
<td><?php echo getTableFieldValue('section', 'section_name', $row1['section_id'], 'section_id') ?>
</td>
<?php
$complaint_ids = $row1['complaints'];
$complaint_ids_array = array();
$complaint_ids_array = explode(",", $complaint_ids);
$complaints = "";
for ($i = 0; $i < count($complaint_ids_array); $i++) {
if ($i == 0) {
if (is_numeric($complaint_ids_array[$i])) {
$complaints = getTableFieldValue('complaints', 'complaint', 'complaint_id', $complaint_ids_array[$i]);
} else {
$complaints = $complaint_ids_array[$i];
}
} else {
if (is_numeric($complaint_ids_array[$i])) {
$complaints = $complaints . "," . getTableFieldValue('complaints', 'complaint', 'complaint_id', $complaint_ids_array[$i]);
} else {
$complaints = $complaints . "," . $complaint_ids_array[$i];
}
}
}
?>
<!-- <td><?php echo $complaints ?></td> -->
<td><?php
if ($chronic_illness == 'ALL') {
echo getCommaSeperatedValuesForInClause("select abnormality_name from abnormality", "abnormality_id", $row1['abnormalitys']);
} else {
echo getTableFieldValue('abnormality', 'abnormality_name', 'abnormality_id', $chronic_illness);
}
?></td>
<td><?php echo getCommaSeperatedValuesForInClause("select ailment_name from ailment ", "ailment_id", $row1['ailments_new']); ?></td>
<td><?php
if ($chronic_illness == 'ALL') {
echo $treatment_text = getTreatmentTextPdf($row1['appointment_id']);
} else {
$get_medicine = "SELECT medicine_name FROM prescription_master WHERE diseases='$chronic_illness' and emp_id='" . $row1['emp_id'] . "'";
$result_medi = mysqli_query($conn, $get_medicine);
error_log($get_medicine . "get medi from presc");
if ($result_medi->num_rows > 0) {
$value_medi = array();
while ($get_medi_row = mysqli_fetch_assoc($result_medi)) {
$value_medi[] = $get_medi_row['medicine_name'];
}
$commaSeparatedValues = "(" . implode(', ', $value_medi) . ")";
}
$sql_tret = "select t.item_id, item_name, for_days, dosage from treatment t, tbl_items i where t.item_id=i.item_id and t.appointment_id='" . $appointment_id . "' and is_display!='N' and t.item_id in $commaSeparatedValues";
error_log($sql_tret . "final sql");
$res_treat = @mysqli_query($GLOBALS['conn'], $sql_tret);
while ($rows_treat = @mysqli_fetch_array($res_treat)) {
extract($rows_treat);
echo getItemWithFormNamePdf($rows_treat['item_id']) . " " . $rows_treat['dosage'] . " for " . $rows_treat['for_days'] . " days" . "<br>";
}
}
?></td>
<?php if ($only_referral == 'Y') { ?>
<td><?php
$emp_id_doc = getTableFieldValue('tbl_users', 'emp_id', 'user_id', $row1['doctor_last_attended']);
echo getTableFieldValue('patient_master', 'patient_name', 'id', '"' . $emp_id_doc . '"');
?>
</td>
<?php } ?>
<?php if ($only_referral == 'Y') { ?>
<td class="referral">
<?php echo getTableFieldValue('referral_point', 'referral_point_name', 'referral_point_id', $row1['referral']) . " - " . getTableFieldValue('referral_point', 'city', 'referral_point_id', $row1['referral']) . " ( " . getTableFieldValue('referral_point', 'hospital_name', 'referral_point_id', $row1['referral']) . " ) "; ?>
</td>
<?php } ?>
</tr>
<?php
$count++;
}
?>
</table>
</body>