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

161 lines
4.8 KiB
PHP

<?php
require 'bar_code_new/vendor/autoload.php';
use Picqer\Barcode\BarcodeGenerator;
use Picqer\Barcode\BarcodeGeneratorSVG;
$generator = new BarcodeGeneratorSVG();
include('includes/functions.php');
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$patient_id = $_POST['emp_id'];
$text2 = $_POST['checkup_id'];
$add_param_ids = getFieldFromTable('add_param_ids', 'checkup_form', 'checkup_id', $text2);
error_log("additional param ids " . $add_param_ids);
$add_param_names = "";
$sql = "select group_concat(distinct(parameter_name)) as parameter_name from checkup_parameter a left join device_param_map b on a.checkup_parameter_id = b.checkup_parameter_id where a.checkup_parameter_id in ($add_param_ids)";
error_log("query " . $sql);
$result = mysqli_query($conn, $sql);
$row = mysqli_fetch_assoc($result);
$add_param_names = $row['parameter_name'];
error_log("add param names " . $add_param_names);
$checkup_type_id = getFieldFromTable('checkup_type_id', 'checkup_form', 'checkup_id', $text2);
$isLabCheckup = getFieldFromTable('type_state', 'checkup_type', 'checkup_type_id', $checkup_type_id);
$checkup_name = getFieldFromTable('checkup_type_name', 'checkup_type', 'checkup_type_id', $checkup_type_id);
$text3 = $_POST['checkup_section_id'];
$second_id = implode(",", $text3);
error_log("all section ids before " . print_r($text3, true));
$values_array = explode(',', $second_id);
$isPresent = false;
if (in_array('add_section', $values_array)) {
$isPresent = true;
$values_array = array_diff($values_array, ['add_section']);
$tests = implode(',', $values_array);
} else {
$isPresent = false;
$tests = implode(',', $values_array);
}
$text3 = explode(",", $tests);
$second_part = 0;
if (is_array($text3)) {
sort($text3);
$second_part = $text3[0];
} else {
$second_part = $text3[0];
}
$barcodeCount = $_POST['barcode_count'];
error_log("all section ids " . print_r($text3, true) . " second part " . $second_part);
$second_names = getCommaSeperatedValuesForInClause("select section_name from checkup_form_section", "section_id", $tests);
?>
<style type="text/css">
* {
font-family: Arial, Helvetica, sans-serif !important;
}
.btn {
background-color: #4CAF50;
border-radius: 5%;
border: none;
color: white;
padding: 15px 32px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
margin: 4px 2px;
cursor: pointer;
}
@media print {
#printPageButton {
display: none;
}
}
</style>
<?php
for ($i = 0; $i < $barcodeCount; $i++) { ?>
<center>
<div style="margin-bottom:5px;">
<div>
<strong style="font-size:12px"><?php echo getFieldFromTable('patient_name', 'patient_master', 'id', $patient_id) . " (" . getFieldFromTable('emp_code', 'patient_master', 'id', $patient_id) . ")"; ?>
<span>
<?php
$dob = getTableFieldValue('patient_master', 'dob', 'id', $patient_id);
$from = new DateTime($dob);
$to = new DateTime('today');
echo $from->diff($to)->y;
?> Y/ &nbsp;<?php echo getTableFieldValue('patient_master', 'gender', 'id', $patient_id) ?></span>
</strong>
</div>
<div>
<strong>
<?php if ($isLabCheckup != 'Yes') { ?>
<span style="font-size:8px;">
<?php echo $checkup_name;
if (!empty($add_param_ids)) echo "(" . $add_param_names . ")"; ?>
</span>
<?php } else { ?>
<span style="font-size:8px;">
<?php echo $second_names;
if ($isPresent == true && !empty($second_names)) {
echo ",";
} ?>
</span>
<span style="font-size:8px;">
<?php if ($isPresent == true) {
echo "Additional/Other Tests ($add_param_names)";
} ?>
</span>
<?php
} ?>
</strong>
</div>
<button align="center" id="printPageButton" class="btn btn-success" onClick="window.print();">Print</button>
</div>
</center>
<center>
<div style="margin:5px">
<?php
// $dataToEmbed = $text2 . "" . $second_part;
// $uniqueNumber1 = uniqid();
$uniqueNumber1 = $text2;
$hexRepresentation1 = substr(dechex(crc32($uniqueNumber1)), 0, 5);
$dataToEmbed = $hexRepresentation1;
$barcode = $generator->getBarcode($dataToEmbed, $generator::TYPE_CODE_128, 1.7, 35);
?>
<img src="data:image/svg+xml;base64,<?php echo base64_encode($barcode); ?>" alt="Barcode">
</div>
<div style="margin-top: 5px;">
<span> <?= $dataToEmbed ?></span>
</div>
</center>
<?php
}
}
?>