Files
2026-06-09 08:41:31 +07:00

189 lines
6.6 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 IFNULL(qp.QR_PrintOutVerifyURL, '') AS verify_url
FROM one_lab.qr_printout qp
JOIN one_lab.t_orderheader_group_result r
ON r.T_OrderHeaderGroupResultT_OrderHeaderID = qp.QR_PrintOutT_OrderHeaderID
AND r.T_OrderHeaderGroupResultGroup_ResultID = qp.QR_PrintOutGroup_ResultID
AND r.T_OrderHeaderGroupResultT_TestID = qp.QR_PrintOutT_TestID
JOIN one_lab.t_orderheader_group_result_details d
ON d.T_OrderHeaderGroupResultDetailsT_OrderHeaderGroupResultID = r.T_OrderHeaderGroupResultID
WHERE d.T_OrderHeaderGroupResultDetailsT_OrderHeaderID = ?
AND d.T_OrderHeaderGroupResultDetailsIsActive = 'Y'
AND r.T_OrderHeaderGroupResultIsActive = 'Y'
AND qp.QR_PrintOutIsActive = 1
AND IFNULL(qp.QR_PrintOutVerifyURL, '') <> ''
ORDER BY qp.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;
}
$verifyUrl = $rs["data"]["verify_url"];
$img_qrcode = $this->post("http://localhost/charts/qrtext.php", $verifyUrl);
header("Content-type: image/png");
echo $img_qrcode;
exit;
}
public function v3_nonlab($resultEntryID)
{
$sql = " SELECT
IFNULL(qp.QR_PrintOutVerifyURL, '') AS verify_url
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;
}
$verifyUrl = $rs["data"]["verify_url"];
$img_qrcode = $this->post("http://localhost/charts/qrtext.php", $verifyUrl);
header("Content-type: image/png");
echo $img_qrcode;
exit;
}
}