ohctech_p8/chronic_medication_medicine_report_excel.php
2024-10-16 19:18:52 +05:30

329 lines
14 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_id = $_REQUEST['chronic_illness'];
if(count($chronic_illness_id)!=1){
foreach (array_keys($chronic_illness_id, 'ALL') as $key) {
unset($chronic_illness_id[$key]);
}
}
// $is_depend = '';
// $cat = '';
// $referral = '';
// $case_type = $_REQUEST['case_type'];
// if ($case_type != 'ALL') {
// $is_case = " and case_type='" . $case_type . "'";
// }
// if ($only_referral == 'Y') {
// $referral = " and referral!='' ";
// }
// if ($detention_sub_cat == 'dep') {
// $is_depend = "and primary_patient_id!=0";
// }
// $is_depend = '';
// $cat = '';
// if ($detention_sub_cat == 'dep') {
// $is_depend = "and primary_patient_id!=0";
// } else if ($detention_sub_cat == 'vis') {
// $is_depend = "and primary_patient_id=0";
// }
// error_log("detention_cat" . $detention_cat);
// if ($detention_cat == '' || $detention_cat == null || $detention_cat == '7') {
// $cat = "";
// } else {
// $cat = " and patient_cat_id='$detention_cat'";
// }
$start = date('d-m-Y', strtotime($_POST['opdDate1']));
$end = date('d-m-Y', strtotime($_POST['opdDate2']));
$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;
}
table ,tr, td{
font-size:12px;
}
.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">
<strong>
<tr bgcolor="#eeeeee">
<td align="left" width="2%">Sr.</td>
<td align="left" width="4%">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%">Chronic Illness</td>
<td valign="top" align="left" width="3%">Chronic Medication Day</td>
<td valign="top" align="left" width="3%">Diagnosis</td>
<td valign="top" align="left" width="5%">Treatment</td>
<td valign="top" align="left" width="3%">Referred By</td>
</tr>
<?php
$app_ids=array();
$count=1;
$chronic_patient_arr=array();
foreach($chronic_illness_id as $key =>$chronic_illness ){
if ($chronic_illness == 'ALL') {
$query = "SELECT distinct(p.emp_id) as emp FROM `prescription_master` p left join view_patient_master v on p.emp_id=v.id where v.status='Active' and p.remission_date is null and p.medicine_name is not null and p.medicine_name!='' and p.ohc_type_id='" . $_SESSION['current_ohcttype'] . "' ";
} else {
$query = "SELECT distinct(p.emp_id) as emp FROM `prescription_master` p left join view_patient_master v on p.emp_id=v.id where v.status='Active' and p.diseases = '".$chronic_illness."' and p.remission_date is null and p.medicine_name is not null and p.medicine_name!='' and p.ohc_type_id='" . $_SESSION['current_ohcttype'] . "' ";
}
$result_query = mysqli_query($conn, $query);
while ($row_query = mysqli_fetch_assoc($result_query)) {
extract($row_query);
if(!in_array($row_query["emp"],$chronic_patient_arr)){
array_push($chronic_patient_arr,$row_query["emp"]);
$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.ohc_type_id='" . $_SESSION['current_ohcttype'] . "' and a.appointment_date BETWEEN STR_TO_DATE('$from_date1','%Y-%m-%d') and STR_TO_DATE('$from_date2','%Y-%m-%d') and emp_id='".$row_query["emp"]."' and chronic_day >0 order by a.appointment_date ASC";
$result = mysqli_query($conn, $sql);
while ($row1 = mysqli_fetch_assoc($result)) {
if(!in_array($row1['appointment_id'],$app_ids)){
array_push($app_ids,$row1['appointment_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 getCommaSeperatedValuesForInClause("select abnormality_name from abnormality", "abnormality_id", $row1['abnormalitys']);
?></td>
<td><?php echo $row1['chronic_day'];?></td>
<td><?php echo getCommaSeperatedValuesForInClause("select ailment_name from ailment ", "ailment_id", $row1['ailments_new']); ?>
</td>
<td><?php
echo $treatment_text = getTreatmentTextPdf($row1['appointment_id']);
?></td>
<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>
</tr>
<?php
$count++;
}
}
}
}
}
?>
</table>
</body>