126 lines
3.9 KiB
PHP
126 lines
3.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;
|
|
}
|
|
}
|