csrtechnew.ohctech.in/mobile_dis_report_excel.php
2025-04-14 13:28:09 +05:30

102 lines
4.3 KiB
PHP

<?php
header("Content-type:application/octet-stream");
header("Content-type: application/x-msdownload");
header("Content-Disposition: attachment; filename=Mobile Dispensary / Weekly Clinic Report.xls");
header("Pragma: no-cache");
header("Expires: 0");
error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED);
?>
<?php
include('includes/config/config.php');
include('includes/functions.php');
//include('pop_up_top.php');
$startDate = date('Y-m-d', strtotime($_POST['procurement_date1']));
$endDate = date('Y-m-d', strtotime($_POST['procurement_date2']));
$ohc = $_POST['pohcid'];
$type = $_POST['type'];
$result = mysqli_query($conn, "SELECT * FROM mobile_dispensary_data WHERE DATE(opd_date) BETWEEN '$startDate' AND '$endDate' AND ohc_type_id = '$ohc'");
function calculateAge($dob) {
$dob = new DateTime($dob);
$today = new DateTime();
return $today->diff($dob)->y;
}
function getValue($id, $key) {
global $conn;
$id = mysqli_real_escape_string($conn, $id);
$key = mysqli_real_escape_string($conn, $key);
$sql = "SELECT checkup_form_value FROM beneficiary_opd_form_key_value WHERE bene_detail_id = '$id' AND bene_form_key = '$key'";
$result = mysqli_query($conn, $sql);
return ($result && $row = mysqli_fetch_assoc($result)) ? $row['checkup_form_value'] : '';
}
?>
<body>
<table width="100%">
<tr>
<td colspan="2" style="text-align: center; font-size: 15px;"><strong>Mobile Dispensary / Weekly Clinic Report</strong></td>
</tr>
<tr>
<td style="font-size: 12px;"><strong>From: <?php echo date("d-M-Y", strtotime($startDate)); ?> To <?php echo date("d-M-Y", strtotime($endDate)); ?></strong></td>
<td style="text-align: right; font-size: 12px;">
<strong>Location: <?= htmlspecialchars(getFieldFromTable('ohc_type_name', 'ohc_type', 'ohc_type_id', $ohc)) ?></strong>
</td>
</tr>
</table>
<div class="table-container">
<table border="1" width="100%" cellspacing="0" class="table-fixed">
<tr>
<th>Sr.</th>
<th>Date</th>
<th>Name Of Site</th>
<th>Case No</th>
<th>Beneficiary Name</th>
<th>Mobile No</th>
<th>Age</th>
<th>Gender</th>
<th>Category</th>
<th>Diagnosis</th>
<?php
$tests_head = ['Sub Category', 'Medicines', 'BP', 'Sugar', 'HB', 'Pulse', 'Temp', 'Weight', 'Lab', 'Refer Note'];
$tests_date = ['sub_cat', 'Medicines', 'BP', 'Sugar', 'HB', 'Pulse', 'Temp', 'Weight', 'Lab', 'refer_note'];
foreach ($tests_head as $test) { echo "<th>$test</th>"; }
?>
</tr>
<?php $count = 1; while ($row1 = $result->fetch_assoc()) { ?>
<tr>
<td><?php echo $count; ?></td>
<td><?php echo date("d-m-Y", strtotime($row1['opd_date'])); ?></td>
<td><?php echo $row1['name_of_site']; ?></td>
<td><?php echo $row1['case_no']; ?></td>
<td><?php echo getFieldFromTable('patient_name', 'patient_master', 'id', $row1['beneficiary']); ?></td>
<td><?php echo getFieldFromTable('aadhar_phone', 'patient_master', 'id', $row1['beneficiary']); ?></td>
<td><?php echo calculateAge(getFieldFromTable('dob', 'patient_master', 'id', $row1['beneficiary'])); ?></td>
<td><?php echo getFieldFromTable('gender', 'patient_master', 'id', $row1['beneficiary']); ?></td>
<td><?php echo getFieldFromTable('disease_cat_name', 'disease_category', 'disease_cat_id', $row1['category']); ?></td>
<td><?php echo getFieldFromTable('ailment_name', 'ailment', 'ailment_id', $row1['diagnosis']); ?></td>
<?php
$testCount = 0;
foreach ($tests_date as $test) {
$value = getValue($row1['id'], $test);
echo "<td>" . ($value ?: ' ') . "</td>";
if ($value) { $testCount++; }
}
?>
</tr>
<?php $count++; } ?>
</table>
</body>