Files
BE_IBL/application/controllers/chart/The_qr.php
2026-05-21 10:15:04 +07:00

180 lines
5.9 KiB
PHP

<?php
class The_qr extends MY_Controller
{
public function __construct()
{
parent::__construct();
}
public function get_one_row($sql, $param = false)
{
if ($param) {
$qry = $this->db->query($sql, $param);
} else {
$qry = $this->db->query($sql);
}
if (!$qry) {
return array("status" => -1);
}
$rows = $qry->result_array();
if (count($rows) == 0) {
return array("status" => 0);
}
return array("status" => 1, "data" => $rows[0]);
}
public function get_rows($sql, $param = false)
{
if ($param) {
$qry = $this->db->query($sql, $param);
} else {
$qry = $this->db->query($sql);
}
if (!$qry) {
return array("status" => -1);
}
$rows = $qry->result_array();
if (count($rows) == 0) {
return array("status" => 0);
}
return array("status" => 1, "data" => $rows);
}
public function v1($orderHeaderID, $date = "")
{
$sql = "call sp_rpt_t_hasil2(?,'admin')";
$rs = $this->get_rows($sql, array($orderHeaderID));
$this->clean_mysqli_connection($this->db->conn_id);
if ($rs["status"] == -1) {
echo "Error : sp_rpt | " . $this->db->error()["message"];
exit;
}
if ($rs["status"] == 0) {
echo "Error : No Order found.";
exit;
}
$rows = $rs["data"];
$r = $rows[0];
$msg = <<<EOF
{$r['T_OrderHeaderLabNumber']}
{$r['M_PatientName']}
EOF;
$msg = trim($msg);
$msg .= "\n";
foreach ($rows as $r) {
$msg .= $r["T_TestNameAA"] . " : " . $r["T_OrderDetailResult"] . "\n";
}
$img_qrcode = $this->post("http://localhost/charts/qrtext.php", $msg);
header("Content-type: image/png");
echo $img_qrcode;
exit;
}
public function post($url, $data)
{
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt(
$ch,
CURLOPT_HTTPHEADER,
array(
'Content-Type: application/text',
'Content-Length: ' . strlen($data)
)
);
$result = curl_exec($ch);
if (curl_error($ch) != "") {
return "ERROR Accessing QrCode\n";
}
return $result;
}
public function v2($orderHeaderID)
{
$this->load->library("Jwt");
$sql = "call sp_rpt_t_hasil2(?,'admin')";
$rs = $this->get_rows($sql, array($orderHeaderID));
$this->clean_mysqli_connection($this->db->conn_id);
if ($rs["status"] == -1) {
echo "Error : sp_rpt | " . $this->db->error()["message"];
exit;
}
if ($rs["status"] == 0) {
echo "Error : No Order found.";
exit;
}
$rows = $rs["data"];
$r = $rows[0];
$header = array(
"nolab" => $r['T_OrderHeaderLabNumber'],
"nama" => $r['M_PatientName'],
"sampling" => $r['T_OrderSampleSamplingDate'] . " " . $r['T_OrderSampleSamplingTime'],
"umur" => $r["Umur"]
);
$detail = array();
foreach ($rows as $r) {
$detail[] = array("px" => $r["T_TestNameAA"], "result" => $r["T_OrderDetailResult"]);
}
$secretToken = "--!!Super!!Suket#@!1231456";
$j_result = json_encode(array("header" => $header, "detail" => $detail));
$jwtToken = JWT::encode($j_result, $secretToken);
$url = "https://result.pramita.co.id/one-api/verify/do/$jwtToken";
$img_qrcode = $this->post("http://localhost/charts/qrtext.php", $url);
header("Content-type: image/png");
echo $img_qrcode;
exit;
}
public function v3($orderHeaderID)
{
$sql = "SELECT QR_PrintOutReportURL
FROM qr_printout
WHERE QR_PrintOutT_OrderHeaderID = ?
AND QR_PrintOutIsActive = 1
ORDER BY QR_PrintOutID DESC
LIMIT 1";
$rs = $this->get_one_row($sql, array($orderHeaderID));
if ($rs["status"] == -1) {
echo "Error : qr_printout | " . $this->db->error()["message"];
exit;
}
if ($rs["status"] == 0) {
echo "Error : No QR Printout found.";
exit;
}
$reportUrl = $rs["data"]["QR_PrintOutReportURL"];
$img_qrcode = $this->post("http://localhost/charts/qrtext.php", $reportUrl);
header("Content-type: image/png");
echo $img_qrcode;
exit;
}
public function v3_nonlab($resultEntryID)
{
$sql = " SELECT
qp.QR_PrintOutReportURL
FROM one_lab.so_resultentry se
JOIN one_lab.t_orderheader oh
ON oh.T_OrderHeaderID = se.SO_ResultEntryT_OrderHeaderID
AND oh.T_OrderHeaderIsActive = 'Y'
JOIN one_lab.qr_printout qp
ON qp.QR_PrintOutT_OrderHeaderID = oh.T_OrderHeaderID
AND qp.QR_PrintOutIsActive = 1
WHERE se.SO_ResultEntryID = ?
ORDER BY qp.QR_PrintOutID DESC
LIMIT 1";
$rs = $this->get_one_row($sql, array($resultEntryID));
if ($rs["status"] == -1) {
echo "Error : qr_printout | " . $this->db->error()["message"];
exit;
}
if ($rs["status"] == 0) {
echo "Error : No QR Printout found.";
exit;
}
$reportUrl = $rs["data"]["QR_PrintOutReportURL"];
$img_qrcode = $this->post("http://localhost/charts/qrtext.php", $reportUrl);
header("Content-type: image/png");
echo $img_qrcode;
exit;
}
}